Commit 2a74d37e authored by maruel@chromium.org's avatar maruel@chromium.org

Move git_cl back into depot_tools.

Remove git_cl_hooks.py since it's now unnecessary.

BUG=
TEST=

Review URL: http://codereview.chromium.org/6758001

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@79715 0039d316-1c4b-4281-b951-d872f2087c98
parent de568681
# Copyright (c) 2010 The Chromium Authors. All rights reserved.
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Top-level presubmit script for depot tools.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
details on the presubmit API built into gcl.
details on the presubmit API built into depot_tools.
"""
UNIT_TESTS = [
......@@ -43,14 +43,68 @@ def CommonChecks(input_api, output_api):
white_list = [r'.*\.py$', r'^git-try$']
black_list = list(input_api.DEFAULT_BLACK_LIST) + [
r'^cpplint\.py$',
r'^git_cl[\/\\]test[\/\\](local_)?rietveld.*',
r'^git_cl[\/\\]upload.*',
r'^tests[\/\\]\w+?[\/\\].+',
]
output.extend(input_api.canned_checks.RunPylint(
input_api,
output_api,
white_list=white_list,
black_list=black_list))
output.extend(RunGitClTests(input_api, output_api))
return output
def RunGitClTests(input_api, output_api):
"""Run all the shells scripts in the directory test.
"""
# Not exposed from InputApi.
from os import listdir
# First loads a local Rietveld instance.
import sys
old_sys_path = sys.path
try:
sys.path = [input_api.PresubmitLocalPath()] + sys.path
from tests import local_rietveld # pylint: disable=W0403
server = local_rietveld.LocalRietveld()
finally:
sys.path = old_sys_path
# Set to True for testing.
verbose = False
if verbose:
stdout = None
stderr = None
else:
stdout = input_api.subprocess.PIPE
stderr = input_api.subprocess.STDOUT
output = []
try:
# Start a local rietveld instance to test against.
server.start_server()
test_path = input_api.os_path.abspath(
input_api.os_path.join(input_api.PresubmitLocalPath(), 'tests'))
for test in listdir(test_path):
# test-lib.sh is not an actual test so it should not be run. The other
# tests are tests known to fail.
DISABLED_TESTS = (
'owners.sh', 'push-from-logs.sh', 'rename.sh', 'test-lib.sh')
if test in DISABLED_TESTS or not test.endswith('.sh'):
continue
print('Running %s' % test)
proc = input_api.subprocess.Popen(
[input_api.os_path.join(test_path, test)],
cwd=test_path,
stdout=stdout,
stderr=stderr)
proc.communicate()
if proc.returncode != 0:
output.append(output_api.PresubmitError('%s failed' % test))
except local_rietveld.Failure, e:
output.append(output_api.PresubmitError('\n'.join(str(i) for i in e.args)))
finally:
server.stop_server()
return output
......
......@@ -3,7 +3,10 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# git-cl -- a git-command for integrating reviews on Rietveld
# Copyright (C) 2008 Evan Martin <martine@danga.com>
base_dir=$(dirname "$0")
"$base_dir"/update_depot_tools
"$base_dir"/git_cl/git-cl "$@"
"$base_dir"/git_cl.py "$@"
......@@ -19,19 +19,23 @@ try:
except ImportError:
pass
# TODO(dpranke): don't use relative import.
import upload # pylint: disable=W0403
try:
# TODO(dpranke): We wrap this in a try block for a limited form of
# backwards-compatibility with older versions of git-cl that weren't
# dependent on depot_tools. This version should still work outside of
# depot_tools as long as --bypass-hooks is used. We should remove this
# once this has baked for a while and things seem safe.
depot_tools_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(depot_tools_path)
import breakpad # pylint: disable=W0611
import simplejson as json # pylint: disable=F0401
except ImportError:
pass
try:
import json
except ImportError:
# Fall back to the packaged version.
from third_party import simplejson as json
from third_party import upload
import breakpad # pylint: disable=W0611
import presubmit_support
import scm
import watchlists
DEFAULT_SERVER = 'http://codereview.appspot.com'
POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s'
......@@ -771,10 +775,6 @@ def ConvertToInteger(inputval):
def RunHook(committing, upstream_branch, rietveld_server, tbr, may_prompt):
"""Calls sys.exit() if the hook fails; returns a HookResults otherwise."""
import presubmit_support
import scm
import watchlists
root = RunCommand(['git', 'rev-parse', '--show-cdup']).strip()
if not root:
root = '.'
......@@ -1311,18 +1311,6 @@ def GetTreeStatus():
def GetTreeStatusReason():
"""Fetches the tree status from a json url and returns the message
with the reason for the tree to be opened or closed."""
# Don't import it at file level since simplejson is not installed by default
# on python 2.5 and it is only used for git-cl tree which isn't often used,
# forcing everyone to install simplejson isn't efficient.
try:
import simplejson as json # pylint: disable=F0401
except ImportError:
try:
import json
except ImportError:
print >> sys.stderr, 'Please install simplejson'
sys.exit(1)
url = settings.GetTreeStatusUrl()
json_url = urlparse.urljoin(url, '/current?format=json')
connection = urllib2.urlopen(json_url)
......
Copyright (c) 2008 Evan Martin <martine@danga.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* 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.
* Neither the name of the author nor the names of contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 OWNER
OR CONTRIBUTORS 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.
# Copyright (c) 2010 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Top-level presubmit script for depot tools.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
details on the presubmit API built into gcl.
"""
def CheckChangeOnUpload(input_api, output_api):
return RunTests(input_api, output_api)
def CheckChangeOnCommit(input_api, output_api):
return RunTests(input_api, output_api)
def RunTests(input_api, output_api):
"""Run all the shells scripts in the directory test.
"""
# Not exposed from InputApi.
from os import listdir
# First loads a local Rietveld instance.
import sys
old_sys_path = sys.path
try:
sys.path = [input_api.PresubmitLocalPath()] + sys.path
from test import local_rietveld # pylint: disable=W0403
server = local_rietveld.LocalRietveld()
finally:
sys.path = old_sys_path
# Set to True for testing.
verbose = False
if verbose:
stdout = None
stderr = None
else:
stdout = input_api.subprocess.PIPE
stderr = input_api.subprocess.STDOUT
output = []
try:
# Start a local rietveld instance to test against.
server.start_server()
test_path = input_api.os_path.abspath(
input_api.os_path.join(input_api.PresubmitLocalPath(), 'test'))
for test in listdir(test_path):
# test-lib.sh is not an actual test so it should not be run. The other
# tests are tests known to fail.
DISABLED_TESTS = (
'owners.sh', 'push-from-logs.sh', 'rename.sh', 'test-lib.sh')
if test in DISABLED_TESTS or not test.endswith('.sh'):
continue
print('Running %s' % test)
proc = input_api.subprocess.Popen(
[input_api.os_path.join(test_path, test)],
cwd=test_path,
stdout=stdout,
stderr=stderr)
proc.communicate()
if proc.returncode != 0:
output.append(output_api.PresubmitError('%s failed' % test))
except local_rietveld.Failure, e:
output.append(output_api.PresubmitError('\n'.join(str(i) for i in e.args)))
finally:
server.stop_server()
return output
#!/usr/bin/python
# git-cl -- a git-command for integrating reviews on Rietveld
# Copyright (C) 2008 Evan Martin <martine@danga.com>
#!/bin/sh
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import sys
base_dir=$(dirname "$0")
import git_cl
if __name__ == '__main__':
sys.exit(git_cl.main(sys.argv[1:]))
"$base_dir"/../git_cl.py "$@"
This diff is collapsed.
# Copyright (c) 2010 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import subprocess
import sys
import breakpad # pylint: disable=W0611
from git_cl import git_cl
from git_cl import upload
import presubmit_support
import scm
import watchlists
# Really ugly hack to quiet upload.py
upload.verbosity = 0
def Backquote(cmd, cwd=None):
"""Like running `cmd` in a shell script."""
return subprocess.Popen(cmd,
cwd=cwd,
stdout=subprocess.PIPE).communicate()[0].strip()
def ConvertToInteger(inputval):
"""Convert a string to integer, but returns either an int or None."""
try:
return int(inputval)
except (TypeError, ValueError):
return None
class ChangeOptions:
def __init__(self, commit=None, upstream_branch=None):
self.commit = commit
self.verbose = None
self.default_presubmit = None
self.may_prompt = None
root = Backquote(['git', 'rev-parse', '--show-cdup'])
if not root:
root = "."
absroot = os.path.abspath(root)
if not root:
raise Exception("Could not get root directory.")
# We use the sha1 of HEAD as a name of this change.
name = Backquote(['git', 'rev-parse', 'HEAD'])
files = scm.GIT.CaptureStatus([root], upstream_branch)
cl = git_cl.Changelist()
issue = ConvertToInteger(cl.GetIssue())
patchset = ConvertToInteger(cl.GetPatchset())
if issue:
description = cl.GetDescription()
else:
# If the change was never uploaded, use the log messages of all commits
# up to the branch point, as git cl upload will prefill the description
# with these log messages.
description = Backquote(['git', 'log', '--pretty=format:%s%n%n%b',
'%s...' % (upstream_branch)])
self.change = presubmit_support.GitChange(name, description, absroot, files,
issue, patchset)
def RunHooks(hook_name, upstream_branch):
commit = (hook_name == 'pre-cl-dcommit')
# Create our options based on the command-line args and the current checkout.
options = ChangeOptions(commit=commit, upstream_branch=upstream_branch)
# Apply watchlists on upload.
if not commit:
watchlist = watchlists.Watchlists(options.change.RepositoryRoot())
files = [f.LocalPath() for f in options.change.AffectedFiles()]
watchers = watchlist.GetWatchersForPaths(files)
Backquote(['git', 'config', '--replace-all',
'rietveld.extracc', ','.join(watchers)])
# Run the presubmit checks.
if presubmit_support.DoPresubmitChecks(options.change,
options.commit,
options.verbose,
sys.stdout,
sys.stdin,
options.default_presubmit,
options.may_prompt):
sys.exit(0)
else:
sys.exit(1)
#!/usr/bin/python
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unit tests for depot_tools."""
......@@ -50,9 +50,9 @@ class LocalRietveld(object):
self.base_dir = os.path.dirname(os.path.abspath(__file__))
self.base_dir = os.path.realpath(os.path.join(self.base_dir, '..'))
self.sdk_path = os.path.abspath(
os.path.join(self.base_dir, '..', '..', 'google_appengine'))
os.path.join(self.base_dir, '..', 'google_appengine'))
self.dev_app = os.path.join(self.sdk_path, 'dev_appserver.py')
self.rietveld = os.path.join(self.base_dir, 'test', 'rietveld')
self.rietveld = os.path.join(self.base_dir, 'tests', 'rietveld')
self.test_server = None
self.port = None
# Generate a friendly environment.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment