| OLD | NEW |
| 1 # Copyright (c) 2012 Google Inc. All rights reserved. | 1 # Copyright (c) 2012 Google Inc. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # Notes: | 5 # Notes: |
| 6 # | 6 # |
| 7 # This is all roughly based on the Makefile system used by the Linux | 7 # This is all roughly based on the Makefile system used by the Linux |
| 8 # kernel, but is a non-recursive make -- we put the entire dependency | 8 # kernel, but is a non-recursive make -- we put the entire dependency |
| 9 # graph in front of make and let it figure it out. | 9 # graph in front of make and let it figure it out. |
| 10 # | 10 # |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 def QuoteIfNecessary(string): | 591 def QuoteIfNecessary(string): |
| 592 """TODO: Should this ideally be replaced with one or more of the above | 592 """TODO: Should this ideally be replaced with one or more of the above |
| 593 functions?""" | 593 functions?""" |
| 594 if '"' in string: | 594 if '"' in string: |
| 595 string = '"' + string.replace('"', '\\"') + '"' | 595 string = '"' + string.replace('"', '\\"') + '"' |
| 596 return string | 596 return string |
| 597 | 597 |
| 598 | 598 |
| 599 def StringToMakefileVariable(string): | 599 def StringToMakefileVariable(string): |
| 600 """Convert a string to a value that is acceptable as a make variable name.""" | 600 """Convert a string to a value that is acceptable as a make variable name.""" |
| 601 # TODO: replace other metacharacters that we encounter. | 601 return re.sub('[^a-zA-Z0-9_]', '_', string) |
| 602 return re.sub('[ {}$]', '_', string) | |
| 603 | 602 |
| 604 | 603 |
| 605 srcdir_prefix = '' | 604 srcdir_prefix = '' |
| 606 def Sourceify(path): | 605 def Sourceify(path): |
| 607 """Convert a path to its source directory form.""" | 606 """Convert a path to its source directory form.""" |
| 608 if '$(' in path: | 607 if '$(' in path: |
| 609 return path | 608 return path |
| 610 if os.path.isabs(path): | 609 if os.path.isabs(path): |
| 611 return path | 610 return path |
| 612 return srcdir_prefix + path | 611 return srcdir_prefix + path |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 output_filename: output .mk file name to write | 683 output_filename: output .mk file name to write |
| 685 spec, configs: gyp info | 684 spec, configs: gyp info |
| 686 part_of_all: flag indicating this target is part of 'all' | 685 part_of_all: flag indicating this target is part of 'all' |
| 687 """ | 686 """ |
| 688 ensure_directory_exists(output_filename) | 687 ensure_directory_exists(output_filename) |
| 689 | 688 |
| 690 self.fp = open(output_filename, 'w') | 689 self.fp = open(output_filename, 'w') |
| 691 | 690 |
| 692 self.fp.write(header) | 691 self.fp.write(header) |
| 693 | 692 |
| 693 self.qualified_target = qualified_target |
| 694 self.path = base_path | 694 self.path = base_path |
| 695 self.target = spec['target_name'] | 695 self.target = spec['target_name'] |
| 696 self.type = spec['type'] | 696 self.type = spec['type'] |
| 697 self.toolset = spec['toolset'] | 697 self.toolset = spec['toolset'] |
| 698 | 698 |
| 699 self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec) | 699 self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec) |
| 700 if self.flavor == 'mac': | 700 if self.flavor == 'mac': |
| 701 self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec) | 701 self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec) |
| 702 else: | 702 else: |
| 703 self.xcode_settings = None | 703 self.xcode_settings = None |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 """Write Makefile code for any 'actions' from the gyp input. | 830 """Write Makefile code for any 'actions' from the gyp input. |
| 831 | 831 |
| 832 extra_sources: a list that will be filled in with newly generated source | 832 extra_sources: a list that will be filled in with newly generated source |
| 833 files, if any | 833 files, if any |
| 834 extra_outputs: a list that will be filled in with any outputs of these | 834 extra_outputs: a list that will be filled in with any outputs of these |
| 835 actions (used to make other pieces dependent on these | 835 actions (used to make other pieces dependent on these |
| 836 actions) | 836 actions) |
| 837 part_of_all: flag indicating this target is part of 'all' | 837 part_of_all: flag indicating this target is part of 'all' |
| 838 """ | 838 """ |
| 839 for action in actions: | 839 for action in actions: |
| 840 name = self.target + '_' + StringToMakefileVariable(action['action_name']) | 840 name = StringToMakefileVariable('%s_%s' % (self.qualified_target, |
| 841 action['action_name'])) |
| 841 self.WriteLn('### Rules for action "%s":' % action['action_name']) | 842 self.WriteLn('### Rules for action "%s":' % action['action_name']) |
| 842 inputs = action['inputs'] | 843 inputs = action['inputs'] |
| 843 outputs = action['outputs'] | 844 outputs = action['outputs'] |
| 844 | 845 |
| 845 # Build up a list of outputs. | 846 # Build up a list of outputs. |
| 846 # Collect the output dirs we'll need. | 847 # Collect the output dirs we'll need. |
| 847 dirs = set() | 848 dirs = set() |
| 848 for out in outputs: | 849 for out in outputs: |
| 849 dir = os.path.split(out)[0] | 850 dir = os.path.split(out)[0] |
| 850 if dir: | 851 if dir: |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 extra_mac_bundle_resources, part_of_all): | 925 extra_mac_bundle_resources, part_of_all): |
| 925 """Write Makefile code for any 'rules' from the gyp input. | 926 """Write Makefile code for any 'rules' from the gyp input. |
| 926 | 927 |
| 927 extra_sources: a list that will be filled in with newly generated source | 928 extra_sources: a list that will be filled in with newly generated source |
| 928 files, if any | 929 files, if any |
| 929 extra_outputs: a list that will be filled in with any outputs of these | 930 extra_outputs: a list that will be filled in with any outputs of these |
| 930 rules (used to make other pieces dependent on these rules) | 931 rules (used to make other pieces dependent on these rules) |
| 931 part_of_all: flag indicating this target is part of 'all' | 932 part_of_all: flag indicating this target is part of 'all' |
| 932 """ | 933 """ |
| 933 for rule in rules: | 934 for rule in rules: |
| 934 name = self.target + '_' + StringToMakefileVariable(rule['rule_name']) | 935 name = StringToMakefileVariable('%s_%s' % (self.qualified_target, |
| 936 rule['rule_name'])) |
| 935 count = 0 | 937 count = 0 |
| 936 self.WriteLn('### Generated for rule %s:' % name) | 938 self.WriteLn('### Generated for rule %s:' % name) |
| 937 | 939 |
| 938 all_outputs = [] | 940 all_outputs = [] |
| 939 | 941 |
| 940 for rule_source in rule.get('rule_sources', []): | 942 for rule_source in rule.get('rule_sources', []): |
| 941 dirs = set() | 943 dirs = set() |
| 942 (rule_source_dirname, rule_source_basename) = os.path.split(rule_source) | 944 (rule_source_dirname, rule_source_basename) = os.path.split(rule_source) |
| 943 (rule_source_root, rule_source_ext) = \ | 945 (rule_source_root, rule_source_ext) = \ |
| 944 os.path.splitext(rule_source_basename) | 946 os.path.splitext(rule_source_basename) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 | 1041 |
| 1040 def WriteCopies(self, copies, extra_outputs, part_of_all): | 1042 def WriteCopies(self, copies, extra_outputs, part_of_all): |
| 1041 """Write Makefile code for any 'copies' from the gyp input. | 1043 """Write Makefile code for any 'copies' from the gyp input. |
| 1042 | 1044 |
| 1043 extra_outputs: a list that will be filled in with any outputs of this action | 1045 extra_outputs: a list that will be filled in with any outputs of this action |
| 1044 (used to make other pieces dependent on this action) | 1046 (used to make other pieces dependent on this action) |
| 1045 part_of_all: flag indicating this target is part of 'all' | 1047 part_of_all: flag indicating this target is part of 'all' |
| 1046 """ | 1048 """ |
| 1047 self.WriteLn('### Generated for copy rule.') | 1049 self.WriteLn('### Generated for copy rule.') |
| 1048 | 1050 |
| 1049 variable = self.target + '_copies' | 1051 name = StringToMakefileVariable(self.qualified_target + '_copies') |
| 1050 outputs = [] | 1052 outputs = [] |
| 1051 for copy in copies: | 1053 for copy in copies: |
| 1052 for path in copy['files']: | 1054 for path in copy['files']: |
| 1053 # Absolutify() calls normpath, stripping trailing slashes. | 1055 # Absolutify() calls normpath, stripping trailing slashes. |
| 1054 path = Sourceify(self.Absolutify(path)) | 1056 path = Sourceify(self.Absolutify(path)) |
| 1055 filename = os.path.split(path)[1] | 1057 filename = os.path.split(path)[1] |
| 1056 output = Sourceify(self.Absolutify(os.path.join(copy['destination'], | 1058 output = Sourceify(self.Absolutify(os.path.join(copy['destination'], |
| 1057 filename))) | 1059 filename))) |
| 1058 | 1060 |
| 1059 # If the output path has variables in it, which happens in practice for | 1061 # If the output path has variables in it, which happens in practice for |
| (...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2130 root_makefile.write(" include " + include_file + "\n") | 2132 root_makefile.write(" include " + include_file + "\n") |
| 2131 root_makefile.write("endif\n") | 2133 root_makefile.write("endif\n") |
| 2132 root_makefile.write('\n') | 2134 root_makefile.write('\n') |
| 2133 | 2135 |
| 2134 if generator_flags.get('auto_regeneration', True): | 2136 if generator_flags.get('auto_regeneration', True): |
| 2135 WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files) | 2137 WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files) |
| 2136 | 2138 |
| 2137 root_makefile.write(SHARED_FOOTER) | 2139 root_makefile.write(SHARED_FOOTER) |
| 2138 | 2140 |
| 2139 root_makefile.close() | 2141 root_makefile.close() |
| OLD | NEW |