Commit fa0ed4a

Browse files
cclaussrvagg
authored andcommitted
build: more Python 3 compat, replace compile with ast
Make Python 3 compatiblity changes so the code works in both Python 2 and Python 3. Especially, make changes required because the compiler module was removed in Python 3 in favor of the ast module that exists in both Python 2 and Python 3. PR-URL: #1820 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rod Vagg <r@va.gg> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent 18d5c7c commit fa0ed4a

7 files changed

Lines changed: 50 additions & 56 deletions

File tree

‎gyp/pylib/gyp/generator/analyzer.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def find_matching_compile_target_names(self):
671671
assertself.is_build_impacted();
672672
# Compile targets are found by searching up from changed targets.
673673
# Reset the visited status for _GetBuildTargets.
674-
fortargetinself._name_to_target.itervalues():
674+
fortargetinself._name_to_target.values():
675675
target.visited=False
676676

677677
supplied_targets=_LookupTargets(self._supplied_target_names_no_all(),

‎gyp/pylib/gyp/generator/eclipse.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def WriteMacros(out, eclipse_langs, defines):
272272
out.write(' <language name="holder for library settings"></language>\n')
273273
forlangineclipse_langs:
274274
out.write(' <language name="%s">\n'%lang)
275-
forkeyinsorted(defines.iterkeys()):
275+
forkeyinsorted(defines):
276276
out.write(' <macro><name>%s</name><value>%s</value></macro>\n'%
277277
(escape(key), escape(defines[key])))
278278
out.write(' </language>\n')

‎gyp/pylib/gyp/generator/make.py‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def Write(self, qualified_target, base_path, output_filename, spec, configs,
821821
gyp.xcode_emulation.MacPrefixHeader(
822822
self.xcode_settings, lambdap: Sourceify(self.Absolutify(p)),
823823
self.Pchify))
824-
sources=filter(Compilable, all_sources)
824+
sources=list(filter(Compilable, all_sources))
825825
ifsources:
826826
self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT1)
827827
extensions=set([os.path.splitext(s)[1] forsinsources])
@@ -950,7 +950,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
950950
'%s%s'
951951
% (name, cd_action, command))
952952
self.WriteLn()
953-
outputs=map(self.Absolutify, outputs)
953+
outputs=[self.Absolutify(output) foroutputinoutputs]
954954
# The makefile rules are all relative to the top dir, but the gyp actions
955955
# are defined relative to their containing dir. This replaces the obj
956956
# variable for the action rule with an absolute version so that the output
@@ -974,7 +974,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
974974
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
975975
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
976976

977-
self.WriteDoCmd(outputs, map(Sourceify, map(self.Absolutify, inputs)),
977+
self.WriteDoCmd(outputs, [Sourceify(self.Absolutify(i)) foriininputs],
978978
part_of_all=part_of_all, command=name)
979979

980980
# Stuff the outputs in a variable so we can refer to them later.
@@ -1023,8 +1023,8 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10231023
extra_sources+=outputs
10241024
ifint(rule.get('process_outputs_as_mac_bundle_resources', False)):
10251025
extra_mac_bundle_resources+=outputs
1026-
inputs=map(Sourceify, map(self.Absolutify, [rule_source] +
1027-
rule.get('inputs', [])))
1026+
inputs=[Sourceify(self.Absolutify(i)) fori
1027+
in [rule_source] +rule.get('inputs', [])]
10281028
actions= ['$(call do_cmd,%s_%d)'% (name, count)]
10291029

10301030
ifname=='resources_grit':
@@ -1040,7 +1040,7 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10401040
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
10411041
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
10421042

1043-
outputs=map(self.Absolutify, outputs)
1043+
outputs=[self.Absolutify(output) foroutputinoutputs]
10441044
all_outputs+=outputs
10451045
# Only write the 'obj' and 'builddir' rules for the "primary" output
10461046
# (:1); it's superfluous for the "extra outputs", and this avoids
@@ -1147,7 +1147,7 @@ def WriteCopies(self, copies, extra_outputs, part_of_all):
11471147
path=gyp.xcode_emulation.ExpandEnvVars(path, env)
11481148
self.WriteDoCmd([output], [path], 'copy', part_of_all)
11491149
outputs.append(output)
1150-
self.WriteLn('%s = %s'% (variable, ' '.join(map(QuoteSpaces, outputs))))
1150+
self.WriteLn('%s = %s'% (variable, ' '.join(QuoteSpaces(o) foroinoutputs)))
11511151
extra_outputs.append('$(%s)'%variable)
11521152
self.WriteLn()
11531153

@@ -1158,7 +1158,7 @@ def WriteMacBundleResources(self, resources, bundle_deps):
11581158

11591159
foroutput, resingyp.xcode_emulation.GetMacBundleResources(
11601160
generator_default_variables['PRODUCT_DIR'], self.xcode_settings,
1161-
map(Sourceify, map(self.Absolutify, resources))):
1161+
[Sourceify(self.Absolutify(r)) forrinresources]):
11621162
_, ext=os.path.splitext(output)
11631163
ifext!='.xcassets':
11641164
# Make does not supports '.xcassets' emulation.
@@ -1238,11 +1238,11 @@ def WriteSources(self, configs, deps, sources,
12381238
self.WriteList(cflags_objcc, 'CFLAGS_OBJCC_%s'%configname)
12391239
includes=config.get('include_dirs')
12401240
ifincludes:
1241-
includes=map(Sourceify, map(self.Absolutify, includes))
1241+
includes=[Sourceify(self.Absolutify(i)) foriinincludes]
12421242
self.WriteList(includes, 'INCS_%s'%configname, prefix='-I')
12431243

1244-
compilable=filter(Compilable, sources)
1245-
objs=map(self.Objectify, map(self.Absolutify, map(Target, compilable)))
1244+
compilable=list(filter(Compilable, sources))
1245+
objs=[self.Objectify(self.Absolutify(Target(c)))forcincompilable]
12461246
self.WriteList(objs, 'OBJS')
12471247

12481248
forobjinobjs:
@@ -1314,7 +1314,7 @@ def WriteSources(self, configs, deps, sources,
13141314

13151315
# If there are any object files in our input file list, link them into our
13161316
# output.
1317-
extra_link_deps+=filter(Linkable, sources)
1317+
extra_link_deps+=list(filter(Linkable, sources))
13181318

13191319
self.WriteLn()
13201320

@@ -1564,7 +1564,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15641564

15651565
# Bundle dependencies. Note that the code below adds actions to this
15661566
# target, so if you move these two lines, move the lines below as well.
1567-
self.WriteList(map(QuoteSpaces, bundle_deps), 'BUNDLE_DEPS')
1567+
self.WriteList([QuoteSpaces(dep) fordepinbundle_deps], 'BUNDLE_DEPS')
15681568
self.WriteLn('%s: $(BUNDLE_DEPS)'%QuoteSpaces(self.output))
15691569

15701570
# After the framework is built, package it. Needs to happen before
@@ -1598,7 +1598,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15981598
ifself.type=='executable':
15991599
self.WriteLn('%s: LD_INPUTS := %s'% (
16001600
QuoteSpaces(self.output_binary),
1601-
' '.join(map(QuoteSpaces, link_deps))))
1601+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16021602
ifself.toolset=='host'andself.flavor=='android':
16031603
self.WriteDoCmd([self.output_binary], link_deps, 'link_host',
16041604
part_of_all, postbuilds=postbuilds)
@@ -1620,7 +1620,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
16201620
elifself.type=='shared_library':
16211621
self.WriteLn('%s: LD_INPUTS := %s'% (
16221622
QuoteSpaces(self.output_binary),
1623-
' '.join(map(QuoteSpaces, link_deps))))
1623+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16241624
self.WriteDoCmd([self.output_binary], link_deps, 'solink', part_of_all,
16251625
postbuilds=postbuilds)
16261626
elifself.type=='loadable_module':
@@ -1746,8 +1746,8 @@ def WriteMakeRule(self, outputs, inputs, actions=None, comment=None,
17461746
output is just a name to run the rule
17471747
command: (optional) command name to generate unambiguous labels
17481748
"""
1749-
outputs=map(QuoteSpaces, outputs)
1750-
inputs=map(QuoteSpaces, inputs)
1749+
outputs=[QuoteSpaces(o) foroinoutputs]
1750+
inputs=[QuoteSpaces(i) foriininputs]
17511751

17521752
ifcomment:
17531753
self.WriteLn('# '+comment)
@@ -1836,7 +1836,7 @@ def WriteAndroidNdkModuleRule(self, module_name, all_sources, link_deps):
18361836
default_cpp_ext=ext
18371837
self.WriteLn('LOCAL_CPP_EXTENSION := '+default_cpp_ext)
18381838

1839-
self.WriteList(map(self.Absolutify, filter(Compilable, all_sources)),
1839+
self.WriteList(list(map(self.Absolutify, filter(Compilable, all_sources))),
18401840
'LOCAL_SRC_FILES')
18411841

18421842
# Filter out those which do not match prefix and suffix and produce
@@ -1979,7 +1979,7 @@ def WriteAutoRegenerationRule(params, root_makefile, makefile_name,
19791979
"%(makefile_name)s: %(deps)s\n"
19801980
"\t$(call do_cmd,regen_makefile)\n\n"% {
19811981
'makefile_name': makefile_name,
1982-
'deps': ' '.join(map(SourceifyAndQuoteSpaces, build_files)),
1982+
'deps': ' '.join(SourceifyAndQuoteSpaces(bf) forbfinbuild_files),
19831983
'cmd': gyp.common.EncodePOSIXShellList(
19841984
[gyp_binary, '-fmake'] +
19851985
gyp.RegenerateFlags(options) +

‎gyp/pylib/gyp/generator/msvs.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name):
26912691

26922692
platform_name=None
26932693
msvs_windows_target_platform_version=None
2694-
forconfigurationinspec['configurations'].itervalues():
2694+
forconfigurationinspec['configurations'].values():
26952695
platform_name=platform_nameor_ConfigPlatform(configuration)
26962696
msvs_windows_target_platform_version= \
26972697
msvs_windows_target_platform_versionor \
@@ -3252,7 +3252,7 @@ def _GetMSBuildProjectReferences(project):
32523252
['Project', guid],
32533253
['ReferenceOutputAssembly', 'false']
32543254
]
3255-
forconfigindependency.spec.get('configurations', {}).itervalues():
3255+
forconfigindependency.spec.get('configurations', {}).values():
32563256
ifconfig.get('msvs_use_library_dependency_inputs', 0):
32573257
project_ref.append(['UseLibraryDependencyInputs', 'true'])
32583258
break
@@ -3321,7 +3321,7 @@ def _GenerateMSBuildProject(project, options, version, generator_flags):
33213321
extension_to_rule_name, _GetUniquePlatforms(spec))
33223322
missing_sources=_VerifySourcesExist(sources, project_dir)
33233323

3324-
forconfigurationinconfigurations.itervalues():
3324+
forconfigurationinconfigurations.values():
33253325
_FinalizeMSBuildSettings(spec, configuration)
33263326

33273327
# Add attributes to root element

‎gyp/pylib/gyp/input.py‎

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44

55
from __future__ importprint_function
66

7-
fromcompiler.astimportConst
8-
fromcompiler.astimportDict
9-
fromcompiler.astimportDiscard
10-
fromcompiler.astimportList
11-
fromcompiler.astimportModule
12-
fromcompiler.astimportNode
13-
fromcompiler.astimportStmt
14-
importcompiler
7+
importast
8+
159
importgyp.common
1610
importgyp.simple_copy
1711
importmultiprocessing
@@ -184,43 +178,39 @@ def CheckedEval(file_contents):
184178
Note that this is slower than eval() is.
185179
"""
186180

187-
ast=compiler.parse(file_contents)
188-
assertisinstance(ast, Module)
189-
c1=ast.getChildren()
190-
assertc1[0] isNone
191-
assertisinstance(c1[1], Stmt)
192-
c2=c1[1].getChildren()
193-
assertisinstance(c2[0], Discard)
194-
c3=c2[0].getChildren()
195-
assertlen(c3) ==1
196-
returnCheckNode(c3[0], [])
181+
syntax_tree=ast.parse(file_contents)
182+
assertisinstance(syntax_tree, ast.Module)
183+
c1=syntax_tree.body
184+
assertlen(c1) ==1
185+
c2=c1[0]
186+
assertisinstance(c2, ast.Expr)
187+
returnCheckNode(c2.value, [])
197188

198189

199190
defCheckNode(node, keypath):
200-
ifisinstance(node, Dict):
191+
ifisinstance(node, ast.Dict):
201192
c=node.getChildren()
202193
dict= {}
203-
forninrange(0, len(c), 2):
204-
assertisinstance(c[n], Const)
205-
key=c[n].getChildren()[0]
194+
forkey, valueinzip(node.keys, node.values):
195+
assertisinstance(key, ast.Str)
196+
key=key.s
206197
ifkeyindict:
207198
raiseGypError("Key '"+key+"' repeated at level "+
208199
repr(len(keypath) +1) +" with key path '"+
209200
'.'.join(keypath) +"'")
210201
kp=list(keypath) # Make a copy of the list for descending this node.
211202
kp.append(key)
212-
dict[key] =CheckNode(c[n+1], kp)
203+
dict[key] =CheckNode(value, kp)
213204
returndict
214-
elifisinstance(node, List):
215-
c=node.getChildren()
205+
elifisinstance(node, ast.List):
216206
children= []
217-
forindex, childinenumerate(c):
207+
forindex, childinenumerate(node.elts):
218208
kp=list(keypath) # Copy list.
219209
kp.append(repr(index))
220210
children.append(CheckNode(child, kp))
221211
returnchildren
222-
elifisinstance(node, Const):
223-
returnnode.getChildren()[0]
212+
elifisinstance(node, ast.Str):
213+
returnnode.s
224214
else:
225215
raiseTypeError("Unknown AST node at key path '"+'.'.join(keypath) +
226216
"': "+repr(node))
@@ -954,8 +944,12 @@ def ExpandVariables(input, phase, variables, build_file):
954944
else:
955945
replacement=variables[contents]
956946

947+
ifisinstance(replacement, bytes) andnotisinstance(replacement, str):
948+
replacement=replacement.decode("utf-8") # done on Python 3 only
957949
iftype(replacement) islist:
958950
foriteminreplacement:
951+
ifisinstance(item, bytes) andnotisinstance(item, str):
952+
item=item.decode("utf-8") # done on Python 3 only
959953
ifnotcontents[-1] =='/'andtype(item) notin (str, int):
960954
raiseGypError('Variable '+contents+
961955
' must expand to a string or list of strings; '+
@@ -1847,7 +1841,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18471841
# Create a DependencyGraphNode for each gyp file containing a target. Put
18481842
# it into a dict for easy access.
18491843
dependency_nodes= {}
1850-
fortargetintargets.iterkeys():
1844+
fortargetintargets:
18511845
build_file=gyp.common.BuildFile(target)
18521846
ifnotbuild_fileindependency_nodes:
18531847
dependency_nodes[build_file] =DependencyGraphNode(build_file)
@@ -1878,7 +1872,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18781872

18791873
# Files that have no dependencies are treated as dependent on root_node.
18801874
root_node=DependencyGraphNode(None)
1881-
forbuild_file_nodeindependency_nodes.itervalues():
1875+
forbuild_file_nodeindependency_nodes.values():
18821876
iflen(build_file_node.dependencies) ==0:
18831877
build_file_node.dependencies.append(root_node)
18841878
root_node.dependents.append(build_file_node)

‎gyp/pylib/gyp/xcode_emulation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ def _HasIOSTarget(targets):
16361636
def_AddIOSDeviceConfigurations(targets):
16371637
"""Clone all targets and append -iphoneos to the name. Configure these targets
16381638
to build for iOS devices and use correct architectures for those builds."""
1639-
fortarget_dictintargets.itervalues():
1639+
fortarget_dictintargets.values():
16401640
toolset=target_dict['toolset']
16411641
configs=target_dict['configurations']
16421642
forconfig_name, config_dictindict(configs).items():

‎gyp/pylib/gyp/xcode_ninja.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _TargetFromSpec(old_spec, params):
8585
"%s/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"%ninja_toplevel
8686

8787
if'configurations'inold_spec:
88-
forconfiginold_spec['configurations'].iterkeys():
88+
forconfiginold_spec['configurations']:
8989
old_xcode_settings= \
9090
old_spec['configurations'][config].get('xcode_settings', {})
9191
if'IPHONEOS_DEPLOYMENT_TARGET'inold_xcode_settings:

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit fa0ed4a

Browse files
cclaussrvagg
authored andcommitted
build: more Python 3 compat, replace compile with ast
Make Python 3 compatiblity changes so the code works in both Python 2 and Python 3. Especially, make changes required because the compiler module was removed in Python 3 in favor of the ast module that exists in both Python 2 and Python 3. PR-URL: #1820 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rod Vagg <r@va.gg> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent 18d5c7c commit fa0ed4a

7 files changed

Lines changed: 50 additions & 56 deletions

File tree

‎gyp/pylib/gyp/generator/analyzer.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def find_matching_compile_target_names(self):
671671
assertself.is_build_impacted();
672672
# Compile targets are found by searching up from changed targets.
673673
# Reset the visited status for _GetBuildTargets.
674-
fortargetinself._name_to_target.itervalues():
674+
fortargetinself._name_to_target.values():
675675
target.visited=False
676676

677677
supplied_targets=_LookupTargets(self._supplied_target_names_no_all(),

‎gyp/pylib/gyp/generator/eclipse.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def WriteMacros(out, eclipse_langs, defines):
272272
out.write(' <language name="holder for library settings"></language>\n')
273273
forlangineclipse_langs:
274274
out.write(' <language name="%s">\n'%lang)
275-
forkeyinsorted(defines.iterkeys()):
275+
forkeyinsorted(defines):
276276
out.write(' <macro><name>%s</name><value>%s</value></macro>\n'%
277277
(escape(key), escape(defines[key])))
278278
out.write(' </language>\n')

‎gyp/pylib/gyp/generator/make.py‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def Write(self, qualified_target, base_path, output_filename, spec, configs,
821821
gyp.xcode_emulation.MacPrefixHeader(
822822
self.xcode_settings, lambdap: Sourceify(self.Absolutify(p)),
823823
self.Pchify))
824-
sources=filter(Compilable, all_sources)
824+
sources=list(filter(Compilable, all_sources))
825825
ifsources:
826826
self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT1)
827827
extensions=set([os.path.splitext(s)[1] forsinsources])
@@ -950,7 +950,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
950950
'%s%s'
951951
% (name, cd_action, command))
952952
self.WriteLn()
953-
outputs=map(self.Absolutify, outputs)
953+
outputs=[self.Absolutify(output) foroutputinoutputs]
954954
# The makefile rules are all relative to the top dir, but the gyp actions
955955
# are defined relative to their containing dir. This replaces the obj
956956
# variable for the action rule with an absolute version so that the output
@@ -974,7 +974,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
974974
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
975975
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
976976

977-
self.WriteDoCmd(outputs, map(Sourceify, map(self.Absolutify, inputs)),
977+
self.WriteDoCmd(outputs, [Sourceify(self.Absolutify(i)) foriininputs],
978978
part_of_all=part_of_all, command=name)
979979

980980
# Stuff the outputs in a variable so we can refer to them later.
@@ -1023,8 +1023,8 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10231023
extra_sources+=outputs
10241024
ifint(rule.get('process_outputs_as_mac_bundle_resources', False)):
10251025
extra_mac_bundle_resources+=outputs
1026-
inputs=map(Sourceify, map(self.Absolutify, [rule_source] +
1027-
rule.get('inputs', [])))
1026+
inputs=[Sourceify(self.Absolutify(i)) fori
1027+
in [rule_source] +rule.get('inputs', [])]
10281028
actions= ['$(call do_cmd,%s_%d)'% (name, count)]
10291029

10301030
ifname=='resources_grit':
@@ -1040,7 +1040,7 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10401040
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
10411041
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
10421042

1043-
outputs=map(self.Absolutify, outputs)
1043+
outputs=[self.Absolutify(output) foroutputinoutputs]
10441044
all_outputs+=outputs
10451045
# Only write the 'obj' and 'builddir' rules for the "primary" output
10461046
# (:1); it's superfluous for the "extra outputs", and this avoids
@@ -1147,7 +1147,7 @@ def WriteCopies(self, copies, extra_outputs, part_of_all):
11471147
path=gyp.xcode_emulation.ExpandEnvVars(path, env)
11481148
self.WriteDoCmd([output], [path], 'copy', part_of_all)
11491149
outputs.append(output)
1150-
self.WriteLn('%s = %s'% (variable, ' '.join(map(QuoteSpaces, outputs))))
1150+
self.WriteLn('%s = %s'% (variable, ' '.join(QuoteSpaces(o) foroinoutputs)))
11511151
extra_outputs.append('$(%s)'%variable)
11521152
self.WriteLn()
11531153

@@ -1158,7 +1158,7 @@ def WriteMacBundleResources(self, resources, bundle_deps):
11581158

11591159
foroutput, resingyp.xcode_emulation.GetMacBundleResources(
11601160
generator_default_variables['PRODUCT_DIR'], self.xcode_settings,
1161-
map(Sourceify, map(self.Absolutify, resources))):
1161+
[Sourceify(self.Absolutify(r)) forrinresources]):
11621162
_, ext=os.path.splitext(output)
11631163
ifext!='.xcassets':
11641164
# Make does not supports '.xcassets' emulation.
@@ -1238,11 +1238,11 @@ def WriteSources(self, configs, deps, sources,
12381238
self.WriteList(cflags_objcc, 'CFLAGS_OBJCC_%s'%configname)
12391239
includes=config.get('include_dirs')
12401240
ifincludes:
1241-
includes=map(Sourceify, map(self.Absolutify, includes))
1241+
includes=[Sourceify(self.Absolutify(i)) foriinincludes]
12421242
self.WriteList(includes, 'INCS_%s'%configname, prefix='-I')
12431243

1244-
compilable=filter(Compilable, sources)
1245-
objs=map(self.Objectify, map(self.Absolutify, map(Target, compilable)))
1244+
compilable=list(filter(Compilable, sources))
1245+
objs=[self.Objectify(self.Absolutify(Target(c)))forcincompilable]
12461246
self.WriteList(objs, 'OBJS')
12471247

12481248
forobjinobjs:
@@ -1314,7 +1314,7 @@ def WriteSources(self, configs, deps, sources,
13141314

13151315
# If there are any object files in our input file list, link them into our
13161316
# output.
1317-
extra_link_deps+=filter(Linkable, sources)
1317+
extra_link_deps+=list(filter(Linkable, sources))
13181318

13191319
self.WriteLn()
13201320

@@ -1564,7 +1564,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15641564

15651565
# Bundle dependencies. Note that the code below adds actions to this
15661566
# target, so if you move these two lines, move the lines below as well.
1567-
self.WriteList(map(QuoteSpaces, bundle_deps), 'BUNDLE_DEPS')
1567+
self.WriteList([QuoteSpaces(dep) fordepinbundle_deps], 'BUNDLE_DEPS')
15681568
self.WriteLn('%s: $(BUNDLE_DEPS)'%QuoteSpaces(self.output))
15691569

15701570
# After the framework is built, package it. Needs to happen before
@@ -1598,7 +1598,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15981598
ifself.type=='executable':
15991599
self.WriteLn('%s: LD_INPUTS := %s'% (
16001600
QuoteSpaces(self.output_binary),
1601-
' '.join(map(QuoteSpaces, link_deps))))
1601+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16021602
ifself.toolset=='host'andself.flavor=='android':
16031603
self.WriteDoCmd([self.output_binary], link_deps, 'link_host',
16041604
part_of_all, postbuilds=postbuilds)
@@ -1620,7 +1620,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
16201620
elifself.type=='shared_library':
16211621
self.WriteLn('%s: LD_INPUTS := %s'% (
16221622
QuoteSpaces(self.output_binary),
1623-
' '.join(map(QuoteSpaces, link_deps))))
1623+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16241624
self.WriteDoCmd([self.output_binary], link_deps, 'solink', part_of_all,
16251625
postbuilds=postbuilds)
16261626
elifself.type=='loadable_module':
@@ -1746,8 +1746,8 @@ def WriteMakeRule(self, outputs, inputs, actions=None, comment=None,
17461746
output is just a name to run the rule
17471747
command: (optional) command name to generate unambiguous labels
17481748
"""
1749-
outputs=map(QuoteSpaces, outputs)
1750-
inputs=map(QuoteSpaces, inputs)
1749+
outputs=[QuoteSpaces(o) foroinoutputs]
1750+
inputs=[QuoteSpaces(i) foriininputs]
17511751

17521752
ifcomment:
17531753
self.WriteLn('# '+comment)
@@ -1836,7 +1836,7 @@ def WriteAndroidNdkModuleRule(self, module_name, all_sources, link_deps):
18361836
default_cpp_ext=ext
18371837
self.WriteLn('LOCAL_CPP_EXTENSION := '+default_cpp_ext)
18381838

1839-
self.WriteList(map(self.Absolutify, filter(Compilable, all_sources)),
1839+
self.WriteList(list(map(self.Absolutify, filter(Compilable, all_sources))),
18401840
'LOCAL_SRC_FILES')
18411841

18421842
# Filter out those which do not match prefix and suffix and produce
@@ -1979,7 +1979,7 @@ def WriteAutoRegenerationRule(params, root_makefile, makefile_name,
19791979
"%(makefile_name)s: %(deps)s\n"
19801980
"\t$(call do_cmd,regen_makefile)\n\n"% {
19811981
'makefile_name': makefile_name,
1982-
'deps': ' '.join(map(SourceifyAndQuoteSpaces, build_files)),
1982+
'deps': ' '.join(SourceifyAndQuoteSpaces(bf) forbfinbuild_files),
19831983
'cmd': gyp.common.EncodePOSIXShellList(
19841984
[gyp_binary, '-fmake'] +
19851985
gyp.RegenerateFlags(options) +

‎gyp/pylib/gyp/generator/msvs.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name):
26912691

26922692
platform_name=None
26932693
msvs_windows_target_platform_version=None
2694-
forconfigurationinspec['configurations'].itervalues():
2694+
forconfigurationinspec['configurations'].values():
26952695
platform_name=platform_nameor_ConfigPlatform(configuration)
26962696
msvs_windows_target_platform_version= \
26972697
msvs_windows_target_platform_versionor \
@@ -3252,7 +3252,7 @@ def _GetMSBuildProjectReferences(project):
32523252
['Project', guid],
32533253
['ReferenceOutputAssembly', 'false']
32543254
]
3255-
forconfigindependency.spec.get('configurations', {}).itervalues():
3255+
forconfigindependency.spec.get('configurations', {}).values():
32563256
ifconfig.get('msvs_use_library_dependency_inputs', 0):
32573257
project_ref.append(['UseLibraryDependencyInputs', 'true'])
32583258
break
@@ -3321,7 +3321,7 @@ def _GenerateMSBuildProject(project, options, version, generator_flags):
33213321
extension_to_rule_name, _GetUniquePlatforms(spec))
33223322
missing_sources=_VerifySourcesExist(sources, project_dir)
33233323

3324-
forconfigurationinconfigurations.itervalues():
3324+
forconfigurationinconfigurations.values():
33253325
_FinalizeMSBuildSettings(spec, configuration)
33263326

33273327
# Add attributes to root element

‎gyp/pylib/gyp/input.py‎

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44

55
from __future__ importprint_function
66

7-
fromcompiler.astimportConst
8-
fromcompiler.astimportDict
9-
fromcompiler.astimportDiscard
10-
fromcompiler.astimportList
11-
fromcompiler.astimportModule
12-
fromcompiler.astimportNode
13-
fromcompiler.astimportStmt
14-
importcompiler
7+
importast
8+
159
importgyp.common
1610
importgyp.simple_copy
1711
importmultiprocessing
@@ -184,43 +178,39 @@ def CheckedEval(file_contents):
184178
Note that this is slower than eval() is.
185179
"""
186180

187-
ast=compiler.parse(file_contents)
188-
assertisinstance(ast, Module)
189-
c1=ast.getChildren()
190-
assertc1[0] isNone
191-
assertisinstance(c1[1], Stmt)
192-
c2=c1[1].getChildren()
193-
assertisinstance(c2[0], Discard)
194-
c3=c2[0].getChildren()
195-
assertlen(c3) ==1
196-
returnCheckNode(c3[0], [])
181+
syntax_tree=ast.parse(file_contents)
182+
assertisinstance(syntax_tree, ast.Module)
183+
c1=syntax_tree.body
184+
assertlen(c1) ==1
185+
c2=c1[0]
186+
assertisinstance(c2, ast.Expr)
187+
returnCheckNode(c2.value, [])
197188

198189

199190
defCheckNode(node, keypath):
200-
ifisinstance(node, Dict):
191+
ifisinstance(node, ast.Dict):
201192
c=node.getChildren()
202193
dict= {}
203-
forninrange(0, len(c), 2):
204-
assertisinstance(c[n], Const)
205-
key=c[n].getChildren()[0]
194+
forkey, valueinzip(node.keys, node.values):
195+
assertisinstance(key, ast.Str)
196+
key=key.s
206197
ifkeyindict:
207198
raiseGypError("Key '"+key+"' repeated at level "+
208199
repr(len(keypath) +1) +" with key path '"+
209200
'.'.join(keypath) +"'")
210201
kp=list(keypath) # Make a copy of the list for descending this node.
211202
kp.append(key)
212-
dict[key] =CheckNode(c[n+1], kp)
203+
dict[key] =CheckNode(value, kp)
213204
returndict
214-
elifisinstance(node, List):
215-
c=node.getChildren()
205+
elifisinstance(node, ast.List):
216206
children= []
217-
forindex, childinenumerate(c):
207+
forindex, childinenumerate(node.elts):
218208
kp=list(keypath) # Copy list.
219209
kp.append(repr(index))
220210
children.append(CheckNode(child, kp))
221211
returnchildren
222-
elifisinstance(node, Const):
223-
returnnode.getChildren()[0]
212+
elifisinstance(node, ast.Str):
213+
returnnode.s
224214
else:
225215
raiseTypeError("Unknown AST node at key path '"+'.'.join(keypath) +
226216
"': "+repr(node))
@@ -954,8 +944,12 @@ def ExpandVariables(input, phase, variables, build_file):
954944
else:
955945
replacement=variables[contents]
956946

947+
ifisinstance(replacement, bytes) andnotisinstance(replacement, str):
948+
replacement=replacement.decode("utf-8") # done on Python 3 only
957949
iftype(replacement) islist:
958950
foriteminreplacement:
951+
ifisinstance(item, bytes) andnotisinstance(item, str):
952+
item=item.decode("utf-8") # done on Python 3 only
959953
ifnotcontents[-1] =='/'andtype(item) notin (str, int):
960954
raiseGypError('Variable '+contents+
961955
' must expand to a string or list of strings; '+
@@ -1847,7 +1841,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18471841
# Create a DependencyGraphNode for each gyp file containing a target. Put
18481842
# it into a dict for easy access.
18491843
dependency_nodes= {}
1850-
fortargetintargets.iterkeys():
1844+
fortargetintargets:
18511845
build_file=gyp.common.BuildFile(target)
18521846
ifnotbuild_fileindependency_nodes:
18531847
dependency_nodes[build_file] =DependencyGraphNode(build_file)
@@ -1878,7 +1872,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18781872

18791873
# Files that have no dependencies are treated as dependent on root_node.
18801874
root_node=DependencyGraphNode(None)
1881-
forbuild_file_nodeindependency_nodes.itervalues():
1875+
forbuild_file_nodeindependency_nodes.values():
18821876
iflen(build_file_node.dependencies) ==0:
18831877
build_file_node.dependencies.append(root_node)
18841878
root_node.dependents.append(build_file_node)

‎gyp/pylib/gyp/xcode_emulation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ def _HasIOSTarget(targets):
16361636
def_AddIOSDeviceConfigurations(targets):
16371637
"""Clone all targets and append -iphoneos to the name. Configure these targets
16381638
to build for iOS devices and use correct architectures for those builds."""
1639-
fortarget_dictintargets.itervalues():
1639+
fortarget_dictintargets.values():
16401640
toolset=target_dict['toolset']
16411641
configs=target_dict['configurations']
16421642
forconfig_name, config_dictindict(configs).items():

‎gyp/pylib/gyp/xcode_ninja.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _TargetFromSpec(old_spec, params):
8585
"%s/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"%ninja_toplevel
8686

8787
if'configurations'inold_spec:
88-
forconfiginold_spec['configurations'].iterkeys():
88+
forconfiginold_spec['configurations']:
8989
old_xcode_settings= \
9090
old_spec['configurations'][config].get('xcode_settings', {})
9191
if'IPHONEOS_DEPLOYMENT_TARGET'inold_xcode_settings:

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit fa0ed4a

Browse files
cclaussrvagg
authored andcommitted
build: more Python 3 compat, replace compile with ast
Make Python 3 compatiblity changes so the code works in both Python 2 and Python 3. Especially, make changes required because the compiler module was removed in Python 3 in favor of the ast module that exists in both Python 2 and Python 3. PR-URL: #1820 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rod Vagg <r@va.gg> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent 18d5c7c commit fa0ed4a

7 files changed

Lines changed: 50 additions & 56 deletions

File tree

‎gyp/pylib/gyp/generator/analyzer.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def find_matching_compile_target_names(self):
671671
assertself.is_build_impacted();
672672
# Compile targets are found by searching up from changed targets.
673673
# Reset the visited status for _GetBuildTargets.
674-
fortargetinself._name_to_target.itervalues():
674+
fortargetinself._name_to_target.values():
675675
target.visited=False
676676

677677
supplied_targets=_LookupTargets(self._supplied_target_names_no_all(),

‎gyp/pylib/gyp/generator/eclipse.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def WriteMacros(out, eclipse_langs, defines):
272272
out.write(' <language name="holder for library settings"></language>\n')
273273
forlangineclipse_langs:
274274
out.write(' <language name="%s">\n'%lang)
275-
forkeyinsorted(defines.iterkeys()):
275+
forkeyinsorted(defines):
276276
out.write(' <macro><name>%s</name><value>%s</value></macro>\n'%
277277
(escape(key), escape(defines[key])))
278278
out.write(' </language>\n')

‎gyp/pylib/gyp/generator/make.py‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def Write(self, qualified_target, base_path, output_filename, spec, configs,
821821
gyp.xcode_emulation.MacPrefixHeader(
822822
self.xcode_settings, lambdap: Sourceify(self.Absolutify(p)),
823823
self.Pchify))
824-
sources=filter(Compilable, all_sources)
824+
sources=list(filter(Compilable, all_sources))
825825
ifsources:
826826
self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT1)
827827
extensions=set([os.path.splitext(s)[1] forsinsources])
@@ -950,7 +950,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
950950
'%s%s'
951951
% (name, cd_action, command))
952952
self.WriteLn()
953-
outputs=map(self.Absolutify, outputs)
953+
outputs=[self.Absolutify(output) foroutputinoutputs]
954954
# The makefile rules are all relative to the top dir, but the gyp actions
955955
# are defined relative to their containing dir. This replaces the obj
956956
# variable for the action rule with an absolute version so that the output
@@ -974,7 +974,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
974974
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
975975
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
976976

977-
self.WriteDoCmd(outputs, map(Sourceify, map(self.Absolutify, inputs)),
977+
self.WriteDoCmd(outputs, [Sourceify(self.Absolutify(i)) foriininputs],
978978
part_of_all=part_of_all, command=name)
979979

980980
# Stuff the outputs in a variable so we can refer to them later.
@@ -1023,8 +1023,8 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10231023
extra_sources+=outputs
10241024
ifint(rule.get('process_outputs_as_mac_bundle_resources', False)):
10251025
extra_mac_bundle_resources+=outputs
1026-
inputs=map(Sourceify, map(self.Absolutify, [rule_source] +
1027-
rule.get('inputs', [])))
1026+
inputs=[Sourceify(self.Absolutify(i)) fori
1027+
in [rule_source] +rule.get('inputs', [])]
10281028
actions= ['$(call do_cmd,%s_%d)'% (name, count)]
10291029

10301030
ifname=='resources_grit':
@@ -1040,7 +1040,7 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10401040
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
10411041
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
10421042

1043-
outputs=map(self.Absolutify, outputs)
1043+
outputs=[self.Absolutify(output) foroutputinoutputs]
10441044
all_outputs+=outputs
10451045
# Only write the 'obj' and 'builddir' rules for the "primary" output
10461046
# (:1); it's superfluous for the "extra outputs", and this avoids
@@ -1147,7 +1147,7 @@ def WriteCopies(self, copies, extra_outputs, part_of_all):
11471147
path=gyp.xcode_emulation.ExpandEnvVars(path, env)
11481148
self.WriteDoCmd([output], [path], 'copy', part_of_all)
11491149
outputs.append(output)
1150-
self.WriteLn('%s = %s'% (variable, ' '.join(map(QuoteSpaces, outputs))))
1150+
self.WriteLn('%s = %s'% (variable, ' '.join(QuoteSpaces(o) foroinoutputs)))
11511151
extra_outputs.append('$(%s)'%variable)
11521152
self.WriteLn()
11531153

@@ -1158,7 +1158,7 @@ def WriteMacBundleResources(self, resources, bundle_deps):
11581158

11591159
foroutput, resingyp.xcode_emulation.GetMacBundleResources(
11601160
generator_default_variables['PRODUCT_DIR'], self.xcode_settings,
1161-
map(Sourceify, map(self.Absolutify, resources))):
1161+
[Sourceify(self.Absolutify(r)) forrinresources]):
11621162
_, ext=os.path.splitext(output)
11631163
ifext!='.xcassets':
11641164
# Make does not supports '.xcassets' emulation.
@@ -1238,11 +1238,11 @@ def WriteSources(self, configs, deps, sources,
12381238
self.WriteList(cflags_objcc, 'CFLAGS_OBJCC_%s'%configname)
12391239
includes=config.get('include_dirs')
12401240
ifincludes:
1241-
includes=map(Sourceify, map(self.Absolutify, includes))
1241+
includes=[Sourceify(self.Absolutify(i)) foriinincludes]
12421242
self.WriteList(includes, 'INCS_%s'%configname, prefix='-I')
12431243

1244-
compilable=filter(Compilable, sources)
1245-
objs=map(self.Objectify, map(self.Absolutify, map(Target, compilable)))
1244+
compilable=list(filter(Compilable, sources))
1245+
objs=[self.Objectify(self.Absolutify(Target(c)))forcincompilable]
12461246
self.WriteList(objs, 'OBJS')
12471247

12481248
forobjinobjs:
@@ -1314,7 +1314,7 @@ def WriteSources(self, configs, deps, sources,
13141314

13151315
# If there are any object files in our input file list, link them into our
13161316
# output.
1317-
extra_link_deps+=filter(Linkable, sources)
1317+
extra_link_deps+=list(filter(Linkable, sources))
13181318

13191319
self.WriteLn()
13201320

@@ -1564,7 +1564,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15641564

15651565
# Bundle dependencies. Note that the code below adds actions to this
15661566
# target, so if you move these two lines, move the lines below as well.
1567-
self.WriteList(map(QuoteSpaces, bundle_deps), 'BUNDLE_DEPS')
1567+
self.WriteList([QuoteSpaces(dep) fordepinbundle_deps], 'BUNDLE_DEPS')
15681568
self.WriteLn('%s: $(BUNDLE_DEPS)'%QuoteSpaces(self.output))
15691569

15701570
# After the framework is built, package it. Needs to happen before
@@ -1598,7 +1598,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15981598
ifself.type=='executable':
15991599
self.WriteLn('%s: LD_INPUTS := %s'% (
16001600
QuoteSpaces(self.output_binary),
1601-
' '.join(map(QuoteSpaces, link_deps))))
1601+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16021602
ifself.toolset=='host'andself.flavor=='android':
16031603
self.WriteDoCmd([self.output_binary], link_deps, 'link_host',
16041604
part_of_all, postbuilds=postbuilds)
@@ -1620,7 +1620,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
16201620
elifself.type=='shared_library':
16211621
self.WriteLn('%s: LD_INPUTS := %s'% (
16221622
QuoteSpaces(self.output_binary),
1623-
' '.join(map(QuoteSpaces, link_deps))))
1623+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16241624
self.WriteDoCmd([self.output_binary], link_deps, 'solink', part_of_all,
16251625
postbuilds=postbuilds)
16261626
elifself.type=='loadable_module':
@@ -1746,8 +1746,8 @@ def WriteMakeRule(self, outputs, inputs, actions=None, comment=None,
17461746
output is just a name to run the rule
17471747
command: (optional) command name to generate unambiguous labels
17481748
"""
1749-
outputs=map(QuoteSpaces, outputs)
1750-
inputs=map(QuoteSpaces, inputs)
1749+
outputs=[QuoteSpaces(o) foroinoutputs]
1750+
inputs=[QuoteSpaces(i) foriininputs]
17511751

17521752
ifcomment:
17531753
self.WriteLn('# '+comment)
@@ -1836,7 +1836,7 @@ def WriteAndroidNdkModuleRule(self, module_name, all_sources, link_deps):
18361836
default_cpp_ext=ext
18371837
self.WriteLn('LOCAL_CPP_EXTENSION := '+default_cpp_ext)
18381838

1839-
self.WriteList(map(self.Absolutify, filter(Compilable, all_sources)),
1839+
self.WriteList(list(map(self.Absolutify, filter(Compilable, all_sources))),
18401840
'LOCAL_SRC_FILES')
18411841

18421842
# Filter out those which do not match prefix and suffix and produce
@@ -1979,7 +1979,7 @@ def WriteAutoRegenerationRule(params, root_makefile, makefile_name,
19791979
"%(makefile_name)s: %(deps)s\n"
19801980
"\t$(call do_cmd,regen_makefile)\n\n"% {
19811981
'makefile_name': makefile_name,
1982-
'deps': ' '.join(map(SourceifyAndQuoteSpaces, build_files)),
1982+
'deps': ' '.join(SourceifyAndQuoteSpaces(bf) forbfinbuild_files),
19831983
'cmd': gyp.common.EncodePOSIXShellList(
19841984
[gyp_binary, '-fmake'] +
19851985
gyp.RegenerateFlags(options) +

‎gyp/pylib/gyp/generator/msvs.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name):
26912691

26922692
platform_name=None
26932693
msvs_windows_target_platform_version=None
2694-
forconfigurationinspec['configurations'].itervalues():
2694+
forconfigurationinspec['configurations'].values():
26952695
platform_name=platform_nameor_ConfigPlatform(configuration)
26962696
msvs_windows_target_platform_version= \
26972697
msvs_windows_target_platform_versionor \
@@ -3252,7 +3252,7 @@ def _GetMSBuildProjectReferences(project):
32523252
['Project', guid],
32533253
['ReferenceOutputAssembly', 'false']
32543254
]
3255-
forconfigindependency.spec.get('configurations', {}).itervalues():
3255+
forconfigindependency.spec.get('configurations', {}).values():
32563256
ifconfig.get('msvs_use_library_dependency_inputs', 0):
32573257
project_ref.append(['UseLibraryDependencyInputs', 'true'])
32583258
break
@@ -3321,7 +3321,7 @@ def _GenerateMSBuildProject(project, options, version, generator_flags):
33213321
extension_to_rule_name, _GetUniquePlatforms(spec))
33223322
missing_sources=_VerifySourcesExist(sources, project_dir)
33233323

3324-
forconfigurationinconfigurations.itervalues():
3324+
forconfigurationinconfigurations.values():
33253325
_FinalizeMSBuildSettings(spec, configuration)
33263326

33273327
# Add attributes to root element

‎gyp/pylib/gyp/input.py‎

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44

55
from __future__ importprint_function
66

7-
fromcompiler.astimportConst
8-
fromcompiler.astimportDict
9-
fromcompiler.astimportDiscard
10-
fromcompiler.astimportList
11-
fromcompiler.astimportModule
12-
fromcompiler.astimportNode
13-
fromcompiler.astimportStmt
14-
importcompiler
7+
importast
8+
159
importgyp.common
1610
importgyp.simple_copy
1711
importmultiprocessing
@@ -184,43 +178,39 @@ def CheckedEval(file_contents):
184178
Note that this is slower than eval() is.
185179
"""
186180

187-
ast=compiler.parse(file_contents)
188-
assertisinstance(ast, Module)
189-
c1=ast.getChildren()
190-
assertc1[0] isNone
191-
assertisinstance(c1[1], Stmt)
192-
c2=c1[1].getChildren()
193-
assertisinstance(c2[0], Discard)
194-
c3=c2[0].getChildren()
195-
assertlen(c3) ==1
196-
returnCheckNode(c3[0], [])
181+
syntax_tree=ast.parse(file_contents)
182+
assertisinstance(syntax_tree, ast.Module)
183+
c1=syntax_tree.body
184+
assertlen(c1) ==1
185+
c2=c1[0]
186+
assertisinstance(c2, ast.Expr)
187+
returnCheckNode(c2.value, [])
197188

198189

199190
defCheckNode(node, keypath):
200-
ifisinstance(node, Dict):
191+
ifisinstance(node, ast.Dict):
201192
c=node.getChildren()
202193
dict= {}
203-
forninrange(0, len(c), 2):
204-
assertisinstance(c[n], Const)
205-
key=c[n].getChildren()[0]
194+
forkey, valueinzip(node.keys, node.values):
195+
assertisinstance(key, ast.Str)
196+
key=key.s
206197
ifkeyindict:
207198
raiseGypError("Key '"+key+"' repeated at level "+
208199
repr(len(keypath) +1) +" with key path '"+
209200
'.'.join(keypath) +"'")
210201
kp=list(keypath) # Make a copy of the list for descending this node.
211202
kp.append(key)
212-
dict[key] =CheckNode(c[n+1], kp)
203+
dict[key] =CheckNode(value, kp)
213204
returndict
214-
elifisinstance(node, List):
215-
c=node.getChildren()
205+
elifisinstance(node, ast.List):
216206
children= []
217-
forindex, childinenumerate(c):
207+
forindex, childinenumerate(node.elts):
218208
kp=list(keypath) # Copy list.
219209
kp.append(repr(index))
220210
children.append(CheckNode(child, kp))
221211
returnchildren
222-
elifisinstance(node, Const):
223-
returnnode.getChildren()[0]
212+
elifisinstance(node, ast.Str):
213+
returnnode.s
224214
else:
225215
raiseTypeError("Unknown AST node at key path '"+'.'.join(keypath) +
226216
"': "+repr(node))
@@ -954,8 +944,12 @@ def ExpandVariables(input, phase, variables, build_file):
954944
else:
955945
replacement=variables[contents]
956946

947+
ifisinstance(replacement, bytes) andnotisinstance(replacement, str):
948+
replacement=replacement.decode("utf-8") # done on Python 3 only
957949
iftype(replacement) islist:
958950
foriteminreplacement:
951+
ifisinstance(item, bytes) andnotisinstance(item, str):
952+
item=item.decode("utf-8") # done on Python 3 only
959953
ifnotcontents[-1] =='/'andtype(item) notin (str, int):
960954
raiseGypError('Variable '+contents+
961955
' must expand to a string or list of strings; '+
@@ -1847,7 +1841,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18471841
# Create a DependencyGraphNode for each gyp file containing a target. Put
18481842
# it into a dict for easy access.
18491843
dependency_nodes= {}
1850-
fortargetintargets.iterkeys():
1844+
fortargetintargets:
18511845
build_file=gyp.common.BuildFile(target)
18521846
ifnotbuild_fileindependency_nodes:
18531847
dependency_nodes[build_file] =DependencyGraphNode(build_file)
@@ -1878,7 +1872,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18781872

18791873
# Files that have no dependencies are treated as dependent on root_node.
18801874
root_node=DependencyGraphNode(None)
1881-
forbuild_file_nodeindependency_nodes.itervalues():
1875+
forbuild_file_nodeindependency_nodes.values():
18821876
iflen(build_file_node.dependencies) ==0:
18831877
build_file_node.dependencies.append(root_node)
18841878
root_node.dependents.append(build_file_node)

‎gyp/pylib/gyp/xcode_emulation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ def _HasIOSTarget(targets):
16361636
def_AddIOSDeviceConfigurations(targets):
16371637
"""Clone all targets and append -iphoneos to the name. Configure these targets
16381638
to build for iOS devices and use correct architectures for those builds."""
1639-
fortarget_dictintargets.itervalues():
1639+
fortarget_dictintargets.values():
16401640
toolset=target_dict['toolset']
16411641
configs=target_dict['configurations']
16421642
forconfig_name, config_dictindict(configs).items():

‎gyp/pylib/gyp/xcode_ninja.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _TargetFromSpec(old_spec, params):
8585
"%s/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"%ninja_toplevel
8686

8787
if'configurations'inold_spec:
88-
forconfiginold_spec['configurations'].iterkeys():
88+
forconfiginold_spec['configurations']:
8989
old_xcode_settings= \
9090
old_spec['configurations'][config].get('xcode_settings', {})
9191
if'IPHONEOS_DEPLOYMENT_TARGET'inold_xcode_settings:

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit fa0ed4a

Browse files
cclaussrvagg
authored andcommitted
build: more Python 3 compat, replace compile with ast
Make Python 3 compatiblity changes so the code works in both Python 2 and Python 3. Especially, make changes required because the compiler module was removed in Python 3 in favor of the ast module that exists in both Python 2 and Python 3. PR-URL: #1820 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rod Vagg <r@va.gg> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent 18d5c7c commit fa0ed4a

7 files changed

Lines changed: 50 additions & 56 deletions

File tree

‎gyp/pylib/gyp/generator/analyzer.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def find_matching_compile_target_names(self):
671671
assertself.is_build_impacted();
672672
# Compile targets are found by searching up from changed targets.
673673
# Reset the visited status for _GetBuildTargets.
674-
fortargetinself._name_to_target.itervalues():
674+
fortargetinself._name_to_target.values():
675675
target.visited=False
676676

677677
supplied_targets=_LookupTargets(self._supplied_target_names_no_all(),

‎gyp/pylib/gyp/generator/eclipse.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def WriteMacros(out, eclipse_langs, defines):
272272
out.write(' <language name="holder for library settings"></language>\n')
273273
forlangineclipse_langs:
274274
out.write(' <language name="%s">\n'%lang)
275-
forkeyinsorted(defines.iterkeys()):
275+
forkeyinsorted(defines):
276276
out.write(' <macro><name>%s</name><value>%s</value></macro>\n'%
277277
(escape(key), escape(defines[key])))
278278
out.write(' </language>\n')

‎gyp/pylib/gyp/generator/make.py‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def Write(self, qualified_target, base_path, output_filename, spec, configs,
821821
gyp.xcode_emulation.MacPrefixHeader(
822822
self.xcode_settings, lambdap: Sourceify(self.Absolutify(p)),
823823
self.Pchify))
824-
sources=filter(Compilable, all_sources)
824+
sources=list(filter(Compilable, all_sources))
825825
ifsources:
826826
self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT1)
827827
extensions=set([os.path.splitext(s)[1] forsinsources])
@@ -950,7 +950,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
950950
'%s%s'
951951
% (name, cd_action, command))
952952
self.WriteLn()
953-
outputs=map(self.Absolutify, outputs)
953+
outputs=[self.Absolutify(output) foroutputinoutputs]
954954
# The makefile rules are all relative to the top dir, but the gyp actions
955955
# are defined relative to their containing dir. This replaces the obj
956956
# variable for the action rule with an absolute version so that the output
@@ -974,7 +974,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
974974
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
975975
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
976976

977-
self.WriteDoCmd(outputs, map(Sourceify, map(self.Absolutify, inputs)),
977+
self.WriteDoCmd(outputs, [Sourceify(self.Absolutify(i)) foriininputs],
978978
part_of_all=part_of_all, command=name)
979979

980980
# Stuff the outputs in a variable so we can refer to them later.
@@ -1023,8 +1023,8 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10231023
extra_sources+=outputs
10241024
ifint(rule.get('process_outputs_as_mac_bundle_resources', False)):
10251025
extra_mac_bundle_resources+=outputs
1026-
inputs=map(Sourceify, map(self.Absolutify, [rule_source] +
1027-
rule.get('inputs', [])))
1026+
inputs=[Sourceify(self.Absolutify(i)) fori
1027+
in [rule_source] +rule.get('inputs', [])]
10281028
actions= ['$(call do_cmd,%s_%d)'% (name, count)]
10291029

10301030
ifname=='resources_grit':
@@ -1040,7 +1040,7 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10401040
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
10411041
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
10421042

1043-
outputs=map(self.Absolutify, outputs)
1043+
outputs=[self.Absolutify(output) foroutputinoutputs]
10441044
all_outputs+=outputs
10451045
# Only write the 'obj' and 'builddir' rules for the "primary" output
10461046
# (:1); it's superfluous for the "extra outputs", and this avoids
@@ -1147,7 +1147,7 @@ def WriteCopies(self, copies, extra_outputs, part_of_all):
11471147
path=gyp.xcode_emulation.ExpandEnvVars(path, env)
11481148
self.WriteDoCmd([output], [path], 'copy', part_of_all)
11491149
outputs.append(output)
1150-
self.WriteLn('%s = %s'% (variable, ' '.join(map(QuoteSpaces, outputs))))
1150+
self.WriteLn('%s = %s'% (variable, ' '.join(QuoteSpaces(o) foroinoutputs)))
11511151
extra_outputs.append('$(%s)'%variable)
11521152
self.WriteLn()
11531153

@@ -1158,7 +1158,7 @@ def WriteMacBundleResources(self, resources, bundle_deps):
11581158

11591159
foroutput, resingyp.xcode_emulation.GetMacBundleResources(
11601160
generator_default_variables['PRODUCT_DIR'], self.xcode_settings,
1161-
map(Sourceify, map(self.Absolutify, resources))):
1161+
[Sourceify(self.Absolutify(r)) forrinresources]):
11621162
_, ext=os.path.splitext(output)
11631163
ifext!='.xcassets':
11641164
# Make does not supports '.xcassets' emulation.
@@ -1238,11 +1238,11 @@ def WriteSources(self, configs, deps, sources,
12381238
self.WriteList(cflags_objcc, 'CFLAGS_OBJCC_%s'%configname)
12391239
includes=config.get('include_dirs')
12401240
ifincludes:
1241-
includes=map(Sourceify, map(self.Absolutify, includes))
1241+
includes=[Sourceify(self.Absolutify(i)) foriinincludes]
12421242
self.WriteList(includes, 'INCS_%s'%configname, prefix='-I')
12431243

1244-
compilable=filter(Compilable, sources)
1245-
objs=map(self.Objectify, map(self.Absolutify, map(Target, compilable)))
1244+
compilable=list(filter(Compilable, sources))
1245+
objs=[self.Objectify(self.Absolutify(Target(c)))forcincompilable]
12461246
self.WriteList(objs, 'OBJS')
12471247

12481248
forobjinobjs:
@@ -1314,7 +1314,7 @@ def WriteSources(self, configs, deps, sources,
13141314

13151315
# If there are any object files in our input file list, link them into our
13161316
# output.
1317-
extra_link_deps+=filter(Linkable, sources)
1317+
extra_link_deps+=list(filter(Linkable, sources))
13181318

13191319
self.WriteLn()
13201320

@@ -1564,7 +1564,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15641564

15651565
# Bundle dependencies. Note that the code below adds actions to this
15661566
# target, so if you move these two lines, move the lines below as well.
1567-
self.WriteList(map(QuoteSpaces, bundle_deps), 'BUNDLE_DEPS')
1567+
self.WriteList([QuoteSpaces(dep) fordepinbundle_deps], 'BUNDLE_DEPS')
15681568
self.WriteLn('%s: $(BUNDLE_DEPS)'%QuoteSpaces(self.output))
15691569

15701570
# After the framework is built, package it. Needs to happen before
@@ -1598,7 +1598,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15981598
ifself.type=='executable':
15991599
self.WriteLn('%s: LD_INPUTS := %s'% (
16001600
QuoteSpaces(self.output_binary),
1601-
' '.join(map(QuoteSpaces, link_deps))))
1601+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16021602
ifself.toolset=='host'andself.flavor=='android':
16031603
self.WriteDoCmd([self.output_binary], link_deps, 'link_host',
16041604
part_of_all, postbuilds=postbuilds)
@@ -1620,7 +1620,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
16201620
elifself.type=='shared_library':
16211621
self.WriteLn('%s: LD_INPUTS := %s'% (
16221622
QuoteSpaces(self.output_binary),
1623-
' '.join(map(QuoteSpaces, link_deps))))
1623+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16241624
self.WriteDoCmd([self.output_binary], link_deps, 'solink', part_of_all,
16251625
postbuilds=postbuilds)
16261626
elifself.type=='loadable_module':
@@ -1746,8 +1746,8 @@ def WriteMakeRule(self, outputs, inputs, actions=None, comment=None,
17461746
output is just a name to run the rule
17471747
command: (optional) command name to generate unambiguous labels
17481748
"""
1749-
outputs=map(QuoteSpaces, outputs)
1750-
inputs=map(QuoteSpaces, inputs)
1749+
outputs=[QuoteSpaces(o) foroinoutputs]
1750+
inputs=[QuoteSpaces(i) foriininputs]
17511751

17521752
ifcomment:
17531753
self.WriteLn('# '+comment)
@@ -1836,7 +1836,7 @@ def WriteAndroidNdkModuleRule(self, module_name, all_sources, link_deps):
18361836
default_cpp_ext=ext
18371837
self.WriteLn('LOCAL_CPP_EXTENSION := '+default_cpp_ext)
18381838

1839-
self.WriteList(map(self.Absolutify, filter(Compilable, all_sources)),
1839+
self.WriteList(list(map(self.Absolutify, filter(Compilable, all_sources))),
18401840
'LOCAL_SRC_FILES')
18411841

18421842
# Filter out those which do not match prefix and suffix and produce
@@ -1979,7 +1979,7 @@ def WriteAutoRegenerationRule(params, root_makefile, makefile_name,
19791979
"%(makefile_name)s: %(deps)s\n"
19801980
"\t$(call do_cmd,regen_makefile)\n\n"% {
19811981
'makefile_name': makefile_name,
1982-
'deps': ' '.join(map(SourceifyAndQuoteSpaces, build_files)),
1982+
'deps': ' '.join(SourceifyAndQuoteSpaces(bf) forbfinbuild_files),
19831983
'cmd': gyp.common.EncodePOSIXShellList(
19841984
[gyp_binary, '-fmake'] +
19851985
gyp.RegenerateFlags(options) +

‎gyp/pylib/gyp/generator/msvs.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name):
26912691

26922692
platform_name=None
26932693
msvs_windows_target_platform_version=None
2694-
forconfigurationinspec['configurations'].itervalues():
2694+
forconfigurationinspec['configurations'].values():
26952695
platform_name=platform_nameor_ConfigPlatform(configuration)
26962696
msvs_windows_target_platform_version= \
26972697
msvs_windows_target_platform_versionor \
@@ -3252,7 +3252,7 @@ def _GetMSBuildProjectReferences(project):
32523252
['Project', guid],
32533253
['ReferenceOutputAssembly', 'false']
32543254
]
3255-
forconfigindependency.spec.get('configurations', {}).itervalues():
3255+
forconfigindependency.spec.get('configurations', {}).values():
32563256
ifconfig.get('msvs_use_library_dependency_inputs', 0):
32573257
project_ref.append(['UseLibraryDependencyInputs', 'true'])
32583258
break
@@ -3321,7 +3321,7 @@ def _GenerateMSBuildProject(project, options, version, generator_flags):
33213321
extension_to_rule_name, _GetUniquePlatforms(spec))
33223322
missing_sources=_VerifySourcesExist(sources, project_dir)
33233323

3324-
forconfigurationinconfigurations.itervalues():
3324+
forconfigurationinconfigurations.values():
33253325
_FinalizeMSBuildSettings(spec, configuration)
33263326

33273327
# Add attributes to root element

‎gyp/pylib/gyp/input.py‎

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44

55
from __future__ importprint_function
66

7-
fromcompiler.astimportConst
8-
fromcompiler.astimportDict
9-
fromcompiler.astimportDiscard
10-
fromcompiler.astimportList
11-
fromcompiler.astimportModule
12-
fromcompiler.astimportNode
13-
fromcompiler.astimportStmt
14-
importcompiler
7+
importast
8+
159
importgyp.common
1610
importgyp.simple_copy
1711
importmultiprocessing
@@ -184,43 +178,39 @@ def CheckedEval(file_contents):
184178
Note that this is slower than eval() is.
185179
"""
186180

187-
ast=compiler.parse(file_contents)
188-
assertisinstance(ast, Module)
189-
c1=ast.getChildren()
190-
assertc1[0] isNone
191-
assertisinstance(c1[1], Stmt)
192-
c2=c1[1].getChildren()
193-
assertisinstance(c2[0], Discard)
194-
c3=c2[0].getChildren()
195-
assertlen(c3) ==1
196-
returnCheckNode(c3[0], [])
181+
syntax_tree=ast.parse(file_contents)
182+
assertisinstance(syntax_tree, ast.Module)
183+
c1=syntax_tree.body
184+
assertlen(c1) ==1
185+
c2=c1[0]
186+
assertisinstance(c2, ast.Expr)
187+
returnCheckNode(c2.value, [])
197188

198189

199190
defCheckNode(node, keypath):
200-
ifisinstance(node, Dict):
191+
ifisinstance(node, ast.Dict):
201192
c=node.getChildren()
202193
dict= {}
203-
forninrange(0, len(c), 2):
204-
assertisinstance(c[n], Const)
205-
key=c[n].getChildren()[0]
194+
forkey, valueinzip(node.keys, node.values):
195+
assertisinstance(key, ast.Str)
196+
key=key.s
206197
ifkeyindict:
207198
raiseGypError("Key '"+key+"' repeated at level "+
208199
repr(len(keypath) +1) +" with key path '"+
209200
'.'.join(keypath) +"'")
210201
kp=list(keypath) # Make a copy of the list for descending this node.
211202
kp.append(key)
212-
dict[key] =CheckNode(c[n+1], kp)
203+
dict[key] =CheckNode(value, kp)
213204
returndict
214-
elifisinstance(node, List):
215-
c=node.getChildren()
205+
elifisinstance(node, ast.List):
216206
children= []
217-
forindex, childinenumerate(c):
207+
forindex, childinenumerate(node.elts):
218208
kp=list(keypath) # Copy list.
219209
kp.append(repr(index))
220210
children.append(CheckNode(child, kp))
221211
returnchildren
222-
elifisinstance(node, Const):
223-
returnnode.getChildren()[0]
212+
elifisinstance(node, ast.Str):
213+
returnnode.s
224214
else:
225215
raiseTypeError("Unknown AST node at key path '"+'.'.join(keypath) +
226216
"': "+repr(node))
@@ -954,8 +944,12 @@ def ExpandVariables(input, phase, variables, build_file):
954944
else:
955945
replacement=variables[contents]
956946

947+
ifisinstance(replacement, bytes) andnotisinstance(replacement, str):
948+
replacement=replacement.decode("utf-8") # done on Python 3 only
957949
iftype(replacement) islist:
958950
foriteminreplacement:
951+
ifisinstance(item, bytes) andnotisinstance(item, str):
952+
item=item.decode("utf-8") # done on Python 3 only
959953
ifnotcontents[-1] =='/'andtype(item) notin (str, int):
960954
raiseGypError('Variable '+contents+
961955
' must expand to a string or list of strings; '+
@@ -1847,7 +1841,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18471841
# Create a DependencyGraphNode for each gyp file containing a target. Put
18481842
# it into a dict for easy access.
18491843
dependency_nodes= {}
1850-
fortargetintargets.iterkeys():
1844+
fortargetintargets:
18511845
build_file=gyp.common.BuildFile(target)
18521846
ifnotbuild_fileindependency_nodes:
18531847
dependency_nodes[build_file] =DependencyGraphNode(build_file)
@@ -1878,7 +1872,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18781872

18791873
# Files that have no dependencies are treated as dependent on root_node.
18801874
root_node=DependencyGraphNode(None)
1881-
forbuild_file_nodeindependency_nodes.itervalues():
1875+
forbuild_file_nodeindependency_nodes.values():
18821876
iflen(build_file_node.dependencies) ==0:
18831877
build_file_node.dependencies.append(root_node)
18841878
root_node.dependents.append(build_file_node)

‎gyp/pylib/gyp/xcode_emulation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ def _HasIOSTarget(targets):
16361636
def_AddIOSDeviceConfigurations(targets):
16371637
"""Clone all targets and append -iphoneos to the name. Configure these targets
16381638
to build for iOS devices and use correct architectures for those builds."""
1639-
fortarget_dictintargets.itervalues():
1639+
fortarget_dictintargets.values():
16401640
toolset=target_dict['toolset']
16411641
configs=target_dict['configurations']
16421642
forconfig_name, config_dictindict(configs).items():

‎gyp/pylib/gyp/xcode_ninja.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _TargetFromSpec(old_spec, params):
8585
"%s/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"%ninja_toplevel
8686

8787
if'configurations'inold_spec:
88-
forconfiginold_spec['configurations'].iterkeys():
88+
forconfiginold_spec['configurations']:
8989
old_xcode_settings= \
9090
old_spec['configurations'][config].get('xcode_settings', {})
9191
if'IPHONEOS_DEPLOYMENT_TARGET'inold_xcode_settings:

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit fa0ed4a

Browse files
cclaussrvagg
authored andcommitted
build: more Python 3 compat, replace compile with ast
Make Python 3 compatiblity changes so the code works in both Python 2 and Python 3. Especially, make changes required because the compiler module was removed in Python 3 in favor of the ast module that exists in both Python 2 and Python 3. PR-URL: #1820 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rod Vagg <r@va.gg> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent 18d5c7c commit fa0ed4a

7 files changed

Lines changed: 50 additions & 56 deletions

File tree

‎gyp/pylib/gyp/generator/analyzer.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def find_matching_compile_target_names(self):
671671
assertself.is_build_impacted();
672672
# Compile targets are found by searching up from changed targets.
673673
# Reset the visited status for _GetBuildTargets.
674-
fortargetinself._name_to_target.itervalues():
674+
fortargetinself._name_to_target.values():
675675
target.visited=False
676676

677677
supplied_targets=_LookupTargets(self._supplied_target_names_no_all(),

‎gyp/pylib/gyp/generator/eclipse.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def WriteMacros(out, eclipse_langs, defines):
272272
out.write(' <language name="holder for library settings"></language>\n')
273273
forlangineclipse_langs:
274274
out.write(' <language name="%s">\n'%lang)
275-
forkeyinsorted(defines.iterkeys()):
275+
forkeyinsorted(defines):
276276
out.write(' <macro><name>%s</name><value>%s</value></macro>\n'%
277277
(escape(key), escape(defines[key])))
278278
out.write(' </language>\n')

‎gyp/pylib/gyp/generator/make.py‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def Write(self, qualified_target, base_path, output_filename, spec, configs,
821821
gyp.xcode_emulation.MacPrefixHeader(
822822
self.xcode_settings, lambdap: Sourceify(self.Absolutify(p)),
823823
self.Pchify))
824-
sources=filter(Compilable, all_sources)
824+
sources=list(filter(Compilable, all_sources))
825825
ifsources:
826826
self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT1)
827827
extensions=set([os.path.splitext(s)[1] forsinsources])
@@ -950,7 +950,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
950950
'%s%s'
951951
% (name, cd_action, command))
952952
self.WriteLn()
953-
outputs=map(self.Absolutify, outputs)
953+
outputs=[self.Absolutify(output) foroutputinoutputs]
954954
# The makefile rules are all relative to the top dir, but the gyp actions
955955
# are defined relative to their containing dir. This replaces the obj
956956
# variable for the action rule with an absolute version so that the output
@@ -974,7 +974,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
974974
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
975975
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
976976

977-
self.WriteDoCmd(outputs, map(Sourceify, map(self.Absolutify, inputs)),
977+
self.WriteDoCmd(outputs, [Sourceify(self.Absolutify(i)) foriininputs],
978978
part_of_all=part_of_all, command=name)
979979

980980
# Stuff the outputs in a variable so we can refer to them later.
@@ -1023,8 +1023,8 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10231023
extra_sources+=outputs
10241024
ifint(rule.get('process_outputs_as_mac_bundle_resources', False)):
10251025
extra_mac_bundle_resources+=outputs
1026-
inputs=map(Sourceify, map(self.Absolutify, [rule_source] +
1027-
rule.get('inputs', [])))
1026+
inputs=[Sourceify(self.Absolutify(i)) fori
1027+
in [rule_source] +rule.get('inputs', [])]
10281028
actions= ['$(call do_cmd,%s_%d)'% (name, count)]
10291029

10301030
ifname=='resources_grit':
@@ -1040,7 +1040,7 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10401040
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
10411041
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
10421042

1043-
outputs=map(self.Absolutify, outputs)
1043+
outputs=[self.Absolutify(output) foroutputinoutputs]
10441044
all_outputs+=outputs
10451045
# Only write the 'obj' and 'builddir' rules for the "primary" output
10461046
# (:1); it's superfluous for the "extra outputs", and this avoids
@@ -1147,7 +1147,7 @@ def WriteCopies(self, copies, extra_outputs, part_of_all):
11471147
path=gyp.xcode_emulation.ExpandEnvVars(path, env)
11481148
self.WriteDoCmd([output], [path], 'copy', part_of_all)
11491149
outputs.append(output)
1150-
self.WriteLn('%s = %s'% (variable, ' '.join(map(QuoteSpaces, outputs))))
1150+
self.WriteLn('%s = %s'% (variable, ' '.join(QuoteSpaces(o) foroinoutputs)))
11511151
extra_outputs.append('$(%s)'%variable)
11521152
self.WriteLn()
11531153

@@ -1158,7 +1158,7 @@ def WriteMacBundleResources(self, resources, bundle_deps):
11581158

11591159
foroutput, resingyp.xcode_emulation.GetMacBundleResources(
11601160
generator_default_variables['PRODUCT_DIR'], self.xcode_settings,
1161-
map(Sourceify, map(self.Absolutify, resources))):
1161+
[Sourceify(self.Absolutify(r)) forrinresources]):
11621162
_, ext=os.path.splitext(output)
11631163
ifext!='.xcassets':
11641164
# Make does not supports '.xcassets' emulation.
@@ -1238,11 +1238,11 @@ def WriteSources(self, configs, deps, sources,
12381238
self.WriteList(cflags_objcc, 'CFLAGS_OBJCC_%s'%configname)
12391239
includes=config.get('include_dirs')
12401240
ifincludes:
1241-
includes=map(Sourceify, map(self.Absolutify, includes))
1241+
includes=[Sourceify(self.Absolutify(i)) foriinincludes]
12421242
self.WriteList(includes, 'INCS_%s'%configname, prefix='-I')
12431243

1244-
compilable=filter(Compilable, sources)
1245-
objs=map(self.Objectify, map(self.Absolutify, map(Target, compilable)))
1244+
compilable=list(filter(Compilable, sources))
1245+
objs=[self.Objectify(self.Absolutify(Target(c)))forcincompilable]
12461246
self.WriteList(objs, 'OBJS')
12471247

12481248
forobjinobjs:
@@ -1314,7 +1314,7 @@ def WriteSources(self, configs, deps, sources,
13141314

13151315
# If there are any object files in our input file list, link them into our
13161316
# output.
1317-
extra_link_deps+=filter(Linkable, sources)
1317+
extra_link_deps+=list(filter(Linkable, sources))
13181318

13191319
self.WriteLn()
13201320

@@ -1564,7 +1564,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15641564

15651565
# Bundle dependencies. Note that the code below adds actions to this
15661566
# target, so if you move these two lines, move the lines below as well.
1567-
self.WriteList(map(QuoteSpaces, bundle_deps), 'BUNDLE_DEPS')
1567+
self.WriteList([QuoteSpaces(dep) fordepinbundle_deps], 'BUNDLE_DEPS')
15681568
self.WriteLn('%s: $(BUNDLE_DEPS)'%QuoteSpaces(self.output))
15691569

15701570
# After the framework is built, package it. Needs to happen before
@@ -1598,7 +1598,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15981598
ifself.type=='executable':
15991599
self.WriteLn('%s: LD_INPUTS := %s'% (
16001600
QuoteSpaces(self.output_binary),
1601-
' '.join(map(QuoteSpaces, link_deps))))
1601+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16021602
ifself.toolset=='host'andself.flavor=='android':
16031603
self.WriteDoCmd([self.output_binary], link_deps, 'link_host',
16041604
part_of_all, postbuilds=postbuilds)
@@ -1620,7 +1620,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
16201620
elifself.type=='shared_library':
16211621
self.WriteLn('%s: LD_INPUTS := %s'% (
16221622
QuoteSpaces(self.output_binary),
1623-
' '.join(map(QuoteSpaces, link_deps))))
1623+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16241624
self.WriteDoCmd([self.output_binary], link_deps, 'solink', part_of_all,
16251625
postbuilds=postbuilds)
16261626
elifself.type=='loadable_module':
@@ -1746,8 +1746,8 @@ def WriteMakeRule(self, outputs, inputs, actions=None, comment=None,
17461746
output is just a name to run the rule
17471747
command: (optional) command name to generate unambiguous labels
17481748
"""
1749-
outputs=map(QuoteSpaces, outputs)
1750-
inputs=map(QuoteSpaces, inputs)
1749+
outputs=[QuoteSpaces(o) foroinoutputs]
1750+
inputs=[QuoteSpaces(i) foriininputs]
17511751

17521752
ifcomment:
17531753
self.WriteLn('# '+comment)
@@ -1836,7 +1836,7 @@ def WriteAndroidNdkModuleRule(self, module_name, all_sources, link_deps):
18361836
default_cpp_ext=ext
18371837
self.WriteLn('LOCAL_CPP_EXTENSION := '+default_cpp_ext)
18381838

1839-
self.WriteList(map(self.Absolutify, filter(Compilable, all_sources)),
1839+
self.WriteList(list(map(self.Absolutify, filter(Compilable, all_sources))),
18401840
'LOCAL_SRC_FILES')
18411841

18421842
# Filter out those which do not match prefix and suffix and produce
@@ -1979,7 +1979,7 @@ def WriteAutoRegenerationRule(params, root_makefile, makefile_name,
19791979
"%(makefile_name)s: %(deps)s\n"
19801980
"\t$(call do_cmd,regen_makefile)\n\n"% {
19811981
'makefile_name': makefile_name,
1982-
'deps': ' '.join(map(SourceifyAndQuoteSpaces, build_files)),
1982+
'deps': ' '.join(SourceifyAndQuoteSpaces(bf) forbfinbuild_files),
19831983
'cmd': gyp.common.EncodePOSIXShellList(
19841984
[gyp_binary, '-fmake'] +
19851985
gyp.RegenerateFlags(options) +

‎gyp/pylib/gyp/generator/msvs.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name):
26912691

26922692
platform_name=None
26932693
msvs_windows_target_platform_version=None
2694-
forconfigurationinspec['configurations'].itervalues():
2694+
forconfigurationinspec['configurations'].values():
26952695
platform_name=platform_nameor_ConfigPlatform(configuration)
26962696
msvs_windows_target_platform_version= \
26972697
msvs_windows_target_platform_versionor \
@@ -3252,7 +3252,7 @@ def _GetMSBuildProjectReferences(project):
32523252
['Project', guid],
32533253
['ReferenceOutputAssembly', 'false']
32543254
]
3255-
forconfigindependency.spec.get('configurations', {}).itervalues():
3255+
forconfigindependency.spec.get('configurations', {}).values():
32563256
ifconfig.get('msvs_use_library_dependency_inputs', 0):
32573257
project_ref.append(['UseLibraryDependencyInputs', 'true'])
32583258
break
@@ -3321,7 +3321,7 @@ def _GenerateMSBuildProject(project, options, version, generator_flags):
33213321
extension_to_rule_name, _GetUniquePlatforms(spec))
33223322
missing_sources=_VerifySourcesExist(sources, project_dir)
33233323

3324-
forconfigurationinconfigurations.itervalues():
3324+
forconfigurationinconfigurations.values():
33253325
_FinalizeMSBuildSettings(spec, configuration)
33263326

33273327
# Add attributes to root element

‎gyp/pylib/gyp/input.py‎

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44

55
from __future__ importprint_function
66

7-
fromcompiler.astimportConst
8-
fromcompiler.astimportDict
9-
fromcompiler.astimportDiscard
10-
fromcompiler.astimportList
11-
fromcompiler.astimportModule
12-
fromcompiler.astimportNode
13-
fromcompiler.astimportStmt
14-
importcompiler
7+
importast
8+
159
importgyp.common
1610
importgyp.simple_copy
1711
importmultiprocessing
@@ -184,43 +178,39 @@ def CheckedEval(file_contents):
184178
Note that this is slower than eval() is.
185179
"""
186180

187-
ast=compiler.parse(file_contents)
188-
assertisinstance(ast, Module)
189-
c1=ast.getChildren()
190-
assertc1[0] isNone
191-
assertisinstance(c1[1], Stmt)
192-
c2=c1[1].getChildren()
193-
assertisinstance(c2[0], Discard)
194-
c3=c2[0].getChildren()
195-
assertlen(c3) ==1
196-
returnCheckNode(c3[0], [])
181+
syntax_tree=ast.parse(file_contents)
182+
assertisinstance(syntax_tree, ast.Module)
183+
c1=syntax_tree.body
184+
assertlen(c1) ==1
185+
c2=c1[0]
186+
assertisinstance(c2, ast.Expr)
187+
returnCheckNode(c2.value, [])
197188

198189

199190
defCheckNode(node, keypath):
200-
ifisinstance(node, Dict):
191+
ifisinstance(node, ast.Dict):
201192
c=node.getChildren()
202193
dict= {}
203-
forninrange(0, len(c), 2):
204-
assertisinstance(c[n], Const)
205-
key=c[n].getChildren()[0]
194+
forkey, valueinzip(node.keys, node.values):
195+
assertisinstance(key, ast.Str)
196+
key=key.s
206197
ifkeyindict:
207198
raiseGypError("Key '"+key+"' repeated at level "+
208199
repr(len(keypath) +1) +" with key path '"+
209200
'.'.join(keypath) +"'")
210201
kp=list(keypath) # Make a copy of the list for descending this node.
211202
kp.append(key)
212-
dict[key] =CheckNode(c[n+1], kp)
203+
dict[key] =CheckNode(value, kp)
213204
returndict
214-
elifisinstance(node, List):
215-
c=node.getChildren()
205+
elifisinstance(node, ast.List):
216206
children= []
217-
forindex, childinenumerate(c):
207+
forindex, childinenumerate(node.elts):
218208
kp=list(keypath) # Copy list.
219209
kp.append(repr(index))
220210
children.append(CheckNode(child, kp))
221211
returnchildren
222-
elifisinstance(node, Const):
223-
returnnode.getChildren()[0]
212+
elifisinstance(node, ast.Str):
213+
returnnode.s
224214
else:
225215
raiseTypeError("Unknown AST node at key path '"+'.'.join(keypath) +
226216
"': "+repr(node))
@@ -954,8 +944,12 @@ def ExpandVariables(input, phase, variables, build_file):
954944
else:
955945
replacement=variables[contents]
956946

947+
ifisinstance(replacement, bytes) andnotisinstance(replacement, str):
948+
replacement=replacement.decode("utf-8") # done on Python 3 only
957949
iftype(replacement) islist:
958950
foriteminreplacement:
951+
ifisinstance(item, bytes) andnotisinstance(item, str):
952+
item=item.decode("utf-8") # done on Python 3 only
959953
ifnotcontents[-1] =='/'andtype(item) notin (str, int):
960954
raiseGypError('Variable '+contents+
961955
' must expand to a string or list of strings; '+
@@ -1847,7 +1841,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18471841
# Create a DependencyGraphNode for each gyp file containing a target. Put
18481842
# it into a dict for easy access.
18491843
dependency_nodes= {}
1850-
fortargetintargets.iterkeys():
1844+
fortargetintargets:
18511845
build_file=gyp.common.BuildFile(target)
18521846
ifnotbuild_fileindependency_nodes:
18531847
dependency_nodes[build_file] =DependencyGraphNode(build_file)
@@ -1878,7 +1872,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18781872

18791873
# Files that have no dependencies are treated as dependent on root_node.
18801874
root_node=DependencyGraphNode(None)
1881-
forbuild_file_nodeindependency_nodes.itervalues():
1875+
forbuild_file_nodeindependency_nodes.values():
18821876
iflen(build_file_node.dependencies) ==0:
18831877
build_file_node.dependencies.append(root_node)
18841878
root_node.dependents.append(build_file_node)

‎gyp/pylib/gyp/xcode_emulation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ def _HasIOSTarget(targets):
16361636
def_AddIOSDeviceConfigurations(targets):
16371637
"""Clone all targets and append -iphoneos to the name. Configure these targets
16381638
to build for iOS devices and use correct architectures for those builds."""
1639-
fortarget_dictintargets.itervalues():
1639+
fortarget_dictintargets.values():
16401640
toolset=target_dict['toolset']
16411641
configs=target_dict['configurations']
16421642
forconfig_name, config_dictindict(configs).items():

‎gyp/pylib/gyp/xcode_ninja.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _TargetFromSpec(old_spec, params):
8585
"%s/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"%ninja_toplevel
8686

8787
if'configurations'inold_spec:
88-
forconfiginold_spec['configurations'].iterkeys():
88+
forconfiginold_spec['configurations']:
8989
old_xcode_settings= \
9090
old_spec['configurations'][config].get('xcode_settings', {})
9191
if'IPHONEOS_DEPLOYMENT_TARGET'inold_xcode_settings:

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit fa0ed4a

Browse files
cclaussrvagg
authored andcommitted
build: more Python 3 compat, replace compile with ast
Make Python 3 compatiblity changes so the code works in both Python 2 and Python 3. Especially, make changes required because the compiler module was removed in Python 3 in favor of the ast module that exists in both Python 2 and Python 3. PR-URL: #1820 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rod Vagg <r@va.gg> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent 18d5c7c commit fa0ed4a

7 files changed

Lines changed: 50 additions & 56 deletions

File tree

‎gyp/pylib/gyp/generator/analyzer.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def find_matching_compile_target_names(self):
671671
assertself.is_build_impacted();
672672
# Compile targets are found by searching up from changed targets.
673673
# Reset the visited status for _GetBuildTargets.
674-
fortargetinself._name_to_target.itervalues():
674+
fortargetinself._name_to_target.values():
675675
target.visited=False
676676

677677
supplied_targets=_LookupTargets(self._supplied_target_names_no_all(),

‎gyp/pylib/gyp/generator/eclipse.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def WriteMacros(out, eclipse_langs, defines):
272272
out.write(' <language name="holder for library settings"></language>\n')
273273
forlangineclipse_langs:
274274
out.write(' <language name="%s">\n'%lang)
275-
forkeyinsorted(defines.iterkeys()):
275+
forkeyinsorted(defines):
276276
out.write(' <macro><name>%s</name><value>%s</value></macro>\n'%
277277
(escape(key), escape(defines[key])))
278278
out.write(' </language>\n')

‎gyp/pylib/gyp/generator/make.py‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def Write(self, qualified_target, base_path, output_filename, spec, configs,
821821
gyp.xcode_emulation.MacPrefixHeader(
822822
self.xcode_settings, lambdap: Sourceify(self.Absolutify(p)),
823823
self.Pchify))
824-
sources=filter(Compilable, all_sources)
824+
sources=list(filter(Compilable, all_sources))
825825
ifsources:
826826
self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT1)
827827
extensions=set([os.path.splitext(s)[1] forsinsources])
@@ -950,7 +950,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
950950
'%s%s'
951951
% (name, cd_action, command))
952952
self.WriteLn()
953-
outputs=map(self.Absolutify, outputs)
953+
outputs=[self.Absolutify(output) foroutputinoutputs]
954954
# The makefile rules are all relative to the top dir, but the gyp actions
955955
# are defined relative to their containing dir. This replaces the obj
956956
# variable for the action rule with an absolute version so that the output
@@ -974,7 +974,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
974974
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
975975
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
976976

977-
self.WriteDoCmd(outputs, map(Sourceify, map(self.Absolutify, inputs)),
977+
self.WriteDoCmd(outputs, [Sourceify(self.Absolutify(i)) foriininputs],
978978
part_of_all=part_of_all, command=name)
979979

980980
# Stuff the outputs in a variable so we can refer to them later.
@@ -1023,8 +1023,8 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10231023
extra_sources+=outputs
10241024
ifint(rule.get('process_outputs_as_mac_bundle_resources', False)):
10251025
extra_mac_bundle_resources+=outputs
1026-
inputs=map(Sourceify, map(self.Absolutify, [rule_source] +
1027-
rule.get('inputs', [])))
1026+
inputs=[Sourceify(self.Absolutify(i)) fori
1027+
in [rule_source] +rule.get('inputs', [])]
10281028
actions= ['$(call do_cmd,%s_%d)'% (name, count)]
10291029

10301030
ifname=='resources_grit':
@@ -1040,7 +1040,7 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10401040
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
10411041
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
10421042

1043-
outputs=map(self.Absolutify, outputs)
1043+
outputs=[self.Absolutify(output) foroutputinoutputs]
10441044
all_outputs+=outputs
10451045
# Only write the 'obj' and 'builddir' rules for the "primary" output
10461046
# (:1); it's superfluous for the "extra outputs", and this avoids
@@ -1147,7 +1147,7 @@ def WriteCopies(self, copies, extra_outputs, part_of_all):
11471147
path=gyp.xcode_emulation.ExpandEnvVars(path, env)
11481148
self.WriteDoCmd([output], [path], 'copy', part_of_all)
11491149
outputs.append(output)
1150-
self.WriteLn('%s = %s'% (variable, ' '.join(map(QuoteSpaces, outputs))))
1150+
self.WriteLn('%s = %s'% (variable, ' '.join(QuoteSpaces(o) foroinoutputs)))
11511151
extra_outputs.append('$(%s)'%variable)
11521152
self.WriteLn()
11531153

@@ -1158,7 +1158,7 @@ def WriteMacBundleResources(self, resources, bundle_deps):
11581158

11591159
foroutput, resingyp.xcode_emulation.GetMacBundleResources(
11601160
generator_default_variables['PRODUCT_DIR'], self.xcode_settings,
1161-
map(Sourceify, map(self.Absolutify, resources))):
1161+
[Sourceify(self.Absolutify(r)) forrinresources]):
11621162
_, ext=os.path.splitext(output)
11631163
ifext!='.xcassets':
11641164
# Make does not supports '.xcassets' emulation.
@@ -1238,11 +1238,11 @@ def WriteSources(self, configs, deps, sources,
12381238
self.WriteList(cflags_objcc, 'CFLAGS_OBJCC_%s'%configname)
12391239
includes=config.get('include_dirs')
12401240
ifincludes:
1241-
includes=map(Sourceify, map(self.Absolutify, includes))
1241+
includes=[Sourceify(self.Absolutify(i)) foriinincludes]
12421242
self.WriteList(includes, 'INCS_%s'%configname, prefix='-I')
12431243

1244-
compilable=filter(Compilable, sources)
1245-
objs=map(self.Objectify, map(self.Absolutify, map(Target, compilable)))
1244+
compilable=list(filter(Compilable, sources))
1245+
objs=[self.Objectify(self.Absolutify(Target(c)))forcincompilable]
12461246
self.WriteList(objs, 'OBJS')
12471247

12481248
forobjinobjs:
@@ -1314,7 +1314,7 @@ def WriteSources(self, configs, deps, sources,
13141314

13151315
# If there are any object files in our input file list, link them into our
13161316
# output.
1317-
extra_link_deps+=filter(Linkable, sources)
1317+
extra_link_deps+=list(filter(Linkable, sources))
13181318

13191319
self.WriteLn()
13201320

@@ -1564,7 +1564,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15641564

15651565
# Bundle dependencies. Note that the code below adds actions to this
15661566
# target, so if you move these two lines, move the lines below as well.
1567-
self.WriteList(map(QuoteSpaces, bundle_deps), 'BUNDLE_DEPS')
1567+
self.WriteList([QuoteSpaces(dep) fordepinbundle_deps], 'BUNDLE_DEPS')
15681568
self.WriteLn('%s: $(BUNDLE_DEPS)'%QuoteSpaces(self.output))
15691569

15701570
# After the framework is built, package it. Needs to happen before
@@ -1598,7 +1598,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15981598
ifself.type=='executable':
15991599
self.WriteLn('%s: LD_INPUTS := %s'% (
16001600
QuoteSpaces(self.output_binary),
1601-
' '.join(map(QuoteSpaces, link_deps))))
1601+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16021602
ifself.toolset=='host'andself.flavor=='android':
16031603
self.WriteDoCmd([self.output_binary], link_deps, 'link_host',
16041604
part_of_all, postbuilds=postbuilds)
@@ -1620,7 +1620,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
16201620
elifself.type=='shared_library':
16211621
self.WriteLn('%s: LD_INPUTS := %s'% (
16221622
QuoteSpaces(self.output_binary),
1623-
' '.join(map(QuoteSpaces, link_deps))))
1623+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16241624
self.WriteDoCmd([self.output_binary], link_deps, 'solink', part_of_all,
16251625
postbuilds=postbuilds)
16261626
elifself.type=='loadable_module':
@@ -1746,8 +1746,8 @@ def WriteMakeRule(self, outputs, inputs, actions=None, comment=None,
17461746
output is just a name to run the rule
17471747
command: (optional) command name to generate unambiguous labels
17481748
"""
1749-
outputs=map(QuoteSpaces, outputs)
1750-
inputs=map(QuoteSpaces, inputs)
1749+
outputs=[QuoteSpaces(o) foroinoutputs]
1750+
inputs=[QuoteSpaces(i) foriininputs]
17511751

17521752
ifcomment:
17531753
self.WriteLn('# '+comment)
@@ -1836,7 +1836,7 @@ def WriteAndroidNdkModuleRule(self, module_name, all_sources, link_deps):
18361836
default_cpp_ext=ext
18371837
self.WriteLn('LOCAL_CPP_EXTENSION := '+default_cpp_ext)
18381838

1839-
self.WriteList(map(self.Absolutify, filter(Compilable, all_sources)),
1839+
self.WriteList(list(map(self.Absolutify, filter(Compilable, all_sources))),
18401840
'LOCAL_SRC_FILES')
18411841

18421842
# Filter out those which do not match prefix and suffix and produce
@@ -1979,7 +1979,7 @@ def WriteAutoRegenerationRule(params, root_makefile, makefile_name,
19791979
"%(makefile_name)s: %(deps)s\n"
19801980
"\t$(call do_cmd,regen_makefile)\n\n"% {
19811981
'makefile_name': makefile_name,
1982-
'deps': ' '.join(map(SourceifyAndQuoteSpaces, build_files)),
1982+
'deps': ' '.join(SourceifyAndQuoteSpaces(bf) forbfinbuild_files),
19831983
'cmd': gyp.common.EncodePOSIXShellList(
19841984
[gyp_binary, '-fmake'] +
19851985
gyp.RegenerateFlags(options) +

‎gyp/pylib/gyp/generator/msvs.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name):
26912691

26922692
platform_name=None
26932693
msvs_windows_target_platform_version=None
2694-
forconfigurationinspec['configurations'].itervalues():
2694+
forconfigurationinspec['configurations'].values():
26952695
platform_name=platform_nameor_ConfigPlatform(configuration)
26962696
msvs_windows_target_platform_version= \
26972697
msvs_windows_target_platform_versionor \
@@ -3252,7 +3252,7 @@ def _GetMSBuildProjectReferences(project):
32523252
['Project', guid],
32533253
['ReferenceOutputAssembly', 'false']
32543254
]
3255-
forconfigindependency.spec.get('configurations', {}).itervalues():
3255+
forconfigindependency.spec.get('configurations', {}).values():
32563256
ifconfig.get('msvs_use_library_dependency_inputs', 0):
32573257
project_ref.append(['UseLibraryDependencyInputs', 'true'])
32583258
break
@@ -3321,7 +3321,7 @@ def _GenerateMSBuildProject(project, options, version, generator_flags):
33213321
extension_to_rule_name, _GetUniquePlatforms(spec))
33223322
missing_sources=_VerifySourcesExist(sources, project_dir)
33233323

3324-
forconfigurationinconfigurations.itervalues():
3324+
forconfigurationinconfigurations.values():
33253325
_FinalizeMSBuildSettings(spec, configuration)
33263326

33273327
# Add attributes to root element

‎gyp/pylib/gyp/input.py‎

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44

55
from __future__ importprint_function
66

7-
fromcompiler.astimportConst
8-
fromcompiler.astimportDict
9-
fromcompiler.astimportDiscard
10-
fromcompiler.astimportList
11-
fromcompiler.astimportModule
12-
fromcompiler.astimportNode
13-
fromcompiler.astimportStmt
14-
importcompiler
7+
importast
8+
159
importgyp.common
1610
importgyp.simple_copy
1711
importmultiprocessing
@@ -184,43 +178,39 @@ def CheckedEval(file_contents):
184178
Note that this is slower than eval() is.
185179
"""
186180

187-
ast=compiler.parse(file_contents)
188-
assertisinstance(ast, Module)
189-
c1=ast.getChildren()
190-
assertc1[0] isNone
191-
assertisinstance(c1[1], Stmt)
192-
c2=c1[1].getChildren()
193-
assertisinstance(c2[0], Discard)
194-
c3=c2[0].getChildren()
195-
assertlen(c3) ==1
196-
returnCheckNode(c3[0], [])
181+
syntax_tree=ast.parse(file_contents)
182+
assertisinstance(syntax_tree, ast.Module)
183+
c1=syntax_tree.body
184+
assertlen(c1) ==1
185+
c2=c1[0]
186+
assertisinstance(c2, ast.Expr)
187+
returnCheckNode(c2.value, [])
197188

198189

199190
defCheckNode(node, keypath):
200-
ifisinstance(node, Dict):
191+
ifisinstance(node, ast.Dict):
201192
c=node.getChildren()
202193
dict= {}
203-
forninrange(0, len(c), 2):
204-
assertisinstance(c[n], Const)
205-
key=c[n].getChildren()[0]
194+
forkey, valueinzip(node.keys, node.values):
195+
assertisinstance(key, ast.Str)
196+
key=key.s
206197
ifkeyindict:
207198
raiseGypError("Key '"+key+"' repeated at level "+
208199
repr(len(keypath) +1) +" with key path '"+
209200
'.'.join(keypath) +"'")
210201
kp=list(keypath) # Make a copy of the list for descending this node.
211202
kp.append(key)
212-
dict[key] =CheckNode(c[n+1], kp)
203+
dict[key] =CheckNode(value, kp)
213204
returndict
214-
elifisinstance(node, List):
215-
c=node.getChildren()
205+
elifisinstance(node, ast.List):
216206
children= []
217-
forindex, childinenumerate(c):
207+
forindex, childinenumerate(node.elts):
218208
kp=list(keypath) # Copy list.
219209
kp.append(repr(index))
220210
children.append(CheckNode(child, kp))
221211
returnchildren
222-
elifisinstance(node, Const):
223-
returnnode.getChildren()[0]
212+
elifisinstance(node, ast.Str):
213+
returnnode.s
224214
else:
225215
raiseTypeError("Unknown AST node at key path '"+'.'.join(keypath) +
226216
"': "+repr(node))
@@ -954,8 +944,12 @@ def ExpandVariables(input, phase, variables, build_file):
954944
else:
955945
replacement=variables[contents]
956946

947+
ifisinstance(replacement, bytes) andnotisinstance(replacement, str):
948+
replacement=replacement.decode("utf-8") # done on Python 3 only
957949
iftype(replacement) islist:
958950
foriteminreplacement:
951+
ifisinstance(item, bytes) andnotisinstance(item, str):
952+
item=item.decode("utf-8") # done on Python 3 only
959953
ifnotcontents[-1] =='/'andtype(item) notin (str, int):
960954
raiseGypError('Variable '+contents+
961955
' must expand to a string or list of strings; '+
@@ -1847,7 +1841,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18471841
# Create a DependencyGraphNode for each gyp file containing a target. Put
18481842
# it into a dict for easy access.
18491843
dependency_nodes= {}
1850-
fortargetintargets.iterkeys():
1844+
fortargetintargets:
18511845
build_file=gyp.common.BuildFile(target)
18521846
ifnotbuild_fileindependency_nodes:
18531847
dependency_nodes[build_file] =DependencyGraphNode(build_file)
@@ -1878,7 +1872,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18781872

18791873
# Files that have no dependencies are treated as dependent on root_node.
18801874
root_node=DependencyGraphNode(None)
1881-
forbuild_file_nodeindependency_nodes.itervalues():
1875+
forbuild_file_nodeindependency_nodes.values():
18821876
iflen(build_file_node.dependencies) ==0:
18831877
build_file_node.dependencies.append(root_node)
18841878
root_node.dependents.append(build_file_node)

‎gyp/pylib/gyp/xcode_emulation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ def _HasIOSTarget(targets):
16361636
def_AddIOSDeviceConfigurations(targets):
16371637
"""Clone all targets and append -iphoneos to the name. Configure these targets
16381638
to build for iOS devices and use correct architectures for those builds."""
1639-
fortarget_dictintargets.itervalues():
1639+
fortarget_dictintargets.values():
16401640
toolset=target_dict['toolset']
16411641
configs=target_dict['configurations']
16421642
forconfig_name, config_dictindict(configs).items():

‎gyp/pylib/gyp/xcode_ninja.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _TargetFromSpec(old_spec, params):
8585
"%s/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"%ninja_toplevel
8686

8787
if'configurations'inold_spec:
88-
forconfiginold_spec['configurations'].iterkeys():
88+
forconfiginold_spec['configurations']:
8989
old_xcode_settings= \
9090
old_spec['configurations'][config].get('xcode_settings', {})
9191
if'IPHONEOS_DEPLOYMENT_TARGET'inold_xcode_settings:

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit fa0ed4a

Browse files
cclaussrvagg
authored andcommitted
build: more Python 3 compat, replace compile with ast
Make Python 3 compatiblity changes so the code works in both Python 2 and Python 3. Especially, make changes required because the compiler module was removed in Python 3 in favor of the ast module that exists in both Python 2 and Python 3. PR-URL: #1820 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rod Vagg <r@va.gg> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent 18d5c7c commit fa0ed4a

7 files changed

Lines changed: 50 additions & 56 deletions

File tree

‎gyp/pylib/gyp/generator/analyzer.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def find_matching_compile_target_names(self):
671671
assertself.is_build_impacted();
672672
# Compile targets are found by searching up from changed targets.
673673
# Reset the visited status for _GetBuildTargets.
674-
fortargetinself._name_to_target.itervalues():
674+
fortargetinself._name_to_target.values():
675675
target.visited=False
676676

677677
supplied_targets=_LookupTargets(self._supplied_target_names_no_all(),

‎gyp/pylib/gyp/generator/eclipse.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def WriteMacros(out, eclipse_langs, defines):
272272
out.write(' <language name="holder for library settings"></language>\n')
273273
forlangineclipse_langs:
274274
out.write(' <language name="%s">\n'%lang)
275-
forkeyinsorted(defines.iterkeys()):
275+
forkeyinsorted(defines):
276276
out.write(' <macro><name>%s</name><value>%s</value></macro>\n'%
277277
(escape(key), escape(defines[key])))
278278
out.write(' </language>\n')

‎gyp/pylib/gyp/generator/make.py‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def Write(self, qualified_target, base_path, output_filename, spec, configs,
821821
gyp.xcode_emulation.MacPrefixHeader(
822822
self.xcode_settings, lambdap: Sourceify(self.Absolutify(p)),
823823
self.Pchify))
824-
sources=filter(Compilable, all_sources)
824+
sources=list(filter(Compilable, all_sources))
825825
ifsources:
826826
self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT1)
827827
extensions=set([os.path.splitext(s)[1] forsinsources])
@@ -950,7 +950,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
950950
'%s%s'
951951
% (name, cd_action, command))
952952
self.WriteLn()
953-
outputs=map(self.Absolutify, outputs)
953+
outputs=[self.Absolutify(output) foroutputinoutputs]
954954
# The makefile rules are all relative to the top dir, but the gyp actions
955955
# are defined relative to their containing dir. This replaces the obj
956956
# variable for the action rule with an absolute version so that the output
@@ -974,7 +974,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
974974
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
975975
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
976976

977-
self.WriteDoCmd(outputs, map(Sourceify, map(self.Absolutify, inputs)),
977+
self.WriteDoCmd(outputs, [Sourceify(self.Absolutify(i)) foriininputs],
978978
part_of_all=part_of_all, command=name)
979979

980980
# Stuff the outputs in a variable so we can refer to them later.
@@ -1023,8 +1023,8 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10231023
extra_sources+=outputs
10241024
ifint(rule.get('process_outputs_as_mac_bundle_resources', False)):
10251025
extra_mac_bundle_resources+=outputs
1026-
inputs=map(Sourceify, map(self.Absolutify, [rule_source] +
1027-
rule.get('inputs', [])))
1026+
inputs=[Sourceify(self.Absolutify(i)) fori
1027+
in [rule_source] +rule.get('inputs', [])]
10281028
actions= ['$(call do_cmd,%s_%d)'% (name, count)]
10291029

10301030
ifname=='resources_grit':
@@ -1040,7 +1040,7 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10401040
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
10411041
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
10421042

1043-
outputs=map(self.Absolutify, outputs)
1043+
outputs=[self.Absolutify(output) foroutputinoutputs]
10441044
all_outputs+=outputs
10451045
# Only write the 'obj' and 'builddir' rules for the "primary" output
10461046
# (:1); it's superfluous for the "extra outputs", and this avoids
@@ -1147,7 +1147,7 @@ def WriteCopies(self, copies, extra_outputs, part_of_all):
11471147
path=gyp.xcode_emulation.ExpandEnvVars(path, env)
11481148
self.WriteDoCmd([output], [path], 'copy', part_of_all)
11491149
outputs.append(output)
1150-
self.WriteLn('%s = %s'% (variable, ' '.join(map(QuoteSpaces, outputs))))
1150+
self.WriteLn('%s = %s'% (variable, ' '.join(QuoteSpaces(o) foroinoutputs)))
11511151
extra_outputs.append('$(%s)'%variable)
11521152
self.WriteLn()
11531153

@@ -1158,7 +1158,7 @@ def WriteMacBundleResources(self, resources, bundle_deps):
11581158

11591159
foroutput, resingyp.xcode_emulation.GetMacBundleResources(
11601160
generator_default_variables['PRODUCT_DIR'], self.xcode_settings,
1161-
map(Sourceify, map(self.Absolutify, resources))):
1161+
[Sourceify(self.Absolutify(r)) forrinresources]):
11621162
_, ext=os.path.splitext(output)
11631163
ifext!='.xcassets':
11641164
# Make does not supports '.xcassets' emulation.
@@ -1238,11 +1238,11 @@ def WriteSources(self, configs, deps, sources,
12381238
self.WriteList(cflags_objcc, 'CFLAGS_OBJCC_%s'%configname)
12391239
includes=config.get('include_dirs')
12401240
ifincludes:
1241-
includes=map(Sourceify, map(self.Absolutify, includes))
1241+
includes=[Sourceify(self.Absolutify(i)) foriinincludes]
12421242
self.WriteList(includes, 'INCS_%s'%configname, prefix='-I')
12431243

1244-
compilable=filter(Compilable, sources)
1245-
objs=map(self.Objectify, map(self.Absolutify, map(Target, compilable)))
1244+
compilable=list(filter(Compilable, sources))
1245+
objs=[self.Objectify(self.Absolutify(Target(c)))forcincompilable]
12461246
self.WriteList(objs, 'OBJS')
12471247

12481248
forobjinobjs:
@@ -1314,7 +1314,7 @@ def WriteSources(self, configs, deps, sources,
13141314

13151315
# If there are any object files in our input file list, link them into our
13161316
# output.
1317-
extra_link_deps+=filter(Linkable, sources)
1317+
extra_link_deps+=list(filter(Linkable, sources))
13181318

13191319
self.WriteLn()
13201320

@@ -1564,7 +1564,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15641564

15651565
# Bundle dependencies. Note that the code below adds actions to this
15661566
# target, so if you move these two lines, move the lines below as well.
1567-
self.WriteList(map(QuoteSpaces, bundle_deps), 'BUNDLE_DEPS')
1567+
self.WriteList([QuoteSpaces(dep) fordepinbundle_deps], 'BUNDLE_DEPS')
15681568
self.WriteLn('%s: $(BUNDLE_DEPS)'%QuoteSpaces(self.output))
15691569

15701570
# After the framework is built, package it. Needs to happen before
@@ -1598,7 +1598,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15981598
ifself.type=='executable':
15991599
self.WriteLn('%s: LD_INPUTS := %s'% (
16001600
QuoteSpaces(self.output_binary),
1601-
' '.join(map(QuoteSpaces, link_deps))))
1601+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16021602
ifself.toolset=='host'andself.flavor=='android':
16031603
self.WriteDoCmd([self.output_binary], link_deps, 'link_host',
16041604
part_of_all, postbuilds=postbuilds)
@@ -1620,7 +1620,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
16201620
elifself.type=='shared_library':
16211621
self.WriteLn('%s: LD_INPUTS := %s'% (
16221622
QuoteSpaces(self.output_binary),
1623-
' '.join(map(QuoteSpaces, link_deps))))
1623+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16241624
self.WriteDoCmd([self.output_binary], link_deps, 'solink', part_of_all,
16251625
postbuilds=postbuilds)
16261626
elifself.type=='loadable_module':
@@ -1746,8 +1746,8 @@ def WriteMakeRule(self, outputs, inputs, actions=None, comment=None,
17461746
output is just a name to run the rule
17471747
command: (optional) command name to generate unambiguous labels
17481748
"""
1749-
outputs=map(QuoteSpaces, outputs)
1750-
inputs=map(QuoteSpaces, inputs)
1749+
outputs=[QuoteSpaces(o) foroinoutputs]
1750+
inputs=[QuoteSpaces(i) foriininputs]
17511751

17521752
ifcomment:
17531753
self.WriteLn('# '+comment)
@@ -1836,7 +1836,7 @@ def WriteAndroidNdkModuleRule(self, module_name, all_sources, link_deps):
18361836
default_cpp_ext=ext
18371837
self.WriteLn('LOCAL_CPP_EXTENSION := '+default_cpp_ext)
18381838

1839-
self.WriteList(map(self.Absolutify, filter(Compilable, all_sources)),
1839+
self.WriteList(list(map(self.Absolutify, filter(Compilable, all_sources))),
18401840
'LOCAL_SRC_FILES')
18411841

18421842
# Filter out those which do not match prefix and suffix and produce
@@ -1979,7 +1979,7 @@ def WriteAutoRegenerationRule(params, root_makefile, makefile_name,
19791979
"%(makefile_name)s: %(deps)s\n"
19801980
"\t$(call do_cmd,regen_makefile)\n\n"% {
19811981
'makefile_name': makefile_name,
1982-
'deps': ' '.join(map(SourceifyAndQuoteSpaces, build_files)),
1982+
'deps': ' '.join(SourceifyAndQuoteSpaces(bf) forbfinbuild_files),
19831983
'cmd': gyp.common.EncodePOSIXShellList(
19841984
[gyp_binary, '-fmake'] +
19851985
gyp.RegenerateFlags(options) +

‎gyp/pylib/gyp/generator/msvs.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name):
26912691

26922692
platform_name=None
26932693
msvs_windows_target_platform_version=None
2694-
forconfigurationinspec['configurations'].itervalues():
2694+
forconfigurationinspec['configurations'].values():
26952695
platform_name=platform_nameor_ConfigPlatform(configuration)
26962696
msvs_windows_target_platform_version= \
26972697
msvs_windows_target_platform_versionor \
@@ -3252,7 +3252,7 @@ def _GetMSBuildProjectReferences(project):
32523252
['Project', guid],
32533253
['ReferenceOutputAssembly', 'false']
32543254
]
3255-
forconfigindependency.spec.get('configurations', {}).itervalues():
3255+
forconfigindependency.spec.get('configurations', {}).values():
32563256
ifconfig.get('msvs_use_library_dependency_inputs', 0):
32573257
project_ref.append(['UseLibraryDependencyInputs', 'true'])
32583258
break
@@ -3321,7 +3321,7 @@ def _GenerateMSBuildProject(project, options, version, generator_flags):
33213321
extension_to_rule_name, _GetUniquePlatforms(spec))
33223322
missing_sources=_VerifySourcesExist(sources, project_dir)
33233323

3324-
forconfigurationinconfigurations.itervalues():
3324+
forconfigurationinconfigurations.values():
33253325
_FinalizeMSBuildSettings(spec, configuration)
33263326

33273327
# Add attributes to root element

‎gyp/pylib/gyp/input.py‎

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44

55
from __future__ importprint_function
66

7-
fromcompiler.astimportConst
8-
fromcompiler.astimportDict
9-
fromcompiler.astimportDiscard
10-
fromcompiler.astimportList
11-
fromcompiler.astimportModule
12-
fromcompiler.astimportNode
13-
fromcompiler.astimportStmt
14-
importcompiler
7+
importast
8+
159
importgyp.common
1610
importgyp.simple_copy
1711
importmultiprocessing
@@ -184,43 +178,39 @@ def CheckedEval(file_contents):
184178
Note that this is slower than eval() is.
185179
"""
186180

187-
ast=compiler.parse(file_contents)
188-
assertisinstance(ast, Module)
189-
c1=ast.getChildren()
190-
assertc1[0] isNone
191-
assertisinstance(c1[1], Stmt)
192-
c2=c1[1].getChildren()
193-
assertisinstance(c2[0], Discard)
194-
c3=c2[0].getChildren()
195-
assertlen(c3) ==1
196-
returnCheckNode(c3[0], [])
181+
syntax_tree=ast.parse(file_contents)
182+
assertisinstance(syntax_tree, ast.Module)
183+
c1=syntax_tree.body
184+
assertlen(c1) ==1
185+
c2=c1[0]
186+
assertisinstance(c2, ast.Expr)
187+
returnCheckNode(c2.value, [])
197188

198189

199190
defCheckNode(node, keypath):
200-
ifisinstance(node, Dict):
191+
ifisinstance(node, ast.Dict):
201192
c=node.getChildren()
202193
dict= {}
203-
forninrange(0, len(c), 2):
204-
assertisinstance(c[n], Const)
205-
key=c[n].getChildren()[0]
194+
forkey, valueinzip(node.keys, node.values):
195+
assertisinstance(key, ast.Str)
196+
key=key.s
206197
ifkeyindict:
207198
raiseGypError("Key '"+key+"' repeated at level "+
208199
repr(len(keypath) +1) +" with key path '"+
209200
'.'.join(keypath) +"'")
210201
kp=list(keypath) # Make a copy of the list for descending this node.
211202
kp.append(key)
212-
dict[key] =CheckNode(c[n+1], kp)
203+
dict[key] =CheckNode(value, kp)
213204
returndict
214-
elifisinstance(node, List):
215-
c=node.getChildren()
205+
elifisinstance(node, ast.List):
216206
children= []
217-
forindex, childinenumerate(c):
207+
forindex, childinenumerate(node.elts):
218208
kp=list(keypath) # Copy list.
219209
kp.append(repr(index))
220210
children.append(CheckNode(child, kp))
221211
returnchildren
222-
elifisinstance(node, Const):
223-
returnnode.getChildren()[0]
212+
elifisinstance(node, ast.Str):
213+
returnnode.s
224214
else:
225215
raiseTypeError("Unknown AST node at key path '"+'.'.join(keypath) +
226216
"': "+repr(node))
@@ -954,8 +944,12 @@ def ExpandVariables(input, phase, variables, build_file):
954944
else:
955945
replacement=variables[contents]
956946

947+
ifisinstance(replacement, bytes) andnotisinstance(replacement, str):
948+
replacement=replacement.decode("utf-8") # done on Python 3 only
957949
iftype(replacement) islist:
958950
foriteminreplacement:
951+
ifisinstance(item, bytes) andnotisinstance(item, str):
952+
item=item.decode("utf-8") # done on Python 3 only
959953
ifnotcontents[-1] =='/'andtype(item) notin (str, int):
960954
raiseGypError('Variable '+contents+
961955
' must expand to a string or list of strings; '+
@@ -1847,7 +1841,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18471841
# Create a DependencyGraphNode for each gyp file containing a target. Put
18481842
# it into a dict for easy access.
18491843
dependency_nodes= {}
1850-
fortargetintargets.iterkeys():
1844+
fortargetintargets:
18511845
build_file=gyp.common.BuildFile(target)
18521846
ifnotbuild_fileindependency_nodes:
18531847
dependency_nodes[build_file] =DependencyGraphNode(build_file)
@@ -1878,7 +1872,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18781872

18791873
# Files that have no dependencies are treated as dependent on root_node.
18801874
root_node=DependencyGraphNode(None)
1881-
forbuild_file_nodeindependency_nodes.itervalues():
1875+
forbuild_file_nodeindependency_nodes.values():
18821876
iflen(build_file_node.dependencies) ==0:
18831877
build_file_node.dependencies.append(root_node)
18841878
root_node.dependents.append(build_file_node)

‎gyp/pylib/gyp/xcode_emulation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ def _HasIOSTarget(targets):
16361636
def_AddIOSDeviceConfigurations(targets):
16371637
"""Clone all targets and append -iphoneos to the name. Configure these targets
16381638
to build for iOS devices and use correct architectures for those builds."""
1639-
fortarget_dictintargets.itervalues():
1639+
fortarget_dictintargets.values():
16401640
toolset=target_dict['toolset']
16411641
configs=target_dict['configurations']
16421642
forconfig_name, config_dictindict(configs).items():

‎gyp/pylib/gyp/xcode_ninja.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _TargetFromSpec(old_spec, params):
8585
"%s/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"%ninja_toplevel
8686

8787
if'configurations'inold_spec:
88-
forconfiginold_spec['configurations'].iterkeys():
88+
forconfiginold_spec['configurations']:
8989
old_xcode_settings= \
9090
old_spec['configurations'][config].get('xcode_settings', {})
9191
if'IPHONEOS_DEPLOYMENT_TARGET'inold_xcode_settings:

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit fa0ed4a

Browse files
cclaussrvagg
authored andcommitted
build: more Python 3 compat, replace compile with ast
Make Python 3 compatiblity changes so the code works in both Python 2 and Python 3. Especially, make changes required because the compiler module was removed in Python 3 in favor of the ast module that exists in both Python 2 and Python 3. PR-URL: #1820 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rod Vagg <r@va.gg> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent 18d5c7c commit fa0ed4a

7 files changed

Lines changed: 50 additions & 56 deletions

File tree

‎gyp/pylib/gyp/generator/analyzer.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def find_matching_compile_target_names(self):
671671
assertself.is_build_impacted();
672672
# Compile targets are found by searching up from changed targets.
673673
# Reset the visited status for _GetBuildTargets.
674-
fortargetinself._name_to_target.itervalues():
674+
fortargetinself._name_to_target.values():
675675
target.visited=False
676676

677677
supplied_targets=_LookupTargets(self._supplied_target_names_no_all(),

‎gyp/pylib/gyp/generator/eclipse.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def WriteMacros(out, eclipse_langs, defines):
272272
out.write(' <language name="holder for library settings"></language>\n')
273273
forlangineclipse_langs:
274274
out.write(' <language name="%s">\n'%lang)
275-
forkeyinsorted(defines.iterkeys()):
275+
forkeyinsorted(defines):
276276
out.write(' <macro><name>%s</name><value>%s</value></macro>\n'%
277277
(escape(key), escape(defines[key])))
278278
out.write(' </language>\n')

‎gyp/pylib/gyp/generator/make.py‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def Write(self, qualified_target, base_path, output_filename, spec, configs,
821821
gyp.xcode_emulation.MacPrefixHeader(
822822
self.xcode_settings, lambdap: Sourceify(self.Absolutify(p)),
823823
self.Pchify))
824-
sources=filter(Compilable, all_sources)
824+
sources=list(filter(Compilable, all_sources))
825825
ifsources:
826826
self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT1)
827827
extensions=set([os.path.splitext(s)[1] forsinsources])
@@ -950,7 +950,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
950950
'%s%s'
951951
% (name, cd_action, command))
952952
self.WriteLn()
953-
outputs=map(self.Absolutify, outputs)
953+
outputs=[self.Absolutify(output) foroutputinoutputs]
954954
# The makefile rules are all relative to the top dir, but the gyp actions
955955
# are defined relative to their containing dir. This replaces the obj
956956
# variable for the action rule with an absolute version so that the output
@@ -974,7 +974,7 @@ def WriteActions(self, actions, extra_sources, extra_outputs,
974974
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
975975
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
976976

977-
self.WriteDoCmd(outputs, map(Sourceify, map(self.Absolutify, inputs)),
977+
self.WriteDoCmd(outputs, [Sourceify(self.Absolutify(i)) foriininputs],
978978
part_of_all=part_of_all, command=name)
979979

980980
# Stuff the outputs in a variable so we can refer to them later.
@@ -1023,8 +1023,8 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10231023
extra_sources+=outputs
10241024
ifint(rule.get('process_outputs_as_mac_bundle_resources', False)):
10251025
extra_mac_bundle_resources+=outputs
1026-
inputs=map(Sourceify, map(self.Absolutify, [rule_source] +
1027-
rule.get('inputs', [])))
1026+
inputs=[Sourceify(self.Absolutify(i)) fori
1027+
in [rule_source] +rule.get('inputs', [])]
10281028
actions= ['$(call do_cmd,%s_%d)'% (name, count)]
10291029

10301030
ifname=='resources_grit':
@@ -1040,7 +1040,7 @@ def WriteRules(self, rules, extra_sources, extra_outputs,
10401040
outputs= [gyp.xcode_emulation.ExpandEnvVars(o, env) foroinoutputs]
10411041
inputs= [gyp.xcode_emulation.ExpandEnvVars(i, env) foriininputs]
10421042

1043-
outputs=map(self.Absolutify, outputs)
1043+
outputs=[self.Absolutify(output) foroutputinoutputs]
10441044
all_outputs+=outputs
10451045
# Only write the 'obj' and 'builddir' rules for the "primary" output
10461046
# (:1); it's superfluous for the "extra outputs", and this avoids
@@ -1147,7 +1147,7 @@ def WriteCopies(self, copies, extra_outputs, part_of_all):
11471147
path=gyp.xcode_emulation.ExpandEnvVars(path, env)
11481148
self.WriteDoCmd([output], [path], 'copy', part_of_all)
11491149
outputs.append(output)
1150-
self.WriteLn('%s = %s'% (variable, ' '.join(map(QuoteSpaces, outputs))))
1150+
self.WriteLn('%s = %s'% (variable, ' '.join(QuoteSpaces(o) foroinoutputs)))
11511151
extra_outputs.append('$(%s)'%variable)
11521152
self.WriteLn()
11531153

@@ -1158,7 +1158,7 @@ def WriteMacBundleResources(self, resources, bundle_deps):
11581158

11591159
foroutput, resingyp.xcode_emulation.GetMacBundleResources(
11601160
generator_default_variables['PRODUCT_DIR'], self.xcode_settings,
1161-
map(Sourceify, map(self.Absolutify, resources))):
1161+
[Sourceify(self.Absolutify(r)) forrinresources]):
11621162
_, ext=os.path.splitext(output)
11631163
ifext!='.xcassets':
11641164
# Make does not supports '.xcassets' emulation.
@@ -1238,11 +1238,11 @@ def WriteSources(self, configs, deps, sources,
12381238
self.WriteList(cflags_objcc, 'CFLAGS_OBJCC_%s'%configname)
12391239
includes=config.get('include_dirs')
12401240
ifincludes:
1241-
includes=map(Sourceify, map(self.Absolutify, includes))
1241+
includes=[Sourceify(self.Absolutify(i)) foriinincludes]
12421242
self.WriteList(includes, 'INCS_%s'%configname, prefix='-I')
12431243

1244-
compilable=filter(Compilable, sources)
1245-
objs=map(self.Objectify, map(self.Absolutify, map(Target, compilable)))
1244+
compilable=list(filter(Compilable, sources))
1245+
objs=[self.Objectify(self.Absolutify(Target(c)))forcincompilable]
12461246
self.WriteList(objs, 'OBJS')
12471247

12481248
forobjinobjs:
@@ -1314,7 +1314,7 @@ def WriteSources(self, configs, deps, sources,
13141314

13151315
# If there are any object files in our input file list, link them into our
13161316
# output.
1317-
extra_link_deps+=filter(Linkable, sources)
1317+
extra_link_deps+=list(filter(Linkable, sources))
13181318

13191319
self.WriteLn()
13201320

@@ -1564,7 +1564,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15641564

15651565
# Bundle dependencies. Note that the code below adds actions to this
15661566
# target, so if you move these two lines, move the lines below as well.
1567-
self.WriteList(map(QuoteSpaces, bundle_deps), 'BUNDLE_DEPS')
1567+
self.WriteList([QuoteSpaces(dep) fordepinbundle_deps], 'BUNDLE_DEPS')
15681568
self.WriteLn('%s: $(BUNDLE_DEPS)'%QuoteSpaces(self.output))
15691569

15701570
# After the framework is built, package it. Needs to happen before
@@ -1598,7 +1598,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
15981598
ifself.type=='executable':
15991599
self.WriteLn('%s: LD_INPUTS := %s'% (
16001600
QuoteSpaces(self.output_binary),
1601-
' '.join(map(QuoteSpaces, link_deps))))
1601+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16021602
ifself.toolset=='host'andself.flavor=='android':
16031603
self.WriteDoCmd([self.output_binary], link_deps, 'link_host',
16041604
part_of_all, postbuilds=postbuilds)
@@ -1620,7 +1620,7 @@ def WriteTarget(self, spec, configs, deps, link_deps, bundle_deps,
16201620
elifself.type=='shared_library':
16211621
self.WriteLn('%s: LD_INPUTS := %s'% (
16221622
QuoteSpaces(self.output_binary),
1623-
' '.join(map(QuoteSpaces, link_deps))))
1623+
' '.join(QuoteSpaces(dep) fordepinlink_deps)))
16241624
self.WriteDoCmd([self.output_binary], link_deps, 'solink', part_of_all,
16251625
postbuilds=postbuilds)
16261626
elifself.type=='loadable_module':
@@ -1746,8 +1746,8 @@ def WriteMakeRule(self, outputs, inputs, actions=None, comment=None,
17461746
output is just a name to run the rule
17471747
command: (optional) command name to generate unambiguous labels
17481748
"""
1749-
outputs=map(QuoteSpaces, outputs)
1750-
inputs=map(QuoteSpaces, inputs)
1749+
outputs=[QuoteSpaces(o) foroinoutputs]
1750+
inputs=[QuoteSpaces(i) foriininputs]
17511751

17521752
ifcomment:
17531753
self.WriteLn('# '+comment)
@@ -1836,7 +1836,7 @@ def WriteAndroidNdkModuleRule(self, module_name, all_sources, link_deps):
18361836
default_cpp_ext=ext
18371837
self.WriteLn('LOCAL_CPP_EXTENSION := '+default_cpp_ext)
18381838

1839-
self.WriteList(map(self.Absolutify, filter(Compilable, all_sources)),
1839+
self.WriteList(list(map(self.Absolutify, filter(Compilable, all_sources))),
18401840
'LOCAL_SRC_FILES')
18411841

18421842
# Filter out those which do not match prefix and suffix and produce
@@ -1979,7 +1979,7 @@ def WriteAutoRegenerationRule(params, root_makefile, makefile_name,
19791979
"%(makefile_name)s: %(deps)s\n"
19801980
"\t$(call do_cmd,regen_makefile)\n\n"% {
19811981
'makefile_name': makefile_name,
1982-
'deps': ' '.join(map(SourceifyAndQuoteSpaces, build_files)),
1982+
'deps': ' '.join(SourceifyAndQuoteSpaces(bf) forbfinbuild_files),
19831983
'cmd': gyp.common.EncodePOSIXShellList(
19841984
[gyp_binary, '-fmake'] +
19851985
gyp.RegenerateFlags(options) +

‎gyp/pylib/gyp/generator/msvs.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name):
26912691

26922692
platform_name=None
26932693
msvs_windows_target_platform_version=None
2694-
forconfigurationinspec['configurations'].itervalues():
2694+
forconfigurationinspec['configurations'].values():
26952695
platform_name=platform_nameor_ConfigPlatform(configuration)
26962696
msvs_windows_target_platform_version= \
26972697
msvs_windows_target_platform_versionor \
@@ -3252,7 +3252,7 @@ def _GetMSBuildProjectReferences(project):
32523252
['Project', guid],
32533253
['ReferenceOutputAssembly', 'false']
32543254
]
3255-
forconfigindependency.spec.get('configurations', {}).itervalues():
3255+
forconfigindependency.spec.get('configurations', {}).values():
32563256
ifconfig.get('msvs_use_library_dependency_inputs', 0):
32573257
project_ref.append(['UseLibraryDependencyInputs', 'true'])
32583258
break
@@ -3321,7 +3321,7 @@ def _GenerateMSBuildProject(project, options, version, generator_flags):
33213321
extension_to_rule_name, _GetUniquePlatforms(spec))
33223322
missing_sources=_VerifySourcesExist(sources, project_dir)
33233323

3324-
forconfigurationinconfigurations.itervalues():
3324+
forconfigurationinconfigurations.values():
33253325
_FinalizeMSBuildSettings(spec, configuration)
33263326

33273327
# Add attributes to root element

‎gyp/pylib/gyp/input.py‎

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44

55
from __future__ importprint_function
66

7-
fromcompiler.astimportConst
8-
fromcompiler.astimportDict
9-
fromcompiler.astimportDiscard
10-
fromcompiler.astimportList
11-
fromcompiler.astimportModule
12-
fromcompiler.astimportNode
13-
fromcompiler.astimportStmt
14-
importcompiler
7+
importast
8+
159
importgyp.common
1610
importgyp.simple_copy
1711
importmultiprocessing
@@ -184,43 +178,39 @@ def CheckedEval(file_contents):
184178
Note that this is slower than eval() is.
185179
"""
186180

187-
ast=compiler.parse(file_contents)
188-
assertisinstance(ast, Module)
189-
c1=ast.getChildren()
190-
assertc1[0] isNone
191-
assertisinstance(c1[1], Stmt)
192-
c2=c1[1].getChildren()
193-
assertisinstance(c2[0], Discard)
194-
c3=c2[0].getChildren()
195-
assertlen(c3) ==1
196-
returnCheckNode(c3[0], [])
181+
syntax_tree=ast.parse(file_contents)
182+
assertisinstance(syntax_tree, ast.Module)
183+
c1=syntax_tree.body
184+
assertlen(c1) ==1
185+
c2=c1[0]
186+
assertisinstance(c2, ast.Expr)
187+
returnCheckNode(c2.value, [])
197188

198189

199190
defCheckNode(node, keypath):
200-
ifisinstance(node, Dict):
191+
ifisinstance(node, ast.Dict):
201192
c=node.getChildren()
202193
dict= {}
203-
forninrange(0, len(c), 2):
204-
assertisinstance(c[n], Const)
205-
key=c[n].getChildren()[0]
194+
forkey, valueinzip(node.keys, node.values):
195+
assertisinstance(key, ast.Str)
196+
key=key.s
206197
ifkeyindict:
207198
raiseGypError("Key '"+key+"' repeated at level "+
208199
repr(len(keypath) +1) +" with key path '"+
209200
'.'.join(keypath) +"'")
210201
kp=list(keypath) # Make a copy of the list for descending this node.
211202
kp.append(key)
212-
dict[key] =CheckNode(c[n+1], kp)
203+
dict[key] =CheckNode(value, kp)
213204
returndict
214-
elifisinstance(node, List):
215-
c=node.getChildren()
205+
elifisinstance(node, ast.List):
216206
children= []
217-
forindex, childinenumerate(c):
207+
forindex, childinenumerate(node.elts):
218208
kp=list(keypath) # Copy list.
219209
kp.append(repr(index))
220210
children.append(CheckNode(child, kp))
221211
returnchildren
222-
elifisinstance(node, Const):
223-
returnnode.getChildren()[0]
212+
elifisinstance(node, ast.Str):
213+
returnnode.s
224214
else:
225215
raiseTypeError("Unknown AST node at key path '"+'.'.join(keypath) +
226216
"': "+repr(node))
@@ -954,8 +944,12 @@ def ExpandVariables(input, phase, variables, build_file):
954944
else:
955945
replacement=variables[contents]
956946

947+
ifisinstance(replacement, bytes) andnotisinstance(replacement, str):
948+
replacement=replacement.decode("utf-8") # done on Python 3 only
957949
iftype(replacement) islist:
958950
foriteminreplacement:
951+
ifisinstance(item, bytes) andnotisinstance(item, str):
952+
item=item.decode("utf-8") # done on Python 3 only
959953
ifnotcontents[-1] =='/'andtype(item) notin (str, int):
960954
raiseGypError('Variable '+contents+
961955
' must expand to a string or list of strings; '+
@@ -1847,7 +1841,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18471841
# Create a DependencyGraphNode for each gyp file containing a target. Put
18481842
# it into a dict for easy access.
18491843
dependency_nodes= {}
1850-
fortargetintargets.iterkeys():
1844+
fortargetintargets:
18511845
build_file=gyp.common.BuildFile(target)
18521846
ifnotbuild_fileindependency_nodes:
18531847
dependency_nodes[build_file] =DependencyGraphNode(build_file)
@@ -1878,7 +1872,7 @@ def VerifyNoGYPFileCircularDependencies(targets):
18781872

18791873
# Files that have no dependencies are treated as dependent on root_node.
18801874
root_node=DependencyGraphNode(None)
1881-
forbuild_file_nodeindependency_nodes.itervalues():
1875+
forbuild_file_nodeindependency_nodes.values():
18821876
iflen(build_file_node.dependencies) ==0:
18831877
build_file_node.dependencies.append(root_node)
18841878
root_node.dependents.append(build_file_node)

‎gyp/pylib/gyp/xcode_emulation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ def _HasIOSTarget(targets):
16361636
def_AddIOSDeviceConfigurations(targets):
16371637
"""Clone all targets and append -iphoneos to the name. Configure these targets
16381638
to build for iOS devices and use correct architectures for those builds."""
1639-
fortarget_dictintargets.itervalues():
1639+
fortarget_dictintargets.values():
16401640
toolset=target_dict['toolset']
16411641
configs=target_dict['configurations']
16421642
forconfig_name, config_dictindict(configs).items():

‎gyp/pylib/gyp/xcode_ninja.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _TargetFromSpec(old_spec, params):
8585
"%s/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"%ninja_toplevel
8686

8787
if'configurations'inold_spec:
88-
forconfiginold_spec['configurations'].iterkeys():
88+
forconfiginold_spec['configurations']:
8989
old_xcode_settings= \
9090
old_spec['configurations'][config].get('xcode_settings', {})
9191
if'IPHONEOS_DEPLOYMENT_TARGET'inold_xcode_settings:

0 commit comments

Comments
 (0)