Flutter Engine
The Flutter Engine
Functions
gn_dart_compile_exe Namespace Reference

Functions

def parse_args (argv)
 
def run_command (command)
 
def main (argv)
 

Function Documentation

◆ main()

def gn_dart_compile_exe.main (   argv)

Definition at line 68 of file gn_dart_compile_exe.py.

68def main(argv):
69 args = parse_args(argv[1:])
70
71 # Unless the path is absolute, this script is designed to run binaries
72 # produced by the current build, which is the current working directory when
73 # this script is run.
74 prebuilt_sdk = os.path.abspath(args.dart_sdk)
75
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)
79 return 1
80
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)
84 return 1
85
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)
90 return 1
91
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)
96 return 1
97
98 # Compile the executable.
99 ok = run_command([
100 dart_binary,
101 "compile",
102 "exe",
103 "--packages",
104 args.packages,
105 f"-Dsdk_hash={args.sdk_hash}",
106 "-o",
107 args.output,
108 args.entry_point,
109 ])
110 if not ok:
111 return 1
112
113 # Collect dependencies by using gen_kernel.
114 with TemporaryDirectory() as tmpdir:
115 output_dill = os.path.join(tmpdir, "output.dill")
116 ok = run_command([
117 dartaotruntime_binary,
118 gen_kernel_snapshot,
119 "--platform",
120 platform_dill,
121 "--packages",
122 args.packages,
123 "--depfile",
124 args.depfile,
125 "-o",
126 output_dill,
127 args.entry_point,
128 ])
129 if not ok:
130 return 1
131
132 # Fix generated depfile to refer to the output file name instead
133 # of referring to the temporary dill file we have generated.
134 with open(args.depfile, "r") as f:
135 content = f.read()
136 (target_name, deps) = content.split(": ", 1)
137 if target_name != output_dill:
138 print(
139 "ERROR: Something is wrong with generated depfile: expected {output_dill} as target, but got {target_name}"
140 )
141 return 1
142 with open(args.depfile, "w") as f:
143 f.write(args.output)
144 f.write(": ")
145 f.write(deps)
146
147 return 0
148
149
def print(*args, **kwargs)
Definition: run_tests.py:49
static void parse_args(int argc, char *argv[], Args *args)
Definition: skqp_main.cpp:97

◆ parse_args()

def gn_dart_compile_exe.parse_args (   argv)

Definition at line 28 of file gn_dart_compile_exe.py.

28def parse_args(argv):
29 parser = argparse.ArgumentParser()
30 parser.add_argument("--dart-sdk",
31 required=True,
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",
35 required=True,
36 help="Dart entry point to precompile")
37 parser.add_argument("--output",
38 required=True,
39 help="Path to resulting executable ")
40 parser.add_argument("--packages",
41 required=True,
42 help="Path to package config file")
43 parser.add_argument("--depfile",
44 required=True,
45 help="Path to depfile to write")
46 return parser.parse_args(argv)
47
48
49# Run a command, swallowing the output unless there is an error.

◆ run_command()

def gn_dart_compile_exe.run_command (   command)

Definition at line 50 of file gn_dart_compile_exe.py.

50def run_command(command):
51 try:
52 subprocess.check_output(command, stderr=subprocess.STDOUT)
53 return True
54 except subprocess.CalledProcessError as e:
55 print("Command failed: " + " ".join(command) + "\n" + "output: " +
56 _decode(e.output))
57 return False
58 except OSError as e:
59 print("Command failed: " + " ".join(command) + "\n" + "output: " +
60 _decode(e.strerror))
61 return False
62
63
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741