Reland "Modified git cl format for distributed histograms"
Modified git cl format for distributed histograms
Reverted because changes regarding distributed histograms were not all landed.
Added in check to ensure only add in a filepath argument if the newest changes
regarding distributed histograms are present. This ensures reliability in the
case of different branches of chromium/src.
Change-Id: I3a1d2a3ce72954a1f2cc2854827c9772ed4873ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2353076
Commit-Queue: Wenhan (Han) Zhang <zwenhan@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
diff --git a/git_cl.py b/git_cl.py
index f071fbc..dc64067 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -5031,16 +5031,42 @@
# whereas the top-level presubmit script merely issues a warning. Formatting
# these files is somewhat slow, so it's important not to duplicate the work.
if not opts.presubmit:
- for xml_dir in GetDirtyMetricsDirs(diff_files):
+ for diff_xml in GetDiffXMLs(diff_files):
+ xml_dir = GetMetricsDir(diff_xml)
+ if not xml_dir:
+ continue
+
tool_dir = os.path.join(top_dir, xml_dir)
pretty_print_tool = os.path.join(tool_dir, 'pretty_print.py')
cmd = ['vpython', pretty_print_tool, '--non-interactive']
+
+ # If the XML file is histograms.xml or enums.xml, add the xml path to the
+ # command as histograms/pretty_print.py now needs a relative path argument
+ # after splitting the histograms into multiple directories.
+ # For example, in tools/metrics/ukm, pretty-print could be run using:
+ # $ python pretty_print.py
+ # But in tools/metrics/histogrmas, pretty-print should be run with an
+ # additional relative path argument, like:
+ # $ python pretty_print.py histograms_xml/UMA/histograms.xml
+ # $ python pretty_print.py enums.xml
+
+ # TODO (crbug/1116488): Remove this check after ensuring that the updated
+ # version of histograms/pretty_print.py is released.
+ filepath_required = os.path.exists(
+ os.path.join(tool_dir, 'validate_prefix.py'))
+
+ if (diff_xml.endswith('histograms.xml')
+ or diff_xml.endswith('enums.xml')) and filepath_required:
+ cmd.append(diff_xml)
+
if opts.dry_run or opts.diff:
cmd.append('--diff')
+
# TODO(isherman): Once this file runs only on Python 3.3+, drop the
# `shell` param and instead replace `'vpython'` with
# `shutil.which('frob')` above: https://stackoverflow.com/a/32799942
- stdout = RunCommand(cmd, cwd=top_dir,
+ stdout = RunCommand(cmd,
+ cwd=top_dir,
shell=sys.platform.startswith('win32'))
if opts.diff:
sys.stdout.write(stdout)
@@ -5050,8 +5076,13 @@
return return_value
-def GetDirtyMetricsDirs(diff_files):
- xml_diff_files = [x for x in diff_files if MatchingFileType(x, ['.xml'])]
+def GetDiffXMLs(diff_files):
+ return [
+ os.path.normpath(x) for x in diff_files if MatchingFileType(x, ['.xml'])
+ ]
+
+
+def GetMetricsDir(diff_xml):
metrics_xml_dirs = [
os.path.join('tools', 'metrics', 'actions'),
os.path.join('tools', 'metrics', 'histograms'),
@@ -5060,9 +5091,9 @@
os.path.join('tools', 'metrics', 'ukm'),
]
for xml_dir in metrics_xml_dirs:
- if any(
- os.path.normpath(file).startswith(xml_dir) for file in xml_diff_files):
- yield xml_dir
+ if diff_xml.startswith(xml_dir):
+ return xml_dir
+ return None
@subcommand.usage('<codereview url or issue id>')