Commit 531d992f authored by Saagar Sanghavi's avatar Saagar Sanghavi Committed by LUCI CQ

Changed naming convention

presubmit:gerrit_host/folder/to/repo:path/to/file/:CheckName
Example
presubmit:chromium-review.googlesource.com/chromium/src/:services/viz/

Bug: 1112667
Change-Id: I095a2c04e73c64d67fa1bb3dbf7e6dfd1d93fe26
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2335873Reviewed-by: 's avatarNodir Turakulov <nodir@chromium.org>
Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Saagar Sanghavi <saagarsanghavi@google.com>
parent 03b15131
...@@ -1290,6 +1290,7 @@ class Changelist(object): ...@@ -1290,6 +1290,7 @@ class Changelist(object):
gclient_utils.FileWrite(description_file, description) gclient_utils.FileWrite(description_file, description)
args.extend(['--json_output', json_output]) args.extend(['--json_output', json_output])
args.extend(['--description_file', description_file]) args.extend(['--description_file', description_file])
args.extend(['--gerrit_project', self._GetGerritProject()])
start = time_time() start = time_time()
cmd = ['vpython', PRESUBMIT_SUPPORT] + args cmd = ['vpython', PRESUBMIT_SUPPORT] + args
......
...@@ -1497,8 +1497,8 @@ def DoPostUploadExecuter(change, ...@@ -1497,8 +1497,8 @@ def DoPostUploadExecuter(change,
return exit_code return exit_code
class PresubmitExecuter(object): class PresubmitExecuter(object):
def __init__(self, change, committing, verbose, def __init__(self, change, committing, verbose, gerrit_obj, dry_run=None,
gerrit_obj, dry_run=None, thread_pool=None, parallel=False): thread_pool=None, parallel=False, gerrit_project=None):
""" """
Args: Args:
change: The Change object. change: The Change object.
...@@ -1516,6 +1516,7 @@ class PresubmitExecuter(object): ...@@ -1516,6 +1516,7 @@ class PresubmitExecuter(object):
self.more_cc = [] self.more_cc = []
self.thread_pool = thread_pool self.thread_pool = thread_pool
self.parallel = parallel self.parallel = parallel
self.gerrit_project = gerrit_project
def ExecPresubmitScript(self, script_text, presubmit_path): def ExecPresubmitScript(self, script_text, presubmit_path):
"""Executes a single presubmit script. """Executes a single presubmit script.
...@@ -1555,12 +1556,21 @@ class PresubmitExecuter(object): ...@@ -1555,12 +1556,21 @@ class PresubmitExecuter(object):
context['__args'] = (input_api, output_api) context['__args'] = (input_api, output_api)
# Get path of presubmit directory relative to repository root # Get path of presubmit directory relative to repository root.
# Always use forward slashes, so that path is same in *nix and Windows # Always use forward slashes, so that path is same in *nix and Windows
root = input_api.change.RepositoryRoot() root = input_api.change.RepositoryRoot()
rel_path = os.path.relpath(presubmit_dir, root) rel_path = os.path.relpath(presubmit_dir, root)
rel_path = rel_path.replace(os.path.sep, '/') rel_path = rel_path.replace(os.path.sep, '/')
# Get the URL of git remote origin and use it to identify host and project
host = ''
if self.gerrit and self.gerrit.host:
host = self.gerrit.host
project = self.gerrit_project or ''
# Prefix for test names
prefix = 'presubmit:%s/%s:%s/' % (host, project, rel_path)
# Perform all the desired presubmit checks. # Perform all the desired presubmit checks.
results = [] results = []
...@@ -1575,7 +1585,7 @@ class PresubmitExecuter(object): ...@@ -1575,7 +1585,7 @@ class PresubmitExecuter(object):
continue continue
logging.debug('Running %s in %s', function_name, presubmit_path) logging.debug('Running %s in %s', function_name, presubmit_path)
results.extend( results.extend(
self._run_check_function(function_name, context, rel_path)) self._run_check_function(function_name, context, prefix))
logging.debug('Running %s done.', function_name) logging.debug('Running %s done.', function_name)
self.more_cc.extend(output_api.more_cc) self.more_cc.extend(output_api.more_cc)
...@@ -1587,7 +1597,7 @@ class PresubmitExecuter(object): ...@@ -1587,7 +1597,7 @@ class PresubmitExecuter(object):
if function_name in context: if function_name in context:
logging.debug('Running %s in %s', function_name, presubmit_path) logging.debug('Running %s in %s', function_name, presubmit_path)
results.extend( results.extend(
self._run_check_function(function_name, context, rel_path)) self._run_check_function(function_name, context, prefix))
logging.debug('Running %s done.', function_name) logging.debug('Running %s done.', function_name)
self.more_cc.extend(output_api.more_cc) self.more_cc.extend(output_api.more_cc)
...@@ -1636,7 +1646,8 @@ def DoPresubmitChecks(change, ...@@ -1636,7 +1646,8 @@ def DoPresubmitChecks(change,
gerrit_obj, gerrit_obj,
dry_run=None, dry_run=None,
parallel=False, parallel=False,
json_output=None): json_output=None,
gerrit_project=None):
"""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
...@@ -1679,7 +1690,7 @@ def DoPresubmitChecks(change, ...@@ -1679,7 +1690,7 @@ def DoPresubmitChecks(change,
results = [] results = []
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) dry_run, thread_pool, parallel, gerrit_project)
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')
...@@ -1923,7 +1934,7 @@ def main(argv=None): ...@@ -1923,7 +1934,7 @@ def main(argv=None):
help='List of files to be marked as modified when ' help='List of files to be marked as modified when '
'executing presubmit or post-upload hooks. fnmatch ' 'executing presubmit or post-upload hooks. fnmatch '
'wildcards can also be used.') 'wildcards can also be used.')
parser.add_argument('--gerrit_project', help=argparse.SUPPRESS)
options = parser.parse_args(argv) options = parser.parse_args(argv)
log_level = logging.ERROR log_level = logging.ERROR
...@@ -1956,7 +1967,8 @@ def main(argv=None): ...@@ -1956,7 +1967,8 @@ def main(argv=None):
gerrit_obj, gerrit_obj,
options.dry_run, options.dry_run,
options.parallel, options.parallel,
options.json_output) options.json_output,
options.gerrit_project)
except PresubmitFailure as e: except PresubmitFailure as e:
print(e, file=sys.stderr) print(e, file=sys.stderr)
print('Maybe your depot_tools is out of date?', file=sys.stderr) print('Maybe your depot_tools is out of date?', file=sys.stderr)
......
...@@ -21,13 +21,15 @@ class ResultSinkStatus(object): ...@@ -21,13 +21,15 @@ class ResultSinkStatus(object):
self.status = STATUS_PASS self.status = STATUS_PASS
@contextlib.contextmanager @contextlib.contextmanager
def setup_rdb(function_name, rel_path): def setup_rdb(function_name, prefix):
"""Context Manager function for ResultDB reporting. """Context Manager function for ResultDB reporting.
Args: Args:
function_name (str): The name of the function we are about to run. function_name (str): The name of the function we are about to run.
rel_path (str): The relative path from the root of the repository to the prefix (str): The prefix for the name of the test. The format for this is
directory defining the check being executed. presubmit:gerrit_host/folder/to/repo:path/to/file/
for example,
presubmit:chromium-review.googlesource.com/chromium/src/:services/viz/
""" """
sink = None sink = None
if 'LUCI_CONTEXT' in os.environ: if 'LUCI_CONTEXT' in os.environ:
...@@ -48,7 +50,7 @@ def setup_rdb(function_name, rel_path): ...@@ -48,7 +50,7 @@ def setup_rdb(function_name, rel_path):
elapsed_time = end_time - start_time elapsed_time = end_time - start_time
if sink != None: if sink != None:
tr = { tr = {
'testId': '{0}/:{1}'.format(rel_path, function_name), 'testId': '{0}:{1}'.format(prefix, function_name),
'status': my_status.status, 'status': my_status.status,
'expected': (my_status.status == STATUS_PASS), 'expected': (my_status.status == STATUS_PASS),
'duration': '{:.9f}s'.format(elapsed_time) 'duration': '{:.9f}s'.format(elapsed_time)
......
...@@ -2677,6 +2677,8 @@ class ChangelistTest(unittest.TestCase): ...@@ -2677,6 +2677,8 @@ class ChangelistTest(unittest.TestCase):
mock.patch('git_cl.time_time').start() mock.patch('git_cl.time_time').start()
mock.patch('metrics.collector').start() mock.patch('metrics.collector').start()
mock.patch('subprocess2.Popen').start() mock.patch('subprocess2.Popen').start()
mock.patch('git_cl.Changelist._GetGerritProject',
return_value='https://chromium-review.googlesource.com').start()
self.addCleanup(mock.patch.stopall) self.addCleanup(mock.patch.stopall)
self.temp_count = 0 self.temp_count = 0
...@@ -2718,6 +2720,7 @@ class ChangelistTest(unittest.TestCase): ...@@ -2718,6 +2720,7 @@ class ChangelistTest(unittest.TestCase):
'--all_files', '--all_files',
'--json_output', '/tmp/fake-temp2', '--json_output', '/tmp/fake-temp2',
'--description_file', '/tmp/fake-temp1', '--description_file', '/tmp/fake-temp1',
'--gerrit_project', 'https://chromium-review.googlesource.com',
]) ])
gclient_utils.FileWrite.assert_called_once_with( gclient_utils.FileWrite.assert_called_once_with(
'/tmp/fake-temp1', 'description') '/tmp/fake-temp1', 'description')
...@@ -2762,6 +2765,7 @@ class ChangelistTest(unittest.TestCase): ...@@ -2762,6 +2765,7 @@ class ChangelistTest(unittest.TestCase):
'--upload', '--upload',
'--json_output', '/tmp/fake-temp2', '--json_output', '/tmp/fake-temp2',
'--description_file', '/tmp/fake-temp1', '--description_file', '/tmp/fake-temp1',
'--gerrit_project', 'https://chromium-review.googlesource.com',
]) ])
gclient_utils.FileWrite.assert_called_once_with( gclient_utils.FileWrite.assert_called_once_with(
'/tmp/fake-temp1', 'description') '/tmp/fake-temp1', 'description')
...@@ -2808,6 +2812,7 @@ class ChangelistTest(unittest.TestCase): ...@@ -2808,6 +2812,7 @@ class ChangelistTest(unittest.TestCase):
'--upload', '--upload',
'--json_output', '/tmp/fake-temp2', '--json_output', '/tmp/fake-temp2',
'--description_file', '/tmp/fake-temp1', '--description_file', '/tmp/fake-temp1',
'--gerrit_project', 'https://chromium-review.googlesource.com',
]) ])
@mock.patch('sys.exit', side_effect=SystemExitMock) @mock.patch('sys.exit', side_effect=SystemExitMock)
......
...@@ -161,6 +161,7 @@ index fe3de7b..54ae6e1 100755 ...@@ -161,6 +161,7 @@ index fe3de7b..54ae6e1 100755
class FakeChange(object): class FakeChange(object):
def __init__(self, obj): def __init__(self, obj):
self._root = obj.fake_root_dir self._root = obj.fake_root_dir
self.issue = 0
def RepositoryRoot(self): def RepositoryRoot(self):
return self._root return self._root
......
...@@ -38,7 +38,7 @@ class TestSetupRDB(unittest.TestCase): ...@@ -38,7 +38,7 @@ class TestSetupRDB(unittest.TestCase):
mock.patch('time.time', side_effect=[1.0, 2.0, 3.0, 4.0, 5.0]).start() mock.patch('time.time', side_effect=[1.0, 2.0, 3.0, 4.0, 5.0]).start()
def test_setup_rdb(self): def test_setup_rdb(self):
with rdb_wrapper.setup_rdb("_foobar", './my/folder') as my_status_obj: with rdb_wrapper.setup_rdb("_foobar", './my/folder/') as my_status_obj:
self.assertEqual(my_status_obj.status, rdb_wrapper.STATUS_PASS) self.assertEqual(my_status_obj.status, rdb_wrapper.STATUS_PASS)
my_status_obj.status = rdb_wrapper.STATUS_FAIL my_status_obj.status = rdb_wrapper.STATUS_FAIL
...@@ -61,7 +61,7 @@ class TestSetupRDB(unittest.TestCase): ...@@ -61,7 +61,7 @@ class TestSetupRDB(unittest.TestCase):
def test_setup_rdb_exception(self): def test_setup_rdb_exception(self):
with self.assertRaises(Exception): with self.assertRaises(Exception):
with rdb_wrapper.setup_rdb("_foobar", './my/folder'): with rdb_wrapper.setup_rdb("_foobar", './my/folder/'):
raise Exception("Generic Error") raise Exception("Generic Error")
expectedTr = { expectedTr = {
......
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