Skip to content

Commit

Permalink
Bug 812179 - Removed hacks for Python < 2.6 from config/ [r=ted]
Browse files Browse the repository at this point in the history
  • Loading branch information
yati-sagade committed Feb 27, 2013
1 parent 72663e9 commit 999eeb2
Show file tree
Hide file tree
Showing 32 changed files with 309 additions and 289 deletions.
3 changes: 2 additions & 1 deletion config/Expression.py
Expand Up @@ -218,7 +218,8 @@ def __init__(self, expression):
self.offset = expression.offset
self.content = expression.content[:3]
def __str__(self):
return 'Unexpected content at offset %i, "%s"'%(self.offset, self.content)
return 'Unexpected content at offset {0}, "{1}"'.format(self.offset,
self.content)

class Context(dict):
"""
Expand Down
23 changes: 12 additions & 11 deletions config/JarMaker.py
Expand Up @@ -7,7 +7,6 @@
See the documentation for jar.mn on MDC for further details on the format.
'''

import sys
import os
import os.path
Expand Down Expand Up @@ -152,11 +151,12 @@ def finalizeJar(self, jarPath, chromebasepath, register,
'..', 'chrome.manifest')

if self.useJarfileManifest:
self.updateManifest(jarPath + '.manifest', chromebasepath % '',
self.updateManifest(jarPath + '.manifest', chromebasepath.format(''),
register)
addEntriesToListFile(chromeManifest, ['manifest chrome/%s.manifest' % (os.path.basename(jarPath),)])
addEntriesToListFile(chromeManifest, ['manifest chrome/{0}.manifest'
.format(os.path.basename(jarPath))])
if self.useChromeManifest:
self.updateManifest(chromeManifest, chromebasepath % 'chrome/',
self.updateManifest(chromeManifest, chromebasepath.format('chrome/'),
register)

# If requested, add a root chrome manifest entry (assumed to be in the parent directory
Expand Down Expand Up @@ -258,9 +258,9 @@ def processJarSection(self, jarfile, lines, jardir):
'''

# chromebasepath is used for chrome registration manifests
# %s is getting replaced with chrome/ for chrome.manifest, and with
# {0} is getting replaced with chrome/ for chrome.manifest, and with
# an empty string for jarfile.manifest
chromebasepath = '%s' + os.path.basename(jarfile)
chromebasepath = '{0}' + os.path.basename(jarfile)
if self.outputFormat == 'jar':
chromebasepath = 'jar:' + chromebasepath + '.jar!'
chromebasepath += '/'
Expand All @@ -272,7 +272,7 @@ def processJarSection(self, jarfile, lines, jardir):
jarfilepath = jarfile + '.jar'
try:
os.makedirs(os.path.dirname(jarfilepath))
except OSError, error:
except OSError as error:
if error.errno != errno.EEXIST:
raise
jf = ZipFile(jarfilepath, 'a', lock = True)
Expand Down Expand Up @@ -345,7 +345,8 @@ def _processEntryLine(self, m, outHelper, jf):
if realsrc is None:
if jf is not None:
jf.close()
raise RuntimeError('File "%s" not found in %s' % (src, ', '.join(src_base)))
raise RuntimeError('File "{0}" not found in {1}'
.format(src, ', '.join(src_base)))
if m.group('optPreprocess'):
outf = outHelper.getOutput(out)
inf = open(realsrc)
Expand Down Expand Up @@ -401,7 +402,7 @@ def getOutput(self, name):
# remove previous link or file
try:
os.remove(out)
except OSError, e:
except OSError as e:
if e.errno != errno.ENOENT:
raise
return open(out, 'wb')
Expand All @@ -411,7 +412,7 @@ def ensureDirFor(self, name):
if not os.path.isdir(outdir):
try:
os.makedirs(outdir)
except OSError, error:
except OSError as error:
if error.errno != errno.EEXIST:
raise
return out
Expand All @@ -425,7 +426,7 @@ def symlink(self, src, dest):
# remove previous link or file
try:
os.remove(out)
except OSError, e:
except OSError as e:
if e.errno != errno.ENOENT:
raise
if sys.platform != "win32":
Expand Down
14 changes: 8 additions & 6 deletions config/Preprocessor.py
Expand Up @@ -77,9 +77,9 @@ def __init__(self):

def warnUnused(self, file):
if self.actionLevel == 0:
sys.stderr.write('%s: WARNING: no preprocessor directives found\n' % file)
sys.stderr.write('{0}: WARNING: no preprocessor directives found\n'.format(file))
elif self.actionLevel == 1:
sys.stderr.write('%s: WARNING: no useful preprocessor directives found\n' % file)
sys.stderr.write('{0}: WARNING: no useful preprocessor directives found\n'.format(file))
pass

def setLineEndings(self, aLE):
Expand All @@ -96,7 +96,9 @@ def setMarker(self, aMarker):
"""
self.marker = aMarker
if aMarker:
self.instruction = re.compile('%s(?P<cmd>[a-z]+)(?:\s(?P<args>.*))?$'%aMarker, re.U)
self.instruction = re.compile('{0}(?P<cmd>[a-z]+)(?:\s(?P<args>.*))?$'
.format(aMarker),
re.U)
self.comment = re.compile(aMarker, re.U)
else:
class NoMatch(object):
Expand Down Expand Up @@ -129,9 +131,9 @@ def write(self, aLine):
self.writtenLines += 1
ln = self.context['LINE']
if self.writtenLines != ln:
self.out.write('//@line %(line)d "%(file)s"%(le)s'%{'line': ln,
'file': self.context['FILE'],
'le': self.LE})
self.out.write('//@line {line} "{file}"{le}'.format(line=ln,
file=self.context['FILE'],
le=self.LE))
self.writtenLines = ln
filteredLine = self.applyFilters(aLine)
if filteredLine != aLine:
Expand Down
8 changes: 5 additions & 3 deletions config/buildlist.py
Expand Up @@ -7,6 +7,7 @@
Usage: buildlist.py <filename> <entry> [<entry> ...]
'''
from __future__ import print_function

import sys
import os
Expand All @@ -20,21 +21,22 @@ def addEntriesToListFile(listFile, entries):
try:
if os.path.exists(listFile):
f = open(listFile)
existing = set([x.strip() for x in f.readlines()])
existing = set(x.strip() for x in f.readlines())
f.close()
else:
existing = set()
f = open(listFile, 'a')
for e in entries:
if e not in existing:
f.write("%s\n" % e)
f.write("{0}\n".format(e))
existing.add(e)
f.close()
finally:
lock = None

if __name__ == '__main__':
if len(sys.argv) < 3:
print >>sys.stderr, "Usage: buildlist.py <list file> <entry> [<entry> ...]"
print("Usage: buildlist.py <list file> <entry> [<entry> ...]",
file=sys.stderr)
sys.exit(1)
addEntriesToListFile(sys.argv[1], sys.argv[2:])
23 changes: 16 additions & 7 deletions config/check_source_count.py
Expand Up @@ -9,7 +9,7 @@
# not, an error message is printed, quoting ERROR_LOCATION, which should
# probably be the filename and line number of the erroneous call to
# check_source_count.py.

from __future__ import print_function
import sys
import os
import re
Expand All @@ -32,17 +32,26 @@
details[f] = num

if count == expected_count:
print "TEST-PASS | check_source_count.py %s | %d" % (search_string, expected_count)
print("TEST-PASS | check_source_count.py {0} | {1}"
.format(search_string, expected_count))

else:
print "TEST-UNEXPECTED-FAIL | check_source_count.py %s | " % (search_string),
print("TEST-UNEXPECTED-FAIL | check_source_count.py {0} | "
.format(search_string),
end='')
if count < expected_count:
print "There are fewer occurrences of /%s/ than expected. This may mean that you have removed some, but forgotten to account for it %s." % (search_string, error_location)
print("There are fewer occurrences of /{0}/ than expected. "
"This may mean that you have removed some, but forgotten to "
"account for it {1}.".format(search_string, error_location))
else:
print "There are more occurrences of /%s/ than expected. We're trying to prevent an increase in the number of %s's, using %s if possible. If it in unavoidable, you should update the expected count %s." % (search_string, search_string, replacement, error_location)
print("There are more occurrences of /{0}/ than expected. We're trying "
"to prevent an increase in the number of {1}'s, using {2} if "
"possible. If it is unavoidable, you should update the expected "
"count {3}.".format(search_string, search_string, replacement,
error_location))

print "Expected: %d; found: %d" % (expected_count, count)
print("Expected: {0}; found: {1}".format(expected_count, count))
for k in sorted(details):
print "Found %d occurences in %s" % (details[k],k)
print("Found {0} occurences in {1}".format(details[k],k))
sys.exit(-1)

8 changes: 4 additions & 4 deletions config/expandlibs.py
Expand Up @@ -26,7 +26,6 @@
descriptor contains. And for each of these LIBS, also apply the same
rules.
'''
from __future__ import with_statement
import sys, os, errno
import expandlibs_config as conf

Expand All @@ -36,7 +35,7 @@ def ensureParentDir(file):
if dir and not os.path.exists(dir):
try:
os.makedirs(dir)
except OSError, error:
except OSError as error:
if error.errno != errno.EEXIST:
raise

Expand Down Expand Up @@ -90,7 +89,8 @@ def __init__(self, content=None):

def __str__(self):
'''Serializes the lib descriptor'''
return '\n'.join('%s = %s' % (k, ' '.join(self[k])) for k in self.KEYS if len(self[k]))
return '\n'.join('{0} = {1}'.format(k, ' '.join(self[k]))
for k in self.KEYS if len(self[k]))

class ExpandArgs(list):
def __init__(self, args):
Expand Down Expand Up @@ -135,4 +135,4 @@ def _expand_desc(self, arg):
return objs

if __name__ == '__main__':
print " ".join(ExpandArgs(sys.argv[1:]))
print(" ".join(ExpandArgs(sys.argv[1:])))
63 changes: 38 additions & 25 deletions config/expandlibs_exec.py
Expand Up @@ -20,10 +20,11 @@
relevant linker options to change the order in which the linker puts the
symbols appear in the resulting binary. Only works for ELF targets.
'''
from __future__ import with_statement
from __future__ import print_function
import sys
import os
from expandlibs import ExpandArgs, relativize, isObject, ensureParentDir, ExpandLibsDeps
from expandlibs import (ExpandArgs, relativize, isObject, ensureParentDir,
ExpandLibsDeps)
import expandlibs_config as conf
from optparse import OptionParser
import subprocess
Expand Down Expand Up @@ -92,10 +93,10 @@ def makelist(self):
if not len(objs): return
fd, tmp = tempfile.mkstemp(suffix=".list",dir=os.curdir)
if conf.EXPAND_LIBS_LIST_STYLE == "linkerscript":
content = ['INPUT("%s")\n' % obj for obj in objs]
content = ['INPUT("{0}")\n'.format(obj) for obj in objs]
ref = tmp
elif conf.EXPAND_LIBS_LIST_STYLE == "list":
content = ["%s\n" % obj for obj in objs]
content = ["{0}\n".format(obj) for obj in objs]
ref = "@" + tmp
else:
os.close(fd)
Expand Down Expand Up @@ -139,9 +140,13 @@ def _getFoldedSections(self):
def _getOrderedSections(self, ordered_symbols):
'''Given an ordered list of symbols, returns the corresponding list
of sections following the order.'''
if not conf.EXPAND_LIBS_ORDER_STYLE in ['linkerscript', 'section-ordering-file']:
raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)
finder = SectionFinder([arg for arg in self if isObject(arg) or os.path.splitext(arg)[1] == conf.LIB_SUFFIX])
if conf.EXPAND_LIBS_ORDER_STYLE not in ['linkerscript',
'section-ordering-file']:
raise Exception('EXPAND_LIBS_ORDER_STYLE "{0}" is not supported'
.format(conf.EXPAND_LIBS_ORDER_STYLE))
finder = SectionFinder([arg for arg in self
if isObject(arg) or
os.path.splitext(arg)[1] == conf.LIB_SUFFIX])
folded = self._getFoldedSections()
sections = set()
ordered_sections = []
Expand Down Expand Up @@ -182,32 +187,35 @@ def orderSymbols(self, order):
linked_sections = [s for s in linked_sections if s in split_sections]

if conf.EXPAND_LIBS_ORDER_STYLE == 'section-ordering-file':
option = '-Wl,--section-ordering-file,%s'
option = '-Wl,--section-ordering-file,{0}'
content = sections
for linked_section in linked_sections:
content.extend(split_sections[linked_section])
content.append('%s.*' % linked_section)
content.append('{0}.*'.format(linked_section))
content.append(linked_section)

elif conf.EXPAND_LIBS_ORDER_STYLE == 'linkerscript':
option = '-Wl,-T,%s'
option = '-Wl,-T,{0}'
section_insert_before = dict(SECTION_INSERT_BEFORE)
for linked_section in linked_sections:
content.append('SECTIONS {')
content.append(' %s : {' % linked_section)
content.extend(' *(%s)' % s for s in split_sections[linked_section])
content.append(' }')
content.append('}')
content.append('INSERT BEFORE %s' % section_insert_before[linked_section])
content.append('SECTIONS {{')
content.append(' {0} : {{'.format(linked_section))
content.extend(' *({0})'
.format(s for s in split_sections[linked_section]))
content.append(' }}')
content.append('}}')
content.append('INSERT BEFORE {0}'
.format(section_insert_before[linked_section]))
else:
raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)
raise Exception('EXPAND_LIBS_ORDER_STYLE "{0}" is not supported'
.format(conf.EXPAND_LIBS_ORDER_STYLE))

fd, tmp = tempfile.mkstemp(dir=os.curdir)
f = os.fdopen(fd, "w")
f.write('\n'.join(content)+'\n')
f.close()
self.tmp.append(tmp)
self.append(option % tmp)
self.append(option.format(tmp))

class SectionFinder(object):
'''Instances of this class allow to map symbol names to sections in
Expand All @@ -216,15 +224,17 @@ class SectionFinder(object):
def __init__(self, objs):
'''Creates an instance, given a list of object files.'''
if not conf.EXPAND_LIBS_ORDER_STYLE in ['linkerscript', 'section-ordering-file']:
raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)
raise Exception('EXPAND_LIBS_ORDER_STYLE "{0}" is not supported'
.format(conf.EXPAND_LIBS_ORDER_STYLE))
self.mapping = {}
for obj in objs:
if not isObject(obj) and os.path.splitext(obj)[1] != conf.LIB_SUFFIX:
raise Exception('%s is not an object nor a static library' % obj)
raise Exception('{0} is not an object nor a static library'
.format(obj))
for symbol, section in SectionFinder._getSymbols(obj):
sym = SectionFinder._normalize(symbol)
if sym in self.mapping:
if not section in self.mapping[sym]:
if section not in self.mapping[sym]:
self.mapping[sym].append(section)
else:
self.mapping[sym] = [section]
Expand Down Expand Up @@ -268,11 +278,11 @@ def _getSymbols(obj):
return syms

def print_command(out, args):
print >>out, "Executing: " + " ".join(args)
print("Executing: " + " ".join(args), file=out)
for tmp in [f for f in args.tmp if os.path.isfile(f)]:
print >>out, tmp + ":"
print(tmp + ":", file=out)
with open(tmp) as file:
print >>out, "".join([" " + l for l in file.readlines()])
print("".join([" " + l for l in file.readlines()]), file=out)
out.flush()

def main():
Expand Down Expand Up @@ -323,7 +333,10 @@ def main():
return
ensureParentDir(options.depend)
with open(options.depend, 'w') as depfile:
depfile.write("%s : %s\n" % (options.target, ' '.join(dep for dep in deps if os.path.isfile(dep) and dep != options.target)))
depfile.write("{0} : {1}\n"
.format(options.target, ' '.join(dep for dep in deps
if os.path.isfile(dep) and
dep != options.target)))


if __name__ == '__main__':
Expand Down

0 comments on commit 999eeb2

Please sign in to comment.