Bug 1237140 - Move DefinesAction from mozbuild.action.process_install_manifest to mozbuild.util. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 19 Jan 2016 10:31:15 +0900
changeset 317598 dc75f7ff583eed24641576e99ba83a37ba30a490
parent 317597 a58563fd4e6cca31564057e7c45090e8c00cc361
child 317599 2ef9b742008ce758dcc3d8d6f1f06dacf2bdb99f
push id1079
push userjlund@mozilla.com
push dateFri, 15 Apr 2016 21:02:33 +0000
treeherdermozilla-release@575fbf6786d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1237140
milestone46.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 1237140 - Move DefinesAction from mozbuild.action.process_install_manifest to mozbuild.util. r=gps
python/mozbuild/mozbuild/action/process_install_manifest.py
python/mozbuild/mozbuild/util.py
--- a/python/mozbuild/mozbuild/action/process_install_manifest.py
+++ b/python/mozbuild/mozbuild/action/process_install_manifest.py
@@ -11,16 +11,17 @@ from mozpack.copier import (
     FileCopier,
     FileRegistry,
 )
 from mozpack.files import (
     BaseFile,
     FileFinder,
 )
 from mozpack.manifests import InstallManifest
+from mozbuild.util import DefinesAction
 
 
 COMPLETE = 'From {dest}: Kept {existing} existing; Added/updated {updated}; ' \
     'Removed {rm_files} files and {rm_dirs} directories.'
 
 
 def process_manifest(destdir, paths, track=None,
         remove_unaccounted=True,
@@ -61,32 +62,16 @@ def process_manifest(destdir, paths, tra
         remove_empty_directories=remove_empty_directories)
 
     if track:
         manifest.write(path=track)
 
     return result
 
 
-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.')
--- a/python/mozbuild/mozbuild/util.py
+++ b/python/mozbuild/mozbuild/util.py
@@ -2,16 +2,17 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # This file contains miscellaneous utility functions that don't belong anywhere
 # in particular.
 
 from __future__ import absolute_import, unicode_literals
 
+import argparse
 import collections
 import difflib
 import errno
 import functools
 import hashlib
 import itertools
 import os
 import re
@@ -969,8 +970,25 @@ def expand_variables(s, variables):
         result += s
         value = variables.get(name)
         if not value:
             continue
         if not isinstance(value, types.StringTypes):
             value = ' '.join(value)
         result += value
     return result
+
+
+class DefinesAction(argparse.Action):
+    '''An ArgumentParser action to handle -Dvar[=value] type of arguments.'''
+    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)