diff options
-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) + } + } + }) +} |