aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/cpp
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2018-05-30 02:47:38 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-30 02:48:59 -0700
commit22f4bb9afa6a8454a15fbd21edbb69c4518fbbf2 (patch)
tree8bf36113542c4ae40e730e25b6a827401368d411 /tools/cpp
parent2cbcde33478756d265a57e88c89732126f33879a (diff)
runfiles,cc: C++ runfiles library in @bazel_tools
Add the C++ runfiles library to @bazel_tools//tools/cpp/runfiles:runfiles. RELNOTES[NEW]: C++,runfiles: to access data-dependencies (runfiles) in C++ programs, use the runfiles library built into Bazel. For usage info, see https://github.com/bazelbuild/bazel/blob/master/tools/cpp/runfiles/runfiles.h Change-Id: I5057a9f477289eea7244c60105e77fc71652a817 Closes #5293. Change-Id: I90cba6fa4c6595c838ae42f9d2c17548c8387e5d PiperOrigin-RevId: 198531849
Diffstat (limited to 'tools/cpp')
-rw-r--r--tools/cpp/runfiles/BUILD1
-rw-r--r--tools/cpp/runfiles/BUILD.tools14
-rw-r--r--tools/cpp/runfiles/runfiles.h15
3 files changed, 18 insertions, 12 deletions
diff --git a/tools/cpp/runfiles/BUILD b/tools/cpp/runfiles/BUILD
index a8f47b9a59..7373b03e37 100644
--- a/tools/cpp/runfiles/BUILD
+++ b/tools/cpp/runfiles/BUILD
@@ -17,6 +17,7 @@ filegroup(
srcs = [
"BUILD.tools",
"runfiles.cc",
+ "runfiles.h",
],
visibility = ["//tools:__pkg__"],
)
diff --git a/tools/cpp/runfiles/BUILD.tools b/tools/cpp/runfiles/BUILD.tools
index 8f0a9cf143..ef9518c05b 100644
--- a/tools/cpp/runfiles/BUILD.tools
+++ b/tools/cpp/runfiles/BUILD.tools
@@ -1,10 +1,8 @@
# This package will host the C++ runfiles library when it's finally released.
-# TODO(laszlocsomor): uncomment the cc_library below when the C++ runfiles library is ready to be
-# released.
-# cc_library(
-# name = "runfiles",
-# srcs = ["runfiles.cc"],
-# hdrs = ["runfiles.h"],
-# visibility = ["//visibility:public"],
-# )
+cc_library(
+ name = "runfiles",
+ srcs = ["runfiles.cc"],
+ hdrs = ["runfiles.h"],
+ visibility = ["//visibility:public"],
+)
diff --git a/tools/cpp/runfiles/runfiles.h b/tools/cpp/runfiles/runfiles.h
index 8c016a3030..b2bfe30517 100644
--- a/tools/cpp/runfiles/runfiles.h
+++ b/tools/cpp/runfiles/runfiles.h
@@ -44,13 +44,20 @@
//
// std::unique_ptr<Runfiles> runfiles(Runfiles::Create(argv[0], &error));
//
-// for (const auto i : runfiles->EnvVars()) {
-// setenv(i.first, i.second, 1);
-// }
// std::string path = runfiles->Rlocation("path/to/binary"));
// if (!path.empty()) {
+// ... // create "args" argument vector for execv
+// const auto envvars = runfiles->EnvVars();
// pid_t child = fork();
-// ...
+// if (child) {
+// int status;
+// waitpid(child, &status, 0);
+// } else {
+// for (const auto i : envvars) {
+// setenv(i.first.c_str(), i.second.c_str(), 1);
+// }
+// execv(args[0], args);
+// }
#ifndef TOOLS_CPP_RUNFILES_RUNFILES_H_
#define TOOLS_CPP_RUNFILES_RUNFILES_H_ 1