From ded64b81cac126a8bf5a553593b8ed9c2ecf98e1 Mon Sep 17 00:00:00 2001 From: Mitchell Kember Date: Thu, 8 Jun 2023 10:05:15 -0700 Subject: [PATCH] [fuchsia] Bump the target API level to 12, and pass it to fidlc This bumps the target Fuchsia API level from 11 to 12. It also makes the GN build pass the API level to fidlc. Previously it relied on the fidlc default of HEAD, meaning all FIDL changes were immediately visible when the SDK rolls. This was never the intention: flutter should be targeting a specific API level. This unblocks https://fxrev.dev/864297 which makes the fidlc --available flag required, and which uncovered this problem. I also copied the changes to gen_response_file.py from https://fxrev.dev/865020 to make it forward --available to fidlc. --- tools/fuchsia/fidl/fidl_library.gni | 5 + tools/fuchsia/fidl/gen_response_file.py | 127 +++++------------------- tools/fuchsia/target_api_level | 2 +- 3 files changed, 32 insertions(+), 102 deletions(-) diff --git a/tools/fuchsia/fidl/fidl_library.gni b/tools/fuchsia/fidl/fidl_library.gni index 8069bb669cb2d..a3722c155fe62 100644 --- a/tools/fuchsia/fidl/fidl_library.gni +++ b/tools/fuchsia/fidl/fidl_library.gni @@ -22,6 +22,9 @@ template("fidl_library") { assert(defined(invoker.sources), "A FIDL library requires some sources.") + assert(fuchsia_target_api_level != -1, + "Must set a target api level when using FIDL libraries") + library_name = target_name if (defined(invoker.name)) { library_name = invoker.name @@ -85,6 +88,8 @@ template("fidl_library") { rebase_path(coding_tables, root_build_dir), "--name", library_name, + "--available", + "fuchsia:${fuchsia_target_api_level}", "--sources", ] + rebase_path(sources, root_build_dir) diff --git a/tools/fuchsia/fidl/gen_response_file.py b/tools/fuchsia/fidl/gen_response_file.py index c44f4784b3b96..02752e4acce9e 100755 --- a/tools/fuchsia/fidl/gen_response_file.py +++ b/tools/fuchsia/fidl/gen_response_file.py @@ -4,128 +4,53 @@ # found in the LICENSE file. import argparse -import os -import string -import sys - - -def read_libraries(libraries_path): - with open(libraries_path) as f: - lines = f.readlines() - return [l.rstrip("\n") for l in lines] - - -def write_libraries(libraries_path, libraries): - directory = os.path.dirname(libraries_path) - if not os.path.exists(directory): - os.makedirs(directory) - with open(libraries_path, "w+") as f: - for library in libraries: - f.write(library) - f.write("\n") +from pathlib import Path def main(): parser = argparse.ArgumentParser( - description="Generate response file for FIDL frontend" + description="Generate response file for FIDL frontend. " + "Arguments not mentioned here are forwarded as is to fidlc." ) parser.add_argument( "--out-response-file", - help="The path for the response file to generate", + help="The path for for the response file to generate", + type=Path, required=True ) parser.add_argument( "--out-libraries", - help="The path for the libraries file to generate", + help="The path for for the libraries file to generate", + type=Path, required=True ) parser.add_argument( - "--json", help="The path for the JSON file to generate, if any" - ) - parser.add_argument( - "--tables", help="The path for the tables file to generate, if any" - ) - parser.add_argument( - "--deprecated-fuchsia-only-c-client", - help="The path for the C simple client file to generate, if any" + "--sources", help="List of FIDL source files", nargs="+", required=True ) - parser.add_argument( - "--deprecated-fuchsia-only-c-header", - help="The path for the C header file to generate, if any" - ) - parser.add_argument( - "--deprecated-fuchsia-only-c-server", - help="The path for the C simple server file to generate, if any" - ) - parser.add_argument( - "--name", help="The name for the generated FIDL library, if any" - ) - parser.add_argument( - "--depfile", help="The name for the generated depfile, if any" - ) - parser.add_argument("--sources", help="List of FIDL source files", nargs="*") parser.add_argument( "--dep-libraries", help="List of dependent libraries", nargs="*" ) - parser.add_argument( - "--experimental-flag", help="List of experimental flags", action="append" - ) - args = parser.parse_args() - - target_libraries = [] - - for dep_libraries_path in args.dep_libraries or []: - dep_libraries = read_libraries(dep_libraries_path) - for library in dep_libraries: - if library in target_libraries: - continue - target_libraries.append(library) - - target_libraries.append(" ".join(sorted(args.sources))) - write_libraries(args.out_libraries, target_libraries) - - response_file = [] - - if args.json: - response_file.append("--json %s" % args.json) - - if args.tables: - response_file.append("--tables %s" % args.tables) - - if args.deprecated_fuchsia_only_c_client: - response_file.append( - "--deprecated-fuchsia-only-c-client %s" % - args.deprecated_fuchsia_only_c_client - ) - - if args.deprecated_fuchsia_only_c_header: - response_file.append( - "--deprecated-fuchsia-only-c-header %s" % - args.deprecated_fuchsia_only_c_header - ) - - if args.deprecated_fuchsia_only_c_server: - response_file.append( - "--deprecated-fuchsia-only-c-server %s" % - args.deprecated_fuchsia_only_c_server - ) - - if args.name: - response_file.append("--name %s" % args.name) - - if args.depfile: - response_file.append("--depfile %s" % args.depfile) + args, args_to_forward = parser.parse_known_args() - if args.experimental_flag: - for experimental_flag in args.experimental_flag: - response_file.append("--experimental %s" % experimental_flag) + # Each line contains a library's source files separated by spaces. + # We use a dict instead of a set to maintain insertion order. + dep_lines = {} + for path in args.dep_libraries or []: + with open(path) as f: + for line in f: + dep_lines[line.rstrip()] = True + libraries = list(dep_lines) + libraries.append(" ".join(sorted(args.sources))) - response_file.extend(["--files %s" % library for library in target_libraries]) + args.out_libraries.parent.mkdir(parents=True, exist_ok=True) + with open(args.out_libraries, "w") as f: + print("\n".join(libraries), file=f) - with open(args.out_response_file, "w+") as f: - f.write(" ".join(response_file)) - f.write("\n") + args.out_response_file.parent.mkdir(parents=True, exist_ok=True) + with open(args.out_response_file, "w") as f: + fidlc_args = args_to_forward + ["--files " + line for line in libraries] + print(" ".join(fidlc_args), file=f) if __name__ == "__main__": - sys.exit(main()) + main() diff --git a/tools/fuchsia/target_api_level b/tools/fuchsia/target_api_level index b4de394767536..48082f72f087c 100644 --- a/tools/fuchsia/target_api_level +++ b/tools/fuchsia/target_api_level @@ -1 +1 @@ -11 +12