Skip to content

Commit

Permalink
Move new runfiles library to //go/runfiles (#3341)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum authored Nov 7, 2022
1 parent c70852e commit 497f92c
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 38 deletions.
23 changes: 2 additions & 21 deletions go/tools/bazel/runfiles/BUILD.bazel → go/runfiles/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "runfiles",
Expand All @@ -23,29 +23,10 @@ go_library(
"manifest.go",
"runfiles.go",
],
importpath = "github.com/bazelbuild/rules_go/go/tools/bazel/runfiles",
importpath = "github.com/bazelbuild/rules_go/go/runfiles",
visibility = ["//visibility:public"],
)

go_test(
name = "runfiles_test",
srcs = [
"fs_test.go",
"runfiles_test.go",
],
data = [
"test.txt",
"//go/tools/bazel/runfiles/testprog",
"@bazel_tools//tools/bash/runfiles",
],
deps = [":runfiles"],
)

exports_files(
["test.txt"],
visibility = ["//go/tools/bazel/runfiles/testprog:__pkg__"],
)

alias(
name = "go_default_library",
actual = ":runfiles",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions go/tools/bazel/runfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const (
// binaries invoked with 'bazel run'. On Windows,
// only tests invoked with 'bazel test' are supported.
//
// Deprecated: Use github.com/bazelbuild/rules_go/go/tools/bazel/runfiles
// instead for cross-platform support matching the behavior of the
// Bazel-provided runfiles libraries.
// Deprecated: Use github.com/bazelbuild/rules_go/go/runfiles instead for
// cross-platform support matching the behavior of the Bazel-provided runfiles
// libraries.
func Runfile(path string) (string, error) {
// Search in working directory
if _, err := os.Stat(path); err == nil {
Expand Down
36 changes: 36 additions & 0 deletions tests/runfiles/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2020 Google LLC
#
# 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
#
# https://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.

load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "runfiles_test",
srcs = [
"fs_test.go",
"runfiles_test.go",
],
data = [
"test.txt",
"//tests/runfiles/testprog",
"@bazel_tools//tools/bash/runfiles",
],
deps = [
"//go/runfiles",
],
)

exports_files(
["test.txt"],
visibility = ["//tests/runfiles/testprog:__pkg__"],
)
10 changes: 5 additions & 5 deletions go/tools/bazel/runfiles/fs_test.go → tests/runfiles/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"testing"
"testing/fstest"

"github.com/bazelbuild/rules_go/go/tools/bazel/runfiles"
"github.com/bazelbuild/rules_go/go/runfiles"
)

func TestFS(t *testing.T) {
Expand All @@ -43,9 +43,9 @@ func TestFS(t *testing.T) {
if runtime.GOOS == "windows" {
// Currently the result of
//
// fsys.Path("io_bazel_rules_go/go/tools/bazel/runfiles/test.txt")
// fsys.Path("io_bazel_rules_go/go/runfiles/test.txt")
// fsys.Path("bazel_tools/tools/bash/runfiles/runfiles.bash")
// fsys.Path("io_bazel_rules_go/go/tools/bazel/runfiles/testprog/testprog")
// fsys.Path("io_bazel_rules_go/go/runfiles/testprog/testprog")
//
// would be a full path like these
//
Expand All @@ -59,8 +59,8 @@ func TestFS(t *testing.T) {
return
}

expected1 := "io_bazel_rules_go/go/tools/bazel/runfiles/test.txt"
expected2 := "io_bazel_rules_go/go/tools/bazel/runfiles/testprog/testprog_/testprog"
expected1 := "io_bazel_rules_go/tests/runfiles/test.txt"
expected2 := "io_bazel_rules_go/tests/runfiles/testprog/testprog_/testprog"
expected3 := "bazel_tools/tools/bash/runfiles/runfiles.bash"
if err := fstest.TestFS(fsys, expected1, expected2, expected3); err != nil {
t.Error(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
"strings"
"testing"

"github.com/bazelbuild/rules_go/go/tools/bazel/runfiles"
"github.com/bazelbuild/rules_go/go/runfiles"
)

func TestPath_FileLookup(t *testing.T) {
path, err := runfiles.Path("io_bazel_rules_go/go/tools/bazel/runfiles/test.txt")
path, err := runfiles.Path("io_bazel_rules_go/tests/runfiles/test.txt")
if err != nil {
t.Fatal(err)
}
Expand All @@ -49,7 +49,7 @@ func TestPath_SubprocessRunfilesLookup(t *testing.T) {
}
// The binary “testprog” is itself built with Bazel, and needs
// runfiles.
testprogRpath := "io_bazel_rules_go/go/tools/bazel/runfiles/testprog/testprog_/testprog"
testprogRpath := "io_bazel_rules_go/tests/runfiles/testprog/testprog_/testprog"
if runtime.GOOS == "windows" {
testprogRpath += ".exe"
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_library(
name = "testprog_lib",
srcs = ["main.go"],
importpath = "github.com/bazelbuild/rules_go/go/tools/bazel/runfiles/testprog",
importpath = "github.com/bazelbuild/rules_go/tests/runfiles/testprog",
visibility = ["//visibility:private"],
deps = ["//go/tools/bazel/runfiles"],
deps = ["//go/runfiles"],
)

go_binary(
name = "testprog",
data = ["//go/tools/bazel/runfiles:test.txt"],
data = ["//tests/runfiles:test.txt"],
embed = [":testprog_lib"],
visibility = ["//go/tools/bazel/runfiles:__pkg__"],
visibility = ["//tests/runfiles:__pkg__"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"fmt"
"io/ioutil"

"github.com/bazelbuild/rules_go/go/tools/bazel/runfiles"
"github.com/bazelbuild/rules_go/go/runfiles"
)

func main() {
path, err := runfiles.Path("io_bazel_rules_go/go/tools/bazel/runfiles/test.txt")
path, err := runfiles.Path("io_bazel_rules_go/tests/runfiles/test.txt")
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 497f92c

Please sign in to comment.