Skip to content

Commit e4c2fe4

Browse files
cblichmanncopybara-github
authored andcommitted
Bazel: Simplify sapi.bzl and always pass api_version
Follow-up to a previous CMake-only change to pass api_version to Bazel as well. Also removes generator version checks, as we're always at version >= 2. PiperOrigin-RevId: 907591256 Change-Id: I09874c5b2523917fbbe546323835326102f27726
1 parent 2c6a392 commit e4c2fe4

2 files changed

Lines changed: 18 additions & 50 deletions

File tree

sandboxed_api/bazel/sapi.bzl

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ def make_exec_label(label):
5353
executable = True,
5454
)
5555

56-
# buildifier: disable=function-docstring
57-
def select_generator(ctx):
58-
return ctx.executable._generator_v2
59-
6056
def sort_deps(deps):
6157
"""Sorts a list of dependencies.
6258
@@ -151,8 +147,6 @@ def _sapi_interface_impl(ctx):
151147
fail("generator_version=1 is no longer supported.")
152148

153149
cpp_toolchain = find_cpp_toolchain(ctx)
154-
generator = select_generator(ctx)
155-
use_clang_generator = ctx.attr.generator_version >= 2
156150

157151
# TODO(szwl): warn if input_files is not set and we didn't find anything
158152
input_files_paths = []
@@ -166,11 +160,10 @@ def _sapi_interface_impl(ctx):
166160
append_arg(args, "--sapi_embed_name", ctx.attr.embed_name)
167161
append_arg(args, "--sapi_functions", ",".join(ctx.attr.functions))
168162
append_arg(args, "--sapi_ns", ctx.attr.namespace)
163+
append_arg(args, "--sapi_api_version", str(ctx.attr.api_version))
164+
append_arg(args, "--sapi_sandbox_mode", ctx.attr.sandbox_mode)
169165

170-
if use_clang_generator:
171-
append_arg(args, "--sapi_sandbox_mode", ctx.attr.sandbox_mode)
172-
173-
if use_clang_generator and ctx.outputs.sandboxee_src_out:
166+
if ctx.outputs.sandboxee_src_out:
174167
append_arg(args, "--sapi_sandboxee_src_out", ctx.outputs.sandboxee_src_out.path)
175168
outs.append(ctx.outputs.sandboxee_src_out)
176169

@@ -204,30 +197,22 @@ def _sapi_interface_impl(ctx):
204197
# Try to find files automatically
205198
input_files_paths += _lib_direct_headers(ctx.attr.lib, cc_ctx)
206199

207-
if use_clang_generator:
208-
input_files += cpp_toolchain.all_files.to_list()
209-
extra_flags += _clang_generator_flags(ctx, cc_ctx, cpp_toolchain, input_files_paths)
210-
else:
211-
append_all(extra_flags, "-D", cc_ctx.defines.to_list())
212-
append_all(extra_flags, "-isystem", cc_ctx.system_includes.to_list())
213-
append_all(extra_flags, "-iquote", cc_ctx.quote_includes.to_list())
214-
append_all(extra_flags, "-I", cc_ctx.includes.to_list())
200+
input_files += cpp_toolchain.all_files.to_list()
201+
extra_flags += _clang_generator_flags(ctx, cc_ctx, cpp_toolchain, input_files_paths)
215202

216-
if use_clang_generator:
217-
args += extra_flags + input_files_paths
218-
else:
219-
append_arg(args, "--sapi_in", ",".join(input_files_paths))
220-
args += ["--"] + extra_flags
203+
args += extra_flags + input_files_paths
221204

222-
progress_msg = ("Generating {} from {} header files." +
223-
"").format(ctx.outputs.out.short_path, len(input_files_paths))
205+
progress_msg = "Generating {} from {} header files.".format(
206+
ctx.outputs.out.short_path,
207+
len(input_files_paths),
208+
)
224209
ctx.actions.run(
225210
inputs = input_files,
226211
outputs = outs,
227212
arguments = args,
228213
mnemonic = "SapiInterfaceGen",
229214
progress_message = progress_msg,
230-
executable = generator,
215+
executable = ctx.executable._generator_v2,
231216
)
232217

233218
# Build rule that generates SAPI interface.

sandboxed_api/tools/clang_generator/generator_tool.cc

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,6 @@ absl::NoDestructor<llvm::cl::list<std::string>> g_sapi_functions(
7272
"empty, generates a SAPI for all functions found."),
7373
llvm::cl::cat(*g_tool_category));
7474

75-
ABSL_DEPRECATED("Pass the input files directly to the tool.")
76-
absl::NoDestructor<llvm::cl::list<std::string>> g_sapi_in(
77-
"sapi_in", llvm::cl::CommaSeparated,
78-
llvm::cl::desc("List of input files to analyze (DEPRECATED)"),
79-
llvm::cl::cat(*g_tool_category));
80-
81-
ABSL_DEPRECATED("Ignored for compatibility.")
82-
absl::NoDestructor<llvm::cl::opt<std::string>> g_sapi_isystem(
83-
"sapi_isystem",
84-
llvm::cl::desc(
85-
"Parameter file with extra system include paths (DEPRECATED)"),
86-
llvm::cl::cat(*g_tool_category));
87-
8875
absl::NoDestructor<llvm::cl::opt<bool>> g_sapi_limit_scan_depth(
8976
"sapi_limit_scan_depth",
9077
llvm::cl::desc("Whether to only scan for functions "
@@ -204,31 +191,27 @@ absl::Status GeneratorMain(int argc, char* argv[]) {
204191
OptionsParser& opt_parser = expected_opt_parser.get();
205192

206193
std::vector<std::string> sources = opt_parser.getSourcePathList();
207-
for (const auto& sapi_in : *g_sapi_in) { // NOLINT
208-
sources.push_back(sapi_in);
209-
}
210194
if (sources.empty()) {
211195
return absl::InvalidArgumentError("Error: No input files.");
212196
}
213197

214198
auto options = GeneratorOptionsFromFlags(sources);
215199

216-
if (options.api_version != 1) {
200+
if (options.api_version < 1) {
217201
return absl::InvalidArgumentError(
218-
"Error: Only API version 1 is currently defined.");
202+
"Error: API versions must be 1 or greater.");
203+
}
204+
if (options.api_version > 1) {
205+
absl::FPrintF(
206+
stderr,
207+
"Warning: API versions greater than 1 are currently experimental.\n");
219208
}
220209

221210
std::unique_ptr<clang::tooling::CompilationDatabase> db =
222211
FromCxxAjustedCompileCommands(
223212
NonOwningCompileCommands(opt_parser.getCompilations()));
224213
clang::tooling::ClangTool tool(*db, sources);
225214

226-
if (!g_sapi_isystem->empty()) { // NOLINT(deprecated)
227-
absl::FPrintF(
228-
stderr,
229-
"Note: Ignoring deprecated command-line option: sapi_isystem\n");
230-
}
231-
232215
if (options.symbol_list_gen) {
233216
SymbolListEmitter emitter;
234217
if (int result = tool.run(

0 commit comments

Comments
 (0)