diff options
author | George Burgess IV <gbiv@google.com> | 2019-09-09 11:12:50 -0700 |
---|---|---|
committer | George Burgess <gbiv@chromium.org> | 2019-09-09 20:19:22 +0000 |
commit | 8e47f36e4e8fd4dd43bda25a430c4929cd6358ce (patch) | |
tree | c39877f51a616972c5e83018f4f4a54839b0dfc9 /compiler_wrapper | |
parent | 7d811f440f3dc7de8ae7f0faa8044fe6751f4944 (diff) | |
download | toolchain-utils-8e47f36e4e8fd4dd43bda25a430c4929cd6358ce.tar.gz |
wrapper: add chmods/umasks to double-build bits
counterpart of I8a92edb8ca7641e443564d20ac32fd78963d3254
BUG=chromium:914081
TEST=go test
Change-Id: I29e22ebd0767d16c1d66bdf41857bf7c79ea11b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1792233
Tested-by: George Burgess <gbiv@chromium.org>
Reviewed-by: Tobias Bosch <tbosch@google.com>
Diffstat (limited to 'compiler_wrapper')
-rw-r--r-- | compiler_wrapper/disable_werror_flag.go | 10 | ||||
-rw-r--r-- | compiler_wrapper/disable_werror_flag_test.go | 61 |
2 files changed, 71 insertions, 0 deletions
diff --git a/compiler_wrapper/disable_werror_flag.go b/compiler_wrapper/disable_werror_flag.go index a5d22f52..b639eb37 100644 --- a/compiler_wrapper/disable_werror_flag.go +++ b/compiler_wrapper/disable_werror_flag.go @@ -10,6 +10,7 @@ import ( "io/ioutil" "os" "strings" + "syscall" ) func shouldForceDisableWError(env env) bool { @@ -65,6 +66,11 @@ func doubleBuildWithWNoError(env env, cfg *config, originalCmd *command) (exitCo // reasonable for that to fail the build. This is all meant for FYI-like // builders in the first place. + // Buildbots use a nonzero umask, which isn't quite what we want: these directories should + // be world-readable and world-writable. + oldMask := syscall.Umask(0) + defer syscall.Umask(oldMask) + // Allow root and regular users to write to this without issue. if err := os.MkdirAll(cfg.newWarningsDir, 0777); err != nil { return 0, wrapErrorwithSourceLocf(err, "error creating warnings directory %s", cfg.newWarningsDir) @@ -83,6 +89,10 @@ func doubleBuildWithWNoError(env env, cfg *config, originalCmd *command) (exitCo return 0, wrapErrorwithSourceLocf(err, "error creating warnings file") } + if err := tmpFile.Chmod(0666); err != nil { + return 0, wrapErrorwithSourceLocf(err, "error chmoding the file to be world-readable/writeable") + } + lines := []string{} if originalStderrBuffer.Len() > 0 { lines = append(lines, originalStderrBuffer.String()) diff --git a/compiler_wrapper/disable_werror_flag_test.go b/compiler_wrapper/disable_werror_flag_test.go index 40d0f8c7..fb25d193 100644 --- a/compiler_wrapper/disable_werror_flag_test.go +++ b/compiler_wrapper/disable_werror_flag_test.go @@ -311,3 +311,64 @@ func readLoggedWarnings(ctx *testContext) *warningsJSONData { } return &jsonData } + +func TestDoubleBuildWerrorChmodsThingsAppropriately(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, "-Werror originalerror") + 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 { + // Later errors are likely senseless if we didn't get called twice. + t.Fatalf("expected 2 calls. Got: %d", ctx.cmdCount) + } + + t.Logf("Warnings dir is at %q", ctx.cfg.newWarningsDir) + warningsDir, err := os.Open(ctx.cfg.newWarningsDir) + if err != nil { + t.Fatalf("failed to open the new warnings dir: %v", err) + } + defer warningsDir.Close() + + fi, err := warningsDir.Stat() + if err != nil { + t.Fatalf("failed stat'ing the warnings dir: %v", err) + } + + permBits := func(mode os.FileMode) int { return int(mode & 0777) } + + if perms := permBits(fi.Mode()); perms != 0777 { + t.Errorf("mode for tempdir are %#o; expected 0777", perms) + } + + entries, err := warningsDir.Readdir(0) + if err != nil { + t.Fatalf("failed reading entries of the tempdir: %v", err) + } + + if len(entries) != 1 { + t.Errorf("found %d tempfiles in the tempdir; expected 1", len(entries)) + } + + for _, e := range entries { + if perms := permBits(e.Mode()); perms != 0666 { + t.Errorf("mode for %q is %#o; expected 0666", e.Name(), perms) + } + } + }) +} |