Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 169ee32

Browse files
committed
[fidl] Pass target API level to fidlc
This makes the GN build pass the target Fuchsia API level to fidlc. Currently it relies on the default of HEAD, meaning all FIDL changes are 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.
1 parent b153753 commit 169ee32

File tree

2 files changed

+31
-101
lines changed

2 files changed

+31
-101
lines changed

tools/fuchsia/fidl/fidl_library.gni

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ template("fidl_library") {
2222

2323
assert(defined(invoker.sources), "A FIDL library requires some sources.")
2424

25+
assert(fuchsia_target_api_level != -1,
26+
"Must set a target api level when using FIDL libraries")
27+
2528
library_name = target_name
2629
if (defined(invoker.name)) {
2730
library_name = invoker.name
@@ -85,6 +88,8 @@ template("fidl_library") {
8588
rebase_path(coding_tables, root_build_dir),
8689
"--name",
8790
library_name,
91+
"--available",
92+
"fuchsia:${fuchsia_target_api_level}",
8893
"--sources",
8994
] + rebase_path(sources, root_build_dir)
9095

tools/fuchsia/fidl/gen_response_file.py

Lines changed: 26 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -4,128 +4,53 @@
44
# found in the LICENSE file.
55

66
import argparse
7-
import os
8-
import string
9-
import sys
10-
11-
12-
def read_libraries(libraries_path):
13-
with open(libraries_path) as f:
14-
lines = f.readlines()
15-
return [l.rstrip("\n") for l in lines]
16-
17-
18-
def write_libraries(libraries_path, libraries):
19-
directory = os.path.dirname(libraries_path)
20-
if not os.path.exists(directory):
21-
os.makedirs(directory)
22-
with open(libraries_path, "w+") as f:
23-
for library in libraries:
24-
f.write(library)
25-
f.write("\n")
7+
from pathlib import Path
268

279

2810
def main():
2911
parser = argparse.ArgumentParser(
30-
description="Generate response file for FIDL frontend"
12+
description="Generate response file for FIDL frontend. "
13+
"Arguments not mentioned here are forwarded as is to fidlc."
3114
)
3215
parser.add_argument(
3316
"--out-response-file",
34-
help="The path for the response file to generate",
17+
help="The path for for the response file to generate",
18+
type=Path,
3519
required=True
3620
)
3721
parser.add_argument(
3822
"--out-libraries",
39-
help="The path for the libraries file to generate",
23+
help="The path for for the libraries file to generate",
24+
type=Path,
4025
required=True
4126
)
4227
parser.add_argument(
43-
"--json", help="The path for the JSON file to generate, if any"
44-
)
45-
parser.add_argument(
46-
"--tables", help="The path for the tables file to generate, if any"
47-
)
48-
parser.add_argument(
49-
"--deprecated-fuchsia-only-c-client",
50-
help="The path for the C simple client file to generate, if any"
28+
"--sources", help="List of FIDL source files", nargs="+", required=True
5129
)
52-
parser.add_argument(
53-
"--deprecated-fuchsia-only-c-header",
54-
help="The path for the C header file to generate, if any"
55-
)
56-
parser.add_argument(
57-
"--deprecated-fuchsia-only-c-server",
58-
help="The path for the C simple server file to generate, if any"
59-
)
60-
parser.add_argument(
61-
"--name", help="The name for the generated FIDL library, if any"
62-
)
63-
parser.add_argument(
64-
"--depfile", help="The name for the generated depfile, if any"
65-
)
66-
parser.add_argument("--sources", help="List of FIDL source files", nargs="*")
6730
parser.add_argument(
6831
"--dep-libraries", help="List of dependent libraries", nargs="*"
6932
)
70-
parser.add_argument(
71-
"--experimental-flag", help="List of experimental flags", action="append"
72-
)
73-
args = parser.parse_args()
74-
75-
target_libraries = []
76-
77-
for dep_libraries_path in args.dep_libraries or []:
78-
dep_libraries = read_libraries(dep_libraries_path)
79-
for library in dep_libraries:
80-
if library in target_libraries:
81-
continue
82-
target_libraries.append(library)
83-
84-
target_libraries.append(" ".join(sorted(args.sources)))
85-
write_libraries(args.out_libraries, target_libraries)
86-
87-
response_file = []
88-
89-
if args.json:
90-
response_file.append("--json %s" % args.json)
91-
92-
if args.tables:
93-
response_file.append("--tables %s" % args.tables)
94-
95-
if args.deprecated_fuchsia_only_c_client:
96-
response_file.append(
97-
"--deprecated-fuchsia-only-c-client %s" %
98-
args.deprecated_fuchsia_only_c_client
99-
)
100-
101-
if args.deprecated_fuchsia_only_c_header:
102-
response_file.append(
103-
"--deprecated-fuchsia-only-c-header %s" %
104-
args.deprecated_fuchsia_only_c_header
105-
)
106-
107-
if args.deprecated_fuchsia_only_c_server:
108-
response_file.append(
109-
"--deprecated-fuchsia-only-c-server %s" %
110-
args.deprecated_fuchsia_only_c_server
111-
)
112-
113-
if args.name:
114-
response_file.append("--name %s" % args.name)
115-
116-
if args.depfile:
117-
response_file.append("--depfile %s" % args.depfile)
33+
args, args_to_forward = parser.parse_known_args()
11834

119-
if args.experimental_flag:
120-
for experimental_flag in args.experimental_flag:
121-
response_file.append("--experimental %s" % experimental_flag)
35+
# Each line contains a library's source files separated by spaces.
36+
# We use a dict instead of a set to maintain insertion order.
37+
dep_lines = {}
38+
for path in args.dep_libraries or []:
39+
with open(path) as f:
40+
for line in f:
41+
dep_lines[line.rstrip()] = True
42+
libraries = list(dep_lines)
43+
libraries.append(" ".join(sorted(args.sources)))
12244

123-
response_file.extend(["--files %s" % library for library in target_libraries])
45+
args.out_libraries.parent.mkdir(parents=True, exist_ok=True)
46+
with open(args.out_libraries, "w") as f:
47+
print("\n".join(libraries), file=f)
12448

125-
with open(args.out_response_file, "w+") as f:
126-
f.write(" ".join(response_file))
127-
f.write("\n")
49+
args.out_response_file.parent.mkdir(parents=True, exist_ok=True)
50+
with open(args.out_response_file, "w") as f:
51+
fidlc_args = args_to_forward + ["--files " + line for line in libraries]
52+
print(" ".join(fidlc_args), file=f)
12853

12954

13055
if __name__ == "__main__":
131-
sys.exit(main())
56+
main()

0 commit comments

Comments
 (0)