Bug 1279048 - Check MOZ_SOURCE_REPO for repository URL; r?ted draft
authorGregory Szorc <gps@mozilla.com>
Wed, 08 Jun 2016 14:54:58 -0700
changeset 411309 0263ef26e528940a7956c8c807c216cc749a01b2
parent 411277 ab70808cd4b6c6ad9a57a9f71cfa495fcea0aecd
child 530719 13fa47fe49b938fb9c880f749b841baec38753ea
push id28883
push userbmo:gps@mozilla.com
push dateWed, 07 Sep 2016 23:36:03 +0000
reviewersted
bugs1279048
milestone51.0a1
Bug 1279048 - Check MOZ_SOURCE_REPO for repository URL; r?ted MOZ_SOURCE_REPO is set by automation to indicate the URL of the current repository. I'm not sure what SRCSRV_ROOT is from. Probably legacy. Use MOZ_SOURCE_REPO instead of SRCSRV_ROOT. MozReview-Commit-ID: IfCSiaqgJb5
toolkit/crashreporter/tools/symbolstore.py
toolkit/crashreporter/tools/unit-symbolstore.py
--- a/toolkit/crashreporter/tools/symbolstore.py
+++ b/toolkit/crashreporter/tools/symbolstore.py
@@ -131,21 +131,25 @@ rootRegex = re.compile(r'^\S+?:/+(?:[^\s
 
 def read_output(*args):
     (stdout, _) = subprocess.Popen(args=args, stdout=subprocess.PIPE).communicate()
     return stdout.rstrip()
 
 class HGRepoInfo:
     def __init__(self, path):
         self.path = path
-        rev = read_output('hg', '-R', path,
-                          'parent', '--template={node|short}')
-        # Look for the default hg path.  If SRVSRV_ROOT is set, we
+
+        rev = os.environ.get('MOZ_SOURCE_CHANGESET')
+        if not rev:
+            rev = read_output('hg', '-R', path,
+                              'parent', '--template={node|short}')
+
+        # Look for the default hg path. If MOZ_SOURCE_REPO is set, we
         # don't bother asking hg.
-        hg_root = os.environ.get("SRCSRV_ROOT")
+        hg_root = os.environ.get('MOZ_SOURCE_REPO')
         if hg_root:
             root = hg_root
         else:
             root = read_output('hg', '-R', path,
                                'showconfig', 'paths.default')
             if not root:
                 print >> sys.stderr, "Failed to get HG Repo for %s" % path
         cleanroot = None
@@ -153,17 +157,17 @@ class HGRepoInfo:
             match = rootRegex.match(root)
             if match:
                 cleanroot = match.group(1)
                 if cleanroot.endswith('/'):
                     cleanroot = cleanroot[:-1]
         if cleanroot is None:
             print >> sys.stderr, textwrap.dedent("""\
                 Could not determine repo info for %s.  This is either not a clone of the web-based
-                repository, or you have not specified SRCSRV_ROOT, or the clone is corrupt.""") % path
+                repository, or you have not specified MOZ_SOURCE_REPO, or the clone is corrupt.""") % path
             sys.exit(1)
         self.rev = rev
         self.root = root
         self.cleanroot = cleanroot
 
     def GetFileInfo(self, file):
         return HGFileInfo(file, self)
 
@@ -200,17 +204,17 @@ class GitRepoInfo:
             match = rootRegex.match(root)
             if match:
                 cleanroot = match.group(1)
                 if cleanroot.endswith('/'):
                     cleanroot = cleanroot[:-1]
         if cleanroot is None:
             print >> sys.stderr, textwrap.dedent("""\
                 Could not determine repo info for %s (%s).  This is either not a clone of a web-based
-                repository, or you have not specified SRCSRV_ROOT, or the clone is corrupt.""") % (path, root)
+                repository, or you have not specified MOZ_SOURCE_REPO, or the clone is corrupt.""") % (path, root)
             sys.exit(1)
         self.rev = rev
         self.cleanroot = cleanroot
 
     def GetFileInfo(self, file):
         return GitFileInfo(file, self)
 
 class GitFileInfo(VCSFileInfo):
@@ -609,17 +613,17 @@ class Dumper:
         in the proper directory structure in  |symbol_path|; processing is performed
         asynchronously, and Finish must be called to wait for it complete and cleanup.
         All files after the first are fallbacks in case the first file does not process
         successfully; if it does, no other files will be touched."""
         self.output_pid(sys.stderr, "Submitting jobs for files: %s" % str(files))
 
         # tries to get the vcs root from the .mozconfig first - if it's not set
         # the tinderbox vcs path will be assigned further down
-        vcs_root = os.environ.get("SRCSRV_ROOT")
+        vcs_root = os.environ.get('MOZ_SOURCE_REPO')
         for arch_num, arch in enumerate(self.archs):
             self.files_record[files] = 0 # record that we submitted jobs for this tuple of files
             self.SubmitJob(files[-1], 'ProcessFilesWork', args=(files, arch_num, arch, vcs_root, after, after_arg), callback=self.ProcessFilesFinished)
 
     def dump_syms_cmdline(self, file, arch, files):
         '''
         Get the commandline used to invoke dump_syms.
         '''
--- a/toolkit/crashreporter/tools/unit-symbolstore.py
+++ b/toolkit/crashreporter/tools/unit-symbolstore.py
@@ -54,16 +54,23 @@ class HelperMixin(object):
     """
     def setUp(self):
         self.test_dir = tempfile.mkdtemp()
         if not self.test_dir.endswith(os.sep):
             self.test_dir += os.sep
         symbolstore.srcdirRepoInfo = {}
         symbolstore.vcsFileInfoCache = {}
 
+        # Remove environment variables that can influence tests.
+        for e in ('MOZ_SOURCE_CHANGESET', 'MOZ_SOURCE_REPO'):
+            try:
+                del os.environ[e]
+            except KeyError:
+                pass
+
     def tearDown(self):
         shutil.rmtree(self.test_dir)
         symbolstore.srcdirRepoInfo = {}
         symbolstore.vcsFileInfoCache = {}
 
     def make_dirs(self, f):
         d = os.path.dirname(f)
         if d and not os.path.exists(d):
@@ -259,16 +266,26 @@ class TestGetVCSFilename(HelperMixin, un
         os.makedirs(os.path.join(srcdir2, ".hg"))
         filename1 = os.path.join(srcdir1, "foo.c")
         filename2 = os.path.join(srcdir2, "bar.c")
         self.assertEqual("hg:example.com/repo:foo.c:abcd1234",
                          symbolstore.GetVCSFilename(filename1, [srcdir1, srcdir2])[0])
         self.assertEqual("hg:example.com/other:bar.c:0987ffff",
                          symbolstore.GetVCSFilename(filename2, [srcdir1, srcdir2])[0])
 
+    def testVCSFilenameEnv(self):
+        # repo URL and changeset read from environment variables if defined.
+        os.environ['MOZ_SOURCE_REPO'] = 'https://somewhere.com/repo'
+        os.environ['MOZ_SOURCE_CHANGESET'] = 'abcdef0123456'
+        os.mkdir(os.path.join(self.test_dir, '.hg'))
+        filename = os.path.join(self.test_dir, 'foo.c')
+        self.assertEqual('hg:somewhere.com/repo:foo.c:abcdef0123456',
+                         symbolstore.GetVCSFilename(filename, [self.test_dir])[0])
+
+
 class TestRepoManifest(HelperMixin, unittest.TestCase):
     def testRepoManifest(self):
         manifest = os.path.join(self.test_dir, "sources.xml")
         open(manifest, "w").write("""<?xml version="1.0" encoding="UTF-8"?>
 <manifest>
 <remote fetch="http://example.com/foo/" name="foo"/>
 <remote fetch="git://example.com/bar/" name="bar"/>
 <default remote="bar"/>