-
-
Notifications
You must be signed in to change notification settings - Fork 636
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
[internal] Infer main
field for go_binary
#13117
Merged
Eric-Arellano
merged 3 commits into
pantsbuild:main
from
Eric-Arellano:go-binary-main-field
Oct 5, 2021
Merged
[internal] Infer main
field for go_binary
#13117
Eric-Arellano
merged 3 commits into
pantsbuild:main
from
Eric-Arellano:go-binary-main-field
Oct 5, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This comment has been minimized.
This comment has been minimized.
Eric-Arellano
force-pushed
the
go-binary-main-field
branch
2 times, most recently
from
October 5, 2021 14:55
20b796e
to
5706079
Compare
# Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels] # Conflicts: # testprojects/src/go/pants_test/BUILD
Eric-Arellano
force-pushed
the
go-binary-main-field
branch
from
October 5, 2021 14:56
5706079
to
e8aa5d7
Compare
tdyas
approved these changes
Oct 5, 2021
# Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
Eric-Arellano
added a commit
that referenced
this pull request
Oct 6, 2021
Closes #13049. This greatly reduces boilerplate and also allows us to make some fields required like `import_path` and `subpath`, so that we don't have to calculate those in consuming rules like `build_go_pkg.py`. ## The address format The generated address looks like `project#./dir`. @tdyas offered that this is intuitive for Go developers because they have to say `go build ./dir` already with the leading `./`. This solves how to represent when the `_go_internal_package` is in the same dir as the `go_mod`: `project#./`. This also makes very clear the difference from external packages like `project#rsc.io/quote` vs. internal packages like `project#./dir`. ## Improves dependency inference Now that the `import_path` field is required for both `_go_internal_package` and `_go_external_package`, we can create a global mapping of `import_path -> pkg_target`. This is necessary for #13114. This also improves performance. We don't need to call `ResolvedGoPackage` on all the candidate targets a package might depend on to calculate their import paths. We do still need it when resolving the deps of a particular `_go_internal_package`, but we can be lazier when we call that codepath in not evaluating all candidate targets. ### `dependencies` benchmark As expected, there is no difference because we are finding the dependencies of everything, so we still have to call `ResolvedGoPackage`. The perf gains are only in things sometimes being less eager, which isn't the case here. Before: ``` ❯ hyperfine -r 5 './pants_from_sources --no-pantsd --no-process-execution-local-cache dependencies ::' Time (mean ± σ): 26.501 s ± 1.537 s [User: 29.554 s, System: 24.115 s] Range (min … max): 24.928 s … 28.763 s 5 runs ``` After: ``` ❯ hyperfine -r 5 './pants_from_sources --no-pantsd --no-process-execution-local-cache dependencies ::' Time (mean ± σ): 26.359 s ± 0.526 s [User: 29.600 s, System: 23.769 s] Range (min … max): 25.625 s … 26.993 s 5 runs ``` ### `package` benchmark Before: ``` ❯ hyperfine -r 5 './pants_from_sources --no-pantsd --no-process-execution-local-cache package ::' Time (mean ± σ): 33.777 s ± 0.248 s [User: 39.221 s, System: 39.389 s] Range (min … max): 33.517 s … 34.062 s 5 runs ``` After: ``` ❯ hyperfine -r 5 './pants_from_sources --no-pantsd --no-process-execution-local-cache package ::' Benchmark #1: ./pants_from_sources --no-pantsd --no-process-execution-local-cache package :: Time (mean ± σ): 31.049 s ± 0.702 s [User: 40.606 s, System: 40.537 s] Range (min … max): 30.512 s … 32.273 s 5 runs ``` ## TODO: fix `go_binary` inference of `main` field #13117 added inference of the `main` field for `go_binary`, that it defaults to the `go_package` defined in that directory. But target generation no longer generates targets actually in each directory. All generated targets are "located" in the BUILD file of the `go_mod`, i.e. their `spec_path` is set to that. So it no longer looks to `AddressSpecs` like there are any targets in each subdirectory, and there are >1 `_go_internal_package` targets in the `go_mod` dir. Instead, we should use the `subpath` field to determine what directory the targets correspond to. [ci skip-rust] [ci skip-build-wheels]
Merged
stuhood
added a commit
to stuhood/pants
that referenced
this pull request
Apr 6, 2022
…build#14980 and pantsbuild#13117. [ci skip-rust] [ci skip-build-wheels]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #13115.
For now, we allow you to still explicitly set the field, which gives an escape valve if >1
go_package
exist for the same directory.