зеркало из https://github.com/mozilla/gecko-dev.git
Bug 797745 - Multiple jar manifests in one run is not used, remove that. Also remove old perl options and un-used options of the perl version. r=ted
This commit is contained in:
Родитель
6a13d90e9a
Коммит
9dda636bd2
|
@ -74,6 +74,9 @@ class JarMaker(object):
|
|||
self.useJarfileManifest = useJarfileManifest
|
||||
self.useChromeManifest = useChromeManifest
|
||||
self.pp = Preprocessor()
|
||||
self.topsourcedir = None
|
||||
self.sourcedirs = []
|
||||
self.localedirs = None
|
||||
|
||||
def getCommandLineParser(self):
|
||||
'''Get a optparse.OptionParser for jarmaker.
|
||||
|
@ -102,22 +105,8 @@ class JarMaker(object):
|
|||
help="top source directory")
|
||||
p.add_option('-c', '--l10n-src', type="string", action="append",
|
||||
help="localization directory")
|
||||
p.add_option('--l10n-base', type="string", action="append", default=[],
|
||||
help="base directory to be used for localization (multiple)")
|
||||
p.add_option('-j', type="string",
|
||||
help="jarfile directory")
|
||||
# backwards compat, not needed
|
||||
p.add_option('-a', action="store_false", default=True,
|
||||
help="NOT SUPPORTED, turn auto-registration of chrome off (installed-chrome.txt)")
|
||||
p.add_option('-d', type="string",
|
||||
help="UNUSED, chrome directory")
|
||||
p.add_option('-o', help="cross compile for auto-registration, ignored")
|
||||
p.add_option('-l', action="store_true",
|
||||
help="ignored (used to switch off locks)")
|
||||
p.add_option('-x', action="store_true",
|
||||
help="force Unix")
|
||||
p.add_option('-z', help="backwards compat, ignored")
|
||||
p.add_option('-p', help="backwards compat, ignored")
|
||||
return p
|
||||
|
||||
def processIncludes(self, includes):
|
||||
|
@ -182,16 +171,21 @@ class JarMaker(object):
|
|||
finally:
|
||||
lock = None
|
||||
|
||||
def makeJar(self, infile=None,
|
||||
jardir='',
|
||||
sourcedirs=[], topsourcedir='', localedirs=None):
|
||||
def makeJar(self, infile, jardir):
|
||||
'''makeJar is the main entry point to JarMaker.
|
||||
|
||||
It takes the input file, the output directory, the source dirs and the
|
||||
top source dir as argument, and optionally the l10n dirs.
|
||||
'''
|
||||
# making paths absolute, guess srcdir if file and add to sourcedirs
|
||||
_normpath = lambda p: os.path.normpath(os.path.abspath(p))
|
||||
self.topsourcedir = _normpath(self.topsourcedir)
|
||||
self.sourcedirs = [_normpath(p) for p in self.sourcedirs]
|
||||
if self.localedirs:
|
||||
self.localedirs = [_normpath(p) for p in self.localedirs]
|
||||
if isinstance(infile, basestring):
|
||||
logging.info("processing " + infile)
|
||||
self.sourcedirs.append(_normpath(os.path.dirname(infile)))
|
||||
pp = self.pp.clone()
|
||||
pp.out = StringIO()
|
||||
pp.do_include(infile)
|
||||
|
@ -205,68 +199,13 @@ class JarMaker(object):
|
|||
if m.group('jarfile') is None:
|
||||
# comment
|
||||
continue
|
||||
self.processJarSection(m.group('jarfile'), lines,
|
||||
jardir, sourcedirs, topsourcedir,
|
||||
localedirs)
|
||||
self.processJarSection(m.group('jarfile'), lines, jardir)
|
||||
except StopIteration:
|
||||
# we read the file
|
||||
pass
|
||||
return
|
||||
|
||||
def makeJars(self, infiles, l10nbases,
|
||||
jardir='',
|
||||
sourcedirs=[], topsourcedir='', localedirs=None):
|
||||
'''makeJars is the second main entry point to JarMaker.
|
||||
|
||||
It takes an iterable sequence of input file names, the l10nbases,
|
||||
the output directory, the source dirs and the
|
||||
top source dir as argument, and optionally the l10n dirs.
|
||||
|
||||
It iterates over all inputs, guesses srcdir and l10ndir from the
|
||||
path and topsourcedir and calls into makeJar.
|
||||
|
||||
The l10ndirs are created by guessing the relativesrcdir, and resolving
|
||||
that against the l10nbases. l10nbases can either be path strings, or
|
||||
callables. In the latter case, that will be called with the
|
||||
relativesrcdir as argument, and is expected to return a path string.
|
||||
This logic is disabled if the jar.mn path is not inside the topsrcdir.
|
||||
'''
|
||||
topsourcedir = os.path.normpath(os.path.abspath(topsourcedir))
|
||||
def resolveL10nBase(relpath):
|
||||
def _resolve(base):
|
||||
if isinstance(base, basestring):
|
||||
return os.path.join(base, relpath)
|
||||
if callable(base):
|
||||
return base(relpath)
|
||||
return base
|
||||
return _resolve
|
||||
for infile in infiles:
|
||||
srcdir = os.path.normpath(os.path.abspath(os.path.dirname(infile)))
|
||||
l10ndir = srcdir
|
||||
if os.path.basename(srcdir) == 'locales':
|
||||
l10ndir = os.path.dirname(l10ndir)
|
||||
|
||||
l10ndirs = None
|
||||
# srcdir may not be a child of topsourcedir, in which case
|
||||
# we assume that the caller passed in suitable sourcedirs,
|
||||
# and just skip passing in localedirs
|
||||
if srcdir.startswith(topsourcedir):
|
||||
rell10ndir = l10ndir[len(topsourcedir):].lstrip(os.sep)
|
||||
|
||||
l10ndirs = map(resolveL10nBase(rell10ndir), l10nbases)
|
||||
if localedirs is not None:
|
||||
l10ndirs += [os.path.normpath(os.path.abspath(s))
|
||||
for s in localedirs]
|
||||
srcdirs = [os.path.normpath(os.path.abspath(s))
|
||||
for s in sourcedirs] + [srcdir]
|
||||
self.makeJar(infile=infile,
|
||||
sourcedirs=srcdirs, topsourcedir=topsourcedir,
|
||||
localedirs=l10ndirs,
|
||||
jardir=jardir)
|
||||
|
||||
|
||||
def processJarSection(self, jarfile, lines,
|
||||
jardir, sourcedirs, topsourcedir, localedirs):
|
||||
def processJarSection(self, jarfile, lines, jardir):
|
||||
'''Internal method called by makeJar to actually process a section
|
||||
of a jar.mn file.
|
||||
|
||||
|
@ -328,30 +267,27 @@ class JarMaker(object):
|
|||
jf.close()
|
||||
lines.pushback(l)
|
||||
return
|
||||
self._processEntryLine(m, sourcedirs, topsourcedir, localedirs,
|
||||
outHelper, jf)
|
||||
self._processEntryLine(m, outHelper, jf)
|
||||
finally:
|
||||
if jf is not None:
|
||||
jf.close()
|
||||
return
|
||||
|
||||
def _processEntryLine(self, m,
|
||||
sourcedirs, topsourcedir, localedirs,
|
||||
outHelper, jf):
|
||||
def _processEntryLine(self, m, outHelper, jf):
|
||||
out = m.group('output')
|
||||
src = m.group('source') or os.path.basename(out)
|
||||
# pick the right sourcedir -- l10n, topsrc or src
|
||||
if m.group('locale'):
|
||||
src_base = localedirs
|
||||
src_base = self.localedirs
|
||||
elif src.startswith('/'):
|
||||
# path/in/jar/file_name.xul (/path/in/sourcetree/file_name.xul)
|
||||
# refers to a path relative to topsourcedir, use that as base
|
||||
# and strip the leading '/'
|
||||
src_base = [topsourcedir]
|
||||
src_base = [self.topsourcedir]
|
||||
src = src[1:]
|
||||
else:
|
||||
# use srcdirs and the objdir (current working dir) for relative paths
|
||||
src_base = sourcedirs + [os.getcwd()]
|
||||
src_base = self.sourcedirs + [os.getcwd()]
|
||||
# check if the source file exists
|
||||
realsrc = None
|
||||
for _srcdir in src_base:
|
||||
|
@ -458,12 +394,15 @@ def main():
|
|||
(options, args) = p.parse_args()
|
||||
jm.processIncludes(options.I)
|
||||
jm.outputFormat = options.f
|
||||
jm.sourcedirs = options.s
|
||||
jm.topsourcedir = options.t
|
||||
if options.e:
|
||||
jm.useChromeManifest = True
|
||||
jm.useJarfileManifest = False
|
||||
if options.bothManifests:
|
||||
jm.useChromeManifest = True
|
||||
jm.useJarfileManifest = True
|
||||
jm.localedirs = options.l10n_src
|
||||
noise = logging.INFO
|
||||
if options.verbose is not None:
|
||||
noise = (options.verbose and logging.DEBUG) or logging.WARN
|
||||
|
@ -475,15 +414,10 @@ def main():
|
|||
topsrc = options.t
|
||||
topsrc = os.path.normpath(os.path.abspath(topsrc))
|
||||
if not args:
|
||||
jm.makeJar(infile=sys.stdin,
|
||||
sourcedirs=options.s, topsourcedir=topsrc,
|
||||
localedirs=options.l10n_src,
|
||||
jardir=options.j)
|
||||
infile = sys.stdin
|
||||
else:
|
||||
jm.makeJars(args, options.l10n_base,
|
||||
jardir=options.j,
|
||||
sourcedirs=options.s, topsourcedir=topsrc,
|
||||
localedirs=options.l10n_src)
|
||||
infile, = args
|
||||
jm.makeJar(infile, options.j)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
@ -137,7 +137,7 @@ class TestJarMaker(unittest.TestCase):
|
|||
"""
|
||||
Unit tests for JarMaker.py
|
||||
"""
|
||||
debug = True # set to True to debug failing tests on disk
|
||||
debug = False # set to True to debug failing tests on disk
|
||||
def setUp(self):
|
||||
self.tmpdir = mkdtemp()
|
||||
self.srcdir = os.path.join(self.tmpdir, 'src')
|
||||
|
@ -152,15 +152,19 @@ class TestJarMaker(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
if self.debug:
|
||||
print self.tmpdir
|
||||
else:
|
||||
elif sys.platform != "win32":
|
||||
# can't clean up on windows
|
||||
rmtree(self.tmpdir)
|
||||
|
||||
def _jar_and_compare(self, *args, **kwargs):
|
||||
def _jar_and_compare(self, infile, **kwargs):
|
||||
jm = JarMaker(outputFormat='jar')
|
||||
kwargs['jardir'] = os.path.join(self.builddir, 'chrome')
|
||||
jardir = os.path.join(self.builddir, 'chrome')
|
||||
if 'topsourcedir' not in kwargs:
|
||||
kwargs['topsourcedir'] = self.srcdir
|
||||
jm.makeJars(*args, **kwargs)
|
||||
for attr in ('topsourcedir', 'sourcedirs'):
|
||||
if attr in kwargs:
|
||||
setattr(jm, attr, kwargs[attr])
|
||||
jm.makeJar(infile, jardir)
|
||||
cwd = os.getcwd()
|
||||
os.chdir(self.builddir)
|
||||
try:
|
||||
|
@ -214,8 +218,7 @@ class TestJarMaker(unittest.TestCase):
|
|||
'''Test a simple jar.mn'''
|
||||
self._create_simple_setup()
|
||||
# call JarMaker
|
||||
rv = self._jar_and_compare((os.path.join(self.srcdir,'jar.mn'),),
|
||||
tuple(),
|
||||
rv = self._jar_and_compare(os.path.join(self.srcdir,'jar.mn'),
|
||||
sourcedirs = [self.srcdir])
|
||||
self.assertTrue(not rv, rv)
|
||||
|
||||
|
@ -226,56 +229,16 @@ class TestJarMaker(unittest.TestCase):
|
|||
|
||||
self._create_simple_setup()
|
||||
jm = JarMaker(outputFormat='symlink')
|
||||
kwargs = {
|
||||
'sourcedirs': [self.srcdir],
|
||||
'topsourcedir': self.srcdir,
|
||||
'jardir': os.path.join(self.builddir, 'chrome'),
|
||||
}
|
||||
jm.makeJars((os.path.join(self.srcdir,'jar.mn'),), tuple(), **kwargs)
|
||||
jm.sourcedirs = [self.srcdir]
|
||||
jm.topsourcedir = self.srcdir
|
||||
jardir = os.path.join(self.builddir, 'chrome')
|
||||
jm.makeJar(os.path.join(self.srcdir,'jar.mn'), jardir)
|
||||
# All we do is check that srcdir/bar points to builddir/chrome/test/dir/foo
|
||||
srcbar = os.path.join(self.srcdir, 'bar')
|
||||
destfoo = os.path.join(self.builddir, 'chrome', 'test', 'dir', 'foo')
|
||||
self.assertTrue(is_symlink_to(destfoo, srcbar),
|
||||
"%s is not a symlink to %s" % (destfoo, srcbar))
|
||||
|
||||
def test_k_multi_relative_jar(self):
|
||||
'''Test the API for multiple l10n jars, with different relative paths'''
|
||||
# create app src content
|
||||
def _mangle(relpath):
|
||||
'method we use to map relpath to srcpaths'
|
||||
return os.path.join(self.srcdir, 'other-' + relpath)
|
||||
jars = []
|
||||
for relpath in ('foo', 'bar'):
|
||||
ldir = os.path.join(self.srcdir, relpath, 'locales')
|
||||
os.makedirs(ldir)
|
||||
jp = os.path.join(ldir, 'jar.mn')
|
||||
jars.append(jp)
|
||||
open(jp, 'w').write('''ab-CD.jar:
|
||||
% locale app ab-CD %app
|
||||
app/''' + relpath + ' (%' + relpath + ''')
|
||||
''')
|
||||
ldir = _mangle(relpath)
|
||||
os.mkdir(ldir)
|
||||
open(os.path.join(ldir, relpath), 'w').write(relpath+" content\n")
|
||||
# create reference
|
||||
mf = open(os.path.join(self.refdir, 'chrome.manifest'), 'w')
|
||||
mf.write('manifest chrome/ab-CD.manifest\n')
|
||||
mf.close()
|
||||
|
||||
chrome_ref = os.path.join(self.refdir, 'chrome')
|
||||
os.mkdir(chrome_ref)
|
||||
mf = open(os.path.join(chrome_ref, 'ab-CD.manifest'), 'wb')
|
||||
mf.write('locale app ab-CD jar:ab-CD.jar!/app\n')
|
||||
mf.close()
|
||||
ldir = os.path.join(chrome_ref, 'ab-CD.jar', 'app')
|
||||
os.makedirs(ldir)
|
||||
for relpath in ('foo', 'bar'):
|
||||
open(os.path.join(ldir, relpath), 'w').write(relpath+" content\n")
|
||||
# call JarMaker
|
||||
difference = self._jar_and_compare(jars,
|
||||
(_mangle,),
|
||||
sourcedirs = [])
|
||||
self.assertTrue(not difference, difference)
|
||||
|
||||
if __name__ == '__main__':
|
||||
mozunit.main()
|
||||
|
|
Загрузка…
Ссылка в новой задаче