680
681
682
683 rewrapper_end = 0
684 for i in range(len(argv)):
685 if argv[i] == '--' and rewrapper_end == 0:
686 rewrapper_end = i + 1
687 if not '/' in argv[i + 1]:
688 argv[i + 1] = './' + argv[i + 1]
689 break
690
691 rewrapper = Rewrapper(argv)
692
693 if rewrapper.exec_root == None:
694 raise Exception('No rewrapper --exec_root was specified')
695
696 if not rewrapper.outputs:
697 raise Exception('No output files were recognized')
698
699
700 if rewrapper.no_remote:
701 run_command(argv[rewrapper_end:], 'local')
702 return 0
703
704
705 package_config = load_package_config(rewrapper.exec_root)
706 if not rewrapper.depfiles:
707 rewrapper.depfiles = [output + '.d' for output in rewrapper.outputs]
708 output_files = rewrapper.outputs + rewrapper.depfiles
709 inputs = find_inputs(rewrapper.entry_points, rewrapper.exec_root,
710 package_config)
711 paths = set(
712 resolve_uri(uri, rewrapper.exec_root, package_config, whole_dir=True)
713 for uri in inputs)
714 paths.add(os.path.join('.dart_tool', 'package_config.json'))
715 for path in rewrapper.extra_paths:
716 paths.add(path)
717
718 working_directory = rewrapper.rebase('.')
719 if not any([path.startswith(working_directory) for path in paths]):
720 paths.add(rewrapper.rebase('build.ninja.stamp'))
721 paths = list(paths)
722 paths.sort()
723
724
725 command = [argv[1]]
726 command.append('--labels=type=tool')
727 command.append('--inputs=' + ','.join(paths))
728 command.append('--output_files=' + ','.join(output_files))
729
730
731
732
733
734 command += argv[2:rewrapper_end] + [
735 rewrite_absolute(arg, rewrapper.exec_root, working_directory)
736 for arg in argv[rewrapper_end:]
737 ]
738
739
740 run_command(command, rewrapper.exec_strategy)
741
742
743
744 for depfile in rewrapper.depfiles:
745 lines = []
746 try:
747 with open(os.path.join(rewrapper.exec_root, depfile), 'r') as file:
748 lines = file.readlines()
749 lines = [
750 line.replace('/b/f/w', rewrapper.exec_root) for line in lines
751 ]
752 with open(os.path.join(rewrapper.exec_root, depfile), 'w') as file:
753 file.writelines(lines)
754 except FileNotFoundError:
755 pass
756
757 return 0
758
759