source: trunk/WebKitTools/Scripts/check-webkit-style @ 58261

Revision 58261, 5.2 KB checked in by ojan@chromium.org, 4 years ago (diff)

2010-04-06 Ojan Vafai <ojan@chromium.org>

Reviewed by Adam Barth.

Include git commits in the diff for webkit-patch upload/land.
https://bugs.webkit.org/show_bug.cgi?id=36394

Adds --squash, --no-squash and --git-commit.

--git-commit will use a specific local commit for land/upload.
If a commit-range is specified, then that range is treated as
a single squashed commit.

--squash will squash all local changes including working copy changes
into a single patch.

--no-squash is the legacy behavior (upload only considers the working copy,
land commits the working copy and then each local commit separately to SVN)

If neither is specified, then an informative error is raised if there is
more than one local commit or when there are local commit(s) and working
copy changes.

If the webkit-patch.squash git config parameter is set, then
that will be respected instead of raising an error.

  • Scripts/check-webkit-style:
  • Scripts/webkitpy/common/checkout/api.py:
  • Scripts/webkitpy/common/checkout/api_unittest.py:
  • Scripts/webkitpy/common/checkout/scm.py:
  • Scripts/webkitpy/common/checkout/scm_unittest.py:
  • Scripts/webkitpy/style/optparser.py: --git-since is removed and --git-commit no longer implies commit_id.. Instead, it treats that individual commit, but also supports commit ranges (e.g. commit_id..) as arguments.
  • Scripts/webkitpy/style/optparser_unittest.py:
  • Scripts/webkitpy/style_references.py:
  • Scripts/webkitpy/tool/commands/download.py:
  • Scripts/webkitpy/tool/commands/upload.py:
  • Scripts/webkitpy/tool/main.py:
  • Scripts/webkitpy/tool/mocktool.py:
  • Scripts/webkitpy/tool/steps/abstractstep.py:
  • Scripts/webkitpy/tool/steps/applypatchwithlocalcommit.py:
  • Scripts/webkitpy/tool/steps/checkstyle.py:
  • Scripts/webkitpy/tool/steps/commit.py:
  • Scripts/webkitpy/tool/steps/options.py:
  • Scripts/webkitpy/tool/steps/postdiff.py:
  • Scripts/webkitpy/tool/steps/preparechangelog.py:
  • Scripts/webkitpy/tool/steps/preparechangelogforrevert.py:
  • Scripts/webkitpy/tool/steps/updatechangelogswithreviewer.py:
  • Scripts/webkitpy/tool/steps/validatereviewer.py:
  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2#
3# Copyright (C) 2009 Google Inc. All rights reserved.
4# Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com)
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met:
9#
10#    * Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12#    * Redistributions in binary form must reproduce the above
13# copyright notice, this list of conditions and the following disclaimer
14# in the documentation and/or other materials provided with the
15# distribution.
16#    * Neither the name of Google Inc. nor the names of its
17# contributors may be used to endorse or promote products derived from
18# this software without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32"""Does WebKit-lint on C/C++ or text files.
33
34The goal of this script is to identify places in the code that *may*
35be in non-compliance with WebKit style.  It does not attempt to fix
36up these problems -- the point is to educate.  It does also not
37attempt to find all problems, or to ensure that everything it does
38find is legitimately a problem.
39
40In particular, we can get very confused by /* and // inside strings!
41We do a small hack, which is to ignore //'s with "'s after them on the
42same line, but it is far from perfect (in either direction).
43"""
44
45import codecs
46import logging
47import os
48import os.path
49import sys
50
51from webkitpy.style_references import detect_checkout
52import webkitpy.style.checker as checker
53from webkitpy.style.checker import PatchChecker
54from webkitpy.style.checker import StyleProcessor
55from webkitpy.style.filereader import TextFileReader
56from webkitpy.style.main import change_directory
57
58_log = logging.getLogger("check-webkit-style")
59
60
61# FIXME: Move this code to style.main.
62def main():
63    # Change stderr to write with replacement characters so we don't die
64    # if we try to print something containing non-ASCII characters.
65    stderr = codecs.StreamReaderWriter(sys.stderr,
66                                       codecs.getreader('utf8'),
67                                       codecs.getwriter('utf8'),
68                                       'replace')
69    # Setting an "encoding" attribute on the stream is necessary to
70    # prevent the logging module from raising an error.  See
71    # the checker.configure_logging() function for more information.
72    stderr.encoding = "UTF-8"
73
74    # FIXME: Change webkitpy.style so that we do not need to overwrite
75    #        the global sys.stderr.  This involves updating the code to
76    #        accept a stream parameter where necessary, and not calling
77    #        sys.stderr explicitly anywhere.
78    sys.stderr = stderr
79
80    args = sys.argv[1:]
81
82    # Checking for the verbose flag before calling check_webkit_style_parser()
83    # lets us enable verbose logging earlier.
84    is_verbose = "-v" in args or "--verbose" in args
85
86    checker.configure_logging(stream=stderr, is_verbose=is_verbose)
87    _log.debug("Verbose logging enabled.")
88
89    parser = checker.check_webkit_style_parser()
90    (paths, options) = parser.parse(args)
91
92    checkout = detect_checkout()
93
94    if checkout is None:
95        if not paths:
96            _log.error("WebKit checkout not found: You must run this script "
97                       "from within a WebKit checkout if you are not passing "
98                       "specific paths to check.")
99            sys.exit(1)
100
101        checkout_root = None
102        _log.debug("WebKit checkout not found for current directory.")
103    else:
104        checkout_root = checkout.root_path()
105        _log.debug("WebKit checkout found with root: %s" % checkout_root)
106
107    configuration = checker.check_webkit_style_configuration(options)
108
109    paths = change_directory(checkout_root=checkout_root, paths=paths)
110
111    style_processor = StyleProcessor(configuration)
112
113    file_reader = TextFileReader(style_processor)
114
115    if paths:
116        file_reader.process_paths(paths)
117    else:
118        patch = checkout.create_patch(options.git_commit, options.squash)
119        patch_checker = PatchChecker(file_reader)
120        patch_checker.check(patch)
121
122    error_count = style_processor.error_count
123    file_count = file_reader.file_count
124
125    _log.info("Total errors found: %d in %d files"
126              % (error_count, file_count))
127    # We fail when style errors are found or there are no checked files.
128    sys.exit(error_count > 0 or file_count == 0)
129
130
131if __name__ == "__main__":
132    main()
Note: See TracBrowser for help on using the repository browser.