Bug 1210642 - Allow to pass defines overrides when processing install manifests. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 01 Oct 2015 08:01:48 +0900
changeset 266206 f2fdb9d0bc086f1ecb5986805254ef988e8520be
parent 266205 1f0ba759efbc710e2db64b215127b7b0f2bf8910
child 266207 42199c7b225a8c5318faf169a8e6e1d24f82cf32
push id29483
push usercbook@mozilla.com
push dateTue, 06 Oct 2015 10:01:59 +0000
treeherdermozilla-central@89732fcdb0ba [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1210642
milestone44.0a1
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 1210642 - Allow to pass defines overrides when processing install manifests. r=gps
python/mozbuild/mozbuild/action/process_install_manifest.py
python/mozbuild/mozpack/manifests.py
--- a/python/mozbuild/mozbuild/action/process_install_manifest.py
+++ b/python/mozbuild/mozbuild/action/process_install_manifest.py
@@ -12,48 +12,69 @@ from mozpack.manifests import InstallMan
 
 COMPLETE = 'From {dest}: Kept {existing} existing; Added/updated {updated}; ' \
     'Removed {rm_files} files and {rm_dirs} directories.'
 
 
 def process_manifest(destdir, paths,
         remove_unaccounted=True,
         remove_all_directory_symlinks=True,
-        remove_empty_directories=True):
+        remove_empty_directories=True,
+        defines={}):
     manifest = InstallManifest()
     for path in paths:
         manifest |= InstallManifest(path=path)
 
     copier = FileCopier()
-    manifest.populate_registry(copier)
+    manifest.populate_registry(copier, defines_override=defines)
     return copier.copy(destdir,
         remove_unaccounted=remove_unaccounted,
         remove_all_directory_symlinks=remove_all_directory_symlinks,
         remove_empty_directories=remove_empty_directories)
 
 
+class DefinesAction(argparse.Action):
+    def __call__(self, parser, namespace, values, option_string):
+        defines = getattr(namespace, self.dest)
+        if defines is None:
+            defines = {}
+        values = values.split('=', 1)
+        if len(values) == 1:
+            name, value = values[0], 1
+        else:
+            name, value = values
+            if value.isdigit():
+                value = int(value)
+        defines[name] = value
+        setattr(namespace, self.dest, defines)
+
+
 def main(argv):
     parser = argparse.ArgumentParser(
         description='Process install manifest files.')
 
     parser.add_argument('destdir', help='Destination directory.')
     parser.add_argument('manifests', nargs='+', help='Path to manifest file(s).')
     parser.add_argument('--no-remove', action='store_true',
         help='Do not remove unaccounted files from destination.')
     parser.add_argument('--no-remove-all-directory-symlinks', action='store_true',
         help='Do not remove all directory symlinks from destination.')
     parser.add_argument('--no-remove-empty-directories', action='store_true',
         help='Do not remove empty directories from destination.')
+    parser.add_argument('-D', action=DefinesAction,
+        dest='defines', metavar="VAR[=VAL]",
+        help='Define a variable to override what is specified in the manifest')
 
     args = parser.parse_args(argv)
 
     result = process_manifest(args.destdir, args.manifests,
         remove_unaccounted=not args.no_remove,
         remove_all_directory_symlinks=not args.no_remove_all_directory_symlinks,
-        remove_empty_directories=not args.no_remove_empty_directories)
+        remove_empty_directories=not args.no_remove_empty_directories,
+        defines=args.defines)
 
     print(COMPLETE.format(dest=args.destdir,
         existing=result.existing_files_count,
         updated=result.updated_files_count,
         rm_files=result.removed_files_count,
         rm_dirs=result.removed_directories_count))
 
 if __name__ == '__main__':
--- a/python/mozbuild/mozpack/manifests.py
+++ b/python/mozbuild/mozpack/manifests.py
@@ -291,22 +291,25 @@ class InstallManifest(object):
             (self.PREPROCESS, source, deps, marker, self._encode_field_entry(defines)))
 
     def _add_entry(self, dest, entry):
         if dest in self._dests:
             raise ValueError('Item already in manifest: %s' % dest)
 
         self._dests[dest] = entry
 
-    def populate_registry(self, registry):
+    def populate_registry(self, registry, defines_override={}):
         """Populate a mozpack.copier.FileRegistry instance with data from us.
 
         The caller supplied a FileRegistry instance (or at least something that
         conforms to its interface) and that instance is populated with data
         from this manifest.
+
+        Defines can be given to override the ones in the manifest for
+        preprocessing.
         """
         for dest in sorted(self._dests):
             entry = self._dests[dest]
             install_type = entry[0]
 
             if install_type == self.SYMLINK:
                 registry.add(dest, AbsoluteSymlinkFile(entry[1]))
                 continue
@@ -335,18 +338,21 @@ class InstallManifest(object):
 
                 for path in paths:
                     source = mozpath.join(base, path)
                     registry.add(mozpath.join(dest, path), cls(source))
 
                 continue
 
             if install_type == self.PREPROCESS:
+                defines = self._decode_field_entry(entry[4])
+                if defines_override:
+                    defines.update(defines_override)
                 registry.add(dest, PreprocessedFile(entry[1],
                     depfile_path=entry[2],
                     marker=entry[3],
-                    defines=self._decode_field_entry(entry[4]),
+                    defines=defines,
                     extra_depends=self._source_files))
 
                 continue
 
             raise Exception('Unknown install type defined in manifest: %d' %
                 install_type)