servo: Merge #16722 - Add clobber mechanism (from UK992:clobber); r=SimonSapin
authorUK992 <urbankrajnc92@gmail.com>
Mon, 08 May 2017 23:53:05 -0500
changeset 357190 34907be7058c10abbac0b56390aa144ac6d4386e
parent 357189 75ff904cfab108f2091bd5bc19fd37c3310f6bca
child 357191 7b21ef8deef2a879cf3676e0da55b6a141b8fda7
push id31783
push usercbook@mozilla.com
push dateTue, 09 May 2017 12:03:48 +0000
treeherdermozilla-central@b0ff0c5c0a35 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersSimonSapin
bugs16722, 16602, 16632
milestone55.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
servo: Merge #16722 - Add clobber mechanism (from UK992:clobber); r=SimonSapin Solution for https://github.com/servo/servo/issues/16602 and https://github.com/servo/servo/issues/16632 Only work when `AUTOCLOBBER` environment variable is defined. CC @SimonSapin @jdm Source-Repo: https://github.com/servo/servo Source-Revision: 9c9bd178713a1def9bec57e7f96e3365252c0f88
servo/CLOBBER
servo/python/servo/build_commands.py
servo/python/servo/command_base.py
new file mode 100644
--- /dev/null
+++ b/servo/CLOBBER
@@ -0,0 +1,8 @@
+# To trigger a clobber replace ALL of the textual description below,
+# giving a pull request number and a one line description of why a clobber is
+# required.
+#
+# Modifying this file will now automatically clobber the buildbot machines \o/
+#
+
+Pull 16722 - Added CLOBBER file
--- a/servo/python/servo/build_commands.py
+++ b/servo/python/servo/build_commands.py
@@ -19,17 +19,17 @@ import shutil
 from time import time
 
 from mach.decorators import (
     CommandArgument,
     CommandProvider,
     Command,
 )
 
-from servo.command_base import CommandBase, cd, call, BIN_SUFFIX
+from servo.command_base import CommandBase, cd, call, check_call, BIN_SUFFIX
 from servo.util import host_triple
 
 
 def format_duration(seconds):
     return str(datetime.timedelta(seconds=int(seconds)))
 
 
 def notify_linux(title, text):
@@ -223,16 +223,17 @@ class MachCommands(CommandBase):
             opts += ["-v"]
         if android:
             target = self.config["android"]["target"]
 
         if target:
             opts += ["--target", target]
 
         self.ensure_bootstrapped(target=target)
+        self.ensure_clobbered()
 
         if debug_mozjs:
             features += ["debugmozjs"]
 
         if features:
             opts += ["--features", "%s" % ' '.join(features)]
 
         build_start = time()
@@ -355,16 +356,17 @@ class MachCommands(CommandBase):
                      help='Build in release mode')
     @CommandArgument('--with-debug-assertions',
                      default=None,
                      action='store_true',
                      help='Enable debug assertions in release')
     def build_cef(self, jobs=None, verbose=False, release=False,
                   with_debug_assertions=False):
         self.ensure_bootstrapped()
+        self.ensure_clobbered()
 
         ret = None
         opts = []
         if jobs is not None:
             opts += ["-j", jobs]
         if verbose:
             opts += ["-v"]
         if release:
@@ -406,16 +408,17 @@ class MachCommands(CommandBase):
                      action='store_true',
                      help='Print verbose output')
     @CommandArgument('--release', '-r',
                      action='store_true',
                      help='Build in release mode')
     def build_geckolib(self, with_gecko=None, jobs=None, verbose=False, release=False):
         self.set_use_stable_rust()
         self.ensure_bootstrapped()
+        self.ensure_clobbered()
 
         env = self.build_env(is_build=True, geckolib=True)
 
         ret = None
         opts = []
         features = []
         if with_gecko is not None:
             features += ["bindgen"]
@@ -450,19 +453,19 @@ class MachCommands(CommandBase):
     @CommandArgument('--manifest-path',
                      default=None,
                      help='Path to the manifest to the package to clean')
     @CommandArgument('--verbose', '-v',
                      action='store_true',
                      help='Print verbose output')
     @CommandArgument('params', nargs='...',
                      help="Command-line arguments to be passed through to Cargo")
-    def clean(self, manifest_path, params, verbose=False):
+    def clean(self, manifest_path=None, params=[], verbose=False):
         self.ensure_bootstrapped()
 
         opts = []
         if manifest_path:
             opts += ["--manifest-path", manifest_path]
         if verbose:
             opts += ["-v"]
         opts += params
-        return call(["cargo", "clean"] + opts,
-                    env=self.build_env(), cwd=self.servo_crate(), verbose=verbose)
+        return check_call(["cargo", "clean"] + opts,
+                          env=self.build_env(), cwd=self.servo_crate(), verbose=verbose)
--- a/servo/python/servo/command_base.py
+++ b/servo/python/servo/command_base.py
@@ -569,8 +569,35 @@ class CommandBase(object):
         cargo_path = path.join(self.config["tools"]["cargo-root"], "cargo", "bin",
                                "cargo" + BIN_SUFFIX)
         cargo_binary_exists = path.exists(cargo_path)
 
         if not self.config["tools"]["system-cargo"] and not cargo_binary_exists:
             Registrar.dispatch("bootstrap-cargo", context=self.context)
 
         self.context.bootstrapped = True
+
+    def ensure_clobbered(self, target_dir=None):
+        if target_dir is None:
+            target_dir = self.get_target_dir()
+        auto = True if os.environ.get('AUTOCLOBBER', False) else False
+        src_clobber = os.path.join(self.context.topdir, 'CLOBBER')
+        target_clobber = os.path.join(target_dir, 'CLOBBER')
+
+        if not os.path.exists(target_dir):
+            os.makedirs(target_dir)
+
+        if not os.path.exists(target_clobber):
+            # Simply touch the file.
+            with open(target_clobber, 'a'):
+                pass
+
+        if auto:
+            if os.path.getmtime(src_clobber) > os.path.getmtime(target_clobber):
+                print('Automatically clobbering target directory: {}'.format(target_dir))
+
+                try:
+                    Registrar.dispatch("clean", context=self.context, verbose=True)
+                    print('Successfully completed auto clobber.')
+                except subprocess.CalledProcessError as error:
+                    sys.exit(error)
+            else:
+                print("Clobber not needed.")