diff --git a/WORKSPACE b/WORKSPACE index a2507a4003..68ce64195a 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -23,3 +23,19 @@ test_chdir_remote() load("@io_bazel_rules_go//tests/integration/popular_repos:popular_repos.bzl", "popular_repos") popular_repos() + +# For manual testing against an LLVM toolchain. +# Use --crosstool_top=@llvm_toolchain//:toolchain +http_archive( + name = "com_grail_bazel_toolchain", + sha256 = "aafea89b6abe75205418c0d2127252948afe6c7f2287a79b67aab3e0c3676c4f", + strip_prefix = "bazel-toolchain-d0a5b0af3102c7c607f2cf098421fcdbaeaaaf19", + urls = ["https://github.com/grailbio/bazel-toolchain/archive/d0a5b0af3102c7c607f2cf098421fcdbaeaaaf19.tar.gz"], +) + +load("@com_grail_bazel_toolchain//toolchain:configure.bzl", "llvm_toolchain") + +llvm_toolchain( + name = "llvm_toolchain", + llvm_version = "6.0.0", +) diff --git a/go/tools/builders/cgo.go b/go/tools/builders/cgo.go index 4a83c799ea..b5aeb75fe9 100644 --- a/go/tools/builders/cgo.go +++ b/go/tools/builders/cgo.go @@ -273,7 +273,7 @@ func fixupLineComments(filename, srcDir string, cFile bool) error { for i, line := range lines { if cFile { if strings.HasPrefix(line, cFileLinePrefix) { - lines[i] = strings.Replace(line, srcDir, "", 1) + lines[i] = strings.Replace(line, srcDir+string(os.PathSeparator), "", 1) } } else { if strings.HasPrefix(line, goFileTrim) { diff --git a/go/tools/builders/stdlib.go b/go/tools/builders/stdlib.go index ef28b769fe..7e45e66b5c 100644 --- a/go/tools/builders/stdlib.go +++ b/go/tools/builders/stdlib.go @@ -66,7 +66,7 @@ func run(args []string) error { os.Setenv("PATH", strings.Join(absPaths, string(os.PathListSeparator))) // Strip path prefix from source files in debug information. - os.Setenv("CGO_CFLAGS", os.Getenv("CGO_CFLAGS")+" -fdebug-prefix-map="+abs(".")+"=") + os.Setenv("CGO_CFLAGS", os.Getenv("CGO_CFLAGS")+" -fdebug-prefix-map="+abs(".")+string(os.PathSeparator)+"=") // Build the commands needed to build the std library in the right mode installArgs := goenv.goCmd("install", "-toolexec", abs(*filterBuildid)) diff --git a/tests/legacy/reproducible_binary/BUILD.bazel b/tests/legacy/reproducible_binary/BUILD.bazel deleted file mode 100644 index a84a8349f3..0000000000 --- a/tests/legacy/reproducible_binary/BUILD.bazel +++ /dev/null @@ -1,23 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test") - -go_library( - name = "go_default_library", - srcs = ["hello.go"], - importpath = "github.com/bazelbuild/rules_go/tests/reproducible_binary", - visibility = ["//visibility:private"], -) - -go_binary( - name = "reproducible_binary", - embed = [":go_default_library"], - visibility = ["//visibility:public"], -) - -# keep -go_test( - name = "go_default_test", - srcs = ["reproducible_binary_test.go"], - args = ["$(location :reproducible_binary)"], - data = [":reproducible_binary"], - rundir = ".", # run in repo root instead of test dir -) diff --git a/tests/legacy/reproducible_binary/hello.go b/tests/legacy/reproducible_binary/hello.go deleted file mode 100644 index 7a2b0076b4..0000000000 --- a/tests/legacy/reproducible_binary/hello.go +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright 2017 The Bazel Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package main - -import "fmt" - -func main() { - // Call a function from the standard library. The test will check whether - // the path to the source file that defines this function gets embedded - // in the binary. - fmt.Println("Hello, world!") -} diff --git a/tests/reproducibility/BUILD.bazel b/tests/reproducibility/BUILD.bazel index e5fe5be149..808a010a35 100644 --- a/tests/reproducibility/BUILD.bazel +++ b/tests/reproducibility/BUILD.bazel @@ -1,5 +1,14 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_test") load("@io_bazel_rules_go//tests:bazel_tests.bzl", "bazel_test", "md5_sum") +go_test( + name = "go_default_test", + srcs = ["reproducible_binary_test.go"], + args = ["$(location //tests/reproducibility/cgo)"], + data = ["//tests/reproducibility/cgo"], + rundir = ".", # run in repo root instead of test dir +) + # A test script that, when run, builds the given targets in a clean build state # with sandboxed strategy, and outputs their md5 digests from the build with # ___MD5___ prefix to each line. @@ -35,6 +44,9 @@ print_digests "@io_bazel_rules_go//tests/reproducibility/cgo", ], tags = ["manual"], + # dbg builds are not reproducible with llvm 6.0 and below (default on macOS). + # https://bugs.llvm.org/show_bug.cgi?id=38050 + #args = ["--compilation_mode=dbg"], ) # A test that runs the above test script twice and diffs the output. @@ -48,6 +60,5 @@ sh_test( "bazel", "exclusive", "local", - "manual", ], ) diff --git a/tests/legacy/reproducible_binary/reproducible_binary_test.go b/tests/reproducibility/reproducible_binary_test.go similarity index 88% rename from tests/legacy/reproducible_binary/reproducible_binary_test.go rename to tests/reproducibility/reproducible_binary_test.go index 9991638dc2..3bf6910aae 100644 --- a/tests/legacy/reproducible_binary/reproducible_binary_test.go +++ b/tests/reproducibility/reproducible_binary_test.go @@ -63,6 +63,16 @@ func TestStandardPath(t *testing.T) { } } +// TestSandbox checks that the bazel-sandbox path does not appear in strings +// from the binary. +func TestSandboxPath(t *testing.T) { + for _, s := range allStrings { + if bytes.Contains(s, []byte("bazel-sandbox")) { + t.Errorf("binary contains bazel sandbox path: %s", s) + } + } +} + // TestUserNameAndHome checks the user name and home directory do not // appear in strings from the binary. func TestUserNameAndHome(t *testing.T) {