diff --git a/build/mozconfig.common b/build/mozconfig.common index 1dfff9deeb26..e329737d363f 100644 --- a/build/mozconfig.common +++ b/build/mozconfig.common @@ -9,3 +9,5 @@ # architectures, though note that if you want to override options set in # another mozconfig file, you'll need to use mozconfig.common.override instead # of this file. + +mk_add_options AUTOCLOBBER=1 diff --git a/client.mk b/client.mk index 6e52b8bb348c..a9d24e3be61f 100644 --- a/client.mk +++ b/client.mk @@ -108,8 +108,8 @@ endef # before evaluation. $(eval $(subst ||,$(CR),$(shell _PYMAKE=$(.PYMAKE) $(TOPSRCDIR)/$(MOZCONFIG_LOADER) $(TOPSRCDIR) 2> $(TOPSRCDIR)/.mozconfig.out | sed 's/$$/||/'))) -ifdef NO_AUTOCLOBBER -export NO_AUTOCLOBBER=1 +ifdef AUTOCLOBBER +export AUTOCLOBBER=1 endif # Automatically add -jN to make flags if not defined. N defaults to number of cores. diff --git a/python/mozbuild/mozbuild/controller/clobber.py b/python/mozbuild/mozbuild/controller/clobber.py index ccfbce341834..2a4ae2622b42 100644 --- a/python/mozbuild/mozbuild/controller/clobber.py +++ b/python/mozbuild/mozbuild/controller/clobber.py @@ -97,7 +97,7 @@ class Clobberer(object): with open(self.obj_clobber, 'a'): pass - def maybe_do_clobber(self, cwd, allow_auto=True, fh=sys.stderr): + def maybe_do_clobber(self, cwd, allow_auto=False, fh=sys.stderr): """Perform a clobber if it is required. Maybe. This is the API the build system invokes to determine if a clobber @@ -120,15 +120,15 @@ class Clobberer(object): return False, False, None # So a clobber is needed. We only perform a clobber if we are - # allowed to perform an automatic clobber (the default) and if the + # allowed to perform an automatic clobber (off by default) and if the # current directory is not under the object directory. The latter is # because operating systems, filesystems, and shell can throw fits # if the current working directory is deleted from under you. While it # can work in some scenarios, we take the conservative approach and # never try. if not allow_auto: - return True, False, self._message( - 'Automatic clobbering has been disabled.') + return True, False, self._message('Automatic clobbering is not ' + 'enabled (add "mk_add_options AUTOCLOBBER=1" to your mozconfig).') if cwd.startswith(self.topobjdir) and cwd != self.topobjdir: return True, False, self._message( @@ -175,7 +175,7 @@ def main(args, env, cwd, fh=sys.stderr): if not os.path.isabs(topobjdir): topobjdir = os.path.abspath(topobjdir) - auto = False if env.get('NO_AUTOCLOBBER', False) else True + auto = True if env.get('AUTOCLOBBER', False) else False clobber = Clobberer(topsrcdir, topobjdir) required, performed, message = clobber.maybe_do_clobber(cwd, auto, fh) diff --git a/python/mozbuild/mozbuild/test/controller/test_clobber.py b/python/mozbuild/mozbuild/test/controller/test_clobber.py index c95d7dcb46da..76b9c158b275 100644 --- a/python/mozbuild/mozbuild/test/controller/test_clobber.py +++ b/python/mozbuild/mozbuild/test/controller/test_clobber.py @@ -52,7 +52,7 @@ class TestClobberer(unittest.TestCase): self.assertFalse(c.clobber_needed()) # Side-effect is topobjdir is created with CLOBBER file touched. - required, performed, reason = c.maybe_do_clobber(os.getcwd()) + required, performed, reason = c.maybe_do_clobber(os.getcwd(), True) self.assertFalse(required) self.assertFalse(performed) self.assertIsNone(reason) @@ -66,7 +66,7 @@ class TestClobberer(unittest.TestCase): c = Clobberer(self.get_topsrcdir(), self.get_tempdir()) self.assertFalse(c.clobber_needed()) - required, performed, reason = c.maybe_do_clobber(os.getcwd()) + required, performed, reason = c.maybe_do_clobber(os.getcwd(), True) self.assertFalse(required) self.assertFalse(performed) self.assertIsNone(reason) @@ -80,7 +80,7 @@ class TestClobberer(unittest.TestCase): with open(c.obj_clobber, 'a'): pass - required, performed, reason = c.maybe_do_clobber(os.getcwd()) + required, performed, reason = c.maybe_do_clobber(os.getcwd(), True) self.assertFalse(required) self.assertFalse(performed) self.assertIsNone(reason) @@ -103,13 +103,7 @@ class TestClobberer(unittest.TestCase): self.assertTrue(c.clobber_needed()) - required, performed, reason = c.maybe_do_clobber(os.getcwd(), False) - self.assertTrue(required) - self.assertFalse(performed) - self.assertIn('Automatic clobbering has been disabled', reason) - - # Now let's actually do it. - required, performed, reason = c.maybe_do_clobber(os.getcwd()) + required, performed, reason = c.maybe_do_clobber(os.getcwd(), True) self.assertTrue(required) self.assertTrue(performed) @@ -148,7 +142,7 @@ class TestClobberer(unittest.TestCase): self.assertTrue(c.clobber_needed()) - required, performed, reason = c.maybe_do_clobber(c.topobjdir) + required, performed, reason = c.maybe_do_clobber(c.topobjdir, True) self.assertTrue(required) self.assertTrue(performed) @@ -169,14 +163,14 @@ class TestClobberer(unittest.TestCase): d = os.path.join(c.topobjdir, 'dummy_dir') os.mkdir(d) - required, performed, reason = c.maybe_do_clobber(d) + required, performed, reason = c.maybe_do_clobber(d, True) self.assertTrue(required) self.assertFalse(performed) self.assertIn('Cannot clobber while the shell is inside', reason) - def test_mozconfig_overrides_auto_clobber(self): - """If NO_AUTOCLOBBER is in the environment, don't auto clobber.""" + def test_mozconfig_opt_in(self): + """Auto clobber iff AUTOCLOBBER is in the environment.""" topsrcdir = self.get_topsrcdir() topobjdir = self.get_tempdir() @@ -194,15 +188,26 @@ class TestClobberer(unittest.TestCase): old_time = os.path.getmtime(os.path.join(topsrcdir, 'CLOBBER')) - 60 os.utime(obj_clobber, (old_time, old_time)) + # Check auto clobber is off by default env = dict(os.environ) - env['NO_AUTOCLOBBER'] = '1' + if env.get('AUTOCLOBBER', False): + del env['AUTOCLOBBER'] s = StringIO() status = clobber([topsrcdir, topobjdir], env, os.getcwd(), s) self.assertEqual(status, 1) - self.assertIn('Automatic clobbering has been disabled', s.getvalue()) + self.assertIn('Automatic clobbering is not enabled', s.getvalue()) self.assertTrue(os.path.exists(dummy_file)) + # Check auto clobber opt-in works + env['AUTOCLOBBER'] = '1' + + s = StringIO() + status = clobber([topsrcdir, topobjdir], env, os.getcwd(), s) + self.assertEqual(status, 1) + self.assertIn('Successfully completed auto clobber', s.getvalue()) + self.assertFalse(os.path.exists(dummy_file)) + if __name__ == '__main__': main()