Merge pull request #96011 from mikedanese/bazel

build: Update bazel to 3.4.1 and k/repo-infra to v0.2.0
This commit is contained in:
Kubernetes Prow Robot 2021-01-08 09:24:53 -08:00 committed by GitHub
commit 0fe6f72d9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 24 deletions

View File

@ -17,7 +17,7 @@ dependencies:
# Bazel
- name: "repo-infra"
version: 0.1.3
version: 0.2.0
refPaths:
- path: build/root/WORKSPACE
match: strip_prefix = "repo-infra-\d+.\d+.\d+"

View File

@ -1 +1 @@
2.2.0
3.4.1

View File

@ -5,10 +5,10 @@ load("//build:workspace_mirror.bzl", "mirror")
http_archive(
name = "io_k8s_repo_infra",
strip_prefix = "repo-infra-0.1.3",
sha256 = "46933bedbd22bc6a26ec6116d0d3e1475ad6b23447648d19abd6493241323311",
sha256 = "2f30f87259fed7262d9b95b2665e3d3ecd928d174a4f0356063bc99056b6f84c",
strip_prefix = "repo-infra-0.2.0",
urls = [
"https://github.com/kubernetes/repo-infra/archive/v0.1.3.tar.gz",
"https://github.com/kubernetes/repo-infra/archive/v0.2.0.tar.gz",
],
)
@ -24,7 +24,7 @@ load("@io_k8s_repo_infra//:repos.bzl", repo_infra_configure = "configure", repo_
# by kubernetes/repo-infra
repo_infra_configure(
go_version = "1.15.5",
minimum_bazel_version = "2.2.0",
minimum_bazel_version = "3.4.1",
)
repo_infra_go_repositories()

View File

@ -17,10 +17,10 @@ limitations under the License.
package fixtures
import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
)
var (
@ -38,24 +38,9 @@ var (
)
func init() {
_, thisFile, _, ok := runtime.Caller(0)
if !ok {
panic("Cannot get path to the fixtures")
}
fixturesDir := filepath.Dir(thisFile)
cwd, err := os.Getwd()
fixturesDir, err := pkgPath()
if err != nil {
panic("Cannot get CWD: " + err.Error())
}
// When tests run in a bazel sandbox `runtime.Caller()`
// returns a relative path, when run with plain `go test` the path
// returned is absolute. To make those fixtures work in both those cases,
// we prepend the CWD iff the CWD is not yet part of the path to the fixtures.
if !strings.HasPrefix(fixturesDir, cwd) {
fixturesDir = filepath.Join(cwd, fixturesDir)
panic(fmt.Sprintf("Cannot get path to the fixtures: %s", err))
}
CaCertPath = filepath.Join(fixturesDir, "ca.pem")
@ -63,3 +48,33 @@ func init() {
ServerKeyPath = filepath.Join(fixturesDir, "server.key")
InvalidCertPath = filepath.Join(fixturesDir, "invalid.pem")
}
// pkgPath returns the absolute file path to this package's directory. With go
// test, we can just look at the runtime call stack. However, bazel compiles go
// binaries with the -trimpath option so the simple approach fails however we
// can consult environment variables to derive the path.
//
// The approach taken here works for both go test and bazel on the assumption
// that if and only if trimpath is passed, we are running under bazel.
func pkgPath() (string, error) {
_, thisFile, _, ok := runtime.Caller(1)
if !ok {
return "", fmt.Errorf("failed to get current file")
}
pkgPath := filepath.Dir(thisFile)
// If we find bazel env variables, then -trimpath was passed so we need to
// construct the path from the environment.
if testSrcdir, testWorkspace := os.Getenv("TEST_SRCDIR"), os.Getenv("TEST_WORKSPACE"); testSrcdir != "" && testWorkspace != "" {
pkgPath = filepath.Join(testSrcdir, testWorkspace, pkgPath)
}
// If the path is still not absolute, something other than bazel compiled
// with -trimpath.
if !filepath.IsAbs(pkgPath) {
return "", fmt.Errorf("can't construct an absolute path from %q", pkgPath)
}
return pkgPath, nil
}