From 37245199effbfd128d6a748d53fdc10fc10b058c Mon Sep 17 00:00:00 2001 From: Laszlo Csomor Date: Wed, 29 Aug 2018 16:34:44 +0200 Subject: [PATCH] C++,runfiles: rename sources to avoid conflict Avoid include collision inside the Bazel source tree when a rule depends on @bazel_tools//tools/cpp/runfiles and includes "tools/cpp/runfiles/runfiles.h", but they end up getting "tools/cpp/runfiles/runfiles.h" from the main repo. Change-Id: Ic0fa23045b25cf9b1987780f9e752a54fa32be45 Details: https://github.com/bazelbuild/bazel/issues/5640#issuecomment-416957997 --- src/create_embedded_tools.py | 2 +- src/test/py/bazel/test_base.py | 2 +- tools/cpp/runfiles/BUILD | 21 ++++++++++++++++--- .../runfiles/{runfiles.cc => runfiles_src.cc} | 2 +- .../runfiles/{runfiles.h => runfiles_src.h} | 7 ++++--- tools/cpp/runfiles/runfiles_test.cc | 2 +- 6 files changed, 26 insertions(+), 10 deletions(-) rename tools/cpp/runfiles/{runfiles.cc => runfiles_src.cc} (98%) rename tools/cpp/runfiles/{runfiles.h => runfiles_src.h} (97%) diff --git a/src/create_embedded_tools.py b/src/create_embedded_tools.py index 4ad4a5a6360db2..ef1e3ca074e2f3 100644 --- a/src/create_embedded_tools.py +++ b/src/create_embedded_tools.py @@ -31,6 +31,7 @@ ('*tools/jdk/BUILD*', lambda x: 'tools/jdk/BUILD'), ('*tools/platforms/platforms.BUILD', lambda x: 'platforms/BUILD'), ('*tools/platforms/*', lambda x: 'platforms/' + os.path.basename(x)), + ('*tools/cpp/runfiles/*', lambda x: 'tools/cpp/runfiles/' + os.path.basename(x)), ('*JavaBuilder*_deploy.jar', lambda x: 'tools/jdk/' + os.path.basename(x)), ('*JacocoCoverage*_deploy.jar', lambda x: 'tools/jdk/JacocoCoverage_deploy.jar'), @@ -44,7 +45,6 @@ lambda x: 'tools/jdk/ExperimentalTestRunner_deploy.jar'), ('*Runner_deploy.jar', lambda x: 'tools/jdk/TestRunner_deploy.jar'), ('*singlejar_local', lambda x: 'tools/jdk/singlejar/singlejar'), - ('src/tools/runfiles/runfiles.py', lambda x: 'tools/runfiles/runfiles.py'), ('*launcher.exe', lambda x: 'tools/launcher/launcher.exe'), ('*def_parser.exe', lambda x: 'tools/def_parser/def_parser.exe'), ('*ijar.exe', lambda x: 'tools/jdk/ijar/ijar.exe'), diff --git a/src/test/py/bazel/test_base.py b/src/test/py/bazel/test_base.py index 8670f0da71b115..6455ae2365bd85 100644 --- a/src/test/py/bazel/test_base.py +++ b/src/test/py/bazel/test_base.py @@ -61,7 +61,7 @@ def setUp(self): self._test_cwd = tempfile.mkdtemp(dir=self._tests_root) self._test_bazelrc = os.path.join(self._temp, 'test_bazelrc') with open(self._test_bazelrc, 'wt') as f: - f.write('build --announce --jobs=8\n') + f.write('build --jobs=8\n') os.chdir(self._test_cwd) def tearDown(self): diff --git a/tools/cpp/runfiles/BUILD b/tools/cpp/runfiles/BUILD index dae87c911ae681..e53618e11e15f4 100644 --- a/tools/cpp/runfiles/BUILD +++ b/tools/cpp/runfiles/BUILD @@ -16,17 +16,32 @@ filegroup( name = "embedded_tools", srcs = [ "BUILD.tools", + ":srcs_for_embedded_tools", + ], + visibility = ["//tools:__pkg__"], +) + +genrule( + name = "srcs_for_embedded_tools", + srcs = [ + "runfiles_src.cc", + "runfiles_src.h", + ], + outs = [ "runfiles.cc", "runfiles.h", ], - visibility = ["//tools:__pkg__"], + cmd = ("sed " + + " 's|^#include.*/runfiles_src.h.*|#include \"tools/cpp/runfiles/runfiles.h\"|' " + + " $(location runfiles_src.cc) > $(location runfiles.cc) && " + + "cp $(location runfiles_src.h) $(location runfiles.h)"), ) cc_library( name = "runfiles", testonly = 1, - srcs = ["runfiles.cc"], - hdrs = ["runfiles.h"], + srcs = ["runfiles_src.cc"], + hdrs = ["runfiles_src.h"], ) cc_test( diff --git a/tools/cpp/runfiles/runfiles.cc b/tools/cpp/runfiles/runfiles_src.cc similarity index 98% rename from tools/cpp/runfiles/runfiles.cc rename to tools/cpp/runfiles/runfiles_src.cc index 64e797f8966e92..4ee1191b669100 100644 --- a/tools/cpp/runfiles/runfiles.cc +++ b/tools/cpp/runfiles/runfiles_src.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/cpp/runfiles/runfiles.h" +#include "tools/cpp/runfiles/runfiles_src.h" // this line is replaced in @bazel_tools #ifdef _WIN32 #include diff --git a/tools/cpp/runfiles/runfiles.h b/tools/cpp/runfiles/runfiles_src.h similarity index 97% rename from tools/cpp/runfiles/runfiles.h rename to tools/cpp/runfiles/runfiles_src.h index cfb1f30e64bf21..e75a569c948e5d 100644 --- a/tools/cpp/runfiles/runfiles.h +++ b/tools/cpp/runfiles/runfiles_src.h @@ -33,12 +33,13 @@ // // int main(int argc, char** argv) { // std::string error; -// std::unique_ptr runfiles(Runfiles::Create(argv[0], -// &error)); if (runfiles == nullptr) { +// std::unique_ptr runfiles( +// Runfiles::Create(argv[0], &error)); +// if (runfiles == nullptr) { // ... // error handling // } // std::string path = -// runfiles->Rlocation("my_workspace/path/to/my/data.txt"); +// runfiles->Rlocation("my_workspace/path/to/my/data.txt"); // ... // // The code above creates a Runfiles object and retrieves a runfile path. diff --git a/tools/cpp/runfiles/runfiles_test.cc b/tools/cpp/runfiles/runfiles_test.cc index d6ecac9344dac8..6f18a9e2e28ea1 100644 --- a/tools/cpp/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 "tools/cpp/runfiles/runfiles.h" +#include "tools/cpp/runfiles/runfiles_src.h" #ifdef _WIN32 #include