Skip to content

Commit 5a86e0f

Browse files
cblichmanncopybara-github
authored andcommitted
Sandboxed API: Pass the api_version to the clang tool
This change introduces a new command-line flag `--sapi_api_version` to the clang tool. The flag defaults to 1, and currently, only API version 1 is supported. PiperOrigin-RevId: 900753148 Change-Id: If6e6469bf21a78823671707a193b4f4662d0b345
1 parent d45b838 commit 5a86e0f

4 files changed

Lines changed: 16 additions & 6 deletions

File tree

cmake/SapiBuildDefs.cmake

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ function(add_sapi_library)
9999
"${_sapi_one_value}" "${_sapi_multi_value}")
100100
set(_sapi_NAME "${ARGV0}")
101101

102-
if(_sapi_API_VERSION AND NOT _sapi_API_VERSION VERSION_EQUAL "1")
103-
message(FATAL_ERROR "API_VERSION \"1\" is the only one defined right now")
104-
endif()
105-
106102
if (_sapi_GENERATOR_VERSION AND (_sapi_GENERATOR_VERSION VERSION_LESS "1" OR _sapi_GENERATOR_VERSION VERSION_GREATER "3"))
107103
message(FATAL_ERROR "GENERATOR_VERSION must be \"1\", \"2\" or \"3\"")
108104
endif()
@@ -192,7 +188,8 @@ function(add_sapi_library)
192188
"--sapi_functions=${_sapi_funcs}"
193189
"--sapi_ns=${_sapi_NAMESPACE}"
194190
)
195-
if(_sapi_use_generator_version VERSION_EQUAL "2" OR _sapi_use_generator_version VERSION_EQUAL "3")
191+
if(_sapi_use_generator_version VERSION_GREATER_EQUAL "2")
192+
list(APPEND _sapi_generator_args "--sapi_api_version=${_sapi_API_VERSION}")
196193
if (_sapi_use_generator_version VERSION_EQUAL "3")
197194
list(APPEND _sapi_generator_args
198195
"--sapi_sandboxee_src_out=${_sapi_gen_sandboxee_src}"

sandboxed_api/bazel/sapi.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ sapi_interface = rule(
262262
"limit_scan_depth": attr.bool(default = False),
263263
"api_version": attr.int(
264264
default = 1,
265-
values = [1], # Only a single version is defined right now
266265
),
267266
"generator_version": attr.int(
268267
default = 2, # Note: always set by sapi_library

sandboxed_api/tools/clang_generator/generator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct GeneratorOptions {
7474

7575
bool has_sandboxee_src_out() const { return !sandboxee_src_out.empty(); }
7676

77+
int api_version = 1;
7778
absl::flat_hash_set<std::string> function_names;
7879
absl::flat_hash_set<std::string> library_headers;
7980
absl::flat_hash_set<std::string> in_files;

sandboxed_api/tools/clang_generator/generator_tool.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ absl::NoDestructor<llvm::cl::extrahelp> g_extra_help(
5151
"Report bugs to <https://github.com/google/sandboxed-api/issues>\n");
5252

5353
// Command line options
54+
absl::NoDestructor<llvm::cl::opt<int>> g_sapi_api_version(
55+
"sapi_api_version", llvm::cl::init(1),
56+
llvm::cl::desc(
57+
"The API version of the Sandboxed API library. Currently only "
58+
"version 1 is supported."),
59+
llvm::cl::cat(*g_tool_category));
60+
5461
absl::NoDestructor<llvm::cl::opt<std::string>> g_sapi_embed_dir(
5562
"sapi_embed_dir", llvm::cl::desc("Directory with embedded includes"),
5663
llvm::cl::cat(*g_tool_category));
@@ -161,6 +168,7 @@ GeneratorOptions GeneratorOptionsFromFlags(
161168
const std::vector<std::string>& sources) {
162169
GeneratorOptions options;
163170
options.work_dir = file_util::fileops::GetCWD();
171+
options.api_version = *g_sapi_api_version;
164172
options.set_function_names(*g_sapi_functions);
165173
options.set_library_headers(*g_library_headers);
166174
for (const auto& input : sources) {
@@ -205,6 +213,11 @@ absl::Status GeneratorMain(int argc, char* argv[]) {
205213

206214
auto options = GeneratorOptionsFromFlags(sources);
207215

216+
if (options.api_version != 1) {
217+
return absl::InvalidArgumentError(
218+
"Error: Only API version 1 is currently defined.");
219+
}
220+
208221
std::unique_ptr<clang::tooling::CompilationDatabase> db =
209222
FromCxxAjustedCompileCommands(
210223
NonOwningCompileCommands(opt_parser.getCompilations()));

0 commit comments

Comments
 (0)