5"""Helper script for GN to run `dart compile exe` and produce a depfile.
8 python3 gn_dart_compile_exe.py \
9 --dart-binary <path to dart binary> \
10 --entry-point <path to dart entry point> \
11 --output <path to resulting executable> \
12 --sdk-hash <SDK hash> \
13 --packages <path to package config file> \
14 --depfile <path to depfile to write>
16This is workaround
for `dart compile exe`
not supporting --depfile option
17in the current version of prebuilt SDK. Once we roll
in a new version
18of checked
in SDK we can remove this helper.
25from tempfile import TemporaryDirectory
29 parser = argparse.ArgumentParser()
30 parser.add_argument("--dart-sdk",
32 help=
"Path to the prebuilt Dart SDK")
33 parser.add_argument(
"--sdk-hash", required=
True, help=
"SDK hash")
34 parser.add_argument(
"--entry-point",
36 help=
"Dart entry point to precompile")
37 parser.add_argument(
"--output",
39 help=
"Path to resulting executable ")
40 parser.add_argument(
"--packages",
42 help=
"Path to package config file")
43 parser.add_argument(
"--depfile",
45 help=
"Path to depfile to write")
46 return parser.parse_args(argv)
52 subprocess.check_output(command, stderr=subprocess.STDOUT)
54 except subprocess.CalledProcessError
as e:
55 print(
"Command failed: " +
" ".
join(command) +
"\n" +
"output: " +
59 print(
"Command failed: " +
" ".
join(command) +
"\n" +
"output: " +
65 return bytes.decode(
"utf-8")
74 prebuilt_sdk = os.path.abspath(args.dart_sdk)
76 dart_binary = os.path.join(prebuilt_sdk,
"bin",
"dart")
77 if not os.path.isfile(dart_binary):
78 print(
"Binary not found: " + dart_binary)
81 dartaotruntime_binary = os.path.join(prebuilt_sdk,
"bin",
"dartaotruntime")
82 if not os.path.isfile(dartaotruntime_binary):
83 print(
"Binary not found: " + dartaotruntime_binary)
86 gen_kernel_snapshot = os.path.join(prebuilt_sdk,
"bin",
"snapshots",
87 "gen_kernel_aot.dart.snapshot")
88 if not os.path.isfile(gen_kernel_snapshot):
89 print(
"Binary not found: " + gen_kernel_snapshot)
92 platform_dill = os.path.join(prebuilt_sdk,
"lib",
"_internal",
93 "vm_platform_strong.dill")
94 if not os.path.isfile(platform_dill):
95 print(
"Binary not found: " + platform_dill)
105 f
"-Dsdk_hash={args.sdk_hash}",
114 with TemporaryDirectory()
as tmpdir:
115 output_dill = os.path.join(tmpdir,
"output.dill")
117 dartaotruntime_binary,
134 with open(args.depfile,
"r")
as f:
136 (target_name, deps) = content.split(
": ", 1)
137 if target_name != output_dill:
139 "ERROR: Something is wrong with generated depfile: expected {output_dill} as target, but got {target_name}"
142 with open(args.depfile,
"w")
as f:
150if __name__ ==
"__main__":
151 sys.exit(
main(sys.argv))
def print(*args, **kwargs)
static SkString join(const CommandLineFlags::StringArray &)