[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>
Sun, 29 Mar 2015 18:47:04 +0000 (18:47 +0000)
committeryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 29 Mar 2015 18:47:04 +0000 (18:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142400

Reviewed by Ryosuke Niwa.

This patch cleans the WebKit folder by deleting SCM untracked files and reverting changes for tracked files.

* BuildSlaveSupport/clean-build:
(main): Adding call to Tools/Scripts/clean-webkit.
* Scripts/clean-webkit: Added.
(main): Removes untracked and changed files.
* Scripts/webkitpy/common/checkout/scm/git.py:
(Git.untracked_files): Retrieves GIT untracked files.
* Scripts/webkitpy/common/checkout/scm/scm.py:
(SCM.untracked_files): Retrieves SVN untracked files.
(SCM):
(SCM.discard_untracked_files): Deletes untracked files/folders.
* Scripts/webkitpy/common/checkout/scm/scm_unittest.py:
(SCMTest._shared_test_untracked_files): Unit testing for untracked files.
(test_untracked_files):
(GitSVNTest.test_untracked_files):
* Scripts/webkitpy/common/checkout/scm/svn.py:
(SVN.untracked_files):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182119 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/git.py
Tools/Scripts/webkitpy/common/checkout/scm/scm.py
Tools/Scripts/webkitpy/common/checkout/scm/scm_unittest.py
Tools/Scripts/webkitpy/common/checkout/scm/svn.py

index eaecb121977b621ed7e207297dcf2e7f96e594db..8108407a57425e3163a2ef2841c40754332a783e 100755 (executable)
@@ -50,5 +50,7 @@ def main():
 
     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 49457fa719cb885b690c456653dd0d5f6a1bbb4b..dd876a53a60d9d250247aabdb3278e7072db122b 100644 (file)
@@ -1,3 +1,29 @@
+2015-03-29  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 deleting SCM untracked files and reverting changes for tracked files.
+
+        * BuildSlaveSupport/clean-build:
+        (main): Adding call to Tools/Scripts/clean-webkit.
+        * Scripts/clean-webkit: Added.
+        (main): Removes untracked and changed files.
+        * Scripts/webkitpy/common/checkout/scm/git.py:
+        (Git.untracked_files): Retrieves GIT untracked files.
+        * Scripts/webkitpy/common/checkout/scm/scm.py:
+        (SCM.untracked_files): Retrieves SVN untracked files.
+        (SCM):
+        (SCM.discard_untracked_files): Deletes untracked files/folders.
+        * Scripts/webkitpy/common/checkout/scm/scm_unittest.py:
+        (SCMTest._shared_test_untracked_files): Unit testing for untracked files.
+        (test_untracked_files):
+        (GitSVNTest.test_untracked_files):
+        * Scripts/webkitpy/common/checkout/scm/svn.py:
+        (SVN.untracked_files):
+
 2015-03-27  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         [CMake] Remove unnecessary INCLUDE_IF_EXISTS macro 
diff --git a/Tools/Scripts/clean-webkit b/Tools/Scripts/clean-webkit
new file mode 100755 (executable)
index 0000000..6a53af8
--- /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()
+
+
+sys.exit(main())
index aad6eadb29630c5792fa0150bc86fbbe87791bef..7e750dc6d47e3a50b74d164e07ad1785e475f016 100644 (file)
@@ -214,6 +214,12 @@ class Git(SCM, SVNRepository):
         updated_in_index_regexp = '^M[ M] (?P<filename>.+)$'
         return self.run_status_and_extract_filenames(status_command, updated_in_index_regexp)
 
+    def untracked_files(self):
+        status_command = [self.executable_name, 'status', '--short', '--ignored']
+        status_command.extend(self._patch_directories)
+        # Remove the last / for folders to match SVN behavior.
+        return [value if not value.endswith('/') else value[:-1] for value in self.run_status_and_extract_filenames(status_command, "^[?!][?!] (?P<filename>.+)$")]
+
     def changed_files(self, git_commit=None):
         # FIXME: --diff-filter could be used to avoid the "extract_filenames" step.
         status_command = [self.executable_name, 'diff', '-r', '--name-status', "--no-renames", "--no-ext-diff", "--full-index", self.merge_base(git_commit)]
index ebb6c0913996c2e2247e20d109e9b61215b418b0..e97adddfbd4fbfd9851f78df6fb016ccbc5dd0f2 100644 (file)
@@ -204,6 +204,16 @@ class SCM:
     def has_working_directory_changes(self):
         self._subclass_must_implement()
 
+    def untracked_files(self):
+        self._subclass_must_implement()
+
+    def discard_untracked_files(self):
+        for filename in self.untracked_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 edf22b1570201cea8d578c6b3e9431c62dfc3912..4e7c04c4984d961786ebd494d32c4aa4a2609bca 100644 (file)
@@ -309,6 +309,29 @@ class SCMTest(unittest.TestCase):
         self.assertItemsEqual(self.scm.changed_files(), ["test_dir/test_file3", "test_file"])
         os.chdir(old_cwd)
 
+    def _shared_test_untracked_files(self, scm):
+        write_into_file_at_path("test_file_new", "new content")
+        self.assertItemsEqual(scm.untracked_files(), ["test_file_new"])
+
+        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"])
+
+        # Validate that untracked_files do not change with .gitignore/svn:ignore.
+        # FIXME: Add svn:ignore property setting
+        write_into_file_at_path(".gitignore", "test_file_new\ntest_dir_new\n")
+        self.assertItemsEqual(scm.untracked_files(), [".gitignore", "test_dir_new", "test_file_new"])
+
+        old_cwd = os.getcwd()
+        os.chdir("test_dir_new")
+        # Validate that untracked_files do not change with our cwd.
+        self.assertItemsEqual(scm.untracked_files(), [".gitignore", "test_dir_new", "test_file_new"])
+
+        os.chdir(old_cwd)
+        shutil.rmtree("test_dir_new")
+        os.remove(".gitignore")
+        os.remove("test_file_new")
+
     def _shared_test_added_files(self):
         write_into_file_at_path("test_file", "changed content")
         self.assertItemsEqual(self.scm.added_files(), [])
@@ -806,6 +829,9 @@ END
     def test_changed_files(self):
         self._shared_test_changed_files()
 
+    def test_untracked_files(self):
+        self._shared_test_untracked_files(self.scm)
+
     def test_changed_files_for_revision(self):
         self._shared_test_changed_files_for_revision()
 
@@ -1459,6 +1485,9 @@ class GitSVNTest(SCMTest):
     def test_changed_files(self):
         self._shared_test_changed_files()
 
+    def test_untracked_files(self):
+        self._shared_test_untracked_files(self.scm)
+
     def test_changed_files_for_revision(self):
         self._shared_test_changed_files_for_revision()
 
index b2a5c951c1cb185bb85c1db4f82ad52bdf88a197..d76b75dab8e45918d7705bebdea80c882b4b8840 100644 (file)
@@ -144,6 +144,11 @@ class SVN(SCM, SVNRepository):
         # FIXME: What about files which are not committed yet?
         return self._run_svn(["diff"], cwd=self.checkout_root, decode_output=False) != ""
 
+    def untracked_files(self):
+        status_command = [self.executable_name, "status", "--no-ignore"]
+        status_command.extend(self._patch_directories)
+        return self.run_status_and_extract_filenames(status_command, self._status_regexp("I?"))
+
     def discard_working_directory_changes(self):
         # Make sure there are no locks lying around from a previously aborted svn invocation.
         # This is slightly dangerous, as it's possible the user is running another svn process