Commit 9b613270 authored by maruel@google.com's avatar maruel@google.com

Fix gclient on posix platforms.

Grab the latest gcl.py and presubmit.py scripts.

TBR=nsylvain
Review URL: http://codereview.chromium.org/93108

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@14403 0039d316-1c4b-4281-b951-d872f2087c98
parent 3380c1a4
...@@ -39,8 +39,8 @@ CODEREVIEW_SETTINGS_FILE = "codereview.settings" ...@@ -39,8 +39,8 @@ CODEREVIEW_SETTINGS_FILE = "codereview.settings"
# Warning message when the change appears to be missing tests. # Warning message when the change appears to be missing tests.
MISSING_TEST_MSG = "Change contains new or modified methods, but no new tests!" MISSING_TEST_MSG = "Change contains new or modified methods, but no new tests!"
# Global cache of files cached in GetInfoDir(). # Caches whether we read the codereview.settings file yet or not.
FILES_CACHE = {} read_gcl_info = False
def IsSVNMoved(filename): def IsSVNMoved(filename):
...@@ -111,62 +111,44 @@ def GetInfoDir(): ...@@ -111,62 +111,44 @@ def GetInfoDir():
return gcl_info_dir return gcl_info_dir
def GetCachedFile(filename, max_age=60*60*24*3, use_root=False): def GetCodeReviewSetting(key):
"""Retrieves a file from the repository and caches it in GetInfoDir() for """Returns a value for the given key for this repository."""
max_age seconds. global read_gcl_info
if not read_gcl_info:
use_root: If False, look up the arborescence for the first match, otherwise go read_gcl_info = True
directory to the root repository.
"""
global FILES_CACHE
if filename not in FILES_CACHE:
# Don't try to look up twice.
FILES_CACHE[filename] = None
# First we check if we have a cached version. # First we check if we have a cached version.
cached_file = os.path.join(GetInfoDir(), filename) cached_settings_file = os.path.join(GetInfoDir(), CODEREVIEW_SETTINGS_FILE)
if (not os.path.exists(cached_file) or if (not os.path.exists(cached_settings_file) or
os.stat(cached_file).st_mtime > max_age): os.stat(cached_settings_file).st_mtime > 60*60*24*3):
dir_info = GetSVNFileInfo(".") dir_info = GetSVNFileInfo(".")
repo_root = dir_info["Repository Root"] repo_root = dir_info["Repository Root"]
if use_root: url_path = dir_info["URL"]
url_path = repo_root settings = ""
else:
url_path = dir_info["URL"]
content = ""
while True: while True:
# Look for the codereview.settings file at the current level. # Look for the codereview.settings file at the current level.
svn_path = url_path + "/" + filename svn_path = url_path + "/" + CODEREVIEW_SETTINGS_FILE
content, rc = RunShellWithReturnCode(["svn", "cat", svn_path]) settings, rc = RunShellWithReturnCode(["svn", "cat", svn_path])
if not rc: if not rc:
# Exit the loop if the file was found. Override content. # Exit the loop if the file was found.
break break
# Make sure to mark settings as empty if not found. # Make sure to mark settings as empty if not found.
content = "" settings = ""
if url_path == repo_root: if url_path == repo_root:
# Reached the root. Abandoning search. # Reached the root. Abandoning search.
break break;
# Go up one level to try again. # Go up one level to try again.
url_path = os.path.dirname(url_path) url_path = os.path.dirname(url_path)
# Write a cached version even if there isn't a file, so we don't try to # Write a cached version even if there isn't a file, so we don't try to
# fetch it each time. # fetch it each time.
WriteFile(cached_file, content) WriteFile(cached_settings_file, settings)
else:
content = ReadFile(cached_settings_file)
FILES_CACHE[filename] = content
return FILES_CACHE[filename]
def GetCodeReviewSetting(key): output = ReadFile(cached_settings_file)
"""Returns a value for the given key for this repository.""" for line in output.splitlines():
# Use '__just_initialized' as a flag to determine if the settings were
# already initialized.
if '__just_initialized' not in CODEREVIEW_SETTINGS:
for line in GetCachedFile(CODEREVIEW_SETTINGS_FILE).splitlines():
if not line or line.startswith("#"): if not line or line.startswith("#"):
continue continue
k, v = line.split(": ", 1) k, v = line.split(": ", 1)
CODEREVIEW_SETTINGS[k] = v CODEREVIEW_SETTINGS[k] = v
CODEREVIEW_SETTINGS.setdefault('__just_initialized', None)
return CODEREVIEW_SETTINGS.get(key, "") return CODEREVIEW_SETTINGS.get(key, "")
...@@ -601,7 +583,7 @@ Basic commands: ...@@ -601,7 +583,7 @@ Basic commands:
[--send_mail] [--no_try] [--no_presubmit] [--send_mail] [--no_try] [--no_presubmit]
Uploads the changelist to the server for review. Uploads the changelist to the server for review.
gcl commit change_name [--no_presubmit] [--force] gcl commit change_name [--force]
Commits the changelist to the repository. Commits the changelist to the repository.
gcl lint change_name gcl lint change_name
...@@ -1010,10 +992,7 @@ def DoPresubmitChecks(change_info, committing): ...@@ -1010,10 +992,7 @@ def DoPresubmitChecks(change_info, committing):
committing, committing,
verbose=False, verbose=False,
output_stream=sys.stdout, output_stream=sys.stdout,
input_stream=sys.stdin, input_stream=sys.stdin)
default_presubmit=
GetCachedFile('PRESUBMIT.py',
use_root=True))
if not result: if not result:
print "\nPresubmit errors, can't continue (use --no_presubmit to bypass)" print "\nPresubmit errors, can't continue (use --no_presubmit to bypass)"
return result return result
......
...@@ -14,7 +14,7 @@ then ...@@ -14,7 +14,7 @@ then
svn -q up "$base_dir/bootstrap" svn -q up "$base_dir/bootstrap"
# Then defer the control to the bootstrapper. # Then defer the control to the bootstrapper.
"$base_dir/bootstrap/gclient.sh" "$base_dir/bootstrap/gclient.sh" "$@"
else else
exec "$base_dir/gclient.py" "$@" exec "$base_dir/gclient.py" "$@"
fi fi
......
...@@ -601,8 +601,7 @@ def DoPresubmitChecks(change_info, ...@@ -601,8 +601,7 @@ def DoPresubmitChecks(change_info,
committing, committing,
verbose, verbose,
output_stream, output_stream,
input_stream, input_stream):
default_presubmit):
"""Runs all presubmit checks that apply to the files in the change. """Runs all presubmit checks that apply to the files in the change.
This finds all PRESUBMIT.py files in directories enclosing the files in the This finds all PRESUBMIT.py files in directories enclosing the files in the
...@@ -618,7 +617,6 @@ def DoPresubmitChecks(change_info, ...@@ -618,7 +617,6 @@ def DoPresubmitChecks(change_info,
verbose: Prints debug info. verbose: Prints debug info.
output_stream: A stream to write output from presubmit tests to. output_stream: A stream to write output from presubmit tests to.
input_stream: A stream to read input from the user. input_stream: A stream to read input from the user.
default_presubmit: A default presubmit script to execute in any case.
Return: Return:
True if execution can continue, False if not. True if execution can continue, False if not.
...@@ -628,10 +626,6 @@ def DoPresubmitChecks(change_info, ...@@ -628,10 +626,6 @@ def DoPresubmitChecks(change_info,
print "Warning, no presubmit.py found." print "Warning, no presubmit.py found."
results = [] results = []
executer = PresubmitExecuter(change_info, committing) executer = PresubmitExecuter(change_info, committing)
if default_presubmit:
if verbose:
print "Running default presubmit script"
results += executer.ExecPresubmitScript(default_presubmit, 'PRESUBMIT.py')
for filename in presubmit_files: for filename in presubmit_files:
if verbose: if verbose:
print "Running %s" % filename print "Running %s" % filename
...@@ -703,12 +697,11 @@ def Main(argv): ...@@ -703,12 +697,11 @@ def Main(argv):
files = ParseFiles(args, options.recursive) files = ParseFiles(args, options.recursive)
if options.verbose: if options.verbose:
print "Found %d files." % len(files) print "Found %d files." % len(files)
return not DoPresubmitChecks(gcl.ChangeInfo(name='temp', files=files), return DoPresubmitChecks(gcl.ChangeInfo(name='temp', files=files),
options.commit, options.commit,
options.verbose, options.verbose,
sys.stdout, sys.stdout,
sys.stdin, sys.stdin)
default_presubmit=None)
if __name__ == '__main__': if __name__ == '__main__':
......
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