-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
add ldflags builder cmd option #6946
Conversation
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 code looks alright, but this PR is missing the tests.
Codecov ReportBase: 90.35% // Head: 90.35% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #6946 +/- ##
=======================================
Coverage 90.35% 90.35%
=======================================
Files 243 243
Lines 14567 14570 +3
=======================================
+ Hits 13162 13165 +3
Misses 1136 1136
Partials 269 269
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
3f43f3e
to
562c1ad
Compare
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.
Thanks for this change, just one question
SkipGetModules bool `mapstructure:"-"` | ||
SkipCompilation bool `mapstructure:"-"` | ||
SkipGetModules bool `mapstructure:"-"` | ||
LDFlags string `mapstructure:"-"` |
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.
How do you expect this to be configured?
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.
As a command line argument. Ex:
builder --ldflags='-X "<pkg>.gitVersion=d49d45c039a2a89a26526afa3658de6429099bef" -X "<pkg>.gitTag=local-testing" -X "<pkg>.whoami=kristina.pathak"'
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.
where is the "--ldflags" flag defined?
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.
SkipGetModules bool `mapstructure:"-"` | ||
SkipCompilation bool `mapstructure:"-"` | ||
SkipGetModules bool `mapstructure:"-"` | ||
LDFlags string `mapstructure:"-"` |
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.
where is the "--ldflags" flag defined?
SkipGetModules bool `mapstructure:"-"` | ||
SkipCompilation bool `mapstructure:"-"` | ||
SkipGetModules bool `mapstructure:"-"` | ||
LDFlags string `mapstructure:"-"` |
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.
This should be part of "Distribution" and we should not have a flag but be part of the yaml config.
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.
Why?
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.
Because there we have other flags, and because we want to go with "configuration as a code". Which means to pass the configuration to the builder as a config file merged into the code repository.
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.
In my example here, you can see that ldflags include git information. The moment these values are committed and pushed, they are incorrect since it will be a new commit hash with new git tags (our tags include datetimes). If ldflags become a configuration value, my automation would have to add it as part of the build process, and the value won't be able to be committed with the rest of the configuration file.
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.
@bogdandrutu, would you be open to moving this value under "Distribution" in the yaml config and allowing it to be set through a flag?
assert.NoError(t, cfg.SetGoPath()) | ||
require.NoError(t, GenerateAndCompile(cfg)) | ||
|
||
// Sleep for 1 second to make sure all processes using the files are completed |
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.
What do you mean?
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.
This logic was taken from pre-existing main tests:
https://github.com/open-telemetry/opentelemetry-collector/blame/80cabdd33c50eaf386293f90fd8ac57cb3a10dc9/cmd/builder/internal/builder/main_test.go#L106
I see that now they have been refactored so will rebase and include my test case, but this logic still exists in those tests.
d49d45c
to
2b9ad71
Compare
|
I just triggered the failed test again. |
Description: Adding a feature -
ldflags
option in builder cmd, to be passed togo build
Link to tracking Issue: #6940
Testing: manually built a collector with custom components who have build variables. Passing
ldflags
set the values of these variables.Documentation: I added a description for the
--help
command, but I can add a small explanation to the README if people would prefer.