build: isolate invocation configuration and execution - #2212
Conversation
There was a problem hiding this comment.
Review summary
Small, well-scoped foundational package (internal/processenv) capturing per-request process inputs (working dir + environment) with Abs/Get/Lookup helpers. The code is clean, go vet and go test ./internal/processenv/ pass, and the tricky clone/snapshot isolation is correctly implemented and tested. No blocking issues; two low-severity notes inline.
I verified the doc's Capture(dir, []string{}) promise empirically: slices.Clone([]string{}) returns a non-nil empty slice, so an explicitly-empty captured environment is correctly isolated and Lookup returns ("", false) without leaking the ambient environment. The doc/code match here — no change needed.
Minor (not blocking):
Lookup(processenv.go:73) does a linear reverse scan per call. Fine for typical low-frequency use; if a future hot-path caller resolves many keys against a largeEnv, consider building a one-timemap(iterating forward to preserve last-wins).processenv_test.go:1: the//go:build !llgotag is unexplained — a one-line comment on why the tests are excluded under thellgotoolchain would help maintainers.
|
|
||
| // Abs resolves path relative to the context working directory. | ||
| func (c Context) Abs(path string) string { | ||
| if path == "" || filepath.IsAbs(path) { |
There was a problem hiding this comment.
Abs returns absolute inputs verbatim while relative inputs go through filepath.Join, which cleans them. So Abs("a/b/../c") is normalized but Abs("/a/b/../c") is not — inconsistent output for callers that expect a canonical path. If verbatim pass-through of absolute paths is intended, a one-line doc note would prevent surprise; otherwise consider filepath.Clean on the absolute branch.
|
|
||
| // Get returns the last value for key in the context environment. | ||
| func (c Context) Get(key string) string { | ||
| if c.Env == nil { |
There was a problem hiding this comment.
A zero Context{} (nil Env) transparently reads the live process environment via os.Getenv/os.LookupEnv, whereas a Captured context with an empty environment is isolated. So a zero-value Context is not an empty/isolated context — a subtle footgun once this package has real consumers. Worth documenting on the Context type that a nil Env means "defer to the live process environment."
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
d425493 to
03fa0a2
Compare
|
I reworked this prerequisite after narrowing the concurrency contract. The previous The new head addresses the actual production side effect directly: LLVM tools are bound to |
a11308a to
287cbcc
Compare
287cbcc to
0f5fc99
Compare
Summary
PATHonce, before builds start, from the existingllvm.New("").BinDir()discoveryConfig, build context, or backend workersInvocationas the explicitBuildinput and keepDo(args, conf)as its compatibility wrapperConfigbefore resolving defaults and compatibility settingscommandEnvvalue to only child-processDirandEnv; cgo, pkg-config, llc, run, and emulator leaf helpers no longer receive the full compiler context only for those valuesLLVM process model
LLVM_CONFIGis a process-startup choice. The shippedcmd/llgoentry point and repository tools that invokebuild.Docallllvm.SetupPath()before starting builds. It prepends the selected bin directory using the platform path-list separator, ignores an empty directory, and does not duplicate an existing entry.After
Buildstarts, LLVM is not reselected or passed through build state. Existing tool usage remains ordinary:clangllcexec.LookPath("llvm-ar")llvm.Envtool helpers retain their original behaviorCross-compilation compilers and explicit overrides such as
LLGO_ARretain their existing precedence.Invocation isolation
Invocationcontains onlyArgs,Config, andDir; it does not expose environment overridesConfigslices/maps are cloned before defaults are resolvedBuildstartspackages.Loadand child commands receive explicitDir/EnvNewDefaultConfno longer createsGOBIN; the linker creates the selected output directory on demandbuild.Do,Build, or package workers mutates processPATHcommandEnvis deliberately limited to cwd/env and is not an extension point for compiler stateReview size
mainataa0bbe44Tests
go test ./internal/build ./cmd/llgo ./xtool/env/llvm -count=1-racegit diff --check