-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[builder] Add --go-build-flags cli flag #12589
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
Conversation
This PR adds the `--go-build-flags` cli flag which will allow the user to pass additional flags for the `go build` command used to compile the collector.
@@ -113,6 +113,7 @@ var replaceModules = []string{ | |||
func newTestConfig(tb testing.TB) *Config { | |||
cfg, err := NewDefaultConfig() | |||
require.NoError(tb, err) | |||
cfg.Distribution.Name = "test_distribution" |
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.
Currently, the integration tests are running with a blank name field, which means the args end up being build -o 'ldflags=-s -w' ...
. So it's building a binary with the name 'ldflags=-s -w' instead of applying the ldflags. It didn't break any tests but is probably not intentional.
I had removed these because I didn't understand what they did at first, and forgot to add them back once I realized why they were there.
Codecov ReportAttention: Patch coverage is
❌ Your patch status has failed because the patch coverage (92.30%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #12589 +/- ##
==========================================
+ Coverage 92.18% 92.21% +0.02%
==========================================
Files 469 469
Lines 25394 25408 +14
==========================================
+ Hits 23409 23429 +20
+ Misses 1574 1570 -4
+ Partials 411 409 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
7525fca
to
9d8ea38
Compare
gcflags := "" | ||
executableName := c.Distribution.Name | ||
if runtime.GOOS == "windows" { | ||
executableName += ".exe" |
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.
Codecov seems to think these aren't covered, but I think they are covered by TestGetGoBuildArgs
.
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 reason you're getting this warning is because the body of the if statement isn't being run in codecov because it's not running in windows. I think this finding should probably be ignored because the test TestGetGoBuildArgs explicitly tests correctly on windows systems
gcflags := "" | ||
executableName := c.Distribution.Name | ||
if runtime.GOOS == "windows" { | ||
executableName += ".exe" |
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 reason you're getting this warning is because the body of the if statement isn't being run in codecov because it's not running in windows. I think this finding should probably be ignored because the test TestGetGoBuildArgs explicitly tests correctly on windows systems
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
@open-telemetry/collector-approvers I think this needs review |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
```console | ||
ocb --config=config.yaml --go-build-flags="-p 32 -buildvcs=false" | ||
``` | ||
If you provide any flags in `--go-build-flags` that are already configured by the builder automatically, **they will be overridden**: |
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.
Is this flexible enough to remove any option passed by default? For example, what if I don't want to pass -trimpath
? Could I do this by overriding it with --go-build-flags
?
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.
so we used to be able to pass the binary name on the command line as well as a lot of other flags
#11576
But that was deprecated in favor of manifest.yaml config values
I am thinking we should try to keep things in the config/manifest file to the maximum extent possible, and adding command line flags should be an exception that requires justification why it can't be in the yaml
|
||
You can provide additional flags to `go build` with the builder flag `--go-build-flags`: | ||
```console | ||
ocb --config=config.yaml --go-build-flags="-p 32 -buildvcs=false" |
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.
Any advantage of this being a CLI flag vs being in config.yaml
?
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.
So I would agree with that approach, except for that we already have --ldflags on the command line
#11996
My question is more if we take this approach (--go-build-flags) if we should deprecate the --ldflags option since --ldflags could be passed with this argument, right?
I would vote moving both this and ldflags to the manifest.yaml in general, though.
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.
I am not convinced that we should be adding more CLI arguments to ocb, especially when we have recently removed several recently (#11576)
I think there is an argument to be made that this and the ld/gc flags should be moved to a config.yaml section
|
||
You can provide additional flags to `go build` with the builder flag `--go-build-flags`: | ||
```console | ||
ocb --config=config.yaml --go-build-flags="-p 32 -buildvcs=false" |
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.
So I would agree with that approach, except for that we already have --ldflags on the command line
#11996
My question is more if we take this approach (--go-build-flags) if we should deprecate the --ldflags option since --ldflags could be passed with this argument, right?
I would vote moving both this and ldflags to the manifest.yaml in general, though.
```console | ||
ocb --config=config.yaml --go-build-flags="-p 32 -buildvcs=false" | ||
``` | ||
If you provide any flags in `--go-build-flags` that are already configured by the builder automatically, **they will be overridden**: |
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.
so we used to be able to pass the binary name on the command line as well as a lot of other flags
#11576
But that was deprecated in favor of manifest.yaml config values
I am thinking we should try to keep things in the config/manifest file to the maximum extent possible, and adding command line flags should be an exception that requires justification why it can't be in the yaml
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
I'm just going to close this I think. The reason I wanted to add this is similar to the reason I opened #11453, which is that there are ways I want to be able to build the Collector from #12591 which this PR addressed still should be fixed. |
Looks like this has been merged, could we have an update README or a instruction to build a exe/msi file will work on Windows? |
@DesAWSume This wasn't merged. The instructions that exist on the README work the same on Windows, the only difference is you will have to rename the resulting binary to have a |
Description
This PR adds the
--go-build-flags
cli flag which will allow the user to pass additional flags for thego build
command used to compile the collector.While doing the refactor, I also made it so that the default binary name now adds the
.exe
extension when building for Windows.Link to tracking issue
Fixes #12588
Fixes #12591
Testing
New unit tests were added to verify the build command args based on the config. A new CompileAndGenerate test case was added as well.
Documentation
A section has been added to the README.