aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormobiletc-prebuild <mobiletc-prebuild@google.com>2024-02-19 08:00:15 -0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-02-19 19:16:09 +0000
commit9bff7a7c2e13b3058618a55d1f5934a5206ffe9f (patch)
treee5b6f1cb5123db83219a50419e53aaf7b3bb3918
parentfd01d9a8a7ef178dfb17527f75e621f6d0b36bed (diff)
downloadtoolchain-utils-9bff7a7c2e13b3058618a55d1f5934a5206ffe9f.tar.gz
compiler_wrapper: automatic sync
This CL automatically brings toolchain-utils' compiler_wrapper/ directory in sync with chromiumos-overlay's. Please see go/crostc-repo/+/main:sync_compiler_wrapper_within_cros.sh for more info on this process. BUG=None TEST=None Change-Id: Ife77212a517d7ed5ce54415738e81374474a71eb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/5306972 Reviewed-by: Bob Haarman <inglorion@chromium.org> Commit-Queue: Bob Haarman <inglorion@chromium.org> Tested-by: mobiletc-prebuild Role Account <mobiletc-prebuild@google.com> Auto-Submit: mobiletc-prebuild Role Account <mobiletc-prebuild@google.com>
-rw-r--r--compiler_wrapper/compiler_wrapper_test.go2
-rw-r--r--compiler_wrapper/cros_hardened_config_test.go4
-rw-r--r--compiler_wrapper/disable_werror_flag.go53
-rw-r--r--compiler_wrapper/disable_werror_flag_test.go77
-rw-r--r--compiler_wrapper/testdata/cros_clang_host_golden/force_disable_werror.json6
-rw-r--r--compiler_wrapper/testdata/cros_hardened_golden/force_disable_werror.json6
-rw-r--r--compiler_wrapper/testdata/cros_hardened_llvmnext_golden/force_disable_werror.json6
-rw-r--r--compiler_wrapper/testdata/cros_hardened_noccache_golden/force_disable_werror.json6
-rw-r--r--compiler_wrapper/testdata/cros_nonhardened_golden/force_disable_werror.json6
9 files changed, 125 insertions, 41 deletions
diff --git a/compiler_wrapper/compiler_wrapper_test.go b/compiler_wrapper/compiler_wrapper_test.go
index a560c9ca..52356f83 100644
--- a/compiler_wrapper/compiler_wrapper_test.go
+++ b/compiler_wrapper/compiler_wrapper_test.go
@@ -136,7 +136,7 @@ func TestLogRusageAndForceDisableWError(t *testing.T) {
ctx.cmdMock = func(cmd *command, stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
switch ctx.cmdCount {
case 1:
- io.WriteString(stderr, "-Werror originalerror")
+ io.WriteString(stderr, arbitraryWerrorStderr)
return newExitCodeError(1)
case 2:
return nil
diff --git a/compiler_wrapper/cros_hardened_config_test.go b/compiler_wrapper/cros_hardened_config_test.go
index 80a261c8..361ba707 100644
--- a/compiler_wrapper/cros_hardened_config_test.go
+++ b/compiler_wrapper/cros_hardened_config_test.go
@@ -204,7 +204,7 @@ func createForceDisableWErrorGoldenInputs() goldenFile {
Env: []string{"FORCE_DISABLE_WERROR=1"},
Cmds: []commandResult{
{
- Stderr: "-Werror originalerror",
+ Stderr: arbitraryWerrorStderr,
ExitCode: 1,
},
okResult,
@@ -215,7 +215,7 @@ func createForceDisableWErrorGoldenInputs() goldenFile {
Env: []string{"FORCE_DISABLE_WERROR=1"},
Cmds: []commandResult{
{
- Stderr: "-Werror originalerror",
+ Stderr: arbitraryWerrorStderr,
ExitCode: 1,
},
errorResult,
diff --git a/compiler_wrapper/disable_werror_flag.go b/compiler_wrapper/disable_werror_flag.go
index 5382c1bd..b6dd844f 100644
--- a/compiler_wrapper/disable_werror_flag.go
+++ b/compiler_wrapper/disable_werror_flag.go
@@ -12,6 +12,7 @@ import (
"io/ioutil"
"os"
"path"
+ "regexp"
"strconv"
"strings"
)
@@ -85,18 +86,18 @@ func processForceDisableWerrorFlag(env env, cfg *config, builder *commandBuilder
return forceDisableWerrorConfig{enabled: envValue != ""}
}
-func disableWerrorFlags(originalArgs []string) []string {
- extraArgs := []string{"-Wno-error"}
+func disableWerrorFlags(originalArgs, extraFlags []string) []string {
+ allExtraFlags := append([]string{}, extraFlags...)
newArgs := make([]string, 0, len(originalArgs)+numWErrorEstimate)
for _, flag := range originalArgs {
if strings.HasPrefix(flag, "-Werror=") {
- extraArgs = append(extraArgs, strings.Replace(flag, "-Werror", "-Wno-error", 1))
+ allExtraFlags = append(allExtraFlags, strings.Replace(flag, "-Werror", "-Wno-error", 1))
}
if !strings.Contains(flag, "-warnings-as-errors") {
newArgs = append(newArgs, flag)
}
}
- return append(newArgs, extraArgs...)
+ return append(newArgs, allExtraFlags...)
}
func isLikelyAConfTest(cfg *config, cmd *command) bool {
@@ -114,6 +115,36 @@ func isLikelyAConfTest(cfg *config, cmd *command) bool {
return false
}
+func getWnoErrorFlags(stdout, stderr []byte) []string {
+ needWnoError := false
+ extraFlags := []string{}
+ for _, submatches := range regexp.MustCompile(`error:.* \[(-W[^\]]+)\]`).FindAllSubmatch(stderr, -1) {
+ bracketedMatch := submatches[1]
+
+ // Some warnings are promoted to errors by -Werror. These contain `-Werror` in the
+ // brackets specifying the warning name. A broad, follow-up `-Wno-error` should
+ // disable those.
+ //
+ // _Others_ are implicitly already errors, and will not be disabled by `-Wno-error`.
+ // These do not have `-Wno-error` in their brackets. These need to explicitly have
+ // `-Wno-error=${warning_name}`. See b/325463152 for an example.
+ if bytes.HasPrefix(bracketedMatch, []byte("-Werror,")) || bytes.HasSuffix(bracketedMatch, []byte(",-Werror")) {
+ needWnoError = true
+ } else {
+ // In this case, the entire bracketed match is the warning flag. Trim the
+ // first two chars off to account for the `-W` matched in the regex.
+ warningName := string(bracketedMatch[2:])
+ extraFlags = append(extraFlags, "-Wno-error="+warningName)
+ }
+ }
+ needWnoError = needWnoError || bytes.Contains(stdout, []byte("warnings-as-errors")) || bytes.Contains(stdout, []byte("clang-diagnostic-"))
+
+ if len(extraFlags) == 0 && !needWnoError {
+ return nil
+ }
+ return append(extraFlags, "-Wno-error")
+}
+
func doubleBuildWithWNoError(env env, cfg *config, originalCmd *command, werrorConfig forceDisableWerrorConfig) (exitCode int, err error) {
originalStdoutBuffer := &bytes.Buffer{}
originalStderrBuffer := &bytes.Buffer{}
@@ -140,13 +171,11 @@ func doubleBuildWithWNoError(env env, cfg *config, originalCmd *command, werrorC
// The only way we can do anything useful is if it looks like the failure
// was -Werror-related.
- originalStdoutBufferBytes := originalStdoutBuffer.Bytes()
- shouldRetry := originalExitCode != 0 &&
- !isLikelyAConfTest(cfg, originalCmd) &&
- (bytes.Contains(originalStderrBuffer.Bytes(), []byte("-Werror")) ||
- bytes.Contains(originalStdoutBufferBytes, []byte("warnings-as-errors")) ||
- bytes.Contains(originalStdoutBufferBytes, []byte("clang-diagnostic-")))
- if !shouldRetry {
+ retryWithExtraFlags := []string{}
+ if originalExitCode != 0 && !isLikelyAConfTest(cfg, originalCmd) {
+ retryWithExtraFlags = getWnoErrorFlags(originalStdoutBuffer.Bytes(), originalStderrBuffer.Bytes())
+ }
+ if len(retryWithExtraFlags) == 0 {
if err := commitOriginalRusage(originalExitCode); err != nil {
return 0, fmt.Errorf("commiting rusage: %v", err)
}
@@ -159,7 +188,7 @@ func doubleBuildWithWNoError(env env, cfg *config, originalCmd *command, werrorC
retryStderrBuffer := &bytes.Buffer{}
retryCommand := &command{
Path: originalCmd.Path,
- Args: disableWerrorFlags(originalCmd.Args),
+ Args: disableWerrorFlags(originalCmd.Args, retryWithExtraFlags),
EnvUpdates: originalCmd.EnvUpdates,
}
diff --git a/compiler_wrapper/disable_werror_flag_test.go b/compiler_wrapper/disable_werror_flag_test.go
index 008c46ea..639d404a 100644
--- a/compiler_wrapper/disable_werror_flag_test.go
+++ b/compiler_wrapper/disable_werror_flag_test.go
@@ -14,10 +14,13 @@ import (
"path"
"path/filepath"
"reflect"
+ "regexp"
"strings"
"testing"
)
+const arbitraryWerrorStderr = "error: foo [-Werror,-Wfoo]"
+
func TestOmitDoubleBuildForSuccessfulCall(t *testing.T) {
withForceDisableWErrorTestContext(t, func(ctx *testContext) {
ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(clangX86_64, mainCc)))
@@ -53,9 +56,39 @@ func TestDoubleBuildWithWNoErrorFlag(t *testing.T) {
if err := verifyArgCount(cmd, 0, "-Wno-error"); err != nil {
return err
}
- fmt.Fprint(stderr, "-Werror originalerror")
+ fmt.Fprint(stderr, arbitraryWerrorStderr)
+ return newExitCodeError(1)
+ case 2:
+ if err := verifyArgCount(cmd, 1, "-Wno-error"); err != nil {
+ return err
+ }
+ return nil
+ default:
+ t.Fatalf("unexpected command: %#v", cmd)
+ return nil
+ }
+ }
+ ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(clangX86_64, mainCc)))
+ if ctx.cmdCount != 2 {
+ t.Errorf("expected 2 calls. Got: %d", ctx.cmdCount)
+ }
+ })
+}
+
+func TestDoubleBuildUsesSpecificWnoErrorFlagsForWarningsThatDefaultToErrors(t *testing.T) {
+ withForceDisableWErrorTestContext(t, func(ctx *testContext) {
+ ctx.cmdMock = func(cmd *command, stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
+ switch ctx.cmdCount {
+ case 1:
+ if err := verifyArgCount(cmd, 0, "-Wno-error"); err != nil {
+ return err
+ }
+ fmt.Fprint(stderr, "error: foo [-Wfoo]")
return newExitCodeError(1)
case 2:
+ if err := verifyArgCount(cmd, 1, "-Wno-error=foo"); err != nil {
+ return err
+ }
if err := verifyArgCount(cmd, 1, "-Wno-error"); err != nil {
return err
}
@@ -72,6 +105,28 @@ func TestDoubleBuildWithWNoErrorFlag(t *testing.T) {
})
}
+func TestDoubleBuildDoesntRecompileIfNoObviousWerrorsExist(t *testing.T) {
+ withForceDisableWErrorTestContext(t, func(ctx *testContext) {
+ ctx.cmdMock = func(cmd *command, stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
+ if ctx.cmdCount != 1 {
+ t.Fatalf("unexpected command: %#v", cmd)
+ }
+ if err := verifyArgCount(cmd, 0, "-Wno-error"); err != nil {
+ return err
+ }
+ fmt.Fprint(stderr, "error: foo bar baz\nwarning: foo [-Wfoo]")
+ return newExitCodeError(1)
+ }
+ exitCode := callCompiler(ctx, ctx.cfg, ctx.newCommand(clangX86_64, mainCc))
+ if exitCode != 1 {
+ t.Errorf("got exit code %d; want 1", exitCode)
+ }
+ if ctx.cmdCount != 1 {
+ t.Errorf("expected 1 call. Got: %d", ctx.cmdCount)
+ }
+ })
+}
+
func TestKnownConfigureFileParsing(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
for _, f := range []string{"conftest.c", "conftest.cpp", "/dev/null"} {
@@ -90,7 +145,7 @@ func TestDoubleBuildWithKnownConfigureFile(t *testing.T) {
if err := verifyArgCount(cmd, 0, "-Wno-error"); err != nil {
return err
}
- fmt.Fprint(stderr, "-Werror originalerror")
+ fmt.Fprint(stderr, arbitraryWerrorStderr)
return newExitCodeError(1)
default:
t.Fatalf("unexpected command: %#v", cmd)
@@ -116,7 +171,7 @@ func TestDoubleBuildWithWNoErrorAndCCache(t *testing.T) {
if err := verifyPath(cmd, "ccache"); err != nil {
return err
}
- fmt.Fprint(stderr, "-Werror originalerror")
+ fmt.Fprint(stderr, arbitraryWerrorStderr)
return newExitCodeError(1)
case 2:
if err := verifyPath(cmd, "ccache"); err != nil {
@@ -141,7 +196,7 @@ func TestForwardStdoutAndStderrWhenDoubleBuildSucceeds(t *testing.T) {
switch ctx.cmdCount {
case 1:
fmt.Fprint(stdout, "originalmessage")
- fmt.Fprint(stderr, "-Werror originalerror")
+ fmt.Fprint(stderr, arbitraryWerrorStderr)
return newExitCodeError(1)
case 2:
fmt.Fprint(stdout, "retrymessage")
@@ -168,7 +223,7 @@ func TestForwardStdoutAndStderrWhenDoubleBuildFails(t *testing.T) {
switch ctx.cmdCount {
case 1:
fmt.Fprint(stdout, "originalmessage")
- fmt.Fprint(stderr, "-Werror originalerror")
+ fmt.Fprint(stderr, arbitraryWerrorStderr)
return newExitCodeError(3)
case 2:
fmt.Fprint(stdout, "retrymessage")
@@ -183,7 +238,7 @@ func TestForwardStdoutAndStderrWhenDoubleBuildFails(t *testing.T) {
if exitCode != 3 {
t.Errorf("unexpected exitcode. Got: %d", exitCode)
}
- if err := verifyNonInternalError(ctx.stderrString(), "-Werror originalerror"); err != nil {
+ if err := verifyNonInternalError(ctx.stderrString(), regexp.QuoteMeta(arbitraryWerrorStderr)); err != nil {
t.Error(err)
}
if !strings.Contains(ctx.stdoutString(), "originalmessage") {
@@ -205,7 +260,7 @@ func TestForwardStdinFromDoubleBuild(t *testing.T) {
switch ctx.cmdCount {
case 1:
- fmt.Fprint(stderr, "-Werror originalerror")
+ fmt.Fprint(stderr, arbitraryWerrorStderr)
return newExitCodeError(1)
case 2:
return nil
@@ -224,7 +279,7 @@ func TestForwardGeneralErrorWhenDoubleBuildFails(t *testing.T) {
ctx.cmdMock = func(cmd *command, stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
switch ctx.cmdCount {
case 1:
- fmt.Fprint(stderr, "-Werror originalerror")
+ fmt.Fprint(stderr, arbitraryWerrorStderr)
return newExitCodeError(3)
case 2:
return errors.New("someerror")
@@ -261,7 +316,7 @@ func TestLogWarningsWhenDoubleBuildSucceeds(t *testing.T) {
switch ctx.cmdCount {
case 1:
fmt.Fprint(stdout, "originalmessage")
- fmt.Fprint(stderr, "-Werror originalerror")
+ fmt.Fprint(stderr, arbitraryWerrorStderr)
return newExitCodeError(1)
case 2:
fmt.Fprint(stdout, "retrymessage")
@@ -299,7 +354,7 @@ func TestLogWarningsWhenDoubleBuildFails(t *testing.T) {
switch ctx.cmdCount {
case 1:
fmt.Fprint(stdout, "originalmessage")
- fmt.Fprint(stderr, "-Werror originalerror")
+ fmt.Fprint(stderr, arbitraryWerrorStderr)
return newExitCodeError(1)
case 2:
fmt.Fprint(stdout, "retrymessage")
@@ -362,7 +417,7 @@ func TestDoubleBuildWerrorChmodsThingsAppropriately(t *testing.T) {
if err := verifyArgCount(cmd, 0, "-Wno-error"); err != nil {
return err
}
- fmt.Fprint(stderr, "-Werror originalerror")
+ fmt.Fprint(stderr, arbitraryWerrorStderr)
return newExitCodeError(1)
case 2:
if err := verifyArgCount(cmd, 1, "-Wno-error"); err != nil {
diff --git a/compiler_wrapper/testdata/cros_clang_host_golden/force_disable_werror.json b/compiler_wrapper/testdata/cros_clang_host_golden/force_disable_werror.json
index d3c4459d..40049689 100644
--- a/compiler_wrapper/testdata/cros_clang_host_golden/force_disable_werror.json
+++ b/compiler_wrapper/testdata/cros_clang_host_golden/force_disable_werror.json
@@ -75,7 +75,7 @@
"path": "/tmp/stable/clang"
},
"exitcode": 1,
- "stderr": "-Werror originalerror"
+ "stderr": "error: foo [-Werror,-Wfoo]"
},
{
"cmd": {
@@ -154,7 +154,7 @@
"path": "/tmp/stable/clang"
},
"exitcode": 1,
- "stderr": "-Werror originalerror"
+ "stderr": "error: foo [-Werror,-Wfoo]"
},
{
"cmd": {
@@ -203,7 +203,7 @@
"path": "./x86_64-cros-linux-gnu-clang"
},
"exitcode": 1,
- "stderr": "-Werror originalerror"
+ "stderr": "error: foo [-Werror,-Wfoo]"
}
}
]
diff --git a/compiler_wrapper/testdata/cros_hardened_golden/force_disable_werror.json b/compiler_wrapper/testdata/cros_hardened_golden/force_disable_werror.json
index 86f8ec5c..ebff9f99 100644
--- a/compiler_wrapper/testdata/cros_hardened_golden/force_disable_werror.json
+++ b/compiler_wrapper/testdata/cros_hardened_golden/force_disable_werror.json
@@ -113,7 +113,7 @@
"path": "ccache"
},
"exitcode": 1,
- "stderr": "-Werror originalerror"
+ "stderr": "error: foo [-Werror,-Wfoo]"
},
{
"cmd": {
@@ -230,7 +230,7 @@
"path": "ccache"
},
"exitcode": 1,
- "stderr": "-Werror originalerror"
+ "stderr": "error: foo [-Werror,-Wfoo]"
},
{
"cmd": {
@@ -298,7 +298,7 @@
"path": "./x86_64-cros-linux-gnu-clang"
},
"exitcode": 1,
- "stderr": "-Werror originalerror"
+ "stderr": "error: foo [-Werror,-Wfoo]"
}
}
]
diff --git a/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/force_disable_werror.json b/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/force_disable_werror.json
index 86f8ec5c..ebff9f99 100644
--- a/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/force_disable_werror.json
+++ b/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/force_disable_werror.json
@@ -113,7 +113,7 @@
"path": "ccache"
},
"exitcode": 1,
- "stderr": "-Werror originalerror"
+ "stderr": "error: foo [-Werror,-Wfoo]"
},
{
"cmd": {
@@ -230,7 +230,7 @@
"path": "ccache"
},
"exitcode": 1,
- "stderr": "-Werror originalerror"
+ "stderr": "error: foo [-Werror,-Wfoo]"
},
{
"cmd": {
@@ -298,7 +298,7 @@
"path": "./x86_64-cros-linux-gnu-clang"
},
"exitcode": 1,
- "stderr": "-Werror originalerror"
+ "stderr": "error: foo [-Werror,-Wfoo]"
}
}
]
diff --git a/compiler_wrapper/testdata/cros_hardened_noccache_golden/force_disable_werror.json b/compiler_wrapper/testdata/cros_hardened_noccache_golden/force_disable_werror.json
index 030daf4a..77485f0f 100644
--- a/compiler_wrapper/testdata/cros_hardened_noccache_golden/force_disable_werror.json
+++ b/compiler_wrapper/testdata/cros_hardened_noccache_golden/force_disable_werror.json
@@ -101,7 +101,7 @@
"path": "../../usr/bin/clang"
},
"exitcode": 1,
- "stderr": "-Werror originalerror"
+ "stderr": "error: foo [-Werror,-Wfoo]"
},
{
"cmd": {
@@ -206,7 +206,7 @@
"path": "../../usr/bin/clang"
},
"exitcode": 1,
- "stderr": "-Werror originalerror"
+ "stderr": "error: foo [-Werror,-Wfoo]"
},
{
"cmd": {
@@ -268,7 +268,7 @@
"path": "./x86_64-cros-linux-gnu-clang"
},
"exitcode": 1,
- "stderr": "-Werror originalerror"
+ "stderr": "error: foo [-Werror,-Wfoo]"
}
}
]
diff --git a/compiler_wrapper/testdata/cros_nonhardened_golden/force_disable_werror.json b/compiler_wrapper/testdata/cros_nonhardened_golden/force_disable_werror.json
index 8a61f36a..0bc33451 100644
--- a/compiler_wrapper/testdata/cros_nonhardened_golden/force_disable_werror.json
+++ b/compiler_wrapper/testdata/cros_nonhardened_golden/force_disable_werror.json
@@ -99,7 +99,7 @@
"path": "ccache"
},
"exitcode": 1,
- "stderr": "-Werror originalerror"
+ "stderr": "error: foo [-Werror,-Wfoo]"
},
{
"cmd": {
@@ -202,7 +202,7 @@
"path": "ccache"
},
"exitcode": 1,
- "stderr": "-Werror originalerror"
+ "stderr": "error: foo [-Werror,-Wfoo]"
},
{
"cmd": {
@@ -263,7 +263,7 @@
"path": "./x86_64-cros-linux-gnu-clang"
},
"exitcode": 1,
- "stderr": "-Werror originalerror"
+ "stderr": "error: foo [-Werror,-Wfoo]"
}
}
]