Move GetInternalDataDependencyFilePath() into internal namespace

Implements #79

PiperOrigin-RevId: 351778836
Change-Id: I726837d8e75880bf5ddfb1a327249dd666adec53
This commit is contained in:
Christian Blichmann 2021-01-14 05:10:54 -08:00 committed by Copybara-Service
parent dbaf95c724
commit 19fd11b91e
11 changed files with 34 additions and 18 deletions

View File

@ -131,7 +131,7 @@ class Sandbox {
sandbox2::PolicyBuilder* builder);
// Path of the sandboxee:
// - relative to runfiles directory: ::sandbox2::GetDataDependencyFilePath()
// - relative to runfiles directory: ::sapi::GetDataDependencyFilePath()
// will be applied to it,
// - absolute: will be used as is.
virtual std::string GetLibPath() const { return ""; }

View File

@ -91,8 +91,9 @@ int main(int argc, char** argv) {
return 1;
}
const std::string path =
sapi::GetInternalDataDependencyFilePath("sandbox2/examples/crc4/crc4bin");
// Note: In your own code, use sapi::GetDataDependencyFilePath() instead.
const std::string path = sapi::internal::GetSapiDataDependencyFilePath(
"sandbox2/examples/crc4/crc4bin");
std::vector<std::string> args = {path};
if (absl::GetFlag(FLAGS_call_syscall_not_allowed)) {
args.push_back("-call_syscall_not_allowed");

View File

@ -117,7 +117,8 @@ int main(int argc, char** argv) {
#endif
// Start a custom fork-server (via sandbox2::Executor).
const std::string path = sapi::GetInternalDataDependencyFilePath(
// Note: In your own code, use sapi::GetDataDependencyFilePath() instead.
const std::string path = sapi::internal::GetSapiDataDependencyFilePath(
"sandbox2/examples/custom_fork/custom_fork_bin");
std::vector<std::string> args = {path};
std::vector<std::string> envs = {};

View File

@ -179,7 +179,8 @@ int main(int argc, char** argv) {
std::thread server_thread{Server,port};
server_thread.detach();
const std::string path = sapi::GetInternalDataDependencyFilePath(
// Note: In your own code, use sapi::GetDataDependencyFilePath() instead.
const std::string path = sapi::internal::GetSapiDataDependencyFilePath(
"sandbox2/examples/network/network_bin");
std::vector<std::string> args = {path};
std::vector<std::string> envs = {};

View File

@ -129,8 +129,9 @@ int main(int argc, char** argv) {
std::thread server_thread{Server,port};
server_thread.detach();
// Note: In your own code, use sapi::GetDataDependencyFilePath() instead.
const std::string path =
sapi::GetInternalDataDependencyFilePath(kSandboxeePath);
sapi::internal::GetSapiDataDependencyFilePath(kSandboxeePath);
std::vector<std::string> args = {path};
if (!absl::GetFlag(FLAGS_connect_with_handler)) {
args.push_back("--noconnect_with_handler");

View File

@ -108,7 +108,8 @@ int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
const std::string path = sapi::GetInternalDataDependencyFilePath(
// Note: In your own code, use sapi::GetDataDependencyFilePath() instead.
const std::string path = sapi::internal::GetSapiDataDependencyFilePath(
"sandbox2/examples/static/static_bin");
std::vector<std::string> args = {path};
auto executor = absl::make_unique<sandbox2::Executor>(path, args);

View File

@ -78,8 +78,9 @@ int main(int argc, char** argv) {
return 1;
}
const std::string path =
sapi::GetInternalDataDependencyFilePath("sandbox2/examples/zlib/zpipe");
// Note: In your own code, use sapi::GetDataDependencyFilePath() instead.
const std::string path = sapi::internal::GetSapiDataDependencyFilePath(
"sandbox2/examples/zlib/zpipe");
std::vector<std::string> args = {path};
if (absl::GetFlag(FLAGS_decompress)) {
args.push_back("-d");

View File

@ -127,6 +127,7 @@ cc_library(
srcs = ["runfiles.cc"],
hdrs = ["runfiles.h"],
copts = sapi_platform_copts(),
visibility = ["//visibility:public"],
deps = [
":file_base",
":flags",

View File

@ -21,11 +21,11 @@
#include "sandboxed_api/util/runfiles.h"
#include "tools/cpp/runfiles/runfiles.h"
using bazel::tools::cpp::runfiles::Runfiles;
namespace sapi {
std::string GetDataDependencyFilePath(absl::string_view relative_path) {
using bazel::tools::cpp::runfiles::Runfiles;
static Runfiles* runfiles = []() {
std::string error;
auto* runfiles = Runfiles::Create(gflags::GetArgv0(), &error);
@ -40,9 +40,12 @@ std::string GetDataDependencyFilePath(absl::string_view relative_path) {
return runfiles->Rlocation(std::string(relative_path));
}
std::string GetInternalDataDependencyFilePath(absl::string_view relative_path) {
return GetDataDependencyFilePath(
file::JoinPath("com_google_sandboxed_api/sandboxed_api", relative_path));
namespace internal {
std::string GetSapiDataDependencyFilePath(absl::string_view relative_path) {
return GetDataDependencyFilePath(file::JoinPath(
"com_google_sandboxed_api", "sandboxed_api", relative_path));
}
} // namespace internal
} // namespace sapi

View File

@ -25,10 +25,13 @@ namespace sapi {
// should be relative to the runfiles directory.
std::string GetDataDependencyFilePath(absl::string_view relative_path);
// Like GetDataDependencyFilePath(), but prepends the location of the Sandboxed
// API root runfiles path.
std::string GetInternalDataDependencyFilePath(absl::string_view relative_path);
namespace internal {
// Like ::sapi::GetDataDependencyFilePath(), but prepends the location of the
// Sandboxed API root runfiles path.
std::string GetSapiDataDependencyFilePath(absl::string_view relative_path);
} // namespace internal
} // namespace sapi
#endif // SANDBOXED_API_UTIL_RUNFILES_H_

View File

@ -37,11 +37,14 @@ std::string GetDataDependencyFilePath(absl::string_view relative_path) {
return file::JoinPath(resolved, relative_path);
}
std::string GetInternalDataDependencyFilePath(absl::string_view relative_path) {
namespace internal {
std::string GetSapiDataDependencyFilePath(absl::string_view relative_path) {
// The Bazel version has an additional "com_google_sandboxed_api" path
// component.
return GetDataDependencyFilePath(
file::JoinPath("sandboxed_api", relative_path));
}
} // namespace internal
} // namespace sapi