Bug 1444534 - Part 1: Allow "locales/en-US" relative paths in localized inputs. r=ted.mielczarek

This cleans up a few things, including simplifying the look of
backend.mk by keeping the relsrcdir in MERGE_RELATIVE_FILE similar to
the source path in the tree.  Before, the locales/ floated around,
which is hard to understand but doesn't matter, since it's stripped by
MERGE_RELATIVE_FILE.

This also tests both relative and topsrcdir-absolute paths.

MozReview-Commit-ID: 1v3y9xGiNfL

--HG--
rename : python/mozbuild/mozbuild/test/backend/data/localized-generated-files-AB_CD/inner/locales/en-US/localized-input => python/mozbuild/mozbuild/test/backend/data/localized-generated-files-AB_CD/locales/en-US/localized-input
extra : rebase_source : 302d7cb638974fc5ec71513f47ce98222c5e3bb6
This commit is contained in:
Nick Alexander 2018-03-08 14:12:44 -08:00
Родитель 9ff601f55f
Коммит c9cc551b04
7 изменённых файлов: 34 добавлений и 12 удалений

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

@ -539,12 +539,17 @@ class RecursiveMakeBackend(CommonBackend):
if obj.inputs: if obj.inputs:
if obj.localized: if obj.localized:
# Localized generated files can have locale-specific inputs, which are # Localized generated files can have locale-specific inputs, which are
# indicated by paths starting with `en-US/` or containing `/locales/en-US/`. # indicated by paths starting with `en-US/` or containing `locales/en-US/`.
def srcpath(p): def srcpath(p):
if '/locales/en-US' in p: if 'locales/en-US' in p:
e, f = p.split('/locales/en-US/', 1) # We need an "absolute source path" relative to
# topsrcdir, like "/source/path".
if not p.startswith('/'):
p = '/' + mozpath.relpath(p.full_path, obj.topsrcdir)
e, f = p.split('locales/en-US/', 1)
assert(f) assert(f)
return '$(call MERGE_RELATIVE_FILE,%s,/locales/%s)' % (f, e) return '$(call MERGE_RELATIVE_FILE,{},{}locales)'.format(
f, e if not e.startswith('/') else e[len('/'):])
elif p.startswith('en-US/'): elif p.startswith('en-US/'):
e, f = p.split('en-US/', 1) e, f = p.split('en-US/', 1)
assert(not e) assert(not e)

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

@ -1461,7 +1461,7 @@ VARIABLES = {
which provides the locale in use, i.e. ``en-US``. which provides the locale in use, i.e. ``en-US``.
2. The ``inputs`` list may contain paths to files that will be taken from the locale 2. The ``inputs`` list may contain paths to files that will be taken from the locale
source directory (see ``LOCALIZED_FILES`` for a discussion of the specifics). Paths source directory (see ``LOCALIZED_FILES`` for a discussion of the specifics). Paths
in ``inputs`` starting with ``en-US/`` or containing ``/locales/en-US/`` are considered in ``inputs`` starting with ``en-US/`` or containing ``locales/en-US/`` are considered
localized files. localized files.
To place the generated output file in a specific location, list its objdir path in To place the generated output file in a specific location, list its objdir path in

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

@ -1188,12 +1188,12 @@ class TreeMetadataEmitter(LoggingMixin):
if isinstance(f, SourcePath): if isinstance(f, SourcePath):
if f.startswith('en-US/'): if f.startswith('en-US/'):
pass pass
elif '/locales/en-US/' in f: elif 'locales/en-US/' in f:
pass pass
else: else:
raise SandboxValidationError( raise SandboxValidationError(
'%s paths must start with `en-US/` or ' '%s paths must start with `en-US/` or '
'contain `/locales/en-US/`: %s' 'contain `locales/en-US/`: %s'
% (var, f,), context) % (var, f,), context)
if not isinstance(f, ObjDirPath): if not isinstance(f, ObjDirPath):

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

@ -16,6 +16,17 @@ LOCALIZED_GENERATED_FILES += [ 'bar{AB_rCD}.xyz' ]
bar = LOCALIZED_GENERATED_FILES['bar{AB_rCD}.xyz'] bar = LOCALIZED_GENERATED_FILES['bar{AB_rCD}.xyz']
bar.script = 'generate-foo.py' bar.script = 'generate-foo.py'
bar.inputs = [ bar.inputs = [
'inner/locales/en-US/localized-input', # Absolute source path.
'/inner/locales/en-US/localized-input',
'non-localized-input',
]
LOCALIZED_GENERATED_FILES += [ 'zot{AB_rCD}.xyz' ]
bar = LOCALIZED_GENERATED_FILES['zot{AB_rCD}.xyz']
bar.script = 'generate-foo.py'
bar.inputs = [
# Relative source path.
'locales/en-US/localized-input',
'non-localized-input', 'non-localized-input',
] ]

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

@ -461,9 +461,15 @@ class TestRecursiveMakeBackend(BackendTester):
'include $(topsrcdir)/config/AB_rCD.mk', 'include $(topsrcdir)/config/AB_rCD.mk',
'GARBAGE += bar$(AB_rCD).xyz', 'GARBAGE += bar$(AB_rCD).xyz',
'EXTRA_MDDEPEND_FILES += bar$(AB_rCD).xyz.pp', 'EXTRA_MDDEPEND_FILES += bar$(AB_rCD).xyz.pp',
'bar$(AB_rCD).xyz: %s/generate-foo.py $(call MERGE_RELATIVE_FILE,localized-input,/locales/inner) $(srcdir)/non-localized-input $(if $(IS_LANGUAGE_REPACK),FORCE)' % env.topsrcdir, 'bar$(AB_rCD).xyz: %s/generate-foo.py $(call MERGE_RELATIVE_FILE,localized-input,inner/locales) $(srcdir)/non-localized-input $(if $(IS_LANGUAGE_REPACK),FORCE)' % env.topsrcdir,
'$(REPORT_BUILD)', '$(REPORT_BUILD)',
'$(call py_action,file_generate,--locale=$(AB_CD) %s/generate-foo.py main bar$(AB_rCD).xyz $(MDDEPDIR)/bar$(AB_rCD).xyz.pp $(call MERGE_RELATIVE_FILE,localized-input,/locales/inner) $(srcdir)/non-localized-input)' % env.topsrcdir, '$(call py_action,file_generate,--locale=$(AB_CD) %s/generate-foo.py main bar$(AB_rCD).xyz $(MDDEPDIR)/bar$(AB_rCD).xyz.pp $(call MERGE_RELATIVE_FILE,localized-input,inner/locales) $(srcdir)/non-localized-input)' % env.topsrcdir,
'',
'GARBAGE += zot$(AB_rCD).xyz',
'EXTRA_MDDEPEND_FILES += zot$(AB_rCD).xyz.pp',
'zot$(AB_rCD).xyz: %s/generate-foo.py $(call MERGE_RELATIVE_FILE,localized-input,locales) $(srcdir)/non-localized-input $(if $(IS_LANGUAGE_REPACK),FORCE)' % env.topsrcdir,
'$(REPORT_BUILD)',
'$(call py_action,file_generate,--locale=$(AB_CD) %s/generate-foo.py main zot$(AB_rCD).xyz $(MDDEPDIR)/zot$(AB_rCD).xyz.pp $(call MERGE_RELATIVE_FILE,localized-input,locales) $(srcdir)/non-localized-input)' % env.topsrcdir,
'', '',
] ]

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

@ -1371,10 +1371,10 @@ class TestEmitterBasic(unittest.TestCase):
def test_localized_files_no_en_us(self): def test_localized_files_no_en_us(self):
"""Test that LOCALIZED_FILES errors if a path does not start with """Test that LOCALIZED_FILES errors if a path does not start with
`en-US/` or contain `/locales/en-US/`.""" `en-US/` or contain `locales/en-US/`."""
reader = self.reader('localized-files-no-en-us') reader = self.reader('localized-files-no-en-us')
with self.assertRaisesRegexp(SandboxValidationError, with self.assertRaisesRegexp(SandboxValidationError,
'LOCALIZED_FILES paths must start with `en-US/` or contain `/locales/en-US/`: foo.js'): 'LOCALIZED_FILES paths must start with `en-US/` or contain `locales/en-US/`: foo.js'):
objs = self.read_topsrcdir(reader) objs = self.read_topsrcdir(reader)
def test_localized_pp_files(self): def test_localized_pp_files(self):