@ -1402,6 +1402,8 @@ class GetPostUploadExecuter(object):
def ExecPresubmitScript ( self , script_text , presubmit_path , gerrit_obj ,
def ExecPresubmitScript ( self , script_text , presubmit_path , gerrit_obj ,
change ) :
change ) :
""" Executes PostUploadHook() from a single presubmit script.
""" Executes PostUploadHook() from a single presubmit script.
Caller is responsible for validating whether the hook should be executed
and should only call this function if it should be .
Args :
Args :
script_text : The text of the presubmit script .
script_text : The text of the presubmit script .
@ -1412,9 +1414,6 @@ class GetPostUploadExecuter(object):
Return :
Return :
A list of results objects .
A list of results objects .
"""
"""
if not _ShouldRunPresubmit ( script_text , self . use_python3 ) :
return { }
context = { }
context = { }
try :
try :
exec ( compile ( script_text , ' PRESUBMIT.py ' , ' exec ' , dont_inherit = True ) ,
exec ( compile ( script_text , ' PRESUBMIT.py ' , ' exec ' , dont_inherit = True ) ,
@ -1473,6 +1472,7 @@ def DoPostUploadExecuter(change, gerrit_obj, verbose, use_python3=False):
sys . stdout . write ( ' Running %s \n ' % filename )
sys . stdout . write ( ' Running %s \n ' % filename )
# Accept CRLF presubmit script.
# Accept CRLF presubmit script.
presubmit_script = gclient_utils . FileRead ( filename , ' rU ' )
presubmit_script = gclient_utils . FileRead ( filename , ' rU ' )
if _ShouldRunPresubmit ( presubmit_script , use_python3 ) :
results . extend ( executer . ExecPresubmitScript (
results . extend ( executer . ExecPresubmitScript (
presubmit_script , filename , gerrit_obj , change ) )
presubmit_script , filename , gerrit_obj , change ) )
@ -1517,6 +1517,8 @@ class PresubmitExecuter(object):
def ExecPresubmitScript ( self , script_text , presubmit_path ) :
def ExecPresubmitScript ( self , script_text , presubmit_path ) :
""" Executes a single presubmit script.
""" Executes a single presubmit script.
Caller is responsible for validating whether the hook should be executed
and should only call this function if it should be .
Args :
Args :
script_text : The text of the presubmit script .
script_text : The text of the presubmit script .
@ -1526,9 +1528,6 @@ class PresubmitExecuter(object):
Return :
Return :
A list of result objects , empty if no problems .
A list of result objects , empty if no problems .
"""
"""
if not _ShouldRunPresubmit ( script_text , self . use_python3 ) :
return [ ]
# Change to the presubmit file's directory to support local imports.
# Change to the presubmit file's directory to support local imports.
main_path = os . getcwd ( )
main_path = os . getcwd ( )
presubmit_dir = os . path . dirname ( presubmit_path )
presubmit_dir = os . path . dirname ( presubmit_path )
@ -1720,18 +1719,26 @@ def DoPresubmitChecks(change,
thread_pool = ThreadPool ( )
thread_pool = ThreadPool ( )
executer = PresubmitExecuter ( change , committing , verbose , gerrit_obj ,
executer = PresubmitExecuter ( change , committing , verbose , gerrit_obj ,
dry_run , thread_pool , parallel , use_python3 )
dry_run , thread_pool , parallel , use_python3 )
skipped_count = 0 ;
if default_presubmit :
if default_presubmit :
if verbose :
if verbose :
sys . stdout . write ( ' Running default presubmit script. \n ' )
sys . stdout . write ( ' Running default presubmit script. \n ' )
fake_path = os . path . join ( change . RepositoryRoot ( ) , ' PRESUBMIT.py ' )
fake_path = os . path . join ( change . RepositoryRoot ( ) , ' PRESUBMIT.py ' )
if _ShouldRunPresubmit ( default_presubmit , use_python3 ) :
results + = executer . ExecPresubmitScript ( default_presubmit , fake_path )
results + = executer . ExecPresubmitScript ( default_presubmit , fake_path )
else :
skipped_count + = 1
for filename in presubmit_files :
for filename in presubmit_files :
filename = os . path . abspath ( filename )
filename = os . path . abspath ( filename )
if verbose :
if verbose :
sys . stdout . write ( ' Running %s \n ' % filename )
sys . stdout . write ( ' Running %s \n ' % filename )
# Accept CRLF presubmit script.
# Accept CRLF presubmit script.
presubmit_script = gclient_utils . FileRead ( filename , ' rU ' )
presubmit_script = gclient_utils . FileRead ( filename , ' rU ' )
if _ShouldRunPresubmit ( presubmit_script , use_python3 ) :
results + = executer . ExecPresubmitScript ( presubmit_script , filename )
results + = executer . ExecPresubmitScript ( presubmit_script , filename )
else :
skipped_count + = 1
results + = thread_pool . RunAsync ( )
results + = thread_pool . RunAsync ( )
messages = { }
messages = { }
@ -1784,6 +1791,7 @@ def DoPresubmitChecks(change,
for warning in messages . get ( ' Warnings ' , [ ] )
for warning in messages . get ( ' Warnings ' , [ ] )
] ,
] ,
' more_cc ' : executer . more_cc ,
' more_cc ' : executer . more_cc ,
' skipped_presubmits ' : skipped_count ,
}
}
gclient_utils . FileWrite (
gclient_utils . FileWrite (