23 subprocess.check_output(command, stderr=subprocess.STDOUT)
25 except subprocess.CalledProcessError
as e:
26 print(e.output.decode(
"utf-8"))
27 if strategy ==
'remote':
28 joined =
' '.
join(command)
29 print(f
'''Failed to run command remotely: {joined}
31If you're seeing this error on a bot and it doesn't happen locally, then you may
32need to teach the script build/rbe/rewrapper_dart.py what the appropriate input
33and outputs files of the command are. You can see the list of used inputs and
34outputs in the rewrapper invocation above. To reproduce this error locally, try
35forcing a remote build by setting the RBE_exec_strategy=remote environment
46 path = os.path.join(exec_root,
'.dart_tool',
'package_config.json')
47 with open(path,
'r')
as file:
48 return json.load(file)
52def resolve_uri(uri, exec_root, package_config, whole_dir=False):
53 if uri.startswith(
'package:'):
54 match = re.search(
r'package:([^/]*)/(.*)', uri)
55 package_name = match.groups()[0]
56 relative = match.groups()[1]
57 package_data =
next(pkg
for pkg
in package_config[
'packages']
58 if pkg[
'name'] == package_name)
59 package_root = package_data[
'rootUri']
60 package_root = package_root[3:]
61 package_uri = package_data[
'packageUri']
63 uri = package_root +
'/' + package_uri
65 uri = package_root +
'/' + package_uri + relative
73 if uri.startswith(
'dart:'):
75 path = os.path.join(exec_root,
resolve_uri(uri, exec_root, package_config))
76 file = open(path,
'r')
78 for line
in file.readlines():
79 tokens = [token
for token
in re.split(
r'\s+', line)
if token !=
'']
80 if not tokens
or tokens[0]
in [
81 '//',
'///',
'/*',
'*/',
'#!',
'library',
'show'
85 if tokens[0]
in [
'const',
'class',
'enum']:
88 )
and tokens[0] ==
'if' and tokens[1] ==
'(dart.library.io)':
89 tokens = [
'import'] + tokens[2:]
90 if tokens[0]
not in [
'import',
'export',
'part']:
93 raise Exception(f
'Bad import statement: {path}: {line}')
94 if tokens[0] ==
'part' and tokens[1] ==
'of':
96 token = tokens[1].replace(
'"',
'').replace(
"'",
'').replace(
';',
'')
97 if token.startswith(
'dart:'):
100 dirname = os.path.dirname(uri)
101 while token.startswith(
'..'):
103 dirname = os.path.dirname(dirname)
104 token = dirname +
'/' + token
114 unexplored =
set(uris)
116 uri = unexplored.pop()
119 if not uri
in inputs:
129 arg = arg.replace(
'file:///' + exec_root,
'../../')
130 arg = arg.replace(
'file://' + exec_root,
'../../')
132 arg = arg.replace(exec_root,
'../../')
135 if arg.endswith(f
'../../{working_directory}/'):
136 arg = arg.replace(f
'../../{working_directory}/',
'.')
138 arg = arg.replace(f
'../../{working_directory}/',
'')
194 for option
in options:
199 elif option.startswith(
'--')
and arg.startswith(f
'{option}='):
202 elif option[0] ==
'-' and option[1] !=
'-' and arg.startswith(
209 raise Exception(f
'''Unsupported operand in state {state}: {arg}
211You need to recognize the argument/option in the build/rbe/rewrapper_dart.py
212script in order to execute this command remotely on RBE. Read the big comments
213in the file explaining what this script is and how it works. Follow this stack
214trace to find the place to insert the appropriate support.
218 if path.startswith(
'package:'):
221 if path.startswith(
'org-dartlang-kernel-service:///'):
223 path[
len(
'org-dartlang-kernel-service:///'):])
224 if path.startswith(
'org-dartlang-kernel-service://'):
226 path[
len(
'org-dartlang-kernel-service://'):])
228 if path.startswith(
'file:////'):
229 path = path[
len(
'file:///'):]
230 elif path.startswith(
'file://'):
231 path = path[
len(
'file://'):]
232 path = os.path.abspath(path)
234 raise Exception(f
"Path isn't inside exec_root: {path}")
240 if arg ==
'rewrapper' or arg.endswith(
'/rewrapper'):
249 with open(self.
optarg,
'r')
as fp:
250 for line
in fp.readlines():
251 key, value = fp.split(
'=')
252 if key ==
'exec_root':
254 elif key ==
'exec_strategy':
264 env_exec_strategy = os.environ.get(
'RBE_exec_strategy')
267 elif arg.startswith(
'-'):
269 elif arg.endswith(
'/dart'):
272 elif arg.endswith(
'/gen_snapshot')
or arg.endswith(
273 '/gen_snapshot_product'):
290 '--packages',
'-D',
'--snapshot-kind',
291 '--depfile_output_filename',
'--coverage',
292 '--ignore-unrecognized-flags'
295 elif arg
in [
'--deterministic',
'--sound-null-safety']:
297 elif arg ==
'compile':
301 'snapshots/dartdev.dart.snapshot')))
305 elif arg ==
'../../pkg/compiler/lib/src/dart2js.dart':
308 elif arg ==
'gen/utils/compiler/dart2js.dart.dill':
311 elif arg ==
'../../pkg/dev_compiler/bin/dartdevc.dart':
314 elif arg ==
'gen/utils/ddc/dartdevc.dart.dill':
317 elif arg ==
'gen/utils/dartanalyzer/dartanalyzer.dart.dill':
320 elif arg ==
'gen/utils/analysis_server/analysis_server.dart.dill':
323 elif arg ==
'../../pkg/front_end/tool/_fasta/compile_platform.dart':
326 elif arg ==
'../../utils/compiler/create_snapshot_entry.dart':
332 elif arg ==
'../../utils/bazel/kernel_worker.dart':
335 elif arg ==
'../../pkg/vm/bin/gen_kernel.dart':
338 elif arg ==
'gen/utils/kernel-service/frontend_server.dart.dill':
341 elif arg ==
'gen/utils/dtd/generate_dtd_snapshot.dart.dill':
344 elif arg ==
'gen/utils/dds/generate_dds_snapshot.dart.dill':
347 elif arg ==
'gen/utils/bazel/kernel_worker.dart.dill':
350 elif arg ==
'gen/utils/dartdev/generate_dartdev_snapshot.dart.dill':
353 elif arg ==
'gen/utils/gen_kernel/bootstrap_gen_kernel.dill':
356 elif arg ==
'gen/utils/kernel-service/kernel-service_snapshot.dart.dill':
361 'vm_platform_strong.dill')))
373 'snapshots/dart2js.dart.snapshot')))
385 elif self.
get_option([
'--platform-binaries']):
388 os.path.join(self.
optarg,
'dart2js_platform.dill')))
390 '--invoker',
'--packages',
'--libraries-spec',
391 '--snapshot-kind',
'--depfile_output_filename',
392 '--coverage',
'--ignore-unrecognized-flags'
403 elif not arg.startswith(
'-'):
420 '--multi-root-scheme',
'--multi-root-output-path',
425 '--canary',
'--no-summarize',
'--sound-null-safety',
426 '--no-sound-null-safety'
429 elif not arg.startswith(
'-'):
430 if arg.endswith(
'.dart'):
440 if arg
in [
'--help']:
453 self.
rebase(os.path.join(self.
optarg,
'compiler_api.dart')))
457 os.path.join(self.
optarg,
'src/io/mapped_file.dart')))
462 compile_platform_args = []
463 single_root_scheme =
None
464 single_root_base =
None
468 single_root_scheme = self.
optarg
470 single_root_base = self.
optarg
472 if 1 <
len(single_root_base)
and single_root_base[-1] ==
'/':
473 single_root_base = single_root_base[:-1]
483 elif not arg.startswith(
'-'):
484 if len(compile_platform_args) == 0:
486 elif len(compile_platform_args) == 1:
488 if sdk.startswith(f
'{single_root_scheme}:///'):
489 sdk = sdk[
len(f
'{single_root_scheme}:///'):]
490 sdk = os.path.join(single_root_base, sdk)
491 if sdk.endswith(
'libraries.json'):
492 sdk = os.path.dirname(sdk)
494 elif len(compile_platform_args) == 2:
496 elif len(compile_platform_args) == 3:
499 elif len(compile_platform_args) == 4:
502 if arg != compile_platform_args[2]:
506 compile_platform_args.append(arg)
515 elif arg
in [
'--no-git-hash']:
530 [
'--packages-file',
'--target',
'--dart-sdk-summary']):
534 '--sound-null-safety',
535 '--no-sound-null-safety',
549 '--packages',
'-D',
'--filesystem-root',
550 '--filesystem-scheme'
553 elif arg
in [
'--no-aot',
'--no-embed-sources']:
555 elif not arg.startswith(
'-'):
572 '--no-embed-sources',
573 '--no-link-platform',
579 elif not arg.startswith(
'-'):
599 elif arg
in [
'--train']:
601 elif not arg.startswith(
'-'):
609 if arg
in [
'--train']:
617 if arg
in [
'--help']:
625 if arg
in [
'--help']:
638 '--sound-null-safety',
'--no-sound-null-safety',
648 if arg
in [
'--help']:
659 '--vm_snapshot_data',
660 '--vm_snapshot_instructions',
661 '--isolate_snapshot_data',
662 '--isolate_snapshot_instructions',
667 '--snapshot_kind',
'--snapshot-kind',
'--coverage',
668 '--ignore-unrecognized-flags'
672 '--sound-null-safety',
677 elif not arg.startswith(
'-'):
688 for i
in range(
len(argv)):
689 if argv[i] ==
'--' and rewrapper_end == 0:
690 rewrapper_end = i + 1
691 if not '/' in argv[i + 1]:
692 argv[i + 1] =
'./' + argv[i + 1]
697 if rewrapper.exec_root ==
None:
698 raise Exception(
'No rewrapper --exec_root was specified')
700 if not rewrapper.outputs:
701 raise Exception(
'No output files were recognized')
704 if rewrapper.no_remote:
710 if not rewrapper.depfiles:
711 rewrapper.depfiles = [output +
'.d' for output
in rewrapper.outputs]
712 output_files = rewrapper.outputs + rewrapper.depfiles
713 inputs =
find_inputs(rewrapper.entry_points, rewrapper.exec_root,
716 resolve_uri(uri, rewrapper.exec_root, package_config, whole_dir=
True)
718 paths.add(os.path.join(
'.dart_tool',
'package_config.json'))
719 for path
in rewrapper.extra_paths:
722 working_directory = rewrapper.rebase(
'.')
723 if not any([path.startswith(working_directory)
for path
in paths]):
724 paths.add(rewrapper.rebase(
'build.ninja.stamp'))
730 command.append(
'--labels=type=tool')
731 command.append(
'--inputs=' +
','.
join(paths))
732 command.append(
'--output_files=' +
','.
join(output_files))
738 command += argv[2:rewrapper_end] + [
740 for arg
in argv[rewrapper_end:]
748 for depfile
in rewrapper.depfiles:
751 with open(os.path.join(rewrapper.exec_root, depfile),
'r')
as file:
752 lines = file.readlines()
754 line.replace(
'/b/f/w', rewrapper.exec_root)
for line
in lines
756 with open(os.path.join(rewrapper.exec_root, depfile),
'w')
as file:
757 file.writelines(lines)
758 except FileNotFoundError:
764if __name__ ==
'__main__':
765 sys.exit(
main(sys.argv))
static float next(float f)
def unsupported(self, state, arg)
def parse_rewrapper(self)
def parse_frontend_server(self)
def parse_kernel_service_snapshot(self)
def parse_generate_dtd_snapshot(self)
def parse_create_snapshot_entry(self)
def parse_dartanalyzer(self)
def parse_kernel_worker(self)
def parse_compile_platform(self)
def parse_gen_snapshot(self)
def parse_generate_dds_snapshot(self)
def parse_generate_dartdev_snapshot(self)
def parse_analysis_server(self)
def parse_gen_kernel(self)
def parse_bootstrap_gen_kernel(self)
def get_option(self, options)
static void append(char **dst, size_t *count, const char *src, size_t n)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
def resolve_uri(uri, exec_root, package_config, whole_dir=False)
def run_command(command, strategy)
def list_imports(uri, exec_root, package_config)
def find_inputs(uris, exec_root, package_config)
def rewrite_absolute(arg, exec_root, working_directory)
def load_package_config(exec_root)
def print(*args, **kwargs)
SIT bool any(const Vec< 1, T > &x)
static SkString join(const CommandLineFlags::StringArray &)