Bug 1253651 - Undo changes to PATH made by activating virtualenv in mach artifact. r=glandium draft
authorChris Manchester <cmanchester@mozilla.com>
Fri, 04 Mar 2016 14:45:00 -0800
changeset 337236 199d3b01fc49b2760ee14a08d4400a1addf83eac
parent 337224 46210f3ae07855edfe1383210d78433e38a6b564
child 515611 37079bad733a8d2647096421516ab020c8cd79c0
push id12301
push usercmanchester@mozilla.com
push dateSun, 06 Mar 2016 19:48:25 +0000
reviewersglandium
bugs1253651
milestone47.0a1
Bug 1253651 - Undo changes to PATH made by activating virtualenv in mach artifact. r=glandium The changes made to PATH by activating the in-tree virtualenv cause some git-cinnabar commands in subprocesses to fail, because git cinnabar is expecting mercurial to be installed, while it is not available from the in-tree virtualenv. To work around this, the changes to PATH made by virtualenv are undone, allowing git-cinnabar to find system python, which is likely to have mercurial installed. MozReview-Commit-ID: 47ceHvMmuyf
python/mozbuild/mozbuild/artifacts.py
python/mozbuild/mozbuild/mach_commands.py
--- a/python/mozbuild/mozbuild/artifacts.py
+++ b/python/mozbuild/mozbuild/artifacts.py
@@ -722,19 +722,16 @@ class Artifacts(object):
         if (hg and git) or (not hg and not git):
             raise ValueError("Must provide path to exactly one of hg and git")
 
         self._tree = tree
         self._job = job or self._guess_artifact_job()
         self._log = log
         self._hg = hg
         self._git = git
-        if self._git:
-            import which
-            self._cinnabar = which.which('git-cinnabar')
         self._cache_dir = cache_dir
         self._skip_cache = skip_cache
 
         try:
             self._artifact_job = get_job_details(self._job, log=self._log)
         except KeyError:
             self.log(logging.INFO, 'artifact',
                 {'job': self._job},
@@ -816,17 +813,17 @@ class Artifacts(object):
 
         # First commit is HEAD, next is HEAD~1, etc.
         rev_list = subprocess.check_output([
             self._git, 'rev-list', '--topo-order',
             'HEAD~{num}..HEAD'.format(num=NUM_REVISIONS_TO_QUERY),
         ])
 
         hg_hash_list = subprocess.check_output([
-            self._cinnabar, 'git2hg'
+            self._git, 'cinnabar', 'git2hg'
         ] + rev_list.splitlines())
 
         zeroes = "0" * 40
 
         hashes = []
         for hg_hash in hg_hash_list.splitlines():
             hg_hash = hg_hash.strip()
             if not hg_hash or hg_hash == zeroes:
@@ -986,17 +983,17 @@ class Artifacts(object):
     def install_from_revset(self, revset, distdir):
         if self._hg:
             revision = subprocess.check_output([self._hg, 'log', '--template', '{node}\n',
                                                 '-r', revset]).strip()
             if len(revision.split('\n')) != 1:
                 raise ValueError('hg revision specification must resolve to exactly one commit')
         else:
             revision = subprocess.check_output([self._git, 'rev-parse', revset]).strip()
-            revision = subprocess.check_output([self._cinnabar, 'git2hg', revision]).strip()
+            revision = subprocess.check_output([self._git, 'cinnabar', 'git2hg', revision]).strip()
             if len(revision.split('\n')) != 1:
                 raise ValueError('hg revision specification must resolve to exactly one commit')
             if revision == "0" * 40:
                 raise ValueError('git revision specification must resolve to a commit known to hg')
 
         self.log(logging.INFO, 'artifact',
                  {'revset': revset,
                   'revision': revision},
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -1484,17 +1484,22 @@ class PackageFrontend(MachCommandBase):
 
         '''
         pass
 
     def _set_log_level(self, verbose):
         self.log_manager.terminal_handler.setLevel(logging.INFO if not verbose else logging.DEBUG)
 
     def _make_artifacts(self, tree=None, job=None, skip_cache=False):
+        # Undo PATH munging that will be done by activating the virtualenv,
+        # so that invoked subprocesses expecting to find system python
+        # (git cinnabar, in particular), will not find virtualenv python.
+        original_path = os.environ.get('PATH', '')
         self._activate_virtualenv()
+        os.environ['PATH'] = original_path
         self.virtualenv_manager.install_pip_package('pylru==1.0.9')
         self.virtualenv_manager.install_pip_package('taskcluster==0.0.32')
         self.virtualenv_manager.install_pip_package('mozregression==1.0.2')
 
         state_dir = self._mach_context.state_dir
         cache_dir = os.path.join(state_dir, 'package-frontend')
 
         try: