Bug 1530908 - Move list of supported artifact builds to an importable module. r=chmanchester
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 06 Mar 2019 22:47:32 +0000
changeset 520603 ecc39e015e7a877c37212def591574a4531d11f1
parent 520602 6b25ace491c34353e04b75ae443bf8c640f00699
child 520604 61dd01ed9002ad05dd35640fdbc770e03b7f7c76
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1530908
milestone67.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 1530908 - Move list of supported artifact builds to an importable module. r=chmanchester Depends on D22054 Differential Revision: https://phabricator.services.mozilla.com/D22055
python/mozbuild/mozbuild/artifact_builds.py
python/mozbuild/mozbuild/artifacts.py
python/mozbuild/mozbuild/mach_commands.py
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/artifact_builds.py
@@ -0,0 +1,31 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# 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/.
+
+# The values correspond to entries at
+# https://tools.taskcluster.net/index/artifacts/#gecko.v2.mozilla-central.latest/gecko.v2.mozilla-central.latest
+JOB_CHOICES = {
+    'android-api-16-opt',
+    'android-api-16-debug',
+    'android-x86-opt',
+    'android-x86_64-opt',
+    'android-x86_64-debug',
+    'android-aarch64-opt',
+    'android-aarch64-debug',
+    'linux-opt',
+    'linux-pgo',
+    'linux-debug',
+    'linux64-opt',
+    'linux64-pgo',
+    'linux64-debug',
+    'macosx64-opt',
+    'macosx64-debug',
+    'win32-opt',
+    'win32-pgo',
+    'win32-debug',
+    'win64-opt',
+    'win64-pgo',
+    'win64-debug',
+    'win64-aarch64-opt',
+    'win64-aarch64-debug',
+}
--- a/python/mozbuild/mozbuild/artifacts.py
+++ b/python/mozbuild/mozbuild/artifacts.py
@@ -63,16 +63,17 @@ import zipfile
 
 import pylru
 from taskgraph.util.taskcluster import (
     find_task_id,
     get_artifact_url,
     list_artifacts,
 )
 
+from mozbuild.artifact_builds import JOB_CHOICES
 from mozbuild.util import (
     ensureParentDir,
     FileAvoidWrite,
     mkdir,
 )
 import mozinstall
 from mozpack.files import (
     JarFinder,
@@ -528,44 +529,31 @@ class WinArtifactJob(ArtifactJob):
                 writer.add(basename.encode('utf-8'), f.open(), mode=f.mode)
                 added_entry = True
 
         if not added_entry:
             raise ValueError('Archive format changed! No pattern from "{patterns}"'
                              'matched an archive path.'.format(
                                  patterns=self.artifact_patterns))
 
-# Keep the keys of this map in sync with the |mach artifact| --job
-# options.  The keys of this map correspond to entries at
-# https://tools.taskcluster.net/index/artifacts/#gecko.v2.mozilla-central.latest/gecko.v2.mozilla-central.latest
-# The values correpsond to a pair of (<package regex>, <test archive regex>).
+
+def startswithwhich(s, prefixes):
+    for prefix in prefixes:
+        if s.startswith(prefix):
+            return prefix
+
+
 JOB_DETAILS = {
-    'android-api-16-opt': AndroidArtifactJob,
-    'android-api-16-debug': AndroidArtifactJob,
-    'android-x86-opt': AndroidArtifactJob,
-    'android-x86_64-opt': AndroidArtifactJob,
-    'android-x86_64-debug': AndroidArtifactJob,
-    'android-aarch64-opt': AndroidArtifactJob,
-    'android-aarch64-debug': AndroidArtifactJob,
-    'linux-opt': LinuxArtifactJob,
-    'linux-pgo': LinuxArtifactJob,
-    'linux-debug': LinuxArtifactJob,
-    'linux64-opt': LinuxArtifactJob,
-    'linux64-pgo': LinuxArtifactJob,
-    'linux64-debug': LinuxArtifactJob,
-    'macosx64-opt': MacArtifactJob,
-    'macosx64-debug': MacArtifactJob,
-    'win32-opt': WinArtifactJob,
-    'win32-pgo': WinArtifactJob,
-    'win32-debug': WinArtifactJob,
-    'win64-opt': WinArtifactJob,
-    'win64-pgo': WinArtifactJob,
-    'win64-debug': WinArtifactJob,
-    'win64-aarch64-opt': WinArtifactJob,
-    'win64-aarch64-debug': WinArtifactJob,
+    j: {
+        'android': AndroidArtifactJob,
+        'linux': LinuxArtifactJob,
+        'macosx': MacArtifactJob,
+        'win': WinArtifactJob,
+    }[startswithwhich(j, ('android', 'linux', 'macosx', 'win'))]
+    for j in JOB_CHOICES
 }
 
 
 
 def cachedmethod(cachefunc):
     '''Decorator to wrap a class or instance method with a memoizing callable that
     saves results in a (possibly shared) cache.
     '''
--- a/python/mozbuild/mozbuild/mach_commands.py
+++ b/python/mozbuild/mozbuild/mach_commands.py
@@ -29,16 +29,17 @@ from mach.decorators import (
     CommandProvider,
     Command,
     SettingsProvider,
     SubCommand,
 )
 
 from mach.main import Mach
 
+from mozbuild.artifact_builds import JOB_CHOICES
 from mozbuild.base import (
     BuildEnvironmentNotFoundException,
     MachCommandBase,
     MachCommandConditions as conditions,
     MozbuildObject,
 )
 from mozbuild.util import ensureParentDir
 
@@ -1180,43 +1181,16 @@ class MachDebug(MachCommandBase):
                         result['defines'] = obj.defines
                     return result
                 elif isinstance(obj, set):
                     return list(obj)
                 return json.JSONEncoder.default(self, obj)
         json.dump(self, cls=EnvironmentEncoder, sort_keys=True, fp=out)
 
 
-JOB_CHOICES = {
-    'android-api-16-opt',
-    'android-api-16-debug',
-    'android-x86-opt',
-    'android-x86_64-opt',
-    'android-x86_64-debug',
-    'android-aarch64-opt',
-    'android-aarch64-debug',
-    'linux-opt',
-    'linux-pgo',
-    'linux-debug',
-    'linux64-opt',
-    'linux64-pgo',
-    'linux64-debug',
-    'macosx64-opt',
-    'macosx64-debug',
-    'win32-opt',
-    'win32-pgo',
-    'win32-debug',
-    'win64-opt',
-    'win64-pgo',
-    'win64-debug',
-    'win64-aarch64-opt',
-    'win64-aarch64-debug',
-}
-
-
 class ArtifactSubCommand(SubCommand):
     def __call__(self, func):
         after = SubCommand.__call__(self, func)
         args = [
             CommandArgument('--tree', metavar='TREE', type=str,
                 help='Firefox tree.'),
             CommandArgument('--job', metavar='JOB', choices=JOB_CHOICES,
                 help='Build job.'),
@@ -1257,22 +1231,17 @@ class PackageFrontend(MachCommandBase):
         hg = None
         if conditions.is_hg(self):
             hg = self.substs['HG']
 
         git = None
         if conditions.is_git(self):
             git = self.substs['GIT']
 
-        from mozbuild.artifacts import (Artifacts, JOB_DETAILS)
-        # We can't derive JOB_CHOICES from JOB_DETAILS because we don't want to
-        # import the artifacts module globally ; and this module can't be
-        # imported in unit tests, so do the check here.
-        assert set(JOB_DETAILS.keys()) == JOB_CHOICES
-
+        from mozbuild.artifacts import Artifacts
         artifacts = Artifacts(tree, self.substs, self.defines, job,
                               log=self.log, cache_dir=cache_dir,
                               skip_cache=skip_cache, hg=hg, git=git,
                               topsrcdir=self.topsrcdir,
                               download_tests=download_tests,
                               download_symbols=download_symbols,
                               download_host_bins=download_host_bins)
         return artifacts