Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1422)

Side by Side Diff: pylib/gyp/generator/ninja.py

Issue 9443044: Beginnings of some msvs_... emulation (windows ninja) (Closed) Base URL: https://gyp.googlecode.com/svn/trunk
Patch Set: comment fixes Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pylib/gyp/msvs_emulation.py » ('j') | pylib/gyp/msvs_emulation.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import copy 5 import copy
6 import gyp 6 import gyp
7 import gyp.common 7 import gyp.common
8 import gyp.msvs_emulation 8 import gyp.msvs_emulation
9 import gyp.MSVSVersion
9 import gyp.system_test 10 import gyp.system_test
10 import gyp.xcode_emulation 11 import gyp.xcode_emulation
11 import os.path 12 import os.path
12 import re 13 import re
13 import subprocess 14 import subprocess
14 import sys 15 import sys
15 16
16 import gyp.ninja_syntax as ninja_syntax 17 import gyp.ninja_syntax as ninja_syntax
17 18
18 generator_default_variables = { 19 generator_default_variables = {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 INTERMEDIATE_DIR = '$!INTERMEDIATE_DIR' 210 INTERMEDIATE_DIR = '$!INTERMEDIATE_DIR'
210 if INTERMEDIATE_DIR in path: 211 if INTERMEDIATE_DIR in path:
211 int_dir = self.GypPathToUniqueOutput('gen') 212 int_dir = self.GypPathToUniqueOutput('gen')
212 # GypPathToUniqueOutput generates a path relative to the product dir, 213 # GypPathToUniqueOutput generates a path relative to the product dir,
213 # so insert product_dir in front if it is provided. 214 # so insert product_dir in front if it is provided.
214 path = path.replace(INTERMEDIATE_DIR, 215 path = path.replace(INTERMEDIATE_DIR,
215 os.path.join(product_dir or '', int_dir)) 216 os.path.join(product_dir or '', int_dir))
216 217
217 if self.flavor == 'win': 218 if self.flavor == 'win':
218 # Don't use os.path.normpath here. Callers pass in './foo' and expect 219 # Don't use os.path.normpath here. Callers pass in './foo' and expect
219 # the result to be runnable, but normpath removes the prefix. 220 # the result to be runnable, but normpath removes the prefix. If the
221 # variable is $! prefixed on Windows, don't modify it (used for compiler
222 # flags, etc.)
223 if path.startswith('$!'):
Nico 2012/02/29 19:44:18 Almost all of this CL looks really good. The only
scottmg 2012/03/01 18:09:04 Heresy in ExpandSpecial!
224 return path[2:]
220 return path.replace('/', '\\') 225 return path.replace('/', '\\')
221 return path 226 return path
222 227
223 def ExpandRuleVariables(self, path, root, dirname, source, ext, name): 228 def ExpandRuleVariables(self, path, root, dirname, source, ext, name):
224 path = path.replace(generator_default_variables['RULE_INPUT_ROOT'], root) 229 path = path.replace(generator_default_variables['RULE_INPUT_ROOT'], root)
225 path = path.replace(generator_default_variables['RULE_INPUT_DIRNAME'], 230 path = path.replace(generator_default_variables['RULE_INPUT_DIRNAME'],
226 dirname) 231 dirname)
227 path = path.replace(generator_default_variables['RULE_INPUT_PATH'], source) 232 path = path.replace(generator_default_variables['RULE_INPUT_PATH'], source)
228 path = path.replace(generator_default_variables['RULE_INPUT_EXT'], ext) 233 path = path.replace(generator_default_variables['RULE_INPUT_EXT'], ext)
229 path = path.replace(generator_default_variables['RULE_INPUT_NAME'], name) 234 path = path.replace(generator_default_variables['RULE_INPUT_NAME'], name)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 Returns None if there are no outputs (e.g. a settings-only 'none' type 301 Returns None if there are no outputs (e.g. a settings-only 'none' type
297 target).""" 302 target)."""
298 303
299 self.config_name = config_name 304 self.config_name = config_name
300 self.name = spec['target_name'] 305 self.name = spec['target_name']
301 self.toolset = spec['toolset'] 306 self.toolset = spec['toolset']
302 config = spec['configurations'][config_name] 307 config = spec['configurations'][config_name]
303 self.target = Target(spec['type']) 308 self.target = Target(spec['type'])
304 309
305 self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec) 310 self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec)
311 self.xcode_settings = self.msvs_settings = None
306 if self.flavor == 'mac': 312 if self.flavor == 'mac':
307 self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec) 313 self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec)
308 else: 314 if self.flavor == 'win':
309 self.xcode_settings = None 315 self.msvs_settings = gyp.msvs_emulation.MsvsSettings(spec)
310 316
311 # Compute predepends for all rules. 317 # Compute predepends for all rules.
312 # actions_depends is the dependencies this target depends on before running 318 # actions_depends is the dependencies this target depends on before running
313 # any of its action/rule/copy steps. 319 # any of its action/rule/copy steps.
314 # compile_depends is the dependencies this target depends on before running 320 # compile_depends is the dependencies this target depends on before running
315 # any of its compile steps. 321 # any of its compile steps.
316 actions_depends = [] 322 actions_depends = []
317 compile_depends = [] 323 compile_depends = []
318 # TODO(evan): it is rather confusing which things are lists and which 324 # TODO(evan): it is rather confusing which things are lists and which
319 # are strings. Fix these. 325 # are strings. Fix these.
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 582
577 def WriteSources(self, config_name, config, sources, predepends, 583 def WriteSources(self, config_name, config, sources, predepends,
578 precompiled_header): 584 precompiled_header):
579 """Write build rules to compile all of |sources|.""" 585 """Write build rules to compile all of |sources|."""
580 if self.toolset == 'target': 586 if self.toolset == 'target':
581 self.ninja.variable('ar', '$ar_target') 587 self.ninja.variable('ar', '$ar_target')
582 self.ninja.variable('cc', '$cc_target') 588 self.ninja.variable('cc', '$cc_target')
583 self.ninja.variable('cxx', '$cxx_target') 589 self.ninja.variable('cxx', '$cxx_target')
584 self.ninja.variable('ld', '$ld_target') 590 self.ninja.variable('ld', '$ld_target')
585 591
592 extra_includes = []
593 extra_defines = []
586 if self.flavor == 'mac': 594 if self.flavor == 'mac':
587 cflags = self.xcode_settings.GetCflags(config_name) 595 cflags = self.xcode_settings.GetCflags(config_name)
588 cflags_c = self.xcode_settings.GetCflagsC(config_name) 596 cflags_c = self.xcode_settings.GetCflagsC(config_name)
589 cflags_cc = self.xcode_settings.GetCflagsCC(config_name) 597 cflags_cc = self.xcode_settings.GetCflagsCC(config_name)
590 cflags_objc = ['$cflags_c'] + \ 598 cflags_objc = ['$cflags_c'] + \
591 self.xcode_settings.GetCflagsObjC(config_name) 599 self.xcode_settings.GetCflagsObjC(config_name)
592 cflags_objcc = ['$cflags_cc'] + \ 600 cflags_objcc = ['$cflags_cc'] + \
593 self.xcode_settings.GetCflagsObjCC(config_name) 601 self.xcode_settings.GetCflagsObjCC(config_name)
602 elif self.flavor == 'win':
603 cflags = self.msvs_settings.GetCflags(config_name)
604 cflags_c = self.msvs_settings.GetCflagsC(config_name)
605 cflags_cc = self.msvs_settings.GetCflagsCC(config_name)
606 extra_includes = self.msvs_settings.GetSystemIncludes(config_name)
607 extra_defines = self.msvs_settings.GetComputedDefines(config_name)
594 else: 608 else:
595 cflags = config.get('cflags', []) 609 cflags = config.get('cflags', [])
596 cflags_c = config.get('cflags_c', []) 610 cflags_c = config.get('cflags_c', [])
597 cflags_cc = config.get('cflags_cc', []) 611 cflags_cc = config.get('cflags_cc', [])
598 612
613 defines = config.get('defines', []) + extra_defines
599 self.WriteVariableList('defines', 614 self.WriteVariableList('defines',
600 [QuoteShellArgument(ninja_syntax.escape('-D' + d), self.flavor) 615 [QuoteShellArgument(ninja_syntax.escape('-D' + d), self.flavor)
601 for d in config.get('defines', [])]) 616 for d in defines])
617 include_dirs = config.get('include_dirs', []) + extra_includes
602 self.WriteVariableList('includes', 618 self.WriteVariableList('includes',
603 ['-I' + self.GypPathToNinja(i) 619 [QuoteShellArgument('-I' + self.GypPathToNinja(i), self.flavor)
604 for i in config.get('include_dirs', [])]) 620 for i in include_dirs])
605 621
606 pch_commands = precompiled_header.GetGchBuildCommands() 622 pch_commands = precompiled_header.GetGchBuildCommands()
607 if self.flavor == 'mac': 623 if self.flavor == 'mac':
608 self.WriteVariableList('cflags_pch_c', 624 self.WriteVariableList('cflags_pch_c',
609 [precompiled_header.GetInclude('c')]) 625 [precompiled_header.GetInclude('c')])
610 self.WriteVariableList('cflags_pch_cc', 626 self.WriteVariableList('cflags_pch_cc',
611 [precompiled_header.GetInclude('cc')]) 627 [precompiled_header.GetInclude('cc')])
612 self.WriteVariableList('cflags_pch_objc', 628 self.WriteVariableList('cflags_pch_objc',
613 [precompiled_header.GetInclude('m')]) 629 [precompiled_header.GetInclude('m')])
614 self.WriteVariableList('cflags_pch_objcc', 630 self.WriteVariableList('cflags_pch_objcc',
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 output = self.ComputeMacBundleBinaryOutput() 720 output = self.ComputeMacBundleBinaryOutput()
705 else: 721 else:
706 output = self.ComputeOutput(spec) 722 output = self.ComputeOutput(spec)
707 extra_bindings.append(('postbuilds', 723 extra_bindings.append(('postbuilds',
708 self.GetPostbuildCommand(spec, output, output))) 724 self.GetPostbuildCommand(spec, output, output)))
709 725
710 if self.flavor == 'mac': 726 if self.flavor == 'mac':
711 ldflags = self.xcode_settings.GetLdflags(config_name, 727 ldflags = self.xcode_settings.GetLdflags(config_name,
712 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']), 728 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']),
713 self.GypPathToNinja) 729 self.GypPathToNinja)
730 elif self.flavor == 'win':
731 ldflags = self.msvs_settings.GetLdflags(config_name,
732 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']),
733 self.GypPathToNinja)
714 else: 734 else:
715 ldflags = config.get('ldflags', []) 735 ldflags = config.get('ldflags', [])
716 self.WriteVariableList('ldflags', 736 self.WriteVariableList('ldflags',
717 gyp.common.uniquer(map(self.ExpandSpecial, 737 gyp.common.uniquer(map(self.ExpandSpecial,
718 ldflags))) 738 ldflags)))
719 739
720 libraries = gyp.common.uniquer(map(self.ExpandSpecial, 740 libraries = gyp.common.uniquer(map(self.ExpandSpecial,
721 spec.get('libraries', []))) 741 spec.get('libraries', [])))
722 if self.flavor == 'mac': 742 if self.flavor == 'mac':
723 libraries = self.xcode_settings.AdjustLibraries(libraries) 743 libraries = self.xcode_settings.AdjustLibraries(libraries)
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 global generator_extra_sources_for_rules 1024 global generator_extra_sources_for_rules
1005 generator_extra_sources_for_rules = getattr(xcode_generator, 1025 generator_extra_sources_for_rules = getattr(xcode_generator,
1006 'generator_extra_sources_for_rules', []) 1026 'generator_extra_sources_for_rules', [])
1007 elif flavor == 'win': 1027 elif flavor == 'win':
1008 default_variables.setdefault('OS', 'win') 1028 default_variables.setdefault('OS', 'win')
1009 default_variables['EXECUTABLE_SUFFIX'] = '.exe' 1029 default_variables['EXECUTABLE_SUFFIX'] = '.exe'
1010 default_variables['STATIC_LIB_PREFIX'] = '' 1030 default_variables['STATIC_LIB_PREFIX'] = ''
1011 default_variables['STATIC_LIB_SUFFIX'] = '.lib' 1031 default_variables['STATIC_LIB_SUFFIX'] = '.lib'
1012 default_variables['SHARED_LIB_PREFIX'] = '' 1032 default_variables['SHARED_LIB_PREFIX'] = ''
1013 default_variables['SHARED_LIB_SUFFIX'] = '.dll' 1033 default_variables['SHARED_LIB_SUFFIX'] = '.dll'
1034 generator_flags = params.get('generator_flags', {})
1035 msvs_version = gyp.MSVSVersion.SelectVisualStudioVersion(
1036 generator_flags.get('msvs_version', 'auto'))
1037 # Stash msvs_version for later (so we don't have to probe the system twice).
1038 params['msvs_version'] = msvs_version
1039
1040 # Set a variable so conditions can be based on msvs_version.
1041 default_variables['MSVS_VERSION'] = msvs_version.ShortName()
1042
1043 # To determine processor word size on Windows, in addition to checking
1044 # PROCESSOR_ARCHITECTURE (which reflects the word size of the current
1045 # process), it is also necessary to check PROCESSOR_ARCHITEW6432 (which
1046 # contains the actual word size of the system when running thru WOW64).
1047 if ('64' in os.environ.get('PROCESSOR_ARCHITECTURE', '') or
1048 '64' in os.environ.get('PROCESSOR_ARCHITEW6432', '')):
1049 default_variables['MSVS_OS_BITS'] = 64
1050 else:
1051 default_variables['MSVS_OS_BITS'] = 32
1014 else: 1052 else:
1015 operating_system = flavor 1053 operating_system = flavor
1016 if flavor == 'android': 1054 if flavor == 'android':
1017 operating_system = 'linux' # Keep this legacy behavior for now. 1055 operating_system = 'linux' # Keep this legacy behavior for now.
1018 default_variables.setdefault('OS', operating_system) 1056 default_variables.setdefault('OS', operating_system)
1019 default_variables.setdefault('SHARED_LIB_SUFFIX', '.so') 1057 default_variables.setdefault('SHARED_LIB_SUFFIX', '.so')
1020 default_variables.setdefault('SHARED_LIB_DIR', 1058 default_variables.setdefault('SHARED_LIB_DIR',
1021 os.path.join('$!PRODUCT_DIR', 'lib')) 1059 os.path.join('$!PRODUCT_DIR', 'lib'))
1022 default_variables.setdefault('LIB_DIR', '') 1060 default_variables.setdefault('LIB_DIR', '')
1023 1061
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 depfile='$out.d') 1137 depfile='$out.d')
1100 else: 1138 else:
1101 # TODO(scottmg): Requires deplist branch of ninja for now (for 1139 # TODO(scottmg): Requires deplist branch of ninja for now (for
1102 # /showIncludes handling). 1140 # /showIncludes handling).
1103 master_ninja.rule( 1141 master_ninja.rule(
1104 'cc', 1142 'cc',
1105 description='CC $out', 1143 description='CC $out',
1106 command=('cmd /c $cc /nologo /showIncludes ' 1144 command=('cmd /c $cc /nologo /showIncludes '
1107 '$defines $includes $cflags $cflags_c ' 1145 '$defines $includes $cflags $cflags_c '
1108 '$cflags_pch_c /c $in /Fo$out ' 1146 '$cflags_pch_c /c $in /Fo$out '
1109 '| ninja-deplist-helper -f cl -o $out.dl'), 1147 '| ninja-deplist-helper -q -f cl -o $out.dl'),
1110 deplist='$out.dl') 1148 deplist='$out.dl')
1111 master_ninja.rule( 1149 master_ninja.rule(
1112 'cxx', 1150 'cxx',
1113 description='CXX $out', 1151 description='CXX $out',
1114 command=('cmd /c $cxx /nologo /showIncludes ' 1152 command=('cmd /c $cxx /nologo /showIncludes '
1115 '$defines $includes $cflags $cflags_cc ' 1153 '$defines $includes $cflags $cflags_cc '
1116 '$cflags_pch_cc /c $in /Fo$out ' 1154 '$cflags_pch_cc /c $in /Fo$out '
1117 '| ninja-deplist-helper -f cl -o $out.dl'), 1155 '| ninja-deplist-helper -q -f cl -o $out.dl'),
1118 deplist='$out.dl') 1156 deplist='$out.dl')
1119 1157
1120 if flavor != 'mac' and flavor != 'win': 1158 if flavor != 'mac' and flavor != 'win':
1121 master_ninja.rule( 1159 master_ninja.rule(
1122 'alink', 1160 'alink',
1123 description='AR $out', 1161 description='AR $out',
1124 command='rm -f $out && $ar rcsT $out $in') 1162 command='rm -f $out && $ar rcsT $out $in')
1125 master_ninja.rule( 1163 master_ninja.rule(
1126 'solink', 1164 'solink',
1127 description='SOLINK $out', 1165 description='SOLINK $out',
(...skipping 10 matching lines...) Expand all
1138 command=('$ld $ldflags -o $out -Wl,-rpath=\$$ORIGIN/lib ' 1176 command=('$ld $ldflags -o $out -Wl,-rpath=\$$ORIGIN/lib '
1139 '-Wl,--start-group $in -Wl,--end-group $libs')) 1177 '-Wl,--start-group $in -Wl,--end-group $libs'))
1140 elif flavor == 'win': 1178 elif flavor == 'win':
1141 master_ninja.rule( 1179 master_ninja.rule(
1142 'alink', 1180 'alink',
1143 description='LIB $out', 1181 description='LIB $out',
1144 command='lib /nologo /OUT:$out $in') 1182 command='lib /nologo /OUT:$out $in')
1145 master_ninja.rule( 1183 master_ninja.rule(
1146 'solink', 1184 'solink',
1147 description='LINK(DLL) $dll', 1185 description='LINK(DLL) $dll',
1148 command=('$ld /nologo /IMPLIB:$implib /DLL $ldflags /OUT:$dll $in $libs')) 1186 command=('$ld /nologo /IMPLIB:$implib /DLL $ldflags /OUT:$dll '
1187 '/PDB:$dll.pdb $in $libs'))
1149 master_ninja.rule( 1188 master_ninja.rule(
1150 'solink_module', 1189 'solink_module',
1151 description='LINK(DLL) $dll', 1190 description='LINK(DLL) $dll',
1152 command=('$ld /nologo /IMPLIB:$implib /DLL $ldflags /OUT:$dll $in $libs')) 1191 command=('$ld /nologo /IMPLIB:$implib /DLL $ldflags /OUT:$dll '
1192 '/PDB:$dll.pdb $in $libs'))
1153 master_ninja.rule( 1193 master_ninja.rule(
1154 'link', 1194 'link',
1155 description='LINK $out', 1195 description='LINK $out',
1156 command=('$ld /nologo $ldflags /OUT:$out $in $libs')) 1196 command=('$ld /nologo $ldflags /OUT:$out /PDB:$out.pdb $in $libs'))
1157 else: 1197 else:
1158 master_ninja.rule( 1198 master_ninja.rule(
1159 'objc', 1199 'objc',
1160 description='OBJC $out', 1200 description='OBJC $out',
1161 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_objc ' 1201 command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_objc '
1162 '$cflags_pch_objc -c $in -o $out'), 1202 '$cflags_pch_objc -c $in -o $out'),
1163 depfile='$out.d') 1203 depfile='$out.d')
1164 master_ninja.rule( 1204 master_ninja.rule(
1165 'objcxx', 1205 'objcxx',
1166 description='OBJCXX $out', 1206 description='OBJCXX $out',
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 1320
1281 user_config = params.get('generator_flags', {}).get('config', None) 1321 user_config = params.get('generator_flags', {}).get('config', None)
1282 if user_config: 1322 if user_config:
1283 GenerateOutputForConfig(target_list, target_dicts, data, params, 1323 GenerateOutputForConfig(target_list, target_dicts, data, params,
1284 user_config) 1324 user_config)
1285 else: 1325 else:
1286 config_names = target_dicts[target_list[0]]['configurations'].keys() 1326 config_names = target_dicts[target_list[0]]['configurations'].keys()
1287 for config_name in config_names: 1327 for config_name in config_names:
1288 GenerateOutputForConfig(target_list, target_dicts, data, params, 1328 GenerateOutputForConfig(target_list, target_dicts, data, params,
1289 config_name) 1329 config_name)
OLDNEW
« no previous file with comments | « no previous file | pylib/gyp/msvs_emulation.py » ('j') | pylib/gyp/msvs_emulation.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698