-
Notifications
You must be signed in to change notification settings - Fork 193
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
Construct package dependencies using Go #3239
Conversation
🤖 Created branch: z_pr3239/skitt/pkgdeps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool! Minor question/docs feedback inline.
pkgdeps = $(shell find $$(go list -json $(1) | jq -r '.Imports[] | select(startswith("$(basepkg)")) | sub("$(basepkg)"; ".")') -name '*.go' -not -name '*_test.go') | ||
|
||
# natdiscovery.pb.go must be listed explicitly because it might not exist when Make evaluates pkgdeps | ||
bin/%/submariner-gateway: main.go $(call pkgdeps,.) pkg/natdiscovery/proto/natdiscovery.pb.go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be?
bin/%/submariner-gateway: main.go $(call pkgdeps,.) pkg/natdiscovery/proto/natdiscovery.pb.go | |
bin/%/submariner-gateway: main.go $(call pkgdeps,./pkg/gateway) pkg/natdiscovery/proto/natdiscovery.pb.go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The root of the dependency tree is the package containing the main file, so .
in this case. However while investigating this comment I realised that .Imports[]
only contains first-level imports, and the pkgdeps
macro really needs to look at .Deps[]
instead…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note too how the argument to pkgdeps
matches the argument to compile.sh
😉
For best results, Make should be told about all the files a given target depends on. For Go programs, this is the program's main Go file, and all non-test Go files in directories corresponding to packages the main Go file depends upon (including transitive dependencies). This adds a Make macro using go list to retrieve a package's dependencies, and constructs the corresponding list of files to use as target prerequisites. Signed-off-by: Stephen Kitt <[email protected]>
🤖 Closed branches: [z_pr3239/skitt/pkgdeps] |
For best results, Make should be told about all the files a given target depends on. For Go programs, this is the program's main Go file, and all non-test Go files in directories corresponding to packages the main Go file depends upon (including transitive dependencies).
This adds a Make macro using go list to retrieve a package's dependencies, and constructs the corresponding list of files to use as target prerequisites.