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
authorAxel Hecht <l10n@mozilla.com>
Sat, 13 Oct 2012 04:37:15 -0400
changeset 110266 0fc7b1fbc8af638ba51e1895d7d1b107d2e512a2
parent 110265 137d665dd6d98f89414cbb88095465b0748bd8d1
child 110267 eaffa9d2341ea5b92c68951d8cda4cb1004b0bbd
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersted
bugs797745
milestone19.0a1
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
config/JarMaker.py
config/tests/unit-JarMaker.py
--- a/config/JarMaker.py
+++ b/config/JarMaker.py
@@ -69,16 +69,19 @@ class JarMaker(object):
   entryline = re.compile(entryre + '(?P<output>[\w\d.\-\_\\\/\+\@]+)\s*(\((?P<locale>\%?)(?P<source>[\w\d.\-\_\\\/\@]+)\))?\s*$')
 
   def __init__(self, outputFormat = 'flat', useJarfileManifest = True,
                useChromeManifest = False):
     self.outputFormat = outputFormat
     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.
 
     This OptionParser has the options for jarmaker as well as
     the options for the inner PreProcessor.
     '''
     # HACK, we need to unescape the string variables we get,
@@ -97,32 +100,18 @@ class JarMaker(object):
                  dest="bothManifests",
                  help="create chrome.manifest and jarfile.manifest")
     p.add_option('-s', type="string", action="append", default=[],
                  help="source directory")
     p.add_option('-t', type="string",
                  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):
     '''Process given includes with the inner PreProcessor.
 
     Only use this for #defines, the includes shouldn't generate
     content.
     '''
@@ -177,101 +166,51 @@ class JarMaker(object):
           myregister[l] = None
         mf.seek(0)
       for k in myregister.iterkeys():
         mf.write(k + os.linesep)
       mf.close()
     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)
     lines = pushback_iter(pp.out.getvalue().splitlines())
     try:
       while True:
         l = lines.next()
         m = self.jarline.match(l)
         if not m:
           raise RuntimeError(l)
         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.
 
     jarfile is the basename of the jarfile or the directory name for 
     flat output, lines is a pushback_iterator of the lines of jar.mn,
     the remaining options are carried over from makeJar.
     '''
 
@@ -323,40 +262,37 @@ class JarMaker(object):
         m = self.entryline.match(l)
         if not m:
           # neither an entry line nor chrome reg, this jar section is done
           self.finalizeJar(jarfile, chromebasepath, register)
           if jf is not None:
             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:
         if os.path.isfile(os.path.join(_srcdir, src)):
           realsrc = os.path.join(_srcdir, src)
           break
       if realsrc is None:
         if jf is not None:
@@ -453,37 +389,35 @@ class JarMaker(object):
           raise WinError()
 
 def main():
   jm = JarMaker()
   p = jm.getCommandLineParser()
   (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
   if sys.version_info[:2] > (2,3):
     logging.basicConfig(format = "%(message)s")
   else:
     logging.basicConfig()
   logging.getLogger().setLevel(noise)
   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()
--- a/config/tests/unit-JarMaker.py
+++ b/config/tests/unit-JarMaker.py
@@ -132,40 +132,44 @@ class _TreeDiff(dircmp):
         if rv['funny']:
             chunks.append("%s don't compare" % ', '.join(rv['funny']))
         return '; '.join(chunks)
 
 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')
         os.mkdir(self.srcdir)
         self.builddir = os.path.join(self.tmpdir, 'build')
         os.mkdir(self.builddir)
         self.refdir = os.path.join(self.tmpdir, 'ref')
         os.mkdir(self.refdir)
         self.stagedir = os.path.join(self.tmpdir, 'stage')
         os.mkdir(self.stagedir)
 
     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:
             # expand build to stage
             for path, dirs, files in os.walk('.'):
                 stagedir = os.path.join(self.stagedir, path)
                 if not os.path.isdir(stagedir):
                     os.mkdir(stagedir)
@@ -209,73 +213,32 @@ class TestJarMaker(unittest.TestCase):
         refpath = os.path.join(self.refdir, 'chrome', 'test.jar', 'dir')
         os.makedirs(refpath)
         open(os.path.join(refpath, 'foo'), 'w').write('content\n')        
 
     def test_a_simple_jar(self):
         '''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)
 
     def test_a_simple_symlink(self):
         '''Test a simple jar.mn with a symlink'''
         if not symlinks_supported(self.srcdir):
             return
 
         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()