Skip to content

Not possible to disable -trimpath flag #1524

@jmdeal

Description

@jmdeal

Currently, ko appends the -trimpath flag to the set of user-defined flags based on the state of the trimpath build option:

ko/pkg/build/gobuild.go

Lines 920 to 924 in 1e8fa79

if g.trimpath {
// The `-trimpath` flag removes file system paths from the resulting binary, to aid reproducibility.
// Ref: https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies
config.Flags = append(config.Flags, "-trimpath")
}

This change was made in #505, and appears to have had the unintended side-effect of preventing users from overriding this flag. Before this PR, this was achievable by providing a build override for that import path. Based on this comment chain, I believe the intention was to still allow users to overwrite this value by providing flag overrides (e.g. []), but this doesn't work today. Since the trimpath option isn't surfaced as a field in the ko config file or as a CLI flag, the flag is always appended.

I have a similar use-case to the original commenter here and don't want to strip out the paths for use when debugging. Ideally, we could surface the existing trimpath field as a CLI flag - this would allow me to achieve my goal by just adding the --disable-optimizations and --trimpaths=false flags when performing a debug build.

If there are alternative approaches available today that I missed, I'd love to hear them, but if not I'd be happy to contribute.

Note: it looks like -trimflags is still added when using --debug as well. This is less relevant for my use-case since I have a workflow that uses ephemeral debug containers in k8s to run delve, but does seem surprising.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions