Repository navigation
refactor(compile): add trimpath to compile to remove local paths - #457
sheldonhull wants to merge 7 commits into
Conversation
- Include trimpath to ensure local filepaths from CI or developer don't get included in the produced artifact. - This was added in Go 1.13, so not sure if there is something special to handle adding this flag only if go version > 1.13.
|
I feel like the EDIT: Ah, I see, that is from #451 and just wasn't removed when making this PR. I'd suggest cleaning that up :D |
|
My mistake. I did a pr for that but did it on main branch in fork resulting
in my new branch including that. I’ll have to separate this out.
|
|
@jaredallard reverted back so pr changes are now just this. Not sure about compatibility for prior go versions to 1.13 like I mentioned but otherwise this will be good for privacy. Right now compiled binary includes full path. Cheers |
Co-authored-by: Horacio Duran <horacio.duran@gmail.com>
jaredallard
left a comment
There was a problem hiding this comment.
Looks reasonable to me :D
natefinch
left a comment
There was a problem hiding this comment.
I applied the trimpath change to current master (0953947) and checked compilation, cross-compilation, deterministic generated output, and cache behavior. The main concern is the compatibility impact of making trimpath unconditional, rather than the flag implementation itself. The inline comment describes a reproduced source-relative asset lookup regression. Go-version availability is no longer a concern with the current Go 1.18 minimum.
| gofiles[i] = filepath.Base(gofiles[i]) | ||
| } | ||
| buildArgs := []string{"build", "-o", compileTo} | ||
| buildArgs := []string{"build", "-o", compileTo, "-trimpath"} |
There was a problem hiding this comment.
Making -trimpath unconditional changes existing magefile behavior with no opt-out. Targets or helper libraries can use runtime.Caller to locate files relative to their source directory. I reproduced a program reading an adjacent asset via filepath.Join(filepath.Dir(file), "asset.txt"): the untrimmed build succeeds when run from another directory, while this build fails with open asset.txt: no such file or directory because the recorded source filename is no longer an absolute filesystem path. This is an inherent tradeoff of trimming paths, not a flag implementation bug. Could we make this opt-in, or provide an explicit opt-out and document the compatibility change, rather than changing all existing magefiles silently?
Go documentation on this: