Bug 1235021 - Add a RenamedSourcePath helper class. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 24 Dec 2015 08:55:26 +0900
changeset 278027 4d191d8983d60511bf53e74e2d4b9eda04ec28ac
parent 278026 531617914786476f3d180ea787c2b245b299cee4
child 278028 a99b3de8d858141e9846e78d5ea7314732d1f114
push id29841
push userryanvm@gmail.com
push dateSat, 02 Jan 2016 00:29:52 +0000
treeherdermozilla-central@f7fbc524f9f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1235021 - Add a RenamedSourcePath helper class. r=gps This class will be used to represent files that are copied with a different name, which we have plenty of in jar manifests.
--- a/python/mozbuild/mozbuild/backend/fastermake.py
+++ b/python/mozbuild/mozbuild/backend/fastermake.py
@@ -40,19 +40,19 @@ class FasterMakeBackend(CommonBackend):
         self._dependencies = OrderedDefaultDict(list)
         self._has_xpidl = False
     def _add_preprocess(self, obj, path, dest, target=None, **kwargs):
         if target is None:
             target = mozpath.basename(path)
-            # This matches what PP_TARGETS do in config/rules.
-            if target.endswith('.in'):
-                target = target[:-3]
+        # This matches what PP_TARGETS do in config/rules.
+        if target.endswith('.in'):
+            target = target[:-3]
         if target.endswith('.css'):
             kwargs['marker'] = '%'
         depfile = mozpath.join(
             self.environment.topobjdir, 'faster', '.deps',
             mozpath.join(obj.install_target, dest, target).replace('/', '_'))
             mozpath.join(obj.srcdir, path),
             mozpath.join(dest, target),
@@ -71,21 +71,22 @@ class FasterMakeBackend(CommonBackend):
         elif isinstance(obj, (FinalTargetFiles,
                               FinalTargetPreprocessedFiles)) and \
             for path, files in obj.files.walk():
                 for f in files:
                     if isinstance(obj, FinalTargetPreprocessedFiles):
                         self._add_preprocess(obj, f.full_path, path,
+                                             target=f.target_basename,
-                            mozpath.join(path, mozpath.basename(f))
+                            mozpath.join(path, f.target_basename)
         elif isinstance(obj, ChromeManifestEntry) and \
             top_level = mozpath.join(obj.install_target, 'chrome.manifest')
             if obj.path != top_level:
                 entry = 'manifest %s' % mozpath.relpath(obj.path,
--- a/python/mozbuild/mozbuild/backend/recursivemake.py
+++ b/python/mozbuild/mozbuild/backend/recursivemake.py
@@ -21,16 +21,17 @@ from reftest import ReftestManifest
 from mozpack.copier import FilePurger
 from mozpack.manifests import (
 import mozpack.path as mozpath
 from mozbuild.frontend.context import (
+    RenamedSourcePath,
 from .common import CommonBackend
 from ..frontend.data import (
@@ -1268,18 +1269,18 @@ INSTALL_TARGETS += %(prefix)s
             backend_file.write('NONRECURSIVE_TARGETS_export_branding_DIRECTORY = $(DEPTH)\n')
             backend_file.write('NONRECURSIVE_TARGETS_export_branding_TARGETS += install-dist/branding\n')
         for path, files in files.walk():
             target_var = (mozpath.join(target, path)
                           if path else target).replace('/', '_')
             have_objdir_files = False
             for f in files:
-                dest = mozpath.join(reltarget, path,
-                                    mozpath.basename(f.full_path))
+                assert not isinstance(f, RenamedSourcePath)
+                dest = mozpath.join(reltarget, path, f.target_basename)
                 if not isinstance(f, ObjDirPath):
                     install_manifest.add_symlink(f.full_path, dest)
                     backend_file.write('%s_FILES += %s\n' % (
                         target_var, self._pretty_path(f, backend_file)))
                     have_objdir_files = True
             if have_objdir_files:
--- a/python/mozbuild/mozbuild/frontend/context.py
+++ b/python/mozbuild/mozbuild/frontend/context.py
@@ -393,16 +393,20 @@ class Path(ContextDerivedValue, unicode)
         return self.__cmp__(other) >= 0
     def __repr__(self):
         return '<%s (%s)%s>' % (self.__class__.__name__, self.srcdir, self)
     def __hash__(self):
         return hash(self.full_path)
+    @memoized_property
+    def target_basename(self):
+        return mozpath.basename(self.full_path)
 class SourcePath(Path):
     """Like Path, but limited to paths in the source directory."""
     def __init__(self, context, value):
         if value.startswith('!'):
             raise ValueError('Object directory paths are not allowed')
         if value.startswith('%'):
             raise ValueError('Filesystem absolute paths are not allowed')
@@ -428,16 +432,34 @@ class SourcePath(Path):
         Ideally, we wouldn't need this function, but the fact that both source
         path under topsrcdir and the external source dir end up mixed in the
         objdir (aka pseudo-rework), this is needed.
         return ObjDirPath(self.context, '!%s' % self).full_path
+class RenamedSourcePath(SourcePath):
+    """Like SourcePath, but with a different base name when installed.
+    The constructor takes a tuple of (source, target_basename).
+    This class is not meant to be exposed to moz.build sandboxes as of now,
+    and is not supported by the RecursiveMake backend.
+    """
+    def __init__(self, context, value):
+        assert isinstance(value, tuple)
+        source, self._target_basename = value
+        super(RenamedSourcePath, self).__init__(context, source)
+    @property
+    def target_basename(self):
+        return self._target_basename
 class ObjDirPath(Path):
     """Like Path, but limited to paths in the object directory."""
     def __init__(self, context, value=None):
         if not value.startswith('!'):
             raise ValueError('Object directory paths must start with ! prefix')
         super(ObjDirPath, self).__init__(context, value)
         if value.startswith('!/'):
--- a/python/mozbuild/mozbuild/frontend/emitter.py
+++ b/python/mozbuild/mozbuild/frontend/emitter.py
@@ -676,17 +676,17 @@ class TreeMetadataEmitter(LoggingMixin):
                                 % (f,), context)
                     if not isinstance(f, ObjDirPath):
                         path = f.full_path
                         if not os.path.exists(path):
                             raise SandboxValidationError(
                                 'File listed in %s does not exist: %s'
                                 % (var, path), context)
-                        if mozpath.basename(f.full_path) not in generated_files:
+                        if f.target_basename not in generated_files:
                             raise SandboxValidationError(
                                 ('Objdir file listed in %s not in ' +
                                  'GENERATED_FILES: %s') % (var, f), context)
             # Addons (when XPI_NAME is defined) and Applications (when
             # DIST_SUBDIR is defined) use a different preferences directory
             # (default/preferences) from the one the GRE uses (defaults/pref).
             # Hence, we move the files from the latter to the former in that