Bug 1128037 - Minimalist support for wildcards in jar manifests. r=gps

This commit is contained in:
Mike Hommey 2015-04-30 16:08:07 +09:00
Родитель a7c7f13a97
Коммит bfe476e5f9
3 изменённых файлов: 94 добавлений и 2 удалений

Просмотреть файл

@ -59,6 +59,15 @@ file from the alternate localization source tree
locale/path/localized.dtd (%localized/path/localized.dtd)
The source tree location can also use wildcards, in which case the path in
jar is expected to be a base directory. Paths before the wildcard are not
made part of the destination path::
path/in/jar/ (source/tree/location/*.xul)
The above will install all xul files under ``source/tree/location`` as
``path/in/jar/*.xul``.
Register Chrome
===============

Просмотреть файл

@ -24,6 +24,7 @@ from mozbuild.util import (
from mozbuild.preprocessor import Preprocessor
from mozbuild.action.buildlist import addEntriesToListFile
from mozpack.files import FileFinder
if sys.platform == 'win32':
from ctypes import windll, WinError
CreateHardLink = windll.kernel32.CreateHardLinkA
@ -74,7 +75,7 @@ class JarMaker(object):
regline = re.compile('\%\s+(.*)$')
entryre = '(?P<optPreprocess>\*)?(?P<optOverwrite>\+?)\s+'
entryline = re.compile(entryre
+ '(?P<output>[\w\d.\-\_\\\/\+\@]+)\s*(\((?P<locale>\%?)(?P<source>[\w\d.\-\_\\\/\@]+)\))?\s*$'
+ '(?P<output>[\w\d.\-\_\\\/\+\@]+)\s*(\((?P<locale>\%?)(?P<source>[\w\d.\-\_\\\/\@\*]+)\))?\s*$'
)
def __init__(self, outputFormat='flat', useJarfileManifest=True,
@ -373,6 +374,29 @@ class JarMaker(object):
# use srcdirs and the objdir (current working dir) for relative paths
src_base = self.sourcedirs + [os.getcwd()]
if '*' in src:
if not out.endswith('/'):
out += '/'
def _prefix(s):
for p in s.split('/'):
if '*' not in p:
yield p + '/'
prefix = ''.join(_prefix(src))
fmt = '%s%s %s%%s (%s%%s)' % (
m.group('optPreprocess') or '',
m.group('optOverwrite') or '',
out,
m.group('locale') or '',
)
for _srcdir in src_base:
finder = FileFinder(_srcdir, find_executables=False)
for path, _ in finder.find(src):
line = fmt % (path[len(prefix):], path)
m = self.entryline.match(line)
if m:
self._processEntryLine(m, outHelper, jf)
return
# check if the source file exists
realsrc = None
for _srcdir in src_base:

Просмотреть файл

@ -233,7 +233,7 @@ class TestJarMaker(unittest.TestCase):
def test_a_simple_symlink(self):
'''Test a simple jar.mn with a symlink'''
if not symlinks_supported(self.srcdir):
return
raise unittest.SkipTest('symlinks not supported')
self._create_simple_setup()
jm = JarMaker(outputFormat='symlink')
@ -247,6 +247,65 @@ class TestJarMaker(unittest.TestCase):
self.assertTrue(is_symlink_to(destfoo, srcbar),
"{0} is not a symlink to {1}".format(destfoo, srcbar))
def _create_wildcard_setup(self):
# create src content
jarf = open(os.path.join(self.srcdir, 'jar.mn'), 'w')
jarf.write('''test.jar:
dir/bar (*.js)
dir/hoge (qux/*)
''')
jarf.close()
open(os.path.join(self.srcdir,'foo.js'),'w').write('foo.js\n')
open(os.path.join(self.srcdir,'bar.js'),'w').write('bar.js\n')
os.makedirs(os.path.join(self.srcdir, 'qux', 'foo'))
open(os.path.join(self.srcdir,'qux', 'foo', '1'),'w').write('1\n')
open(os.path.join(self.srcdir,'qux', 'foo', '2'),'w').write('2\n')
open(os.path.join(self.srcdir,'qux', 'baz'),'w').write('baz\n')
# create reference
refpath = os.path.join(self.refdir, 'chrome', 'test.jar', 'dir')
os.makedirs(os.path.join(refpath, 'bar'))
os.makedirs(os.path.join(refpath, 'hoge', 'foo'))
open(os.path.join(refpath, 'bar', 'foo.js'), 'w').write('foo.js\n')
open(os.path.join(refpath, 'bar', 'bar.js'), 'w').write('bar.js\n')
open(os.path.join(refpath, 'hoge', 'foo', '1'), 'w').write('1\n')
open(os.path.join(refpath, 'hoge', 'foo', '2'), 'w').write('2\n')
open(os.path.join(refpath, 'hoge', 'baz'), 'w').write('baz\n')
def test_a_wildcard_jar(self):
'''Test a wildcard in jar.mn'''
self._create_wildcard_setup()
# call JarMaker
rv = self._jar_and_compare(os.path.join(self.srcdir,'jar.mn'),
sourcedirs = [self.srcdir])
self.assertTrue(not rv, rv)
def test_a_wildcard_symlink(self):
'''Test a wildcard in jar.mn with symlinks'''
if not symlinks_supported(self.srcdir):
raise unittest.SkipTest('symlinks not supported')
self._create_wildcard_setup()
jm = JarMaker(outputFormat='symlink')
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)
expected_symlinks = {
('bar', 'foo.js'): ('foo.js',),
('bar', 'bar.js'): ('bar.js',),
('hoge', 'foo', '1'): ('qux', 'foo', '1'),
('hoge', 'foo', '2'): ('qux', 'foo', '2'),
('hoge', 'baz'): ('qux', 'baz'),
}
for dest, src in expected_symlinks.iteritems():
srcpath = os.path.join(self.srcdir, *src)
destpath = os.path.join(self.builddir, 'chrome', 'test', 'dir',
*dest)
self.assertTrue(is_symlink_to(destpath, srcpath),
"{0} is not a symlink to {1}".format(destpath,
srcpath))
class Test_relativesrcdir(unittest.TestCase):
def setUp(self):