Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Unified Diff: presubmit_support.py

Issue 949273002: Add ability to specify and run post upload hooks (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Call specific post upload hooks first Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « git_cl.py ('k') | tests/git_cl_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: presubmit_support.py
diff --git a/presubmit_support.py b/presubmit_support.py
index b386524068c1ceddc44fc4e10edc4c596d6f577c..db677cfd042b3f0f3d277d6aac19611b3cb3bfe4 100755
--- a/presubmit_support.py
+++ b/presubmit_support.py
@@ -1143,6 +1143,37 @@ class GetTryMastersExecuter(object):
return get_preferred_try_masters(project, change)
+class GetPostUploadExecuter(object):
+ @staticmethod
+ def ExecPresubmitScript(script_text, presubmit_path, cl, change):
+ """Executes PostUploadHook() from a single presubmit script.
+
+ Args:
+ script_text: The text of the presubmit script.
+ presubmit_path: Project script to run.
+ cl: The Changelist object.
+ change: The Change object.
+
+ Return:
+ A list of results objects.
+ """
+ context = {}
+ try:
+ exec script_text in context
+ except Exception, e:
+ raise PresubmitFailure('"%s" had an exception.\n%s'
+ % (presubmit_path, e))
+
+ function_name = 'PostUploadHook'
+ if function_name not in context:
+ return {}
+ post_upload_hook = context[function_name]
+ if not len(inspect.getargspec(post_upload_hook)[0]) == 3:
+ raise PresubmitFailure(
+ 'Expected function "PostUploadHook" to take three arguments.')
+ return post_upload_hook(cl, change, OutputApi(False))
+
+
def DoGetTrySlaves(change,
changed_files,
repository_root,
@@ -1263,6 +1294,49 @@ def DoGetTryMasters(change,
return results
+def DoPostUploadExecuter(change,
+ cl,
+ repository_root,
+ verbose,
+ output_stream):
+ """Execute the post upload hook.
+
+ Args:
+ change: The Change object.
+ cl: The Changelist object.
+ repository_root: The repository root.
+ verbose: Prints debug info.
+ output_stream: A stream to write debug output to.
+ """
+ presubmit_files = ListRelevantPresubmitFiles(
+ change.LocalPaths(), repository_root)
+ if not presubmit_files and verbose:
+ output_stream.write("Warning, no PRESUBMIT.py found.\n")
+ results = []
+ executer = GetPostUploadExecuter()
+ # The root presubmit file should be executed after the ones in subdirectories.
+ # i.e. the specific post upload hooks should run before the general ones.
+ # Thus, reverse the order provided by ListRelevantPresubmitFiles.
+ presubmit_files.reverse()
+
+ for filename in presubmit_files:
+ filename = os.path.abspath(filename)
+ if verbose:
+ output_stream.write("Running %s\n" % filename)
+ # Accept CRLF presubmit script.
+ presubmit_script = gclient_utils.FileRead(filename, 'rU')
+ results.extend(executer.ExecPresubmitScript(
+ presubmit_script, filename, cl, change))
+ output_stream.write('\n')
+ if results:
+ output_stream.write('** Post Upload Hook Messages **\n')
+ for result in results:
+ result.handle(output_stream)
+ output_stream.write('\n')
+
+ return results
+
+
class PresubmitExecuter(object):
def __init__(self, change, committing, rietveld_obj, verbose):
"""
« no previous file with comments | « git_cl.py ('k') | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698