bug 797745, use l10n-base and relativesrcdir instead of config.mk for l10n-merge, r=ted

--HG--
extra : rebase_source : 0d280e5cfabe7efdbe112309da6ef87d3848c441
This commit is contained in:
Axel Hecht 2012-11-01 13:25:53 +01:00
parent 8ba6137c34
commit c315945bdd
4 changed files with 101 additions and 18 deletions

View File

@ -77,6 +77,9 @@ class JarMaker(object):
self.topsourcedir = None
self.sourcedirs = []
self.localedirs = None
self.l10nbase = None
self.l10nmerge = None
self.relativesrcdir = None
def getCommandLineParser(self):
'''Get a optparse.OptionParser for jarmaker.
@ -105,6 +108,12 @@ 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="store",
help="base directory to be used for localization (requires relativesrcdir)")
p.add_option('--locale-mergedir', type="string", action="store",
help="base directory to be used for l10n-merge (requires l10n-base and relativesrcdir)")
p.add_option('--relativesrcdir', type="string",
help="relativesrcdir to be used for localization")
p.add_option('-j', type="string",
help="jarfile directory")
return p
@ -170,7 +179,7 @@ class JarMaker(object):
mf.close()
finally:
lock = None
def makeJar(self, infile, jardir):
'''makeJar is the main entry point to JarMaker.
@ -183,6 +192,8 @@ class JarMaker(object):
self.sourcedirs = [_normpath(p) for p in self.sourcedirs]
if self.localedirs:
self.localedirs = [_normpath(p) for p in self.localedirs]
elif self.relativesrcdir:
self.localedirs = self.generateLocaleDirs(self.relativesrcdir)
if isinstance(infile, basestring):
logging.info("processing " + infile)
self.sourcedirs.append(_normpath(os.path.dirname(infile)))
@ -205,6 +216,23 @@ class JarMaker(object):
pass
return
def generateLocaleDirs(self, relativesrcdir):
if os.path.basename(relativesrcdir) == 'locales':
# strip locales
l10nrelsrcdir = os.path.dirname(relativesrcdir)
else:
l10nrelsrcdir = relativesrcdir
locdirs = []
# generate locales dirs, merge, l10nbase, en-US
if self.l10nmerge:
locdirs.append(os.path.join(self.l10nmerge, l10nrelsrcdir))
if self.l10nbase:
locdirs.append(os.path.join(self.l10nbase, l10nrelsrcdir))
if self.l10nmerge or not self.l10nbase:
# add en-US if we merge, or if it's not l10n
locdirs.append(os.path.join(self.topsourcedir, relativesrcdir, 'en-US'))
return locdirs
def processJarSection(self, jarfile, lines, jardir):
'''Internal method called by makeJar to actually process a section
of a jar.mn file.
@ -323,7 +351,7 @@ class JarMaker(object):
outf.write(inf.read())
outf.close()
inf.close()
class OutputHelper_jar(object):
'''Provide getDestModTime and getOutput for a given jarfile.
@ -402,6 +430,16 @@ def main():
if options.bothManifests:
jm.useChromeManifest = True
jm.useJarfileManifest = True
if options.l10n_base:
if not options.relativesrcdir:
p.error('relativesrcdir required when using l10n-base')
if options.l10n_src:
p.error('both l10n-src and l10n-base are not supported')
jm.l10nbase = options.l10n_base
jm.relativesrcdir = options.relativesrcdir
jm.l10nmerge = options.locale_mergedir
elif options.locale_mergedir:
p.error('l10n-base required when using locale-mergedir')
jm.localedirs = options.l10n_src
noise = logging.INFO
if options.verbose is not None:

View File

@ -703,17 +703,21 @@ ifdef relativesrcdir
LOCALE_SRCDIR = $(call EXPAND_LOCALE_SRCDIR,$(relativesrcdir))
endif
ifdef LOCALE_SRCDIR
# if LOCALE_MERGEDIR is set, use mergedir first, then the localization,
# and finally en-US
ifdef relativesrcdir
MAKE_JARS_FLAGS += --relativesrcdir=$(relativesrcdir)
ifneq (en-US,$(AB_CD))
ifdef LOCALE_MERGEDIR
MAKE_JARS_FLAGS += -c $(LOCALE_MERGEDIR)/$(subst /locales,,$(relativesrcdir))
MAKE_JARS_FLAGS += --locale-mergedir=$(LOCALE_MERGEDIR)
endif
ifdef IS_LANGUAGE_REPACK
MAKE_JARS_FLAGS += --l10n-base=$(L10NBASEDIR)
endif
else
MAKE_JARS_FLAGS += -c $(LOCALE_SRCDIR)
ifdef LOCALE_MERGEDIR
MAKE_JARS_FLAGS += -c $(topsrcdir)/$(relativesrcdir)/en-US
endif
endif
endif # en-US
else
MAKE_JARS_FLAGS += -c $(LOCALE_SRCDIR)
endif # ! relativesrcdir
ifdef LOCALE_MERGEDIR
MERGE_FILE = $(firstword \

View File

@ -4,6 +4,7 @@ import os, sys, os.path, time, inspect
from filecmp import dircmp
from tempfile import mkdtemp
from shutil import rmtree, copy2
from StringIO import StringIO
from zipfile import ZipFile
import mozunit
from JarMaker import JarMaker
@ -240,5 +241,41 @@ class TestJarMaker(unittest.TestCase):
"%s is not a symlink to %s" % (destfoo, srcbar))
class Test_relativesrcdir(unittest.TestCase):
def setUp(self):
self.jm = JarMaker()
self.jm.topsourcedir = '/TOPSOURCEDIR'
self.jm.relativesrcdir = 'browser/locales'
self.fake_empty_file = StringIO()
self.fake_empty_file.name = 'fake_empty_file'
def tearDown(self):
del self.jm
del self.fake_empty_file
def test_en_US(self):
jm = self.jm
jm.makeJar(self.fake_empty_file, '/NO_OUTPUT_REQUIRED')
self.assertEquals(jm.localedirs,
[
os.path.join(os.path.abspath('/TOPSOURCEDIR'),
'browser/locales', 'en-US')
])
def test_l10n_no_merge(self):
jm = self.jm
jm.l10nbase = '/L10N_BASE'
jm.makeJar(self.fake_empty_file, '/NO_OUTPUT_REQUIRED')
self.assertEquals(jm.localedirs, [os.path.join('/L10N_BASE', 'browser')])
def test_l10n_merge(self):
jm = self.jm
jm.l10nbase = '/L10N_BASE'
jm.l10nmerge = '/L10N_MERGE'
jm.makeJar(self.fake_empty_file, '/NO_OUTPUT_REQUIRED')
self.assertEquals(jm.localedirs,
[os.path.join('/L10N_MERGE', 'browser'),
os.path.join('/L10N_BASE', 'browser'),
os.path.join(os.path.abspath('/TOPSOURCEDIR'),
'browser/locales', 'en-US')
])
if __name__ == '__main__':
mozunit.main()

View File

@ -703,17 +703,21 @@ ifdef relativesrcdir
LOCALE_SRCDIR = $(call EXPAND_LOCALE_SRCDIR,$(relativesrcdir))
endif
ifdef LOCALE_SRCDIR
# if LOCALE_MERGEDIR is set, use mergedir first, then the localization,
# and finally en-US
ifdef relativesrcdir
MAKE_JARS_FLAGS += --relativesrcdir=$(relativesrcdir)
ifneq (en-US,$(AB_CD))
ifdef LOCALE_MERGEDIR
MAKE_JARS_FLAGS += -c $(LOCALE_MERGEDIR)/$(subst /locales,,$(relativesrcdir))
MAKE_JARS_FLAGS += --locale-mergedir=$(LOCALE_MERGEDIR)
endif
ifdef IS_LANGUAGE_REPACK
MAKE_JARS_FLAGS += --l10n-base=$(L10NBASEDIR)
endif
else
MAKE_JARS_FLAGS += -c $(LOCALE_SRCDIR)
ifdef LOCALE_MERGEDIR
MAKE_JARS_FLAGS += -c $(topsrcdir)/$(relativesrcdir)/en-US
endif
endif
endif # en-US
else
MAKE_JARS_FLAGS += -c $(LOCALE_SRCDIR)
endif # ! relativesrcdir
ifdef LOCALE_MERGEDIR
MERGE_FILE = $(firstword \