From 9565d990f4e2630dbf37c636299b9ddbd58b4f6b Mon Sep 17 00:00:00 2001 From: Xiangdong Ji Date: Thu, 2 Feb 2023 14:20:16 +0800 Subject: [PATCH] cmd/go: honor user-specified -c=N User-specified '-c=N' options should take precedence over the default one generated by cmd/go. Change-Id: I9021440b4a4286f8d6f92acb745a777cf234a82b Reviewed-on: https://go-review.googlesource.com/c/go/+/465095 Reviewed-by: Bryan Mills Reviewed-by: David Chase Auto-Submit: Bryan Mills Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot --- src/cmd/go/internal/work/gc.go | 2 +- src/cmd/go/testdata/script/build_gcflags_order.txt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/internal/work/gc.go b/src/cmd/go/internal/work/gc.go index ded751f4d4..1193a5bbfd 100644 --- a/src/cmd/go/internal/work/gc.go +++ b/src/cmd/go/internal/work/gc.go @@ -169,7 +169,7 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg, embedcfg } // Add -c=N to use concurrent backend compilation, if possible. if c := gcBackendConcurrency(gcflags); c > 1 { - gcflags = append(gcflags, fmt.Sprintf("-c=%d", c)) + defaultGcFlags = append(defaultGcFlags, fmt.Sprintf("-c=%d", c)) } args := []any{cfg.BuildToolexec, base.Tool("compile"), "-o", ofile, "-trimpath", a.trimpath(), defaultGcFlags, gcflags} diff --git a/src/cmd/go/testdata/script/build_gcflags_order.txt b/src/cmd/go/testdata/script/build_gcflags_order.txt index 0ffe1570f6..3725c89eb3 100644 --- a/src/cmd/go/testdata/script/build_gcflags_order.txt +++ b/src/cmd/go/testdata/script/build_gcflags_order.txt @@ -4,6 +4,8 @@ cd m go build -n -gcflags=-lang=go1.17 stderr ' -lang=go1.16.* -lang=go1.17' +! go build -gcflags='-c 0' +stderr 'compile: -c must be at least 1, got 0' -- m/go.mod -- module example.com -- 2.50.0