Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor files name #1767

Merged
merged 7 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type config struct {
type bag map[string]struct{}

func main() {

app := &cli.App{
Name: "depgraph",
Usage: "generate a dot graph",
Expand Down Expand Up @@ -219,8 +218,6 @@ func getWriter(config config) (io.Writer, error) {
// folder
func walkFn(config config, links map[string]bag) filepath.WalkFunc {
return func(path string, f os.FileInfo, err error) error {
fset := token.NewFileSet()

if err != nil {
return xerrors.Errorf("got an error while walking: %v", err)
}
Expand All @@ -237,47 +234,52 @@ func walkFn(config config, links map[string]bag) filepath.WalkFunc {
return nil
}

astFile, err := parser.ParseFile(fset, path, nil, parser.ImportsOnly)
if err != nil {
return xerrors.Errorf("failed to parse file: %v", err)
}
return walkTroughImports(config, links, path)
}
}

path = filepath.Dir(path)
// This is the full package path. From "mino" we want
// "go.dedis.ch/dela/mino"
packagePath := config.Modname + path
func walkTroughImports(config config, links map[string]bag, path string) error {
fset := token.NewFileSet()
astFile, err := parser.ParseFile(fset, path, nil, parser.ImportsOnly)
if err != nil {
return xerrors.Errorf("failed to parse file: %v", err)
}

if !isIncluded(packagePath, config.Includes) ||
isExcluded(packagePath, config.Excludes) {
return nil
}
path = filepath.Dir(path)
// This is the full package path. From "mino" we want
// "go.dedis.ch/dela/mino"
packagePath := config.Modname + path

for _, s := range astFile.Imports {
// because an import path is always surrounded with "" we remove
// them
importPath := s.Path.Value[1 : len(s.Path.Value)-1]
if !isIncluded(packagePath, config.Includes) ||
isExcluded(packagePath, config.Excludes) {
return nil
}

if !isIncluded(importPath, config.Includes) ||
isExcluded(importPath, config.Excludes) {
for _, s := range astFile.Imports {
// because an import path is always surrounded with "" we remove
// them
importPath := s.Path.Value[1 : len(s.Path.Value)-1]

continue
}
if !isIncluded(importPath, config.Includes) ||
isExcluded(importPath, config.Excludes) {

// in the case the package imports a package from the same module,
// we want to keep only the "relative" name. From
// "go.dedis.ch/dela/mino/minogrpc" we want only "mino/minogrpc".
importPath = strings.TrimPrefix(importPath, config.Modname)
continue
}

if links[packagePath[len(config.Modname):]] == nil {
links[packagePath[len(config.Modname):]] = make(bag)
}
// in the case the package imports a package from the same module,
// we want to keep only the "relative" name. From
// "go.dedis.ch/dela/mino/minogrpc" we want only "mino/minogrpc".
importPath = strings.TrimPrefix(importPath, config.Modname)

// add the dependency to the bag
links[packagePath[len(config.Modname):]][importPath] = struct{}{}
if links[packagePath[len(config.Modname):]] == nil {
links[packagePath[len(config.Modname):]] = make(bag)
}

return nil
// add the dependency to the bag
links[packagePath[len(config.Modname):]][importPath] = struct{}{}
}

return nil
}

func displayGraph(out io.Writer, links map[string]bag, interfaces bag) {
Expand Down
File renamed without changes.
File renamed without changes.
70 changes: 0 additions & 70 deletions be1-go/network/socket/mod.go

This file was deleted.

Loading
Loading