Conversation
Enables programmatic control of whether `ko` adds the `-trimpath` flag to `go build`. The `-trimpath` flag removes file system paths from the resulting binary. `ko` adds `-trimpath` by default as it aids in achieving reproducible builds. However, removing file system paths makes interactive debugging more challenging, in particular in mapping source file locations in the IDE to debug information in the binary. If you set `Trimpath` to `false` to enable interactive debugging, you probably also want to set `DisableOptimizations` to `true` to disable compiler optimizations and inlining. Reference for `-trimpath`: https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies Resolves: #500 Related: #71, #78, GoogleContainerTools/skaffold#6843
Codecov Report
@@ Coverage Diff @@
## main #505 +/- ##
==========================================
+ Coverage 50.15% 51.12% +0.97%
==========================================
Files 41 41
Lines 1944 1950 +6
==========================================
+ Hits 975 997 +22
+ Misses 809 794 -15
+ Partials 160 159 -1
Continue to review full report at Codecov.
|
| if !ok { | ||
| // Apply default build flags in case none were supplied | ||
| config := g.buildConfigs[ip] | ||
| if g.trimpath { |
There was a problem hiding this comment.
I am trying to disable -trimpath for local debugging. After reading #500 (comment) I hoped that setting flags: [] should be sufficient to do so.
Maybe, we could change the check in this line in the following way:
if g.trimpath && config.Flags == nil {Or is there another way to make a build without trimpath that I am currently missing?
There was a problem hiding this comment.
flags: [] should be sufficient I believe, or if not then you could set some other flag, such as ["-v"].
Did you verify that ko picked up the build config correctly from .ko.yaml?
There was a problem hiding this comment.
Yes, I verified that the .ko.yaml is used by adding an invalid flag that made the build fail. I also did a local build of ko with a print statement and the trimpath flag was always appended no matter if other flags were set or not.
Enables programmatic control of adding the
-trimpathflag togo build.The
-trimpathflag removes file system paths from the resulting binary.koadds-trimpathby default as it aids in achieving reproducible builds.However, removing file system paths makes interactive debugging more challenging, in particular in mapping source file locations in the IDE to debug information in the binary.
If you set
Trimpathtofalseto enable interactive debugging, you likely also want to setDisableOptimizationstotrueto disable compiler optimizations and inlining.Reference for
-trimpath: https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependenciesResolves: #500
Related: #71, #78, GoogleContainerTools/skaffold#6843