[buildbot] clean-build script should remove untracked files and revert local changes too
authoryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Jan 2016 14:00:00 +0000 (14:00 +0000)
committeryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Jan 2016 14:00:00 +0000 (14:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142400

Reviewed by Ryosuke Niwa.

This patch cleans the WebKit folder by reverting tracked files changes and deleting SCM untracked files, including SCM ignored files.
A helper routine SCM.discard_untracked_files is added for that purpose.

* BuildSlaveSupport/clean-build:
(main): Making call to Scripts/clean-webkit
* Scripts/clean-webkit: Added.
(main): Revert changes and delete untracked files.
* Scripts/webkitpy/common/checkout/scm/scm.py:
(SCM.discard_untracked_files): Helper function to discard untracked files or folders found by SCM.
* Scripts/webkitpy/common/checkout/scm/scm_unittest.py:
(SCMTest._shared_test_discard_untracked_files):
(test_discard_untracked_files): Tests that untracked file and untracked folder get discarded correctly.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@194696 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/BuildSlaveSupport/clean-build
Tools/ChangeLog
Tools/Scripts/clean-webkit [new file with mode: 0755]
Tools/Scripts/webkitpy/common/checkout/scm/scm.py
Tools/Scripts/webkitpy/common/checkout/scm/scm_unittest.py

index 1ff6bb0..d9f0a15 100755 (executable)
@@ -53,7 +53,10 @@ def main():
     webkit_build_directory = subprocess.Popen(['perl', os.path.join(os.path.dirname(__file__), "..", "Scripts", "webkit-build-directory"),
         "--" + platform, "--" + options.configuration, '--top-level'], stdout=subprocess.PIPE).communicate()[0].strip()
 
-    shutil.rmtree(webkit_build_directory)
+    if (os.path.isdir(webkit_build_directory)):
+        shutil.rmtree(webkit_build_directory)
+
+    subprocess.Popen(['python', os.path.join(os.path.dirname(__file__), "..", "Scripts", "clean-webkit")])
 
 if __name__ == '__main__':
     sys.exit(main())
index 45d789f..e1995f5 100644 (file)
@@ -1,3 +1,23 @@
+2016-01-07  Youenn Fablet  <youenn.fablet@crf.canon.fr>
+
+        [buildbot] clean-build script should remove untracked files and revert local changes too
+        https://bugs.webkit.org/show_bug.cgi?id=142400
+
+        Reviewed by Ryosuke Niwa.
+
+        This patch cleans the WebKit folder by reverting tracked files changes and deleting SCM untracked files, including SCM ignored files.
+        A helper routine SCM.discard_untracked_files is added for that purpose.
+
+        * BuildSlaveSupport/clean-build:
+        (main): Making call to Scripts/clean-webkit
+        * Scripts/clean-webkit: Added.
+        (main): Revert changes and delete untracked files.
+        * Scripts/webkitpy/common/checkout/scm/scm.py:
+        (SCM.discard_untracked_files): Helper function to discard untracked files or folders found by SCM.
+        * Scripts/webkitpy/common/checkout/scm/scm_unittest.py:
+        (SCMTest._shared_test_discard_untracked_files):
+        (test_discard_untracked_files): Tests that untracked file and untracked folder get discarded correctly.
+
 2016-01-06  Simon Fraser  <simon.fraser@apple.com>
 
         Add a setting and preferences to enable display-list drawing. Does nothing yet.
diff --git a/Tools/Scripts/clean-webkit b/Tools/Scripts/clean-webkit
new file mode 100755 (executable)
index 0000000..0a54166
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+# Copyright (C) 2015 Canon Incorporated. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above
+#    copyright notice, this list of conditions and the following
+#    disclaimer.
+# 2. Redistributions in binary form must reproduce the above
+#    copyright notice, this list of conditions and the following
+#    disclaimer in the documentation and/or other materials
+#    provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+import sys
+
+from webkitpy.common.checkout.scm.detection import SCMDetector
+from webkitpy.common.host import Host
+from webkitpy.common.system.filesystem import FileSystem
+
+
+def main():
+    fs = FileSystem()
+    host = Host()
+    scm = SCMDetector(fs, host.executive).detect_scm_system(fs.getcwd())
+    
+    scm.discard_working_directory_changes()
+    scm.discard_untracked_files(discard_ignored_files=True)
+
+
+sys.exit(main())
index 8b8e53e..eb77c22 100644 (file)
@@ -207,6 +207,13 @@ class SCM:
     def untracked_files(self, include_ignored_files=False):
         self._subclass_must_implement()
 
+    def discard_untracked_files(self, discard_ignored_files=False):
+        for filename in self.untracked_files(discard_ignored_files):
+            if self._filesystem.isdir(filename):
+                self._filesystem.rmtree(filename)
+            else:
+                self._filesystem.remove(filename)
+
     def discard_working_directory_changes(self):
         self._subclass_must_implement()
 
index 44c6fcf..96ac565 100644 (file)
@@ -332,6 +332,28 @@ class SCMTest(unittest.TestCase):
         os.remove("test_file_new")
         os.remove("test_file_new.pyc")
 
+    def _shared_test_discard_untracked_files(self, scm):
+        write_into_file_at_path("test_file_new", "new content")
+        os.mkdir("test_dir_new")
+        write_into_file_at_path("test_dir_new/test_file_new", "new stuff")
+        self.assertItemsEqual(scm.untracked_files(), ["test_dir_new", "test_file_new"])
+        scm.discard_untracked_files()
+        self.assertItemsEqual(scm.untracked_files(), [])
+
+        write_into_file_at_path("test_file_new.pyc", "new content")
+        self.assertItemsEqual(scm.untracked_files(True), ["test_file_new.pyc"])
+        scm.discard_untracked_files(discard_ignored_files=False)
+        self.assertItemsEqual(scm.untracked_files(True), ["test_file_new.pyc"])
+        scm.discard_untracked_files(discard_ignored_files=True)
+        self.assertItemsEqual(scm.untracked_files(True), [])
+
+        if os.path.isdir("test_dir_new"):
+            shutil.rmtree("test_dir_new")
+        if os.path.isfile("test_file_new"):
+            os.remove("test_file_new")
+        if os.path.isfile("test_file_new.pyc"):
+            os.remove("test_file_new.pyc")
+
     def _shared_test_added_files(self):
         write_into_file_at_path("test_file", "changed content")
         self.assertItemsEqual(self.scm.added_files(), [])
@@ -832,6 +854,9 @@ END
     def test_untracked_files(self):
         self._shared_test_untracked_files(self.scm)
 
+    def test_discard_untracked_files(self):
+        self._shared_test_discard_untracked_files(self.scm)
+
     def test_changed_files_for_revision(self):
         self._shared_test_changed_files_for_revision()