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: bazelbuild#5640 (comment)
  • Loading branch information
laszlocsomor committed Aug 29, 2018
1 parent 1655933 commit 46899a8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/create_embedded_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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
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 46899a8

Please sign in to comment.