Skip to content

Commit

Permalink
Use output dir for empty packages to be hermetic (#3098)
Browse files Browse the repository at this point in the history
With an empty lib reproducibility test
  • Loading branch information
joeljeske committed Mar 31, 2022
1 parent 11d6100 commit 4013954
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion go/tools/builders/compilepkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ func compileArchive(
defer cleanup()

if len(srcs.goSrcs) == 0 {
emptyPath := filepath.Join(workDir, "_empty.go")
// We need to run the compiler to create a valid archive, even if there's
// nothing in it. GoPack will complain if we try to add assembly or cgo
// objects.
// _empty.go needs to be in a deterministic location (not tmpdir) in order
// to ensure deterministic output
emptyPath := filepath.Join(filepath.Dir(outPath), "_empty.go")
if err := ioutil.WriteFile(emptyPath, []byte("package empty\n"), 0666); err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/reproducibility/reproducibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ func TestMain(m *testing.M) {
bazel_testing.TestMain(m, bazel_testing.Args{
Main: `
-- BUILD.bazel --
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_library(
name = "empty_lib",
srcs = [],
importpath = "empty_lib",
)
go_binary(
name = "hello",
Expand Down

0 comments on commit 4013954

Please sign in to comment.