Skip to content

Commit

Permalink
C++,runfiles: rename sources to avoid conflict
Browse files Browse the repository at this point in the history
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: #5640 (comment)

Closes #6023.

Change-Id: Ic0fa23045b25cf9b1987780f9e752a54fa32be45
PiperOrigin-RevId: 210878008
  • Loading branch information
laszlocsomor authored and Copybara-Service committed Aug 30, 2018
1 parent 54e31ac commit 131e31c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/create_embedded_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
('*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'),
Expand All @@ -44,7 +46,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'),
Expand Down
2 changes: 1 addition & 1 deletion src/test/py/bazel/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
21 changes: 18 additions & 3 deletions tools/cpp/runfiles/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <windows.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
//
// int main(int argc, char** argv) {
// std::string error;
// std::unique_ptr<Runfiles> runfiles(Runfiles::Create(argv[0],
// &error)); if (runfiles == nullptr) {
// std::unique_ptr<Runfiles> 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.
Expand Down
2 changes: 1 addition & 1 deletion tools/cpp/runfiles/runfiles_test.cc
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.

#include "tools/cpp/runfiles/runfiles.h"
#include "tools/cpp/runfiles/runfiles_src.h"

#ifdef _WIN32
#include <windows.h>
Expand Down

0 comments on commit 131e31c

Please sign in to comment.