Generate an external makefile to do a set of rules. Arguments: rules: the list of rules to include output_dir: path containing project and gyp files spec: project specification data sources: set of sources known options: global generator options actions_to_ad
(rules, output_dir, spec, sources, options, actions_to_add)
| 654 | |
| 655 | |
| 656 | def _GenerateExternalRules(rules, output_dir, spec, sources, options, actions_to_add): |
| 657 | """Generate an external makefile to do a set of rules. |
| 658 | |
| 659 | Arguments: |
| 660 | rules: the list of rules to include |
| 661 | output_dir: path containing project and gyp files |
| 662 | spec: project specification data |
| 663 | sources: set of sources known |
| 664 | options: global generator options |
| 665 | actions_to_add: The list of actions we will add to. |
| 666 | """ |
| 667 | filename = "{}_rules{}.mk".format(spec["target_name"], options.suffix) |
| 668 | mk_file = gyp.common.WriteOnDiff(os.path.join(output_dir, filename)) |
| 669 | # Find cygwin style versions of some paths. |
| 670 | mk_file.write('OutDirCygwin:=$(shell cygpath -u "$(OutDir)")\n') |
| 671 | mk_file.write('IntDirCygwin:=$(shell cygpath -u "$(IntDir)")\n') |
| 672 | # Gather stuff needed to emit all: target. |
| 673 | all_inputs = OrderedSet() |
| 674 | all_outputs = OrderedSet() |
| 675 | all_output_dirs = OrderedSet() |
| 676 | first_outputs = [] |
| 677 | for rule in rules: |
| 678 | trigger_files = _FindRuleTriggerFiles(rule, sources) |
| 679 | for tf in trigger_files: |
| 680 | inputs, outputs = _RuleInputsAndOutputs(rule, tf) |
| 681 | all_inputs.update(OrderedSet(inputs)) |
| 682 | all_outputs.update(OrderedSet(outputs)) |
| 683 | # Only use one target from each rule as the dependency for |
| 684 | # 'all' so we don't try to build each rule multiple times. |
| 685 | first_outputs.append(next(iter(outputs))) |
| 686 | # Get the unique output directories for this rule. |
| 687 | output_dirs = [os.path.split(i)[0] for i in outputs] |
| 688 | for od in output_dirs: |
| 689 | all_output_dirs.add(od) |
| 690 | first_outputs_cyg = [_Cygwinify(i) for i in first_outputs] |
| 691 | # Write out all: target, including mkdir for each output directory. |
| 692 | mk_file.write("all: %s\n" % " ".join(first_outputs_cyg)) |
| 693 | for od in all_output_dirs: |
| 694 | if od: |
| 695 | mk_file.write('\tmkdir -p `cygpath -u "%s"`\n' % od) |
| 696 | mk_file.write("\n") |
| 697 | # Define how each output is generated. |
| 698 | for rule in rules: |
| 699 | trigger_files = _FindRuleTriggerFiles(rule, sources) |
| 700 | for tf in trigger_files: |
| 701 | # Get all the inputs and outputs for this rule for this trigger file. |
| 702 | inputs, outputs = _RuleInputsAndOutputs(rule, tf) |
| 703 | inputs = [_Cygwinify(i) for i in inputs] |
| 704 | outputs = [_Cygwinify(i) for i in outputs] |
| 705 | # Prepare the command line for this rule. |
| 706 | cmd = [_RuleExpandPath(c, tf) for c in rule["action"]] |
| 707 | cmd = ['"%s"' % i for i in cmd] |
| 708 | cmd = " ".join(cmd) |
| 709 | # Add it to the makefile. |
| 710 | mk_file.write("{}: {}\n".format(" ".join(outputs), " ".join(inputs))) |
| 711 | mk_file.write("\t%s\n\n" % cmd) |
| 712 | # Close up the file. |
| 713 | mk_file.close() |
no test coverage detected