Skip to content

Commit

Permalink
gyp: replace deprecated functions
Browse files Browse the repository at this point in the history
* assertEquals() with assertEqual()
* iteritems() with items() for Python 3.
* xrange() with range() for Python 3.

#1150
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
rodrigc authored and rvagg committed Apr 24, 2019
1 parent 2040cd2 commit 7535e44
Show file tree
Hide file tree
Showing 22 changed files with 129 additions and 130 deletions.
3 changes: 1 addition & 2 deletions gyp/PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@
def _LicenseHeader(input_api):
# Accept any year number from 2009 to the current year.
current_year = int(input_api.time.strftime('%Y'))
allowed_years = (str(s) for s in reversed(xrange(2009, current_year + 1)))

allowed_years = (str(s) for s in reversed(range(2009, current_year + 1)))
years_re = '(' + '|'.join(allowed_years) + ')'

# The (c) is deprecated, but tolerate it until it's removed from all files.
Expand Down
8 changes: 4 additions & 4 deletions gyp/pylib/gyp/MSVSSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def ConvertVCMacrosToMSBuild(s):
'$(PlatformName)': '$(Platform)',
'$(SafeInputName)': '%(Filename)',
}
for old, new in replace_map.iteritems():
for old, new in replace_map.items():
s = s.replace(old, new)
s = FixVCMacroSlashes(s)
return s
Expand All @@ -455,10 +455,10 @@ def ConvertToMSBuildSettings(msvs_settings, stderr=sys.stderr):
dictionaries of settings and their values.
"""
msbuild_settings = {}
for msvs_tool_name, msvs_tool_settings in msvs_settings.iteritems():
for msvs_tool_name, msvs_tool_settings in msvs_settings.items():
if msvs_tool_name in _msvs_to_msbuild_converters:
msvs_tool = _msvs_to_msbuild_converters[msvs_tool_name]
for msvs_setting, msvs_value in msvs_tool_settings.iteritems():
for msvs_setting, msvs_value in msvs_tool_settings.items():
if msvs_setting in msvs_tool:
# Invoke the translation function.
try:
Expand Down Expand Up @@ -515,7 +515,7 @@ def _ValidateSettings(validators, settings, stderr):
for tool_name in settings:
if tool_name in validators:
tool_validators = validators[tool_name]
for setting, value in settings[tool_name].iteritems():
for setting, value in settings[tool_name].items():
if setting in tool_validators:
try:
tool_validators[setting](value)
Expand Down
4 changes: 2 additions & 2 deletions gyp/pylib/gyp/MSVSUserFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def AddDebugSettings(self, config_name, command, environment = {},

if environment and isinstance(environment, dict):
env_list = ['%s="%s"' % (key, val)
for (key,val) in environment.iteritems()]
for (key,val) in environment.items()]
environment = ' '.join(env_list)
else:
environment = ''
Expand Down Expand Up @@ -135,7 +135,7 @@ def AddDebugSettings(self, config_name, command, environment = {},
def WriteIfChanged(self):
"""Writes the user file."""
configs = ['Configurations']
for config, spec in sorted(self.configurations.iteritems()):
for config, spec in sorted(self.configurations.items()):
configs.append(spec)

content = ['VisualStudioUserFile',
Expand Down
2 changes: 1 addition & 1 deletion gyp/pylib/gyp/MSVSUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def InsertLargePdbShims(target_list, target_dicts, vars):

# Set up the shim to output its PDB to the same location as the final linker
# target.
for config_name, config in shim_dict.get('configurations').iteritems():
for config_name, config in shim_dict.get('configurations').items():
pdb_path = _GetPdbPath(target_dict, config_name, vars)

# A few keys that we don't want to propagate.
Expand Down
4 changes: 2 additions & 2 deletions gyp/pylib/gyp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def Noop(value):
# We always want to ignore the environment when regenerating, to avoid
# duplicate or changed flags in the environment at the time of regeneration.
flags = ['--ignore-environment']
for name, metadata in options._regeneration_metadata.iteritems():
for name, metadata in options._regeneration_metadata.items():
opt = metadata['opt']
value = getattr(options, name)
value_predicate = metadata['type'] == 'path' and FixPath or Noop
Expand Down Expand Up @@ -434,7 +434,7 @@ def gyp_main(args):
build_file_dir = os.path.abspath(os.path.dirname(build_file))
build_file_dir_components = build_file_dir.split(os.path.sep)
components_len = len(build_file_dir_components)
for index in xrange(components_len - 1, -1, -1):
for index in range(components_len - 1, -1, -1):
if build_file_dir_components[index] == 'src':
options.depth = os.path.sep.join(build_file_dir_components)
break
Expand Down
2 changes: 1 addition & 1 deletion gyp/pylib/gyp/easy_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _ConstructContentList(xml_parts, specification, pretty, level=0):
# Optionally in second position is a dictionary of the attributes.
rest = specification[1:]
if rest and isinstance(rest[0], dict):
for at, val in sorted(rest[0].iteritems()):
for at, val in sorted(rest[0].items()):
xml_parts.append(' %s="%s"' % (at, _XmlEscape(val, attr=True)))
rest = rest[1:]
if rest:
Expand Down
6 changes: 3 additions & 3 deletions gyp/pylib/gyp/generator/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def WriteSourceFlags(self, spec, configs):
Args:
spec, configs: input from gyp.
"""
for configname, config in sorted(configs.iteritems()):
for configname, config in sorted(configs.items()):
extracted_includes = []

self.WriteLn('\n# Flags passed to both C and C++ files.')
Expand Down Expand Up @@ -790,7 +790,7 @@ def WriteTargetFlags(self, spec, configs, link_deps):
static_libs, dynamic_libs, ldflags_libs = self.FilterLibraries(libraries)

if self.type != 'static_library':
for configname, config in sorted(configs.iteritems()):
for configname, config in sorted(configs.items()):
ldflags = list(config.get('ldflags', []))
self.WriteLn('')
self.WriteList(ldflags, 'LOCAL_LDFLAGS_%s' % configname)
Expand Down Expand Up @@ -839,7 +839,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, part_of_all,
settings = spec.get('aosp_build_settings', {})
if settings:
self.WriteLn('### Set directly by aosp_build_settings.')
for k, v in settings.iteritems():
for k, v in settings.items():
if isinstance(v, list):
self.WriteList(v, k)
else:
Expand Down
2 changes: 1 addition & 1 deletion gyp/pylib/gyp/generator/gypd.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def GenerateOutput(target_list, target_dicts, data, params):
if not output_file in output_files:
output_files[output_file] = input_file

for output_file, input_file in output_files.iteritems():
for output_file, input_file in output_files.items():
output = open(output_file, 'w')
pprint.pprint(data[input_file], output)
output.close()
4 changes: 2 additions & 2 deletions gyp/pylib/gyp/generator/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def _ValidateSourcesForOSX(spec, all_sources):
basenames.setdefault(basename, []).append(source)

error = ''
for basename, files in basenames.iteritems():
for basename, files in basenames.items():
if len(files) > 1:
error += ' %s: %s\n' % (basename, ' '.join(files))

Expand Down Expand Up @@ -1547,7 +1547,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
# Postbuilds expect to be run in the gyp file's directory, so insert an
# implicit postbuild to cd to there.
postbuilds.insert(0, gyp.common.EncodePOSIXShellList(['cd', self.path]))
for i in xrange(len(postbuilds)):
for i in range(len(postbuilds)):
if not postbuilds[i].startswith('$'):
postbuilds[i] = EscapeShellArgument(postbuilds[i])
self.WriteLn('%s: builddir := $(abs_builddir)' % QuoteSpaces(self.output))
Expand Down
58 changes: 29 additions & 29 deletions gyp/pylib/gyp/generator/msvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def _AddCustomBuildToolForMSVS(p, spec, primary_input,
'CommandLine': cmd,
})
# Add to the properties of primary input for each config.
for config_name, c_data in spec['configurations'].iteritems():
for config_name, c_data in spec['configurations'].items():
p.AddFileConfig(_FixPath(primary_input),
_ConfigFullName(config_name, c_data), tools=[tool])

Expand Down Expand Up @@ -971,7 +971,7 @@ def _ValidateSourcesForMSVSProject(spec, version):
basenames.setdefault(basename, []).append(source)

error = ''
for basename, files in basenames.iteritems():
for basename, files in basenames.items():
if len(files) > 1:
error += ' %s: %s\n' % (basename, ' '.join(files))

Expand Down Expand Up @@ -1003,7 +1003,7 @@ def _GenerateMSVSProject(project, options, version, generator_flags):
relative_path_of_gyp_file = gyp.common.RelativePath(gyp_path, project_dir)

config_type = _GetMSVSConfigurationType(spec, project.build_file)
for config_name, config in spec['configurations'].iteritems():
for config_name, config in spec['configurations'].items():
_AddConfigurationToMSVSProject(p, spec, config_type, config_name, config)

# MSVC08 and prior version cannot handle duplicate basenames in the same
Expand Down Expand Up @@ -1369,10 +1369,10 @@ def _ConvertToolsToExpectedForm(tools):
A list of Tool objects.
"""
tool_list = []
for tool, settings in tools.iteritems():
for tool, settings in tools.items():
# Collapse settings with lists.
settings_fixed = {}
for setting, value in settings.iteritems():
for setting, value in settings.items():
if type(value) == list:
if ((tool == 'VCLinkerTool' and
setting == 'AdditionalDependencies') or
Expand Down Expand Up @@ -1547,7 +1547,7 @@ def _IdlFilesHandledNonNatively(spec, sources):
def _GetPrecompileRelatedFiles(spec):
# Gather a list of precompiled header related sources.
precompiled_related = []
for _, config in spec['configurations'].iteritems():
for _, config in spec['configurations'].items():
for k in precomp_keys:
f = config.get(k)
if f:
Expand All @@ -1558,7 +1558,7 @@ def _GetPrecompileRelatedFiles(spec):
def _ExcludeFilesFromBeingBuilt(p, spec, excluded_sources, excluded_idl,
list_excluded):
exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl)
for file_name, excluded_configs in exclusions.iteritems():
for file_name, excluded_configs in exclusions.items():
if (not list_excluded and
len(excluded_configs) == len(spec['configurations'])):
# If we're not listing excluded files, then they won't appear in the
Expand All @@ -1575,7 +1575,7 @@ def _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl):
# Exclude excluded sources from being built.
for f in excluded_sources:
excluded_configs = []
for config_name, config in spec['configurations'].iteritems():
for config_name, config in spec['configurations'].items():
precomped = [_FixPath(config.get(i, '')) for i in precomp_keys]
# Don't do this for ones that are precompiled header related.
if f not in precomped:
Expand All @@ -1585,7 +1585,7 @@ def _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl):
# Exclude them now.
for f in excluded_idl:
excluded_configs = []
for config_name, config in spec['configurations'].iteritems():
for config_name, config in spec['configurations'].items():
excluded_configs.append((config_name, config))
exclusions[f] = excluded_configs
return exclusions
Expand All @@ -1594,7 +1594,7 @@ def _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl):
def _AddToolFilesToMSVS(p, spec):
# Add in tool files (rules).
tool_files = OrderedSet()
for _, config in spec['configurations'].iteritems():
for _, config in spec['configurations'].items():
for f in config.get('msvs_tool_files', []):
tool_files.add(f)
for f in tool_files:
Expand All @@ -1607,7 +1607,7 @@ def _HandlePreCompiledHeaders(p, sources, spec):
# kind (i.e. C vs. C++) as the precompiled header source stub needs
# to have use of precompiled headers disabled.
extensions_excluded_from_precompile = []
for config_name, config in spec['configurations'].iteritems():
for config_name, config in spec['configurations'].items():
source = config.get('msvs_precompiled_source')
if source:
source = _FixPath(source)
Expand All @@ -1628,7 +1628,7 @@ def DisableForSourceTree(source_tree):
else:
basename, extension = os.path.splitext(source)
if extension in extensions_excluded_from_precompile:
for config_name, config in spec['configurations'].iteritems():
for config_name, config in spec['configurations'].items():
tool = MSVSProject.Tool('VCCLCompilerTool',
{'UsePrecompiledHeader': '0',
'ForcedIncludeFiles': '$(NOINHERIT)'})
Expand Down Expand Up @@ -1679,7 +1679,7 @@ def _WriteMSVSUserFile(project_path, version, spec):
return # Nothing to add
# Write out the user file.
user_file = _CreateMSVSUserFile(project_path, version, spec)
for config_name, c_data in spec['configurations'].iteritems():
for config_name, c_data in spec['configurations'].items():
user_file.AddDebugSettings(_ConfigFullName(config_name, c_data),
action, environment, working_directory)
user_file.WriteIfChanged()
Expand Down Expand Up @@ -1730,7 +1730,7 @@ def _GetPathDict(root, path):
def _DictsToFolders(base_path, bucket, flat):
# Convert to folders recursively.
children = []
for folder, contents in bucket.iteritems():
for folder, contents in bucket.items():
if type(contents) == dict:
folder_children = _DictsToFolders(os.path.join(base_path, folder),
contents, flat)
Expand Down Expand Up @@ -1802,7 +1802,7 @@ def _GetPlatformOverridesOfProject(spec):
# Prepare a dict indicating which project configurations are used for which
# solution configurations for this target.
config_platform_overrides = {}
for config_name, c in spec['configurations'].iteritems():
for config_name, c in spec['configurations'].items():
config_fullname = _ConfigFullName(config_name, c)
platform = c.get('msvs_target_platform', _ConfigPlatform(c))
fixed_config_fullname = '%s|%s' % (
Expand Down Expand Up @@ -1941,7 +1941,7 @@ def PerformBuild(data, configurations, params):
msvs_version = params['msvs_version']
devenv = os.path.join(msvs_version.path, 'Common7', 'IDE', 'devenv.com')

for build_file, build_file_dict in data.iteritems():
for build_file, build_file_dict in data.items():
(build_file_root, build_file_ext) = os.path.splitext(build_file)
if build_file_ext != '.gyp':
continue
Expand Down Expand Up @@ -1990,7 +1990,7 @@ def GenerateOutput(target_list, target_dicts, data, params):
configs = set()
for qualified_target in target_list:
spec = target_dicts[qualified_target]
for config_name, config in spec['configurations'].iteritems():
for config_name, config in spec['configurations'].items():
configs.add(_ConfigFullName(config_name, config))
configs = list(configs)

Expand Down Expand Up @@ -2630,7 +2630,7 @@ def _GetConfigurationCondition(name, settings):

def _GetMSBuildProjectConfigurations(configurations):
group = ['ItemGroup', {'Label': 'ProjectConfigurations'}]
for (name, settings) in sorted(configurations.iteritems()):
for (name, settings) in sorted(configurations.items()):
configuration, platform = _GetConfigurationAndPlatform(name, settings)
designation = '%s|%s' % (configuration, platform)
group.append(
Expand Down Expand Up @@ -2700,7 +2700,7 @@ def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name):

def _GetMSBuildConfigurationDetails(spec, build_file):
properties = {}
for name, settings in spec['configurations'].iteritems():
for name, settings in spec['configurations'].items():
msbuild_attributes = _GetMSBuildAttributes(spec, settings, build_file)
condition = _GetConfigurationCondition(name, settings)
character_set = msbuild_attributes.get('CharacterSet')
Expand Down Expand Up @@ -2729,7 +2729,7 @@ def _GetMSBuildPropertySheets(configurations):
user_props = r'$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props'
additional_props = {}
props_specified = False
for name, settings in sorted(configurations.iteritems()):
for name, settings in sorted(configurations.items()):
configuration = _GetConfigurationCondition(name, settings)
if 'msbuild_props' in settings:
additional_props[configuration] = _FixPaths(settings['msbuild_props'])
Expand All @@ -2751,7 +2751,7 @@ def _GetMSBuildPropertySheets(configurations):
]
else:
sheets = []
for condition, props in additional_props.iteritems():
for condition, props in additional_props.items():
import_group = [
'ImportGroup',
{'Label': 'PropertySheets',
Expand Down Expand Up @@ -2878,7 +2878,7 @@ def _GetMSBuildConfigurationGlobalProperties(spec, configurations, build_file):
new_paths = '$(ExecutablePath);' + ';'.join(new_paths)

properties = {}
for (name, configuration) in sorted(configurations.iteritems()):
for (name, configuration) in sorted(configurations.items()):
condition = _GetConfigurationCondition(name, configuration)
attributes = _GetMSBuildAttributes(spec, configuration, build_file)
msbuild_settings = configuration['finalized_msbuild_settings']
Expand All @@ -2903,7 +2903,7 @@ def _GetMSBuildConfigurationGlobalProperties(spec, configurations, build_file):
_AddConditionalProperty(properties, condition, 'ExecutablePath',
new_paths)
tool_settings = msbuild_settings.get('', {})
for name, value in sorted(tool_settings.iteritems()):
for name, value in sorted(tool_settings.items()):
formatted_value = _GetValueFormattedForMSBuild('', name, value)
_AddConditionalProperty(properties, condition, name, formatted_value)
return _GetMSBuildPropertyGroup(spec, None, properties)
Expand Down Expand Up @@ -2972,7 +2972,7 @@ def GetEdges(node):
# NOTE: reverse(topsort(DAG)) = topsort(reverse_edges(DAG))
for name in reversed(properties_ordered):
values = properties[name]
for value, conditions in sorted(values.iteritems()):
for value, conditions in sorted(values.items()):
if len(conditions) == num_configurations:
# If the value is the same all configurations,
# just add one unconditional entry.
Expand All @@ -2985,18 +2985,18 @@ def GetEdges(node):

def _GetMSBuildToolSettingsSections(spec, configurations):
groups = []
for (name, configuration) in sorted(configurations.iteritems()):
for (name, configuration) in sorted(configurations.items()):
msbuild_settings = configuration['finalized_msbuild_settings']
group = ['ItemDefinitionGroup',
{'Condition': _GetConfigurationCondition(name, configuration)}
]
for tool_name, tool_settings in sorted(msbuild_settings.iteritems()):
for tool_name, tool_settings in sorted(msbuild_settings.items()):
# Skip the tool named '' which is a holder of global settings handled
# by _GetMSBuildConfigurationGlobalProperties.
if tool_name:
if tool_settings:
tool = [tool_name]
for name, value in sorted(tool_settings.iteritems()):
for name, value in sorted(tool_settings.items()):
formatted_value = _GetValueFormattedForMSBuild(tool_name, name,
value)
tool.append([name, formatted_value])
Expand Down Expand Up @@ -3196,7 +3196,7 @@ def _AddSources2(spec, sources, exclusions, grouped_sources,
{'Condition': condition},
'true'])
# Add precompile if needed
for config_name, configuration in spec['configurations'].iteritems():
for config_name, configuration in spec['configurations'].items():
precompiled_source = configuration.get('msvs_precompiled_source', '')
if precompiled_source != '':
precompiled_source = _FixPath(precompiled_source)
Expand Down Expand Up @@ -3436,7 +3436,7 @@ def _GenerateActionsForMSBuild(spec, actions_to_add):
"""
sources_handled_by_action = OrderedSet()
actions_spec = []
for primary_input, actions in actions_to_add.iteritems():
for primary_input, actions in actions_to_add.items():
inputs = OrderedSet()
outputs = OrderedSet()
descriptions = []
Expand Down
Loading

0 comments on commit 7535e44

Please sign in to comment.