Bug 1200293 - mach target for mozregression. r=ahal
authorJulien Pagès <j.parkouss@gmail.com>
Sat, 05 Sep 2015 18:27:23 +0200
changeset 294138 f811b227edb3cf2aebaaa71a99432648ce05b493
parent 294137 c94d1fbf9c4f10a73ea3e1531d318bb8b101d400
child 294139 4f4bdab7f61d9889d5e8bd61a6566fc14d94a11e
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs1200293
milestone43.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 1200293 - mach target for mozregression. r=ahal
tools/mach_commands.py
--- a/tools/mach_commands.py
+++ b/tools/mach_commands.py
@@ -11,17 +11,17 @@ import platform
 import errno
 
 from mach.decorators import (
     CommandArgument,
     CommandProvider,
     Command,
 )
 
-from mozbuild.base import MachCommandBase
+from mozbuild.base import MachCommandBase, MozbuildObject
 
 
 @CommandProvider
 class SearchProvider(object):
     @Command('mxr', category='misc',
         description='Search for something in MXR.')
     @CommandArgument('term', nargs='+', help='Term(s) to search for.')
     def mxr(self, term):
@@ -371,8 +371,63 @@ class FormatProvider(MachCommandBase):
             temp = target + ".tmp"
             with open(temp, "wb") as fh:
                 fh.write(data)
                 fh.close()
             os.chmod(temp, os.stat(temp).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
             os.rename(temp, target)
         return target
 
+def mozregression_import():
+    # Lazy loading of mozregression.
+    # Note that only the mach_interface module should be used from this file.
+    try:
+        import mozregression.mach_interface
+    except ImportError:
+        return None
+    return mozregression.mach_interface
+
+
+def mozregression_create_parser():
+    # Create the mozregression command line parser.
+    # if mozregression is not installed, or not up to date, it will
+    # first be installed.
+    cmd = MozbuildObject.from_environment()
+    cmd._activate_virtualenv()
+    mozregression = mozregression_import()
+    if not mozregression:
+        # mozregression is not here at all, install it
+        cmd.virtualenv_manager.install_pip_package('mozregression')
+        print("mozregression was installed. please re-run your"
+              " command.")
+    else:
+        # check if there is a new release available
+        release = mozregression.new_release_on_pypi()
+        if release:
+            print(release)
+            # there is one, so install it. Note that install_pip_package
+            # does not work here, so just run pip directly.
+            cmd.virtualenv_manager._run_pip([
+                'install',
+                'mozregression==%s' % release
+            ])
+            print("mozregression was updated to version %s. please"
+                  " re-run your command." % release)
+        else:
+            # mozregression is up to date, return the parser.
+            return mozregression.parser()
+    # exit if we updated or installed mozregression because
+    # we may have already imported mozregression and running it
+    # as this may cause issues.
+    sys.exit(0)
+
+
+@CommandProvider
+class MozregressionCommand(MachCommandBase):
+    @Command('mozregression',
+             category='misc',
+             description=("Regression range finder for nightly"
+                          " and inbound builds."),
+             parser=mozregression_create_parser)
+    def run(self, **options):
+        self._activate_virtualenv()
+        mozregression = mozregression_import()
+        mozregression.run(options)