Skip to content

Commit 5fcc83f

Browse files
committed
remove gotmp dir
1 parent 45a6cc9 commit 5fcc83f

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

go/private/rules/binary.bzl

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,10 @@ def _go_tool_binary_impl(ctx):
485485
name += ".exe"
486486

487487
out = ctx.actions.declare_file(name)
488-
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")
491488
if sdk.goos == "windows":
489+
# Using pre-declared directory for temporary output as there is no safe
490+
# way under Windows to create unique temporary dir.
491+
gotmp = ctx.actions.declare_directory("gotmp")
492492
cmd = """@echo off
493493
set GOMAXPROCS=1
494494
set GOCACHE=%cd%\\{gotmp}\\gocache
@@ -525,16 +525,10 @@ exit /b %GO_EXIT_CODE%
525525
mnemonic = "GoToolchainBinaryBuild",
526526
)
527527
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.
528+
# In case actions are running unsandboxed, GOCACHE under `./fake-home` may have been polluted by previous actions.
529+
# -a flag forces a rebuild so we don't read anything from it and are unaffected.
530+
# For sandboxed actions, `./fake-home` would have been cleared by Bazel after action finished
531+
# because it's not a declared output.
538532
args = ctx.actions.args()
539533
args.add("build")
540534
args.add("-a")
@@ -555,14 +549,14 @@ exit /b %GO_EXIT_CODE%
555549
# GOCACHE and GOPATH will default themselves to locations under $HOME.
556550
# Otherwise we would need to set them explicitly, in which case they must be absolute paths.
557551
# That would require a wrapper script/shell dependency.
558-
"HOME": gotmp.path,
552+
"HOME": "./fake-home",
559553
},
560554
inputs = depset(
561555
ctx.files.srcs,
562556
transitive = [sdk.headers, sdk.srcs, sdk.libs, sdk.tools],
563557
),
564-
outputs = [out],
565558
toolchain = None,
559+
outputs = [out],
566560
mnemonic = "GoToolchainBinaryBuild",
567561
)
568562

0 commit comments

Comments
 (0)