Skip to content

Commit

Permalink
refactor: sort dependsOn
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <knqyf263@gmail.com>
  • Loading branch information
knqyf263 committed Nov 21, 2024
1 parent 4bfc5b6 commit 2a5e77b
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pkg/dependency/parser/golang/binary/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc
Relationship: ftypes.RelationshipUnknown,
})
}
sort.Sort(pkgs)

// There are times when gobinaries don't contain Main information.
// e.g. `Go` binaries (e.g. `go`, `gofmt`, etc.)
Expand All @@ -111,20 +110,23 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc
Version: version,
Relationship: ftypes.RelationshipRoot,
}

depIDs := lo.Map(pkgs, func(pkg ftypes.Package, _ int) string {
return pkg.ID
})
sort.Strings(depIDs)

deps = []ftypes.Dependency{
{
ID: root.ID,
// Consider all packages as dependencies of the main module.
DependsOn: lo.Map(pkgs, func(pkg ftypes.Package, _ int) string {
return pkg.ID
}),
ID: root.ID,
DependsOn: depIDs, // Consider all packages as dependencies of the main module.
},
}
// Add main module
pkgs = append(pkgs, root)
sort.Sort(pkgs)
}

sort.Sort(pkgs)
return pkgs, deps, nil
}

Expand Down

0 comments on commit 2a5e77b

Please sign in to comment.