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

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

Issue 10698023: Get ninja working for nacl. (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: Created 8 years, 5 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 | « PRESUBMIT.py ('k') | pylib/gyp/msvs_emulation.py » ('j') | no next file with comments »
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.MSVSVersion
10 import gyp.system_test 10 import gyp.system_test
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 if INTERMEDIATE_DIR in path: 243 if INTERMEDIATE_DIR in path:
244 int_dir = self.GypPathToUniqueOutput('gen') 244 int_dir = self.GypPathToUniqueOutput('gen')
245 # GypPathToUniqueOutput generates a path relative to the product dir, 245 # GypPathToUniqueOutput generates a path relative to the product dir,
246 # so insert product_dir in front if it is provided. 246 # so insert product_dir in front if it is provided.
247 path = path.replace(INTERMEDIATE_DIR, 247 path = path.replace(INTERMEDIATE_DIR,
248 os.path.join(product_dir or '', int_dir)) 248 os.path.join(product_dir or '', int_dir))
249 return path 249 return path
250 250
251 def ExpandRuleVariables(self, path, root, dirname, source, ext, name): 251 def ExpandRuleVariables(self, path, root, dirname, source, ext, name):
252 if self.flavor == 'win': 252 if self.flavor == 'win':
253 path = self.msvs_settings.ConvertVSMacros(path) 253 path = self.msvs_settings.ConvertVSMacros(
254 path, config=self.config_name)
254 path = path.replace(generator_default_variables['RULE_INPUT_ROOT'], root) 255 path = path.replace(generator_default_variables['RULE_INPUT_ROOT'], root)
255 path = path.replace(generator_default_variables['RULE_INPUT_DIRNAME'], 256 path = path.replace(generator_default_variables['RULE_INPUT_DIRNAME'],
256 dirname) 257 dirname)
257 path = path.replace(generator_default_variables['RULE_INPUT_PATH'], source) 258 path = path.replace(generator_default_variables['RULE_INPUT_PATH'], source)
258 path = path.replace(generator_default_variables['RULE_INPUT_EXT'], ext) 259 path = path.replace(generator_default_variables['RULE_INPUT_EXT'], ext)
259 path = path.replace(generator_default_variables['RULE_INPUT_NAME'], name) 260 path = path.replace(generator_default_variables['RULE_INPUT_NAME'], name)
260 return path 261 return path
261 262
262 def GypPathToNinja(self, path, env=None): 263 def GypPathToNinja(self, path, env=None):
263 """Translate a gyp path to a ninja path, optionally expanding environment 264 """Translate a gyp path to a ninja path, optionally expanding environment
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 config = spec['configurations'][config_name] 339 config = spec['configurations'][config_name]
339 self.target = Target(spec['type']) 340 self.target = Target(spec['type'])
340 341
341 self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec) 342 self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec)
342 self.xcode_settings = self.msvs_settings = None 343 self.xcode_settings = self.msvs_settings = None
343 if self.flavor == 'mac': 344 if self.flavor == 'mac':
344 self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec) 345 self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec)
345 if self.flavor == 'win': 346 if self.flavor == 'win':
346 self.msvs_settings = gyp.msvs_emulation.MsvsSettings(spec, 347 self.msvs_settings = gyp.msvs_emulation.MsvsSettings(spec,
347 generator_flags) 348 generator_flags)
348 # TODO(scottmg): x64 support. 349 target_platform = self.msvs_settings.GetTargetPlatform(config_name)
349 self.ninja.variable('arch', self.win_env['x86']) 350 self.ninja.variable('arch', self.win_env[target_platform])
350 351
351 # Compute predepends for all rules. 352 # Compute predepends for all rules.
352 # actions_depends is the dependencies this target depends on before running 353 # actions_depends is the dependencies this target depends on before running
353 # any of its action/rule/copy steps. 354 # any of its action/rule/copy steps.
354 # compile_depends is the dependencies this target depends on before running 355 # compile_depends is the dependencies this target depends on before running
355 # any of its compile steps. 356 # any of its compile steps.
356 actions_depends = [] 357 actions_depends = []
357 compile_depends = [] 358 compile_depends = []
358 # TODO(evan): it is rather confusing which things are lists and which 359 # TODO(evan): it is rather confusing which things are lists and which
359 # are strings. Fix these. 360 # are strings. Fix these.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 if message: 501 if message:
501 return '%s %s' % (verb, self.ExpandSpecial(message)) 502 return '%s %s' % (verb, self.ExpandSpecial(message))
502 else: 503 else:
503 return '%s %s: %s' % (verb, self.name, fallback) 504 return '%s %s: %s' % (verb, self.name, fallback)
504 505
505 def WriteActions(self, actions, extra_sources, prebuild, 506 def WriteActions(self, actions, extra_sources, prebuild,
506 extra_mac_bundle_resources): 507 extra_mac_bundle_resources):
507 # Actions cd into the base directory. 508 # Actions cd into the base directory.
508 env = self.GetSortedXcodeEnv() 509 env = self.GetSortedXcodeEnv()
509 if self.flavor == 'win': 510 if self.flavor == 'win':
510 env = self.msvs_settings.GetVSMacroEnv('$!PRODUCT_DIR') 511 env = self.msvs_settings.GetVSMacroEnv(
512 '$!PRODUCT_DIR', config=self.config_name)
511 all_outputs = [] 513 all_outputs = []
512 for action in actions: 514 for action in actions:
513 # First write out a rule for the action. 515 # First write out a rule for the action.
514 name = '%s_%s' % (action['action_name'], 516 name = '%s_%s' % (action['action_name'],
515 hashlib.md5(self.qualified_target).hexdigest()) 517 hashlib.md5(self.qualified_target).hexdigest())
516 description = self.GenerateDescription('ACTION', 518 description = self.GenerateDescription('ACTION',
517 action.get('message', None), 519 action.get('message', None),
518 name) 520 name)
519 is_cygwin = (self.msvs_settings.IsRuleRunUnderCygwin(action) 521 is_cygwin = (self.msvs_settings.IsRuleRunUnderCygwin(action)
520 if self.flavor == 'win' else False) 522 if self.flavor == 'win' else False)
521 args = action['action'] 523 args = action['action']
522 args = [self.msvs_settings.ConvertVSMacros(arg, self.base_to_build) 524 args = [self.msvs_settings.ConvertVSMacros(
525 arg, self.base_to_build, config=self.config_name)
523 for arg in args] if self.flavor == 'win' else args 526 for arg in args] if self.flavor == 'win' else args
524 rule_name = self.WriteNewNinjaRule(name, args, description, 527 rule_name = self.WriteNewNinjaRule(name, args, description,
525 is_cygwin, env=env) 528 is_cygwin, env=env)
526 529
527 inputs = [self.GypPathToNinja(i, env) for i in action['inputs']] 530 inputs = [self.GypPathToNinja(i, env) for i in action['inputs']]
528 if int(action.get('process_outputs_as_sources', False)): 531 if int(action.get('process_outputs_as_sources', False)):
529 extra_sources += action['outputs'] 532 extra_sources += action['outputs']
530 if int(action.get('process_outputs_as_mac_bundle_resources', False)): 533 if int(action.get('process_outputs_as_mac_bundle_resources', False)):
531 extra_mac_bundle_resources += action['outputs'] 534 extra_mac_bundle_resources += action['outputs']
532 outputs = [self.GypPathToNinja(o, env) for o in action['outputs']] 535 outputs = [self.GypPathToNinja(o, env) for o in action['outputs']]
(...skipping 17 matching lines...) Expand all
550 # Skip a rule with no action and no inputs. 553 # Skip a rule with no action and no inputs.
551 if 'action' not in rule and not rule.get('rule_sources', []): 554 if 'action' not in rule and not rule.get('rule_sources', []):
552 continue 555 continue
553 args = rule['action'] 556 args = rule['action']
554 description = self.GenerateDescription( 557 description = self.GenerateDescription(
555 'RULE', 558 'RULE',
556 rule.get('message', None), 559 rule.get('message', None),
557 ('%s ' + generator_default_variables['RULE_INPUT_PATH']) % name) 560 ('%s ' + generator_default_variables['RULE_INPUT_PATH']) % name)
558 is_cygwin = (self.msvs_settings.IsRuleRunUnderCygwin(rule) 561 is_cygwin = (self.msvs_settings.IsRuleRunUnderCygwin(rule)
559 if self.flavor == 'win' else False) 562 if self.flavor == 'win' else False)
560 args = [self.msvs_settings.ConvertVSMacros(arg, self.base_to_build) 563 args = [self.msvs_settings.ConvertVSMacros(
564 arg, self.base_to_build, config=self.config_name)
561 for arg in args] if self.flavor == 'win' else args 565 for arg in args] if self.flavor == 'win' else args
562 rule_name = self.WriteNewNinjaRule(name, args, description, is_cygwin) 566 rule_name = self.WriteNewNinjaRule(name, args, description, is_cygwin)
563 567
564 # TODO: if the command references the outputs directly, we should 568 # TODO: if the command references the outputs directly, we should
565 # simplify it to just use $out. 569 # simplify it to just use $out.
566 570
567 # Rules can potentially make use of some special variables which 571 # Rules can potentially make use of some special variables which
568 # must vary per source file. 572 # must vary per source file.
569 # Compute the list of variables we'll need to provide. 573 # Compute the list of variables we'll need to provide.
570 special_locals = ('source', 'root', 'dirname', 'ext', 'name') 574 special_locals = ('source', 'root', 'dirname', 'ext', 'name')
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 cflags_objcc)) 747 cflags_objcc))
744 self.ninja.newline() 748 self.ninja.newline()
745 outputs = [] 749 outputs = []
746 for source in sources: 750 for source in sources:
747 filename, ext = os.path.splitext(source) 751 filename, ext = os.path.splitext(source)
748 ext = ext[1:] 752 ext = ext[1:]
749 obj_ext = self.obj_ext 753 obj_ext = self.obj_ext
750 if ext in ('cc', 'cpp', 'cxx'): 754 if ext in ('cc', 'cpp', 'cxx'):
751 command = 'cxx' 755 command = 'cxx'
752 elif ext == 'c' or (ext in ('s', 'S') and self.flavor != 'win'): 756 elif ext == 'c' or (ext in ('s', 'S') and self.flavor != 'win'):
753 # TODO(scottmg): .s files won't be handled by the Windows compiler.
754 # We could add support for .asm, though that's only supported on
755 # x86. Currently not used in Chromium in favor of other third-party
756 # assemblers.
757 command = 'cc' 757 command = 'cc'
758 elif (self.flavor == 'win' and ext == 'asm' and
759 self.msvs_settings.GetTargetPlatform(config_name) == 'Win32'):
760 # Asm files only get auto assembled for x86 (not x64).
761 command = 'asm'
762 # Add the _asm suffix as msvs is capable of handling .cc and
763 # .asm files of the same name without collision.
764 obj_ext = '_asm.obj'
758 elif self.flavor == 'mac' and ext == 'm': 765 elif self.flavor == 'mac' and ext == 'm':
759 command = 'objc' 766 command = 'objc'
760 elif self.flavor == 'mac' and ext == 'mm': 767 elif self.flavor == 'mac' and ext == 'mm':
761 command = 'objcxx' 768 command = 'objcxx'
762 elif self.flavor == 'win' and ext == 'rc': 769 elif self.flavor == 'win' and ext == 'rc':
763 command = 'rc' 770 command = 'rc'
764 obj_ext = '.res' 771 obj_ext = '.res'
765 else: 772 else:
766 # Ignore unhandled extensions. 773 # Ignore unhandled extensions.
767 continue 774 continue
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 # should be scoped to the subninja. 1109 # should be scoped to the subninja.
1103 rule_name = self.name 1110 rule_name = self.name
1104 if self.toolset == 'target': 1111 if self.toolset == 'target':
1105 rule_name += '.' + self.toolset 1112 rule_name += '.' + self.toolset
1106 rule_name += '.' + name 1113 rule_name += '.' + name
1107 rule_name = re.sub('[^a-zA-Z0-9_]', '_', rule_name) 1114 rule_name = re.sub('[^a-zA-Z0-9_]', '_', rule_name)
1108 1115
1109 args = args[:] 1116 args = args[:]
1110 1117
1111 if self.flavor == 'win': 1118 if self.flavor == 'win':
1112 description = self.msvs_settings.ConvertVSMacros(description) 1119 description = self.msvs_settings.ConvertVSMacros(
1120 description, config=self.config_name)
1113 1121
1114 # gyp dictates that commands are run from the base directory. 1122 # gyp dictates that commands are run from the base directory.
1115 # cd into the directory before running, and adjust paths in 1123 # cd into the directory before running, and adjust paths in
1116 # the arguments to point to the proper locations. 1124 # the arguments to point to the proper locations.
1117 rspfile = None 1125 rspfile = None
1118 rspfile_content = None 1126 rspfile_content = None
1119 args = [self.ExpandSpecial(arg, self.base_to_build) for arg in args] 1127 args = [self.ExpandSpecial(arg, self.base_to_build) for arg in args]
1120 if self.flavor == 'win': 1128 if self.flavor == 'win':
1121 rspfile = rule_name + '.$unique_name.rsp' 1129 rspfile = rule_name + '.$unique_name.rsp'
1122 # The cygwin case handles this inside the bash sub-shell. 1130 # The cygwin case handles this inside the bash sub-shell.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 flock = 'flock' 1267 flock = 'flock'
1260 if flavor == 'mac': 1268 if flavor == 'mac':
1261 flock = './gyp-mac-tool flock' 1269 flock = './gyp-mac-tool flock'
1262 master_ninja.variable('cc', os.environ.get('CC', cc)) 1270 master_ninja.variable('cc', os.environ.get('CC', cc))
1263 master_ninja.variable('cxx', os.environ.get('CXX', cxx)) 1271 master_ninja.variable('cxx', os.environ.get('CXX', cxx))
1264 if flavor == 'win': 1272 if flavor == 'win':
1265 master_ninja.variable('ld', 'link.exe') 1273 master_ninja.variable('ld', 'link.exe')
1266 master_ninja.variable('idl', 'midl.exe') 1274 master_ninja.variable('idl', 'midl.exe')
1267 master_ninja.variable('ar', 'lib.exe') 1275 master_ninja.variable('ar', 'lib.exe')
1268 master_ninja.variable('rc', 'rc.exe') 1276 master_ninja.variable('rc', 'rc.exe')
1277 master_ninja.variable('asm', 'ml.exe')
1269 else: 1278 else:
1270 master_ninja.variable('ld', flock + ' linker.lock $cxx') 1279 master_ninja.variable('ld', flock + ' linker.lock $cxx')
1271 master_ninja.variable('ar', os.environ.get('AR', 'ar')) 1280 master_ninja.variable('ar', os.environ.get('AR', 'ar'))
1272 1281
1273 master_ninja.variable('ar_target', os.environ.get('AR_target', '$ar')) 1282 master_ninja.variable('ar_target', os.environ.get('AR_target', '$ar'))
1274 master_ninja.variable('cc_target', os.environ.get('CC_target', '$cc')) 1283 master_ninja.variable('cc_target', os.environ.get('CC_target', '$cc'))
1275 master_ninja.variable('cxx_target', os.environ.get('CXX_target', '$cxx')) 1284 master_ninja.variable('cxx_target', os.environ.get('CXX_target', '$cxx'))
1276 if flavor == 'win': 1285 if flavor == 'win':
1277 master_ninja.variable('ld_target', os.environ.get('LD_target', '$ld')) 1286 master_ninja.variable('ld_target', os.environ.get('LD_target', '$ld'))
1278 else: 1287 else:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 command=('%s gyp-win-tool midl-wrapper $arch $outdir ' 1355 command=('%s gyp-win-tool midl-wrapper $arch $outdir '
1347 '$tlb $h $dlldata $iid $proxy $in ' 1356 '$tlb $h $dlldata $iid $proxy $in '
1348 '$idlflags' % sys.executable)) 1357 '$idlflags' % sys.executable))
1349 master_ninja.rule( 1358 master_ninja.rule(
1350 'rc', 1359 'rc',
1351 description='RC $in', 1360 description='RC $in',
1352 # Note: $in must be last otherwise rc.exe complains. 1361 # Note: $in must be last otherwise rc.exe complains.
1353 command=('%s gyp-win-tool rc-wrapper ' 1362 command=('%s gyp-win-tool rc-wrapper '
1354 '$arch $rc $defines $includes $rcflags /fo$out $in' % 1363 '$arch $rc $defines $includes $rcflags /fo$out $in' %
1355 sys.executable)) 1364 sys.executable))
1365 master_ninja.rule(
1366 'asm',
1367 description='ASM $in',
1368 command=('%s gyp-win-tool asm-wrapper '
1369 '$arch $asm $defines $includes /c /Fo $out $in' %
1370 sys.executable))
1356 1371
1357 if flavor != 'mac' and flavor != 'win': 1372 if flavor != 'mac' and flavor != 'win':
1358 master_ninja.rule( 1373 master_ninja.rule(
1359 'alink', 1374 'alink',
1360 description='AR $out', 1375 description='AR $out',
1361 command='rm -f $out && $ar rcsT $out $in') 1376 command='rm -f $out && $ar rcsT $out $in')
1362 master_ninja.rule( 1377 master_ninja.rule(
1363 'solink', 1378 'solink',
1364 description='SOLINK $out', 1379 description='SOLINK $out',
1365 command=('$ld -shared $ldflags -o $out -Wl,-soname=$soname ' 1380 command=('$ld -shared $ldflags -o $out -Wl,-soname=$soname '
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 1560
1546 user_config = params.get('generator_flags', {}).get('config', None) 1561 user_config = params.get('generator_flags', {}).get('config', None)
1547 if user_config: 1562 if user_config:
1548 GenerateOutputForConfig(target_list, target_dicts, data, params, 1563 GenerateOutputForConfig(target_list, target_dicts, data, params,
1549 user_config) 1564 user_config)
1550 else: 1565 else:
1551 config_names = target_dicts[target_list[0]]['configurations'].keys() 1566 config_names = target_dicts[target_list[0]]['configurations'].keys()
1552 for config_name in config_names: 1567 for config_name in config_names:
1553 GenerateOutputForConfig(target_list, target_dicts, data, params, 1568 GenerateOutputForConfig(target_list, target_dicts, data, params,
1554 config_name) 1569 config_name)
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | pylib/gyp/msvs_emulation.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698