diff --git a/src/main/cpp/util/BUILD b/src/main/cpp/util/BUILD index 11db4ca0472e5a..0ab331d6c81d05 100644 --- a/src/main/cpp/util/BUILD +++ b/src/main/cpp/util/BUILD @@ -47,9 +47,9 @@ cc_library( ":ijar", "//src/test/cpp/util:__pkg__", "//src/tools/launcher:__subpackages__", - "//src/tools/runfiles:__pkg__", "//src/tools/singlejar:__pkg__", "//third_party/def_parser:__pkg__", + "//tools/cpp/runfiles:__pkg__", ], deps = [ ":blaze_exit_code", diff --git a/src/tools/runfiles/BUILD b/src/tools/runfiles/BUILD index d3545fd3e7d8ca..5ac490d1e2e67b 100644 --- a/src/tools/runfiles/BUILD +++ b/src/tools/runfiles/BUILD @@ -20,8 +20,6 @@ filegroup( name = "embedded_tools", srcs = [ "BUILD.tools", - "runfiles.cc", - "runfiles.h", "runfiles.py", "//src/tools/runfiles/java/com/google/devtools/build/runfiles:embedded_tools", ], @@ -40,35 +38,6 @@ py_test( deps = [":py-runfiles"], ) -cc_library( - name = "cc-runfiles", - srcs = ["runfiles.cc"], - hdrs = ["runfiles.h"], - # This library is available to clients under - # @bazel_tools//tools/runfiles:cc-runfiles, with the same source files. - # The include statement in runfiles.cc that includes runfiles.h must work - # both here in the //src/tools/runfiles package, and in the - # @bazel_tools//tools/runfiles package. - # runfiles.cc includes "tools/runfiles/runfiles.h" so we need to tell the - # compiler to prepend "src" to it so the include path is valid. - # Alternatively we could omit this "copts" attribute here and add some - # include path manipulating attributes to - # @bazel_tools//tools/runfiles:cc-runfiles instead -- that would work too, - # but I (laszlocsomor@) find this solution (i.e. the "copts" attribute on - # this rule) to be simpler. - copts = ["-Isrc"], -) - -cc_test( - name = "cc-runfiles-test", - srcs = ["runfiles_test.cc"], - deps = [ - ":cc-runfiles", - "//src/main/cpp/util:file", - "//third_party:gtest", - ], -) - sh_library( name = "runfiles_sh_lib", srcs = ["runfiles.sh"], diff --git a/tools/BUILD b/tools/BUILD index 4488574d28943b..14a8115edc4a41 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -48,7 +48,7 @@ filegroup( "//tools/build_rules:embedded_tools_srcs", "//tools/buildstamp:srcs", "//tools/coverage:srcs", - "//tools/cpp:srcs", + "//tools/cpp:embedded_tools", "//tools/genrule:srcs", "//tools/j2objc:srcs", "//tools/jdk:package-srcs", diff --git a/tools/cpp/runfiles/BUILD b/tools/cpp/runfiles/BUILD new file mode 100644 index 00000000000000..6937bfb6a4094e --- /dev/null +++ b/tools/cpp/runfiles/BUILD @@ -0,0 +1,31 @@ +filegroup( + name = "srcs", + srcs = glob(["**"]), + visibility = ["//tools/cpp:__pkg__"], +) + +filegroup( + name = "embedded_tools", + srcs = [ + "BUILD.tools", + "runfiles.cc", + "runfiles.h", + ], + visibility = ["//tools/cpp:__pkg__"], +) + +cc_library( + name = "runfiles", + srcs = ["runfiles.cc"], + hdrs = ["runfiles.h"], +) + +cc_test( + name = "runfiles-test", + srcs = ["runfiles_test.cc"], + deps = [ + ":runfiles", + "//src/main/cpp/util:file", + "//third_party:gtest", + ], +) diff --git a/tools/cpp/runfiles/BUILD.tools b/tools/cpp/runfiles/BUILD.tools new file mode 100644 index 00000000000000..ffc1769a1ff38e --- /dev/null +++ b/tools/cpp/runfiles/BUILD.tools @@ -0,0 +1,2 @@ +# This package will host the C++ runfiles library when it's ready. +# Follow the progress on https://github.com/bazelbuild/bazel/issues/4460 diff --git a/src/tools/runfiles/runfiles.cc b/tools/cpp/runfiles/runfiles.cc similarity index 98% rename from src/tools/runfiles/runfiles.cc rename to tools/cpp/runfiles/runfiles.cc index b1a870558bb6c0..9ecc033a046fb3 100644 --- a/src/tools/runfiles/runfiles.cc +++ b/tools/cpp/runfiles/runfiles.cc @@ -11,7 +11,7 @@ // 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. -#include "tools/runfiles/runfiles.h" +#include "tools/cpp/runfiles/runfiles.h" #ifdef COMPILER_MSVC #include @@ -32,6 +32,8 @@ #endif // COMPILER_MSVC namespace bazel { +namespace tools { +namespace cpp { namespace runfiles { using std::function; @@ -314,4 +316,6 @@ Runfiles* Runfiles::CreateDirectoryBased(const string& directory_path, } } // namespace runfiles +} // namespace cpp +} // namespace tools } // namespace bazel diff --git a/src/tools/runfiles/runfiles.h b/tools/cpp/runfiles/runfiles.h similarity index 92% rename from src/tools/runfiles/runfiles.h rename to tools/cpp/runfiles/runfiles.h index 20e9dca1e12b22..d4af4627b726bb 100644 --- a/src/tools/runfiles/runfiles.h +++ b/tools/cpp/runfiles/runfiles.h @@ -16,13 +16,13 @@ // // Usage: // -// #include "tools/runfiles/runfiles.h" +// #include "tools/cpp/runfiles/runfiles.h" // ... +// using namespace bazel::tools::cpp::runfiles::Runfiles; // // int main(int argc, char** argv) { // std::string error; -// std::unique_ptr runfiles( -// bazel::runfiles::Runfiles::Create(argv[0], &error)); +// std::unique_ptr runfiles(Runfiles::Create(argv[0], &error)); // if (runfiles == nullptr) { // ... // error handling // } @@ -39,19 +39,18 @@ // If you want to explicitly create a manifest- or directory-based // implementation, you can do so as follows: // -// std::unique_ptr runfiles1( -// bazel::runfiles::Runfiles::CreateManifestBased( +// std::unique_ptr runfiles1( +// Runfiles::CreateManifestBased( // "path/to/foo.runfiles/MANIFEST", &error)); // -// std::unique_ptr runfiles2( -// bazel::runfiles::Runfiles::CreateDirectoryBased( +// std::unique_ptr runfiles2( +// Runfiles::CreateDirectoryBased( // "path/to/foo.runfiles", &error)); // // If you want to start child processes that also need runfiles, you need to set // the right environment variables for them: // -// std::unique_ptr runfiles( -// bazel::runfiles::Runfiles::Create(argv[0], &error)); +// std::unique_ptr runfiles(Runfiles::Create(argv[0], &error)); // // for (const auto i : runfiles->EnvVars()) { // setenv(i.first, i.second, 1); @@ -70,6 +69,8 @@ #include namespace bazel { +namespace tools { +namespace cpp { namespace runfiles { class Runfiles { @@ -179,6 +180,8 @@ bool TestOnly_IsAbsolute(const std::string& path); } // namespace testing } // namespace runfiles +} // namespace cpp +} // namespace tools } // namespace bazel #endif // BAZEL_SRC_TOOLS_RUNFILES_RUNFILES_H_ diff --git a/src/tools/runfiles/runfiles_test.cc b/tools/cpp/runfiles/runfiles_test.cc similarity index 98% rename from src/tools/runfiles/runfiles_test.cc rename to tools/cpp/runfiles/runfiles_test.cc index 9fe95aa19b2197..eb27ce1d933b89 100644 --- a/src/tools/runfiles/runfiles_test.cc +++ b/tools/cpp/runfiles/runfiles_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/tools/runfiles/runfiles.h" +#include "tools/cpp/runfiles/runfiles.h" #ifdef COMPILER_MSVC #include @@ -31,11 +31,13 @@ #define LINE() T(__LINE__) namespace bazel { +namespace tools { +namespace cpp { namespace runfiles { namespace { -using bazel::runfiles::testing::TestOnly_CreateRunfiles; -using bazel::runfiles::testing::TestOnly_IsAbsolute; +using bazel::tools::cpp::runfiles::testing::TestOnly_CreateRunfiles; +using bazel::tools::cpp::runfiles::testing::TestOnly_IsAbsolute; using std::cerr; using std::endl; using std::function; @@ -470,4 +472,6 @@ TEST_F(RunfilesTest, IsAbsolute) { } // namespace } // namespace runfiles +} // namespace cpp +} // namespace tools } // namespace bazel