diff --git a/go/tools/bazel/runfiles/BUILD.bazel b/go/runfiles/BUILD.bazel similarity index 63% rename from go/tools/bazel/runfiles/BUILD.bazel rename to go/runfiles/BUILD.bazel index 3c5a0acd71..67dedc9c79 100644 --- a/go/tools/bazel/runfiles/BUILD.bazel +++ b/go/runfiles/BUILD.bazel @@ -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", @@ -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", diff --git a/go/tools/bazel/runfiles/directory.go b/go/runfiles/directory.go similarity index 100% rename from go/tools/bazel/runfiles/directory.go rename to go/runfiles/directory.go diff --git a/go/tools/bazel/runfiles/fs.go b/go/runfiles/fs.go similarity index 100% rename from go/tools/bazel/runfiles/fs.go rename to go/runfiles/fs.go diff --git a/go/tools/bazel/runfiles/global.go b/go/runfiles/global.go similarity index 100% rename from go/tools/bazel/runfiles/global.go rename to go/runfiles/global.go diff --git a/go/tools/bazel/runfiles/manifest.go b/go/runfiles/manifest.go similarity index 100% rename from go/tools/bazel/runfiles/manifest.go rename to go/runfiles/manifest.go diff --git a/go/tools/bazel/runfiles/runfiles.go b/go/runfiles/runfiles.go similarity index 100% rename from go/tools/bazel/runfiles/runfiles.go rename to go/runfiles/runfiles.go diff --git a/go/tools/bazel/runfiles.go b/go/tools/bazel/runfiles.go index 6a0ba787f3..a2ac11d81c 100644 --- a/go/tools/bazel/runfiles.go +++ b/go/tools/bazel/runfiles.go @@ -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 { diff --git a/tests/runfiles/BUILD.bazel b/tests/runfiles/BUILD.bazel new file mode 100644 index 0000000000..99334bafef --- /dev/null +++ b/tests/runfiles/BUILD.bazel @@ -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__"], +) diff --git a/go/tools/bazel/runfiles/fs_test.go b/tests/runfiles/fs_test.go similarity index 89% rename from go/tools/bazel/runfiles/fs_test.go rename to tests/runfiles/fs_test.go index 9594b161b5..82e79564fa 100644 --- a/go/tools/bazel/runfiles/fs_test.go +++ b/tests/runfiles/fs_test.go @@ -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) { @@ -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 // @@ -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) diff --git a/go/tools/bazel/runfiles/runfiles_test.go b/tests/runfiles/runfiles_test.go similarity index 93% rename from go/tools/bazel/runfiles/runfiles_test.go rename to tests/runfiles/runfiles_test.go index c4852bee9b..fd09a137b7 100644 --- a/go/tools/bazel/runfiles/runfiles_test.go +++ b/tests/runfiles/runfiles_test.go @@ -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) } @@ -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" } diff --git a/go/tools/bazel/runfiles/test.txt b/tests/runfiles/test.txt similarity index 100% rename from go/tools/bazel/runfiles/test.txt rename to tests/runfiles/test.txt diff --git a/go/tools/bazel/runfiles/testprog/BUILD.bazel b/tests/runfiles/testprog/BUILD.bazel similarity index 77% rename from go/tools/bazel/runfiles/testprog/BUILD.bazel rename to tests/runfiles/testprog/BUILD.bazel index 46958bdb1a..2eee947a98 100644 --- a/go/tools/bazel/runfiles/testprog/BUILD.bazel +++ b/tests/runfiles/testprog/BUILD.bazel @@ -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__"], ) diff --git a/go/tools/bazel/runfiles/testprog/main.go b/tests/runfiles/testprog/main.go similarity index 84% rename from go/tools/bazel/runfiles/testprog/main.go rename to tests/runfiles/testprog/main.go index 5bcd8f5db6..be7a1c62d2 100644 --- a/go/tools/bazel/runfiles/testprog/main.go +++ b/tests/runfiles/testprog/main.go @@ -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) }