Bug 1419182 - Pass topsrcdir into compare-mozconfigs.py; r=mshal
authorGregory Szorc <gps@mozilla.com>
Mon, 20 Nov 2017 14:34:50 -0800
changeset 701838 489860a7e03a7113521434f2cd6699664232dcfe
parent 701837 a7a3f0cdc871de643b8a9cef7a752e6cdcb865c1
child 701839 a1040ffa24e2988c36af13aa09106494dc08274f
push id90298
push userbmo:bpostelnicu@mozilla.com
push dateWed, 22 Nov 2017 10:54:01 +0000
reviewersmshal
bugs1419182
milestone59.0a1
Bug 1419182 - Pass topsrcdir into compare-mozconfigs.py; r=mshal We currently have the logic for compare-mozconfigs spread across 2 Python files. I'd like to move the logic into 1 file so we can do nicer things more easily. In preparation for this, change compare-mozconfigs.py to receive an argument that is the path to the topsrcdir. Also, switch to argparse because it is more modern. MozReview-Commit-ID: 7oFQzAdmcim
build/compare-mozconfig/compare-mozconfigs-wrapper.py
build/compare-mozconfig/compare-mozconfigs.py
--- a/build/compare-mozconfig/compare-mozconfigs-wrapper.py
+++ b/build/compare-mozconfig/compare-mozconfigs-wrapper.py
@@ -31,29 +31,26 @@ class TestCompareMozconfigs(unittest.Tes
         for platform in PLATFORMS:
             log.info('Comparing platform %s' % platform)
             python_exe = substs['PYTHON']
             topsrcdir = substs['top_srcdir']
 
             # construct paths and args for compare-mozconfig
             browser_dir = path.join(topsrcdir, 'browser')
             script_path = path.join(topsrcdir, 'build/compare-mozconfig/compare-mozconfigs.py')
-            whitelist_path = path.join(browser_dir, 'config/mozconfigs/whitelist')
             beta_mozconfig_path = path.join(browser_dir, 'config/mozconfigs', platform, 'beta')
             release_mozconfig_path = path.join(browser_dir, 'config/mozconfigs', platform, 'release')
             nightly_mozconfig_path = path.join(browser_dir, 'config/mozconfigs', platform, 'nightly')
 
             log.info("Comparing beta against nightly mozconfigs")
-            ret_code = subprocess.call([python_exe, script_path, '--whitelist',
-                                        whitelist_path,
+            ret_code = subprocess.call([python_exe, script_path, topsrcdir,
                                         platform + ',' + beta_mozconfig_path +
                                         ',' + nightly_mozconfig_path])
             self.assertEqual(0, ret_code)
 
             log.info("Comparing release against nightly mozconfigs")
-            ret_code = subprocess.call([python_exe, script_path, '--whitelist',
-                                        whitelist_path,
+            ret_code = subprocess.call([python_exe, script_path, topsrcdir,
                                         platform + ',' + release_mozconfig_path +
                                         ',' + nightly_mozconfig_path])
             self.assertEqual(0, ret_code)
 
 if __name__ == '__main__':
     mozunit.main()
--- a/build/compare-mozconfig/compare-mozconfigs.py
+++ b/build/compare-mozconfig/compare-mozconfigs.py
@@ -3,16 +3,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/.
 
 # originally from https://hg.mozilla.org/build/tools/file/4ab9c1a4e05b/scripts/release/compare-mozconfigs.py
 
 from __future__ import unicode_literals
 
 import logging
+import os
 import sys
 import difflib
 
 FAILURE_CODE = 1
 SUCCESS_CODE = 0
 
 log = logging.getLogger(__name__)
 
@@ -87,27 +88,32 @@ def verify_mozconfigs(mozconfig_pair, ni
     return success
 
 def get_mozconfig(path):
     """Consumes a path and returns a list of lines from the mozconfig file."""
     with open(path, 'rb') as fh:
         return fh.readlines()
 
 if __name__ == '__main__':
-    from optparse import OptionParser
-    parser = OptionParser()
+    import argparse
 
-    parser.add_option('--whitelist', dest='whitelist')
-    options, args = parser.parse_args()
+    parser = argparse.ArgumentParser()
+    parser.add_argument('topsrcdir', help='Path to root of source checkout')
+    parser.add_argument('args', nargs='*')
+
+    args = parser.parse_args()
 
     logging.basicConfig(level=logging.INFO)
 
-    mozconfig_whitelist = readConfig(options.whitelist)
+    whitelist = os.path.join(args.topsrcdir, 'browser', 'config', 'mozconfigs',
+                             'whitelist')
 
-    for arg in args:
+    mozconfig_whitelist = readConfig(whitelist)
+
+    for arg in args.args:
         platform, mozconfig_path, nightly_mozconfig_path = arg.split(',')
 
         mozconfig_lines = get_mozconfig(mozconfig_path)
         nightly_mozconfig_lines = get_mozconfig(nightly_mozconfig_path)
 
         mozconfig_pair = (mozconfig_path, mozconfig_lines)
         nightly_mozconfig_pair = (nightly_mozconfig_path,
                                   nightly_mozconfig_lines)