Skip to content

Commit c2d4e08

Browse files
committed
remove gotmp dir
1 parent 45a6cc9 commit c2d4e08

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

go/private/rules/binary.bzl

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,10 @@ def _go_tool_binary_impl(ctx):
486486

487487
out = ctx.actions.declare_file(name)
488488

489-
# Using pre-declared directory for temporary output to avoid needing to use shell to create it.
490-
gotmp = ctx.actions.declare_directory(name + "_gotmp")
489+
# Using pre-declared directory for temporary output to avoid dependencies
490+
# on shell or non-hermetic coreutils.
491+
gotmp = ctx.actions.declare_directory("gotmp")
492+
491493
if sdk.goos == "windows":
492494
cmd = """@echo off
493495
set GOMAXPROCS=1
@@ -525,22 +527,14 @@ exit /b %GO_EXIT_CODE%
525527
mnemonic = "GoToolchainBinaryBuild",
526528
)
527529
else:
528-
# A dummy action to generate `gotmp`; this way the compilation below can avoid listing it in `outputs`.
529-
# The net effect is to avoid copying out the GOCACHE when actions run sandboxed.
530-
# Incidentally, this makes the reproducibility test pass.
531-
ctx.actions.write(
532-
output = gotmp,
533-
content = "",
534-
)
535-
536-
# In case actions are running unsandboxed, GOCACHE in `gotmp` may have been polluted.
537-
# -a flag forces a rebuild so we are not affected by it.
530+
# -a flag instructs the compiler to not read from GOCACHE and force a rebuild.
531+
# This provides extra safety in cases of unsandboxed execution.
538532
args = ctx.actions.args()
539533
args.add("build")
540534
args.add("-a")
541535
args.add("-o", out)
542536
args.add("-trimpath")
543-
args.add("-ldflags", ctx.attr.ldflags, format = '-buildid="" %s')
537+
args.add("-ldflags", ctx.attr.ldflags, format = '-w -s -buildid="" %s')
544538
args.add_all(ctx.files.srcs)
545539

546540
ctx.actions.run(
@@ -552,17 +546,14 @@ exit /b %GO_EXIT_CODE%
552546
"GO111MODULE": "off",
553547
"GOTELEMETRY": "off",
554548
"GOENV": "off",
555-
# GOCACHE and GOPATH will default themselves to locations under $HOME.
556-
# Otherwise we would need to set them explicitly, in which case they must be absolute paths.
557-
# That would require a wrapper script/shell dependency.
558549
"HOME": gotmp.path,
559550
},
560551
inputs = depset(
561552
ctx.files.srcs,
562553
transitive = [sdk.headers, sdk.srcs, sdk.libs, sdk.tools],
563554
),
564-
outputs = [out],
565555
toolchain = None,
556+
outputs = [out, gotmp],
566557
mnemonic = "GoToolchainBinaryBuild",
567558
)
568559

tests/integration/reproducibility/reproducibility_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ func Test(t *testing.T) {
221221
go func(i int) {
222222
defer wg.Done()
223223
dirHashes[i], errs[i] = hashFiles(filepath.Join(dirs[i], "bazel-out/"), func(root, path string) bool {
224+
// Exclude the GOCACHE that was written for go_tool_binary.
225+
if strings.HasSuffix(path, "/gotmp") {
226+
return true
227+
}
228+
224229
// Hash everything but actions stdout/stderr and the volatile-status.txt file
225230
// as they are expected to change
226231
return strings.HasPrefix(path, filepath.Join(root, "_tmp")) ||

0 commit comments

Comments
 (0)