From 55dced2da0f48110bc320c09ede7632bd5b1d7f2 Mon Sep 17 00:00:00 2001
From: Chris Manchester <cmanchester@mozilla.com>
Date: Thu, 11 Oct 2018 19:16:49 +0000
Subject: [PATCH] Bug 1497359 - Detect and reject re-use of objdirs between
 Make and Tup in configure. r=froydnj

Differential Revision: https://phabricator.services.mozilla.com/D8289

--HG--
extra : moz-landing-system : lando
---
 moz.configure                                 | 21 +++++++++++++++++++
 .../mozbuild/mozbuild/controller/building.py  | 10 ---------
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/moz.configure b/moz.configure
index 03058785f5638..750198c742189 100755
--- a/moz.configure
+++ b/moz.configure
@@ -287,6 +287,27 @@ def build_backends(backends):
 
 set_config('BUILD_BACKENDS', build_backends)
 
+
+@depends(check_build_environment, build_backends)
+@imports('glob')
+def check_objdir_backend_reuse(build_env, backends):
+    # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
+    # intentionally vague for use with the substring match below.
+    incompatible_backends = (
+        ('Tup', 'Make'),
+        ('Make', 'Tup')
+    )
+    for backend_file in glob.iglob(os.path.join(build_env.topobjdir,
+                                                'backend.*Backend')):
+        for prev, curr in incompatible_backends:
+            if prev in backend_file and any(curr in b for b in backends):
+                die("The active objdir, %s, was previously "
+                    "used to build with a %s based backend. "
+                    "Change objdirs (by setting MOZ_OBJDIR in "
+                    "your mozconfig) or clobber to continue.\n",
+                    build_env.topobjdir, prev)
+
+
 option('--disable-gtest-in-build',
        help='Force disable building the gtest libxul during the build.',
        when='--enable-compile-environment')
diff --git a/python/mozbuild/mozbuild/controller/building.py b/python/mozbuild/mozbuild/controller/building.py
index 81cba232e36bf..bcacd3f8ffaa4 100644
--- a/python/mozbuild/mozbuild/controller/building.py
+++ b/python/mozbuild/mozbuild/controller/building.py
@@ -1050,16 +1050,6 @@ class BuildDriver(MozbuildObject):
             status = None
             active_backend = config.substs.get('BUILD_BACKENDS', [None])[0]
             if active_backend and 'Make' not in active_backend:
-                for backend_file in glob.iglob(mozpath.join(self.topobjdir,
-                                                            'backend.*Backend')):
-                    if 'Make' in backend_file:
-                        self.log(logging.ERROR, 'backend',
-                                 {'objdir': self.topobjdir},
-                                 "The active objdir, {objdir}, was previously "
-                                 "used to build with a Make-based backend. "
-                                 "Change objdirs (by setting MOZ_OBJDIR in "
-                                 "your mozconfig) to continue.\n")
-                        return 1
                 # Record whether a clobber was requested so we can print
                 # a special message later if the build fails.
                 clobber_requested = False
-- 
GitLab