diff options
author | Spandan Das <spandandas@google.com> | 2023-06-14 01:36:50 +0000 |
---|---|---|
committer | Spandan Das <spandandas@google.com> | 2023-06-14 16:36:40 +0000 |
commit | 49dcd021242b91376524f85bfec457f8e81051e4 (patch) | |
tree | d9fac15bb5a835ae6ba757dc5eaf6ef597ea44cf /tests/core/stdlib/buildid_test.go | |
parent | 9803cf8403d7105bddc1d5304d6e694b781a6605 (diff) | |
parent | 286e96454a739681639ef3289d92c23060fcb5af (diff) | |
download | bazelbuild-rules_go-49dcd021242b91376524f85bfec457f8e81051e4.tar.gz |
Merge remote-tracking branch 'aosp/upstream-master' into merge_rules_go
Create two more files
- LICENSE which is a symlink to LICENSE.txt
- OWNERS
Test: N/A
Change-Id: If65c9397956c6d37c2cf65902b92f1b5c8a51dee
Diffstat (limited to 'tests/core/stdlib/buildid_test.go')
-rw-r--r-- | tests/core/stdlib/buildid_test.go | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/core/stdlib/buildid_test.go b/tests/core/stdlib/buildid_test.go new file mode 100644 index 00000000..d95ba903 --- /dev/null +++ b/tests/core/stdlib/buildid_test.go @@ -0,0 +1,93 @@ +//go:build go1.10 +// +build go1.10 + +/* Copyright 2018 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 buildid_test + +import ( + "bytes" + "errors" + "os" + "os/exec" + "path/filepath" + "testing" + + "github.com/bazelbuild/rules_go/go/runfiles" +) + +func TestEmptyBuildID(t *testing.T) { + // Locate the buildid tool and several archive files to check. + // fmt.a - pure go + // crypto/aes.a - contains assembly + // runtime/cgo.a - contains cgo + // The path may vary depending on platform and architecture, so just + // do a search. + var buildidPath string + pkgPaths := map[string]string{ + "fmt.a": "", + "aes.a": "", + "cgo.a": "", + } + stdlibPkgDir, err := runfiles.Rlocation("io_bazel_rules_go/stdlib_/pkg") + if err != nil { + t.Fatal(err) + } + n := len(pkgPaths) + done := errors.New("done") + var visit filepath.WalkFunc + visit = func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if filepath.Base(path) == "buildid" && (info.Mode()&0111) != 0 { + buildidPath = path + } + for pkg := range pkgPaths { + if filepath.Base(path) == pkg { + pkgPaths[pkg] = path + n-- + } + } + if buildidPath != "" && n == 0 { + return done + } + return nil + } + if err = filepath.Walk(stdlibPkgDir, visit); err != nil && err != done { + t.Fatal(err) + } + if buildidPath == "" { + t.Fatal("buildid not found") + } + + for pkg, path := range pkgPaths { + if path == "" { + t.Errorf("could not locate %s", pkg) + continue + } + // Equivalent to: go tool buildid pkg.a + // It's an error if this produces any output. + cmd := exec.Command(buildidPath, path) + out, err := cmd.Output() + if err != nil { + t.Error(err) + } + if len(bytes.TrimSpace(out)) > 0 { + t.Errorf("%s: unexpected buildid: %s", path, out) + } + } +} |