From ffd4e1270a6f6bf72747774f2e243a77b7aa31ab Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Wed, 5 Jun 2019 00:25:50 -0700 Subject: [PATCH] Internal change PiperOrigin-RevId: 251590551 Change-Id: Ic69f8f5f798006c0d096357b7a746cdc4ce530a3 --- sandboxed_api/BUILD.bazel | 2 +- sandboxed_api/client.cc | 2 +- sandboxed_api/examples/stringop/BUILD.bazel | 2 +- .../examples/stringop/main_stringop.cc | 2 +- sandboxed_api/examples/sum/BUILD.bazel | 2 +- sandboxed_api/examples/sum/main_sum.cc | 2 +- sandboxed_api/examples/zlib/BUILD.bazel | 2 +- sandboxed_api/examples/zlib/main_zlib.cc | 2 +- sandboxed_api/sandbox2/BUILD.bazel | 6 +-- sandboxed_api/sandbox2/CMakeLists.txt | 12 ++--- .../sandbox2/examples/crc4/BUILD.bazel | 6 +-- .../sandbox2/examples/crc4/crc4bin.cc | 5 +- .../sandbox2/examples/crc4/crc4sandbox.cc | 7 ++- .../sandbox2/examples/custom_fork/BUILD.bazel | 4 +- .../examples/custom_fork/custom_fork_bin.cc | 2 +- .../custom_fork/custom_fork_sandbox.cc | 2 +- .../sandbox2/examples/static/BUILD.bazel | 2 +- .../examples/static/static_sandbox.cc | 2 +- .../sandbox2/examples/tool/BUILD.bazel | 2 +- .../sandbox2/examples/tool/sandbox2tool.cc | 6 +-- .../sandbox2/examples/zlib/BUILD.bazel | 2 +- .../sandbox2/examples/zlib/zpipe_sandbox.cc | 6 +-- sandboxed_api/sandbox2/monitor.cc | 4 +- sandboxed_api/sandbox2/policy.cc | 4 +- sandboxed_api/sandbox2/stack-trace.cc | 2 +- sandboxed_api/sandbox2/stack-trace.h | 2 +- sandboxed_api/sandbox2/stack-trace_test.cc | 4 +- sandboxed_api/sandbox2/util/BUILD.bazel | 2 +- sandboxed_api/sandbox2/util/CMakeLists.txt | 2 +- sandboxed_api/sandbox2/util/runfiles.cc | 5 +- sandboxed_api/util/BUILD.bazel | 8 +++ sandboxed_api/util/CMakeLists.txt | 9 ++++ sandboxed_api/util/flag.h | 49 +++++++++++++++++++ 33 files changed, 116 insertions(+), 55 deletions(-) create mode 100644 sandboxed_api/util/flag.h diff --git a/sandboxed_api/BUILD.bazel b/sandboxed_api/BUILD.bazel index 9a24df4..c13a2d4 100644 --- a/sandboxed_api/BUILD.bazel +++ b/sandboxed_api/BUILD.bazel @@ -173,7 +173,7 @@ cc_library( "//sandboxed_api/sandbox2:client", "//sandboxed_api/sandbox2:comms", "//sandboxed_api/sandbox2:forkingclient", - "@com_google_absl//absl/flags:flag", + "//sandboxed_api/util:flags", "@com_google_absl//absl/strings", "@com_google_glog//:glog", "@com_google_protobuf//:protobuf", diff --git a/sandboxed_api/client.cc b/sandboxed_api/client.cc index 3d76dcb..bdd8435 100644 --- a/sandboxed_api/client.cc +++ b/sandboxed_api/client.cc @@ -23,7 +23,7 @@ #include #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" -#include "absl/flags/flag.h" +#include "sandboxed_api/util/flag.h" #include "absl/strings/str_cat.h" #include "sandboxed_api/call.h" #include "sandboxed_api/lenval_core.h" diff --git a/sandboxed_api/examples/stringop/BUILD.bazel b/sandboxed_api/examples/stringop/BUILD.bazel index ee24ad7..d460a3b 100644 --- a/sandboxed_api/examples/stringop/BUILD.bazel +++ b/sandboxed_api/examples/stringop/BUILD.bazel @@ -28,9 +28,9 @@ cc_test( "//sandboxed_api:vars", "//sandboxed_api/examples/stringop/lib:stringop-sapi", "//sandboxed_api/examples/stringop/lib:stringop_params_proto_cc", + "//sandboxed_api/util:flags", "//sandboxed_api/util:status", "//sandboxed_api/util:status_matchers", - "@com_google_absl//absl/flags:flag", "@com_google_absl//absl/memory", "@com_google_absl//absl/time", "@com_google_googletest//:gtest_main", diff --git a/sandboxed_api/examples/stringop/main_stringop.cc b/sandboxed_api/examples/stringop/main_stringop.cc index bc4ae51..2501474 100644 --- a/sandboxed_api/examples/stringop/main_stringop.cc +++ b/sandboxed_api/examples/stringop/main_stringop.cc @@ -19,7 +19,7 @@ #include #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "absl/flags/flag.h" +#include "sandboxed_api/util/flag.h" #include "absl/memory/memory.h" #include "absl/time/time.h" #include "sandboxed_api/examples/stringop/lib/sandbox.h" diff --git a/sandboxed_api/examples/sum/BUILD.bazel b/sandboxed_api/examples/sum/BUILD.bazel index a9e96d6..709b999 100644 --- a/sandboxed_api/examples/sum/BUILD.bazel +++ b/sandboxed_api/examples/sum/BUILD.bazel @@ -26,8 +26,8 @@ cc_binary( "//sandboxed_api:vars", "//sandboxed_api/examples/sum/lib:sum-sapi", "//sandboxed_api/examples/sum/lib:sum_params_proto_cc", + "//sandboxed_api/util:flags", "//sandboxed_api/util:status", - "@com_google_absl//absl/flags:flag", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", ], diff --git a/sandboxed_api/examples/sum/main_sum.cc b/sandboxed_api/examples/sum/main_sum.cc index 78c3fb6..d260af3 100644 --- a/sandboxed_api/examples/sum/main_sum.cc +++ b/sandboxed_api/examples/sum/main_sum.cc @@ -17,7 +17,7 @@ #include #include -#include "absl/flags/flag.h" +#include "sandboxed_api/util/flag.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" #include "sandboxed_api/examples/sum/lib/sandbox.h" diff --git a/sandboxed_api/examples/zlib/BUILD.bazel b/sandboxed_api/examples/zlib/BUILD.bazel index f506032..22c8f11 100644 --- a/sandboxed_api/examples/zlib/BUILD.bazel +++ b/sandboxed_api/examples/zlib/BUILD.bazel @@ -42,7 +42,7 @@ cc_binary( ":zlib-sapi", ":zlib-sapi_embed", "//sandboxed_api:vars", + "//sandboxed_api/util:flags", "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/flags:flag", ], ) diff --git a/sandboxed_api/examples/zlib/main_zlib.cc b/sandboxed_api/examples/zlib/main_zlib.cc index 82c1156..d3c46d8 100644 --- a/sandboxed_api/examples/zlib/main_zlib.cc +++ b/sandboxed_api/examples/zlib/main_zlib.cc @@ -17,7 +17,7 @@ #include #include "absl/base/macros.h" -#include "absl/flags/flag.h" +#include "sandboxed_api/util/flag.h" #include "sandboxed_api/examples/zlib/zlib-sapi.sapi.h" #include "sandboxed_api/examples/zlib/zlib-sapi_embed.h" #include "sandboxed_api/vars.h" diff --git a/sandboxed_api/sandbox2/BUILD.bazel b/sandboxed_api/sandbox2/BUILD.bazel index ca04114..e6eef73 100644 --- a/sandboxed_api/sandbox2/BUILD.bazel +++ b/sandboxed_api/sandbox2/BUILD.bazel @@ -184,8 +184,8 @@ cc_library( ":syscall", ":violation_proto_cc", "//sandboxed_api/sandbox2/util:bpf_helper", + "//sandboxed_api/util:flags", "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/flags:flag", "@com_google_absl//absl/types:optional", "@org_kernel_libcap//:libcap", ], @@ -302,7 +302,7 @@ cc_library( "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", - "@com_google_absl//absl/flags:flag", + "//sandboxed_api/util:flags", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", @@ -728,8 +728,8 @@ cc_test( "//sandboxed_api/sandbox2/util:bpf_helper", "//sandboxed_api/sandbox2/util:fileops", "//sandboxed_api/sandbox2/util:temp_file", + "//sandboxed_api/util:flags", "//sandboxed_api/util:status_matchers", - "@com_google_absl//absl/flags:flag", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", "@com_google_googletest//:gtest_main", diff --git a/sandboxed_api/sandbox2/CMakeLists.txt b/sandboxed_api/sandbox2/CMakeLists.txt index b40c1c2..54a68f5 100644 --- a/sandboxed_api/sandbox2/CMakeLists.txt +++ b/sandboxed_api/sandbox2/CMakeLists.txt @@ -187,7 +187,6 @@ add_library(sandbox2_policy STATIC add_library(sandbox2::policy ALIAS sandbox2_policy) target_link_libraries(sandbox2_policy PRIVATE absl::core_headers - absl::flags absl::optional libcap::libcap sandbox2::bpf_helper @@ -198,6 +197,7 @@ target_link_libraries(sandbox2_policy PRIVATE sandbox2::syscall sandbox2::violation_proto sapi::base + sapi::flags ) # sandboxed_api/sandbox2:notify @@ -284,7 +284,6 @@ add_library(sandbox2::sandbox2 ALIAS sandbox2_sandbox2) target_link_libraries(sandbox2_sandbox2 PRIVATE absl::core_headers absl::flat_hash_map - absl::flags absl::flat_hash_set absl::memory absl::optional @@ -319,7 +318,8 @@ target_link_libraries(sandbox2_sandbox2 sapi::base sapi::status sapi::statusor - PUBLIC sandbox2::logsink + PUBLIC sapi::flags + sandbox2::logsink ) # sandboxed_api/sandbox2:client @@ -779,7 +779,6 @@ add_dependencies(stack-trace_test sandbox2::testcase_symbolize ) target_link_libraries(stack-trace_test PRIVATE - absl::flags absl::memory absl::strings sandbox2::bpf_helper @@ -789,6 +788,7 @@ target_link_libraries(stack-trace_test PRIVATE sandbox2::temp_file sandbox2::testing sandbox2::util + sapi::flags sapi::status_matchers sapi::test_main ) @@ -805,12 +805,12 @@ add_dependencies(ipc_test sandbox2::testcase_ipc ) target_link_libraries(ipc_test PRIVATE - absl::flags absl::memory sandbox2::bpf_helper sandbox2::comms sandbox2::sandbox2 sandbox2::testing + sapi::flags sapi::status_matchers sapi::test_main ) @@ -854,7 +854,6 @@ add_dependencies(policybuilder_test sandbox2::testcase_print_fds ) target_link_libraries(policybuilder_test PRIVATE - absl::flags absl::memory absl::strings glog::glog @@ -862,6 +861,7 @@ target_link_libraries(policybuilder_test PRIVATE sandbox2::comms sandbox2::sandbox2 sandbox2::testing + sapi::flags sapi::status_matchers sapi::test_main ) diff --git a/sandboxed_api/sandbox2/examples/crc4/BUILD.bazel b/sandboxed_api/sandbox2/examples/crc4/BUILD.bazel index a91e251..60be656 100644 --- a/sandboxed_api/sandbox2/examples/crc4/BUILD.bazel +++ b/sandboxed_api/sandbox2/examples/crc4/BUILD.bazel @@ -34,8 +34,7 @@ cc_binary( "//sandboxed_api/sandbox2:comms", "//sandboxed_api/sandbox2/util:bpf_helper", "//sandboxed_api/sandbox2/util:runfiles", - "@com_google_absl//absl/flags:flag", - "@com_google_absl//absl/flags:parse", + "//sandboxed_api/util:flags", "@com_google_absl//absl/memory", ], ) @@ -49,9 +48,8 @@ cc_binary( "//sandboxed_api/sandbox2:client", "//sandboxed_api/sandbox2:comms", "//sandboxed_api/sandbox2:util", + "//sandboxed_api/util:flags", "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/flags:flag", - "@com_google_absl//absl/flags:parse", ], ) diff --git a/sandboxed_api/sandbox2/examples/crc4/crc4bin.cc b/sandboxed_api/sandbox2/examples/crc4/crc4bin.cc index 0b07336..8a44bf2 100644 --- a/sandboxed_api/sandbox2/examples/crc4/crc4bin.cc +++ b/sandboxed_api/sandbox2/examples/crc4/crc4bin.cc @@ -21,8 +21,7 @@ #include #include -#include "absl/flags/flag.h" -#include "absl/flags/parse.h" +#include "sandboxed_api/util/flag.h" #include "sandboxed_api/sandbox2/client.h" #include "sandboxed_api/sandbox2/comms.h" #include "sandboxed_api/sandbox2/util.h" @@ -47,7 +46,7 @@ static uint32_t ComputeCRC4Impl(const uint8_t* ptr, uint64_t len) { } int main(int argc, char** argv) { - absl::ParseCommandLine(argc, argv); + google::ParseCommandLineFlags(&argc, &argv, false); // Set-up the sandbox2::Client object, using a file descriptor (1023). sandbox2::Comms comms(sandbox2::Comms::kSandbox2ClientCommsFD); diff --git a/sandboxed_api/sandbox2/examples/crc4/crc4sandbox.cc b/sandboxed_api/sandbox2/examples/crc4/crc4sandbox.cc index 508f8da..ccf971b 100644 --- a/sandboxed_api/sandbox2/examples/crc4/crc4sandbox.cc +++ b/sandboxed_api/sandbox2/examples/crc4/crc4sandbox.cc @@ -28,8 +28,7 @@ #include #include -#include "absl/flags/flag.h" -#include "absl/flags/parse.h" +#include "sandboxed_api/util/flag.h" #include "absl/memory/memory.h" #include "sandboxed_api/sandbox2/comms.h" #include "sandboxed_api/sandbox2/executor.h" @@ -42,7 +41,7 @@ #include "sandboxed_api/sandbox2/util/bpf_helper.h" #include "sandboxed_api/sandbox2/util/runfiles.h" -ABSL_FLAG(std::string, input, "", "Input to calculate CRC4 of."); +ABSL_FLAG(string, input, "", "Input to calculate CRC4 of."); ABSL_FLAG(bool, call_syscall_not_allowed, false, "Have sandboxee call clone (violation)."); @@ -83,7 +82,7 @@ bool SandboxedCRC4(sandbox2::Comms* comms, uint32_t* crc4) { } // namespace int main(int argc, char** argv) { - absl::ParseCommandLine(argc, argv); + google::ParseCommandLineFlags(&argc, &argv, true); google::InitGoogleLogging(argv[0]); if (absl::GetFlag(FLAGS_input).empty()) { diff --git a/sandboxed_api/sandbox2/examples/custom_fork/BUILD.bazel b/sandboxed_api/sandbox2/examples/custom_fork/BUILD.bazel index 192a6e0..37554e7 100644 --- a/sandboxed_api/sandbox2/examples/custom_fork/BUILD.bazel +++ b/sandboxed_api/sandbox2/examples/custom_fork/BUILD.bazel @@ -31,9 +31,9 @@ cc_binary( "//sandboxed_api/sandbox2:comms", "//sandboxed_api/sandbox2:forkserver", "//sandboxed_api/sandbox2/util:runfiles", + "//sandboxed_api/util:flags", "//sandboxed_api/util:raw_logging", "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/flags:flag", "@com_google_absl//absl/memory", ], ) @@ -46,7 +46,7 @@ cc_binary( deps = [ "//sandboxed_api/sandbox2:comms", "//sandboxed_api/sandbox2:forkingclient", + "//sandboxed_api/util:flags", "//sandboxed_api/util:raw_logging", - "@com_google_absl//absl/flags:flag", ], ) diff --git a/sandboxed_api/sandbox2/examples/custom_fork/custom_fork_bin.cc b/sandboxed_api/sandbox2/examples/custom_fork/custom_fork_bin.cc index 71917d0..a08ba21 100644 --- a/sandboxed_api/sandbox2/examples/custom_fork/custom_fork_bin.cc +++ b/sandboxed_api/sandbox2/examples/custom_fork/custom_fork_bin.cc @@ -20,7 +20,7 @@ #include -#include "absl/flags/flag.h" +#include "sandboxed_api/util/flag.h" #include "sandboxed_api/sandbox2/comms.h" #include "sandboxed_api/sandbox2/forkingclient.h" #include "sandboxed_api/util/raw_logging.h" diff --git a/sandboxed_api/sandbox2/examples/custom_fork/custom_fork_sandbox.cc b/sandboxed_api/sandbox2/examples/custom_fork/custom_fork_sandbox.cc index 05d23a1..ee76145 100644 --- a/sandboxed_api/sandbox2/examples/custom_fork/custom_fork_sandbox.cc +++ b/sandboxed_api/sandbox2/examples/custom_fork/custom_fork_sandbox.cc @@ -24,7 +24,7 @@ #include #include -#include "absl/flags/flag.h" +#include "sandboxed_api/util/flag.h" #include "absl/memory/memory.h" #include "sandboxed_api/sandbox2/comms.h" #include "sandboxed_api/sandbox2/executor.h" diff --git a/sandboxed_api/sandbox2/examples/static/BUILD.bazel b/sandboxed_api/sandbox2/examples/static/BUILD.bazel index 6804a02..2c03279 100644 --- a/sandboxed_api/sandbox2/examples/static/BUILD.bazel +++ b/sandboxed_api/sandbox2/examples/static/BUILD.bazel @@ -33,7 +33,7 @@ cc_binary( "//sandboxed_api/sandbox2", "//sandboxed_api/sandbox2/util:bpf_helper", "//sandboxed_api/sandbox2/util:runfiles", - "@com_google_absl//absl/flags:flag", + "//sandboxed_api/util:flags", "@com_google_absl//absl/memory", ], ) diff --git a/sandboxed_api/sandbox2/examples/static/static_sandbox.cc b/sandboxed_api/sandbox2/examples/static/static_sandbox.cc index 66b442e..cb442da 100644 --- a/sandboxed_api/sandbox2/examples/static/static_sandbox.cc +++ b/sandboxed_api/sandbox2/examples/static/static_sandbox.cc @@ -28,7 +28,7 @@ #include #include -#include "absl/flags/flag.h" +#include "sandboxed_api/util/flag.h" #include "absl/memory/memory.h" #include "sandboxed_api/sandbox2/executor.h" #include "sandboxed_api/sandbox2/ipc.h" diff --git a/sandboxed_api/sandbox2/examples/tool/BUILD.bazel b/sandboxed_api/sandbox2/examples/tool/BUILD.bazel index a7c8866..9745474 100644 --- a/sandboxed_api/sandbox2/examples/tool/BUILD.bazel +++ b/sandboxed_api/sandbox2/examples/tool/BUILD.bazel @@ -33,7 +33,7 @@ cc_binary( "//sandboxed_api/sandbox2", "//sandboxed_api/sandbox2:util", "//sandboxed_api/sandbox2/util:bpf_helper", - "@com_google_absl//absl/flags:flag", + "//sandboxed_api/util:flags", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", diff --git a/sandboxed_api/sandbox2/examples/tool/sandbox2tool.cc b/sandboxed_api/sandbox2/examples/tool/sandbox2tool.cc index fb89088..f83a3b4 100644 --- a/sandboxed_api/sandbox2/examples/tool/sandbox2tool.cc +++ b/sandboxed_api/sandbox2/examples/tool/sandbox2tool.cc @@ -30,7 +30,7 @@ #include #include -#include "absl/flags/flag.h" +#include "sandboxed_api/util/flag.h" #include "absl/memory/memory.h" #include "absl/strings/str_format.h" #include "absl/strings/str_split.h" @@ -69,9 +69,9 @@ ABSL_FLAG(uint64_t, sandbox2tool_walltime_timeout, 60U, "Wall-time timeout in seconds (if >0)"); ABSL_FLAG(uint64_t, sandbox2tool_file_size_creation_limit, 1024U, "Maximum size of created files"); -ABSL_FLAG(std::string, sandbox2tool_cwd, "/", +ABSL_FLAG(string, sandbox2tool_cwd, "/", "If not empty, chdir to the directory before sandboxed"); -ABSL_FLAG(std::string, sandbox2tool_additional_bind_mounts, "", +ABSL_FLAG(string, sandbox2tool_additional_bind_mounts, "", "If user namespaces are enabled, this option will add additional " "bind mounts. Mounts are separated by comma and can optionally " "specify a target using \"=>\" " diff --git a/sandboxed_api/sandbox2/examples/zlib/BUILD.bazel b/sandboxed_api/sandbox2/examples/zlib/BUILD.bazel index c000d0f..1e17e7e 100644 --- a/sandboxed_api/sandbox2/examples/zlib/BUILD.bazel +++ b/sandboxed_api/sandbox2/examples/zlib/BUILD.bazel @@ -27,7 +27,7 @@ cc_binary( "//sandboxed_api/sandbox2:comms", "//sandboxed_api/sandbox2/util:bpf_helper", "//sandboxed_api/sandbox2/util:runfiles", - "@com_google_absl//absl/flags:flag", + "//sandboxed_api/util:flags", "@com_google_absl//absl/memory", ], ) diff --git a/sandboxed_api/sandbox2/examples/zlib/zpipe_sandbox.cc b/sandboxed_api/sandbox2/examples/zlib/zpipe_sandbox.cc index 28a6db3..7071a9f 100644 --- a/sandboxed_api/sandbox2/examples/zlib/zpipe_sandbox.cc +++ b/sandboxed_api/sandbox2/examples/zlib/zpipe_sandbox.cc @@ -27,7 +27,7 @@ #include #include -#include "absl/flags/flag.h" +#include "sandboxed_api/util/flag.h" #include "absl/memory/memory.h" #include "sandboxed_api/sandbox2/comms.h" #include "sandboxed_api/sandbox2/executor.h" @@ -40,8 +40,8 @@ #include "sandboxed_api/sandbox2/util/bpf_helper.h" #include "sandboxed_api/sandbox2/util/runfiles.h" -ABSL_FLAG(std::string, input, "", "Input file"); -ABSL_FLAG(std::string, output, "", "Output file"); +ABSL_FLAG(string, input, "", "Input file"); +ABSL_FLAG(string, output, "", "Output file"); ABSL_FLAG(bool, decompress, false, "Decompress instead of compress."); namespace { diff --git a/sandboxed_api/sandbox2/monitor.cc b/sandboxed_api/sandbox2/monitor.cc index 7571ba5..c18b657 100644 --- a/sandboxed_api/sandbox2/monitor.cc +++ b/sandboxed_api/sandbox2/monitor.cc @@ -42,7 +42,7 @@ #include #include -#include "absl/flags/flag.h" +#include "sandboxed_api/util/flag.h" #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" @@ -69,7 +69,7 @@ ABSL_FLAG(bool, sandbox2_report_on_sandboxee_timeout, true, "Report sandbox2 sandboxee timeouts"); ABSL_DECLARE_FLAG(bool, sandbox2_danger_danger_permit_all); -ABSL_DECLARE_FLAG(std::string, sandbox2_danger_danger_permit_all_and_log); +ABSL_DECLARE_FLAG(string, sandbox2_danger_danger_permit_all_and_log); namespace sandbox2 { diff --git a/sandboxed_api/sandbox2/policy.cc b/sandboxed_api/sandbox2/policy.cc index bcbdbe2..d1394e9 100644 --- a/sandboxed_api/sandbox2/policy.cc +++ b/sandboxed_api/sandbox2/policy.cc @@ -27,7 +27,7 @@ #include #include -#include "absl/flags/flag.h" +#include "sandboxed_api/util/flag.h" #include "external/org_kernel_libcap/libcap/include/sys/capability.h" #include "sandboxed_api/sandbox2/bpfdisassembler.h" #include "sandboxed_api/sandbox2/comms.h" @@ -37,7 +37,7 @@ ABSL_FLAG(bool, sandbox2_danger_danger_permit_all, false, "Allow all syscalls, useful for testing"); -ABSL_FLAG(std::string, sandbox2_danger_danger_permit_all_and_log, "", +ABSL_FLAG(string, sandbox2_danger_danger_permit_all_and_log, "", "Allow all syscalls and log them into specified file"); namespace sandbox2 { diff --git a/sandboxed_api/sandbox2/stack-trace.cc b/sandboxed_api/sandbox2/stack-trace.cc index 99e87e1..5a795b1 100644 --- a/sandboxed_api/sandbox2/stack-trace.cc +++ b/sandboxed_api/sandbox2/stack-trace.cc @@ -24,7 +24,7 @@ #include #include -#include "absl/flags/flag.h" +#include "sandboxed_api/util/flag.h" #include "absl/memory/memory.h" #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" diff --git a/sandboxed_api/sandbox2/stack-trace.h b/sandboxed_api/sandbox2/stack-trace.h index 3296df9..d28a979 100644 --- a/sandboxed_api/sandbox2/stack-trace.h +++ b/sandboxed_api/sandbox2/stack-trace.h @@ -24,7 +24,7 @@ #include #include -#include "absl/flags/flag.h" +#include "sandboxed_api/util/flag.h" #include "sandboxed_api/sandbox2/mounts.h" #include "sandboxed_api/sandbox2/policy.h" #include "sandboxed_api/sandbox2/regs.h" diff --git a/sandboxed_api/sandbox2/stack-trace_test.cc b/sandboxed_api/sandbox2/stack-trace_test.cc index faf6333..b36e842 100644 --- a/sandboxed_api/sandbox2/stack-trace_test.cc +++ b/sandboxed_api/sandbox2/stack-trace_test.cc @@ -19,7 +19,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "absl/flags/flag.h" +#include "sandboxed_api/util/flag.h" #include "absl/memory/memory.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -48,7 +48,7 @@ namespace { template class TemporaryFlagOverride { public: - using Flag = absl::Flag; + using Flag = T; TemporaryFlagOverride(Flag* flag, T value) : flag_(flag), original_value_(absl::GetFlag(*flag)) { absl::SetFlag(flag, value); diff --git a/sandboxed_api/sandbox2/util/BUILD.bazel b/sandboxed_api/sandbox2/util/BUILD.bazel index 3e27b8e..8e28039 100644 --- a/sandboxed_api/sandbox2/util/BUILD.bazel +++ b/sandboxed_api/sandbox2/util/BUILD.bazel @@ -221,9 +221,9 @@ cc_library( copts = sapi_platform_copts(), deps = [ ":file_base", + "//sandboxed_api/util:flags", "//sandboxed_api/util:raw_logging", "@bazel_tools//tools/cpp/runfiles", - "@com_google_absl//absl/flags:flag", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", ], diff --git a/sandboxed_api/sandbox2/util/CMakeLists.txt b/sandboxed_api/sandbox2/util/CMakeLists.txt index 93470b7..eff68c5 100644 --- a/sandboxed_api/sandbox2/util/CMakeLists.txt +++ b/sandboxed_api/sandbox2/util/CMakeLists.txt @@ -214,10 +214,10 @@ add_library(sandbox2_util_runfiles STATIC ) add_library(sandbox2::runfiles ALIAS sandbox2_util_runfiles) target_link_libraries(sandbox2_util_runfiles PRIVATE - absl::flags absl::str_format absl::strings sandbox2::file_base sapi::base + sapi::flags sapi::raw_logging ) diff --git a/sandboxed_api/sandbox2/util/runfiles.cc b/sandboxed_api/sandbox2/util/runfiles.cc index c55d5b0..3b88db7 100644 --- a/sandboxed_api/sandbox2/util/runfiles.cc +++ b/sandboxed_api/sandbox2/util/runfiles.cc @@ -14,10 +14,10 @@ #include -#include "absl/flags/internal/program_name.h" #include "absl/strings/str_format.h" #include "sandboxed_api/sandbox2/util/path.h" #include "sandboxed_api/sandbox2/util/runfiles.h" +#include "sandboxed_api/util/flag.h" #include "sandboxed_api/util/raw_logging.h" #include "tools/cpp/runfiles/runfiles.h" @@ -28,8 +28,7 @@ namespace sandbox2 { std::string GetDataDependencyFilePath(absl::string_view relative_path) { static Runfiles* runfiles = []() { std::string error; - auto* runfiles = - Runfiles::Create(absl::flags_internal::ProgramInvocationName(), &error); + auto* runfiles = Runfiles::Create(gflags::GetArgv0(), &error); SAPI_RAW_CHECK(runfiles != nullptr, "%s", error); // Setup environment for child processes. diff --git a/sandboxed_api/util/BUILD.bazel b/sandboxed_api/util/BUILD.bazel index f6a115f..5403e16 100644 --- a/sandboxed_api/util/BUILD.bazel +++ b/sandboxed_api/util/BUILD.bazel @@ -115,6 +115,14 @@ cc_test( ], ) +# Compatibility layer for Abseil's flags vs. gFlags +cc_library( + name = "flags", + hdrs = ["flag.h"], + copts = sapi_platform_copts(), + deps = ["@com_github_gflags_gflags//:gflags"], +) + # Small support library emulating verbose logging using Abseil's raw logging # facility. cc_library( diff --git a/sandboxed_api/util/CMakeLists.txt b/sandboxed_api/util/CMakeLists.txt index 2ab3a6c..c923181 100644 --- a/sandboxed_api/util/CMakeLists.txt +++ b/sandboxed_api/util/CMakeLists.txt @@ -81,6 +81,15 @@ target_link_libraries(status_test PRIVATE ) gtest_discover_tests(status_test) +# sandboxed_api/util:flag +add_library(sapi_util_flags STATIC + flag.h +) +add_library(sapi::flags ALIAS sapi_util_flags) +target_link_libraries(sapi_util_flags PUBLIC + gflags +) + # sandboxed_api/util:raw_logging add_library(sapi_util_raw_logging STATIC raw_logging.cc diff --git a/sandboxed_api/util/flag.h b/sandboxed_api/util/flag.h new file mode 100644 index 0000000..4c1131a --- /dev/null +++ b/sandboxed_api/util/flag.h @@ -0,0 +1,49 @@ +// Copyright 2019 Google LLC. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// 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. + +#ifndef SANDBOXED_API_UTIL_FLAG_H_ +#define SANDBOXED_API_UTIL_FLAG_H_ + +#include + +#define ABSL_FLAG(type, name, default_value, help) \ + DEFINE_##type(name, default_value, help) +#define ABSL_RETIRED_FLAG ABSL_FLAG +#define ABSL_DECLARE_FLAG(type, name) DECLARE_##type(name) + +// Internal defines for compatility with gflags and standard integer types. +#define DECLARE_int32_t DECLARE_int32 +#define DECLARE_int64_t DECLARE_int64 +#define DECLARE_uint32_t DECLARE_uint32 +#define DECLARE_uint64_t DECLARE_uint64 +#define DEFINE_int32_t DEFINE_int32 +#define DEFINE_int64_t DEFINE_int64 +#define DEFINE_uint32_t DEFINE_uint32 +#define DEFINE_uint64_t DEFINE_uint64 + +namespace absl { + +template +const T& GetFlag(const T& flag) { + return flag; +} + +template +void SetFlag(T* flag, const T& value) { + *flag = value; +} + +} // namespace absl + +#endif // SANDBOXED_API_UTIL_FLAG_H_