зеркало из https://github.com/mozilla/gecko-dev.git
bug 1409721 - add LOCALIZED_FILES and LOCALIZED_PP_FILES to moz.build sandbox. r=nalexander
This commit adds new moz.build sandbox symbols that are intended to be used for localized files: LOCALIZED_FILES and LOCALIZED_PP_FILES. They are currently just do-nothing subclasses of FinalTarget[Preprocessor]Files, but the next change in this series will add support for them to the recursive make backend. Because they subclass FinalTarget[Preprocessor]Files, build backends that are not concerned about localized builds should be able to handle them as if they were FINAL_TARGET[_PP]_FILES without any additional code. MozReview-Commit-ID: K0baBZ0F7av --HG-- extra : rebase_source : 323e2993638fb0ba44ed89a4e0edd16b27a287e0 extra : source : e3ce81bc209b09b6771d7056d1fb06a65e27dc0d
This commit is contained in:
Родитель
ae41f5bf71
Коммит
1d8717cfce
|
@ -1415,6 +1415,53 @@ VARIABLES = {
|
|||
"""Like ``FINAL_TARGET_FILES``, with preprocessing.
|
||||
"""),
|
||||
|
||||
'LOCALIZED_FILES': (ContextDerivedTypedHierarchicalStringList(Path), list,
|
||||
"""List of locale-dependent files to be installed into the application
|
||||
directory.
|
||||
|
||||
This functions similarly to ``FINAL_TARGET_FILES``, but the files are
|
||||
sourced from the locale directory and will vary per localization.
|
||||
For an en-US build, this is functionally equivalent to
|
||||
``FINAL_TARGET_FILES``. For a build with ``--enable-ui-locale``,
|
||||
the file will be taken from ``$LOCALE_SRCDIR``, with the leading
|
||||
``en-US`` removed. For a l10n repack of an en-US build, the file
|
||||
will be taken from the first location where it exists from:
|
||||
* the merged locale directory if it exists
|
||||
* ``$LOCALE_SRCDIR`` with the leading ``en-US`` removed
|
||||
* the in-tree en-US location
|
||||
|
||||
Paths specified here must be relative to the source directory and must
|
||||
include a leading ``en-US``. Wildcards are allowed, and will be
|
||||
expanded at the time of locale packaging to match files in the
|
||||
locale directory.
|
||||
|
||||
Files that are missing from a locale will typically have the en-US
|
||||
version used, but for wildcard expansions only files from the
|
||||
locale directory will be used, even if that means no files will
|
||||
be copied.
|
||||
|
||||
Example::
|
||||
|
||||
LOCALIZED_FILES.foo += [
|
||||
'en-US/foo.js',
|
||||
'en-US/things/*.ini',
|
||||
]
|
||||
|
||||
If this was placed in ``toolkit/locales/moz.build``, it would copy
|
||||
``toolkit/locales/en-US/foo.js`` and
|
||||
``toolkit/locales/en-US/things/*.ini`` to ``$(DIST)/bin/foo`` in an
|
||||
en-US build, and in a build of a different locale (or a repack),
|
||||
it would copy ``$(LOCALE_SRCDIR)/toolkit/foo.js`` and
|
||||
``$(LOCALE_SRCDIR)/toolkit/things/*.ini``.
|
||||
"""),
|
||||
|
||||
'LOCALIZED_PP_FILES': (ContextDerivedTypedHierarchicalStringList(Path), list,
|
||||
"""Like ``LOCALIZED_FILES``, with preprocessing.
|
||||
|
||||
Note that the ``AB_CD`` define is available and expands to the current
|
||||
locale being packaged, as with preprocessed entries in jar manifests.
|
||||
"""),
|
||||
|
||||
'OBJDIR_FILES': (ContextDerivedTypedHierarchicalStringList(Path), list,
|
||||
"""List of files to be installed anywhere in the objdir. Use sparingly.
|
||||
|
||||
|
|
|
@ -980,6 +980,19 @@ class FinalTargetPreprocessedFiles(ContextDerived):
|
|||
ContextDerived.__init__(self, sandbox)
|
||||
self.files = files
|
||||
|
||||
class LocalizedFiles(FinalTargetFiles):
|
||||
"""Sandbox container object for LOCALIZED_FILES, which is a
|
||||
HierarchicalStringList.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class LocalizedPreprocessedFiles(FinalTargetPreprocessedFiles):
|
||||
"""Sandbox container object for LOCALIZED_PP_FILES, which is a
|
||||
HierarchicalStringList.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class ObjdirFiles(FinalTargetFiles):
|
||||
"""Sandbox container object for OBJDIR_FILES, which is a
|
||||
|
|
|
@ -57,6 +57,8 @@ from .data import (
|
|||
Library,
|
||||
Linkable,
|
||||
LocalInclude,
|
||||
LocalizedFiles,
|
||||
LocalizedPreprocessedFiles,
|
||||
ObjdirFiles,
|
||||
ObjdirPreprocessedFiles,
|
||||
PerSourceFlag,
|
||||
|
@ -1079,6 +1081,8 @@ class TreeMetadataEmitter(LoggingMixin):
|
|||
('EXPORTS', Exports),
|
||||
('FINAL_TARGET_FILES', FinalTargetFiles),
|
||||
('FINAL_TARGET_PP_FILES', FinalTargetPreprocessedFiles),
|
||||
('LOCALIZED_FILES', LocalizedFiles),
|
||||
('LOCALIZED_PP_FILES', LocalizedPreprocessedFiles),
|
||||
('OBJDIR_FILES', ObjdirFiles),
|
||||
('OBJDIR_PP_FILES', ObjdirPreprocessedFiles),
|
||||
('TEST_HARNESS_FILES', TestHarnessFiles),
|
||||
|
@ -1103,13 +1107,19 @@ class TreeMetadataEmitter(LoggingMixin):
|
|||
if mozpath.split(base)[0] == 'res':
|
||||
has_resources = True
|
||||
for f in files:
|
||||
if ((var == 'FINAL_TARGET_PP_FILES' or
|
||||
var == 'OBJDIR_PP_FILES') and
|
||||
if (var in ('FINAL_TARGET_PP_FILES',
|
||||
'OBJDIR_PP_FILES',
|
||||
'LOCALIZED_FILES',
|
||||
'LOCALIZED_PP_FILES') and
|
||||
not isinstance(f, SourcePath)):
|
||||
raise SandboxValidationError(
|
||||
('Only source directory paths allowed in ' +
|
||||
'%s: %s')
|
||||
% (var, f,), context)
|
||||
if var.startswith('LOCALIZED_') and not f.startswith('en-US/'):
|
||||
raise SandboxValidationError(
|
||||
'%s paths must start with `en-US/`: %s'
|
||||
% (var, f,), context)
|
||||
if not isinstance(f, ObjDirPath):
|
||||
path = f.full_path
|
||||
if '*' not in path and not os.path.exists(path):
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# Any copyright is dedicated to the Public Domain.
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
LOCALIZED_FILES.foo += [
|
||||
'en-US/bar.ini',
|
||||
'foo.js',
|
||||
]
|
|
@ -0,0 +1,9 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# Any copyright is dedicated to the Public Domain.
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
LOCALIZED_FILES.foo += [
|
||||
'en-US/bar.ini',
|
||||
'en-US/code/*.js',
|
||||
'en-US/foo.js',
|
||||
]
|
|
@ -0,0 +1,8 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# Any copyright is dedicated to the Public Domain.
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
LOCALIZED_PP_FILES.foo += [
|
||||
'en-US/bar.ini',
|
||||
'en-US/foo.js',
|
||||
]
|
|
@ -33,6 +33,8 @@ from mozbuild.frontend.data import (
|
|||
JARManifest,
|
||||
LinkageMultipleRustLibrariesError,
|
||||
LocalInclude,
|
||||
LocalizedFiles,
|
||||
LocalizedPreprocessedFiles,
|
||||
Program,
|
||||
RustLibrary,
|
||||
RustProgram,
|
||||
|
@ -1235,6 +1237,46 @@ class TestEmitterBasic(unittest.TestCase):
|
|||
'Only source directory paths allowed in FINAL_TARGET_PP_FILES:'):
|
||||
self.read_topsrcdir(reader)
|
||||
|
||||
def test_localized_files(self):
|
||||
"""Test that LOCALIZED_FILES works properly."""
|
||||
reader = self.reader('localized-files')
|
||||
objs = self.read_topsrcdir(reader)
|
||||
|
||||
self.assertEqual(len(objs), 1)
|
||||
self.assertIsInstance(objs[0], LocalizedFiles)
|
||||
|
||||
for path, files in objs[0].files.walk():
|
||||
self.assertEqual(path, 'foo')
|
||||
self.assertEqual(len(files), 3)
|
||||
|
||||
expected = {'en-US/bar.ini', 'en-US/code/*.js', 'en-US/foo.js'}
|
||||
for f in files:
|
||||
self.assertTrue(unicode(f) in expected)
|
||||
|
||||
def test_localized_files_no_en_us(self):
|
||||
"""Test that LOCALIZED_FILES errors if a path does not start with
|
||||
`en-US/`."""
|
||||
reader = self.reader('localized-files-no-en-us')
|
||||
with self.assertRaisesRegexp(SandboxValidationError,
|
||||
'LOCALIZED_FILES paths must start with `en-US/`:'):
|
||||
objs = self.read_topsrcdir(reader)
|
||||
|
||||
def test_localized_pp_files(self):
|
||||
"""Test that LOCALIZED_PP_FILES works properly."""
|
||||
reader = self.reader('localized-pp-files')
|
||||
objs = self.read_topsrcdir(reader)
|
||||
|
||||
self.assertEqual(len(objs), 1)
|
||||
self.assertIsInstance(objs[0], LocalizedPreprocessedFiles)
|
||||
|
||||
for path, files in objs[0].files.walk():
|
||||
self.assertEqual(path, 'foo')
|
||||
self.assertEqual(len(files), 2)
|
||||
|
||||
expected = {'en-US/bar.ini', 'en-US/foo.js'}
|
||||
for f in files:
|
||||
self.assertTrue(unicode(f) in expected)
|
||||
|
||||
def test_rust_library_no_cargo_toml(self):
|
||||
'''Test that defining a RustLibrary without a Cargo.toml fails.'''
|
||||
reader = self.reader('rust-library-no-cargo-toml')
|
||||
|
|
Загрузка…
Ссылка в новой задаче