Bug 1752968 - Make single-locale l10n repacks minify .properties files. r=firefox-build-system-reviewers,eemeli,glandium

Differential Revision: https://phabricator.services.mozilla.com/D138365
This commit is contained in:
Nick Alexander 2022-02-23 23:11:50 +00:00
parent fb38db6876
commit 96e06a21d5
4 changed files with 18 additions and 6 deletions

View File

@ -270,7 +270,9 @@ def _repack(app_finder, l10n_finder, copier, formatter, non_chrome=set()):
copier[path].preload([l.replace(locale, l10n_locale) for l in log])
def repack(source, l10n, extra_l10n={}, non_resources=[], non_chrome=set()):
def repack(
source, l10n, extra_l10n={}, non_resources=[], non_chrome=set(), minify=False
):
"""
Replace localized data from the `source` directory with localized data
from `l10n` and `extra_l10n`.
@ -289,15 +291,16 @@ def repack(source, l10n, extra_l10n={}, non_resources=[], non_chrome=set()):
is in that format.
The `non_chrome` argument gives a list of file/directory patterns for
localized files that are not listed in a chrome.manifest.
If `minify`, `.properties` files are minified.
"""
app_finder = UnpackFinder(source)
l10n_finder = UnpackFinder(l10n)
app_finder = UnpackFinder(source, minify=minify)
l10n_finder = UnpackFinder(l10n, minify=minify)
if extra_l10n:
finders = {
"": l10n_finder,
}
for base, path in six.iteritems(extra_l10n):
finders[base] = UnpackFinder(path)
finders[base] = UnpackFinder(path, minify=minify)
l10n_finder = ComposedFinder(finders)
copier = FileCopier()
compress = min(app_finder.compressed, JAR_DEFLATED)

View File

@ -42,11 +42,12 @@ class UnpackFinder(BaseFinder):
or with files from a FileFinder using the given path as its root.
"""
def __init__(self, source, omnijar_name=None, unpack_xpi=True):
def __init__(self, source, omnijar_name=None, unpack_xpi=True, **kwargs):
if isinstance(source, BaseFinder):
assert not kwargs
self._finder = source
else:
self._finder = FileFinder(source)
self._finder = FileFinder(source, **kwargs)
self.base = self._finder.base
self.files = FileRegistry()
self.kind = "flat"

View File

@ -114,6 +114,7 @@ repackage-zip: UNPACKAGE='$(ZIP_IN)'
repackage-zip:
$(PYTHON3) $(MOZILLA_DIR)/toolkit/mozapps/installer/l10n-repack.py '$(STAGEDIST)' $(DIST)/xpi-stage/locale-$(AB_CD) \
$(MOZ_PKG_EXTRAL10N) \
$(if $(MOZ_PACKAGER_MINIFY),--minify) \
$(if $(filter omni,$(MOZ_PACKAGER_FORMAT)),$(if $(NON_OMNIJAR_FILES),--non-resource $(NON_OMNIJAR_FILES)))
ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))

View File

@ -56,6 +56,12 @@ def main():
default=[],
help="Extra files not to be considered as resources",
)
parser.add_argument(
"--minify",
action="store_true",
default=False,
help="Make some files more compact while packaging",
)
args = parser.parse_args()
buildconfig.substs["USE_ELF_HACK"] = False
@ -66,6 +72,7 @@ def main():
extra_l10n=dict(args.extra_l10n),
non_resources=args.non_resource,
non_chrome=NON_CHROME,
minify=args.minify,
)