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

Side by Side Diff: pylib/gyp/MSVSSettings.py

Issue 1454433002: Python 3 compatibility Base URL: https://chromium.googlesource.com/external/gyp.git@master
Patch Set: Rebase with master (4ec6c4e3a94bd04a6da2858163d40b2429b8aad1) Created 4 years, 8 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
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 r"""Code to validate and convert settings of the Microsoft build tools. 5 r"""Code to validate and convert settings of the Microsoft build tools.
6 6
7 This file contains code to validate and convert settings of the Microsoft 7 This file contains code to validate and convert settings of the Microsoft
8 build tools. The function ConvertToMSBuildSettings(), ValidateMSVSSettings(), 8 build tools. The function ConvertToMSBuildSettings(), ValidateMSVSSettings(),
9 and ValidateMSBuildSettings() are the entry points. 9 and ValidateMSBuildSettings() are the entry points.
10 10
11 This file was created by comparing the projects created by Visual Studio 2008 11 This file was created by comparing the projects created by Visual Studio 2008
12 and Visual Studio 2010 for all available settings through the user interface. 12 and Visual Studio 2010 for all available settings through the user interface.
13 The MSBuild schemas were also considered. They are typically found in the 13 The MSBuild schemas were also considered. They are typically found in the
14 MSBuild install directory, e.g. c:\Program Files (x86)\MSBuild 14 MSBuild install directory, e.g. c:\Program Files (x86)\MSBuild
15 """ 15 """
16 16
17 from __future__ import print_function
18
17 import sys 19 import sys
18 import re 20 import re
19 21
22 try:
23 basestring = basestring
24 except NameError:
25 basestring = str
26
20 # Dictionaries of settings validators. The key is the tool name, the value is 27 # Dictionaries of settings validators. The key is the tool name, the value is
21 # a dictionary mapping setting names to validation functions. 28 # a dictionary mapping setting names to validation functions.
22 _msvs_validators = {} 29 _msvs_validators = {}
23 _msbuild_validators = {} 30 _msbuild_validators = {}
24 31
25 32
26 # A dictionary of settings converters. The key is the tool name, the value is 33 # A dictionary of settings converters. The key is the tool name, the value is
27 # a dictionary mapping setting names to conversion functions. 34 # a dictionary mapping setting names to conversion functions.
28 _msvs_to_msbuild_converters = {} 35 _msvs_to_msbuild_converters = {}
29 36
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 # This may be unrecognized because it's an exclusion list. If the 400 # This may be unrecognized because it's an exclusion list. If the
394 # setting name has the _excluded suffix, then check the root name. 401 # setting name has the _excluded suffix, then check the root name.
395 unrecognized = True 402 unrecognized = True
396 m = re.match(_EXCLUDED_SUFFIX_RE, setting) 403 m = re.match(_EXCLUDED_SUFFIX_RE, setting)
397 if m: 404 if m:
398 root_setting = m.group(1) 405 root_setting = m.group(1)
399 unrecognized = root_setting not in settings 406 unrecognized = root_setting not in settings
400 407
401 if unrecognized: 408 if unrecognized:
402 # We don't know this setting. Give a warning. 409 # We don't know this setting. Give a warning.
403 print >> stderr, error_msg 410 print(error_msg, file=stderr)
404 411
405 412
406 def FixVCMacroSlashes(s): 413 def FixVCMacroSlashes(s):
407 """Replace macros which have excessive following slashes. 414 """Replace macros which have excessive following slashes.
408 415
409 These macros are known to have a built-in trailing slash. Furthermore, many 416 These macros are known to have a built-in trailing slash. Furthermore, many
410 scripts hiccup on processing paths with extra slashes in the middle. 417 scripts hiccup on processing paths with extra slashes in the middle.
411 418
412 This list is probably not exhaustive. Add as needed. 419 This list is probably not exhaustive. Add as needed.
413 """ 420 """
(...skipping 12 matching lines...) Expand all
426 '$(ConfigurationName)': '$(Configuration)', 433 '$(ConfigurationName)': '$(Configuration)',
427 '$(InputDir)': '%(RelativeDir)', 434 '$(InputDir)': '%(RelativeDir)',
428 '$(InputExt)': '%(Extension)', 435 '$(InputExt)': '%(Extension)',
429 '$(InputFileName)': '%(Filename)%(Extension)', 436 '$(InputFileName)': '%(Filename)%(Extension)',
430 '$(InputName)': '%(Filename)', 437 '$(InputName)': '%(Filename)',
431 '$(InputPath)': '%(Identity)', 438 '$(InputPath)': '%(Identity)',
432 '$(ParentName)': '$(ProjectFileName)', 439 '$(ParentName)': '$(ProjectFileName)',
433 '$(PlatformName)': '$(Platform)', 440 '$(PlatformName)': '$(Platform)',
434 '$(SafeInputName)': '%(Filename)', 441 '$(SafeInputName)': '%(Filename)',
435 } 442 }
436 for old, new in replace_map.iteritems(): 443 for old, new in replace_map.items():
437 s = s.replace(old, new) 444 s = s.replace(old, new)
438 s = FixVCMacroSlashes(s) 445 s = FixVCMacroSlashes(s)
439 return s 446 return s
440 447
441 448
442 def ConvertToMSBuildSettings(msvs_settings, stderr=sys.stderr): 449 def ConvertToMSBuildSettings(msvs_settings, stderr=sys.stderr):
443 """Converts MSVS settings (VS2008 and earlier) to MSBuild settings (VS2010+). 450 """Converts MSVS settings (VS2008 and earlier) to MSBuild settings (VS2010+).
444 451
445 Args: 452 Args:
446 msvs_settings: A dictionary. The key is the tool name. The values are 453 msvs_settings: A dictionary. The key is the tool name. The values are
447 themselves dictionaries of settings and their values. 454 themselves dictionaries of settings and their values.
448 stderr: The stream receiving the error messages. 455 stderr: The stream receiving the error messages.
449 456
450 Returns: 457 Returns:
451 A dictionary of MSBuild settings. The key is either the MSBuild tool name 458 A dictionary of MSBuild settings. The key is either the MSBuild tool name
452 or the empty string (for the global settings). The values are themselves 459 or the empty string (for the global settings). The values are themselves
453 dictionaries of settings and their values. 460 dictionaries of settings and their values.
454 """ 461 """
455 msbuild_settings = {} 462 msbuild_settings = {}
456 for msvs_tool_name, msvs_tool_settings in msvs_settings.iteritems(): 463 for msvs_tool_name, msvs_tool_settings in msvs_settings.items():
457 if msvs_tool_name in _msvs_to_msbuild_converters: 464 if msvs_tool_name in _msvs_to_msbuild_converters:
458 msvs_tool = _msvs_to_msbuild_converters[msvs_tool_name] 465 msvs_tool = _msvs_to_msbuild_converters[msvs_tool_name]
459 for msvs_setting, msvs_value in msvs_tool_settings.iteritems(): 466 for msvs_setting, msvs_value in msvs_tool_settings.items():
460 if msvs_setting in msvs_tool: 467 if msvs_setting in msvs_tool:
461 # Invoke the translation function. 468 # Invoke the translation function.
462 try: 469 try:
463 msvs_tool[msvs_setting](msvs_value, msbuild_settings) 470 msvs_tool[msvs_setting](msvs_value, msbuild_settings)
464 except ValueError, e: 471 except ValueError as e:
465 print >> stderr, ('Warning: while converting %s/%s to MSBuild, ' 472 print(('Warning: while converting %s/%s to MSBuild, '
466 '%s' % (msvs_tool_name, msvs_setting, e)) 473 '%s' % (msvs_tool_name, msvs_setting, e)),
474 file=stderr)
467 else: 475 else:
468 _ValidateExclusionSetting(msvs_setting, 476 _ValidateExclusionSetting(msvs_setting,
469 msvs_tool, 477 msvs_tool,
470 ('Warning: unrecognized setting %s/%s ' 478 ('Warning: unrecognized setting %s/%s '
471 'while converting to MSBuild.' % 479 'while converting to MSBuild.' %
472 (msvs_tool_name, msvs_setting)), 480 (msvs_tool_name, msvs_setting)),
473 stderr) 481 stderr)
474 else: 482 else:
475 print >> stderr, ('Warning: unrecognized tool %s while converting to ' 483 print(('Warning: unrecognized tool %s while converting to '
476 'MSBuild.' % msvs_tool_name) 484 'MSBuild.' % msvs_tool_name), file=stderr)
477 return msbuild_settings 485 return msbuild_settings
478 486
479 487
480 def ValidateMSVSSettings(settings, stderr=sys.stderr): 488 def ValidateMSVSSettings(settings, stderr=sys.stderr):
481 """Validates that the names of the settings are valid for MSVS. 489 """Validates that the names of the settings are valid for MSVS.
482 490
483 Args: 491 Args:
484 settings: A dictionary. The key is the tool name. The values are 492 settings: A dictionary. The key is the tool name. The values are
485 themselves dictionaries of settings and their values. 493 themselves dictionaries of settings and their values.
486 stderr: The stream receiving the error messages. 494 stderr: The stream receiving the error messages.
(...skipping 19 matching lines...) Expand all
506 514
507 Args: 515 Args:
508 validators: A dictionary of tools and their validators. 516 validators: A dictionary of tools and their validators.
509 settings: A dictionary. The key is the tool name. The values are 517 settings: A dictionary. The key is the tool name. The values are
510 themselves dictionaries of settings and their values. 518 themselves dictionaries of settings and their values.
511 stderr: The stream receiving the error messages. 519 stderr: The stream receiving the error messages.
512 """ 520 """
513 for tool_name in settings: 521 for tool_name in settings:
514 if tool_name in validators: 522 if tool_name in validators:
515 tool_validators = validators[tool_name] 523 tool_validators = validators[tool_name]
516 for setting, value in settings[tool_name].iteritems(): 524 for setting, value in settings[tool_name].items():
517 if setting in tool_validators: 525 if setting in tool_validators:
518 try: 526 try:
519 tool_validators[setting](value) 527 tool_validators[setting](value)
520 except ValueError, e: 528 except ValueError as e:
521 print >> stderr, ('Warning: for %s/%s, %s' % 529 print(('Warning: for %s/%s, %s' %
522 (tool_name, setting, e)) 530 (tool_name, setting, e)), file=stderr)
523 else: 531 else:
524 _ValidateExclusionSetting(setting, 532 _ValidateExclusionSetting(setting,
525 tool_validators, 533 tool_validators,
526 ('Warning: unrecognized setting %s/%s' % 534 ('Warning: unrecognized setting %s/%s' %
527 (tool_name, setting)), 535 (tool_name, setting)),
528 stderr) 536 stderr)
529 537
530 else: 538 else:
531 print >> stderr, ('Warning: unrecognized tool %s' % tool_name) 539 print(('Warning: unrecognized tool %s' % tool_name), file=stderr)
532 540
533 541
534 # MSVS and MBuild names of the tools. 542 # MSVS and MBuild names of the tools.
535 _compile = _Tool('VCCLCompilerTool', 'ClCompile') 543 _compile = _Tool('VCCLCompilerTool', 'ClCompile')
536 _link = _Tool('VCLinkerTool', 'Link') 544 _link = _Tool('VCLinkerTool', 'Link')
537 _midl = _Tool('VCMIDLTool', 'Midl') 545 _midl = _Tool('VCMIDLTool', 'Midl')
538 _rc = _Tool('VCResourceCompilerTool', 'ResourceCompile') 546 _rc = _Tool('VCResourceCompilerTool', 'ResourceCompile')
539 _lib = _Tool('VCLibrarianTool', 'Lib') 547 _lib = _Tool('VCLibrarianTool', 'Lib')
540 _manifest = _Tool('VCManifestTool', 'Manifest') 548 _manifest = _Tool('VCManifestTool', 'Manifest')
541 _masm = _Tool('MASM', 'MASM') 549 _masm = _Tool('MASM', 'MASM')
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 _MSBuildOnly(_manifest, 'SuppressDependencyElement', _boolean) # /nodependency 1095 _MSBuildOnly(_manifest, 'SuppressDependencyElement', _boolean) # /nodependency
1088 _MSBuildOnly(_manifest, 'TrackerLogDirectory', _folder_name) 1096 _MSBuildOnly(_manifest, 'TrackerLogDirectory', _folder_name)
1089 1097
1090 1098
1091 # Directives for MASM. 1099 # Directives for MASM.
1092 # See "$(VCTargetsPath)\BuildCustomizations\masm.xml" for the schema of the 1100 # See "$(VCTargetsPath)\BuildCustomizations\masm.xml" for the schema of the
1093 # MSBuild MASM settings. 1101 # MSBuild MASM settings.
1094 1102
1095 # Options that have the same name in MSVS and MSBuild. 1103 # Options that have the same name in MSVS and MSBuild.
1096 _Same(_masm, 'UseSafeExceptionHandlers', _boolean) # /safeseh 1104 _Same(_masm, 'UseSafeExceptionHandlers', _boolean) # /safeseh
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698