Skip to content

Commit

Permalink
[Chrome Stdlib]: Support renaming of test data objects
Browse files Browse the repository at this point in the history
Allow files to be renamed while keeping the same sha256.

The previous version of the presubmit fails when we try to do this as it checks that when a file is removed, the matching hash is also removed from the DEPS file. In the case of renaming the hash stays the same and we want to explicitly allow this.

Change-Id: Iedb384858d45f078b04740b2937650061af1d861
Bug: 312895063
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5575129
Commit-Queue: Rasika Navarange <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1309836}
  • Loading branch information
Rasika Navarange authored and Chromium LUCI CQ committed Jun 4, 2024
1 parent 8a2dc60 commit 277cd66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -3425,10 +3425,13 @@ def CheckEachPerfettoTestDataFileHasDepsEntry(input_api, output_api):

# Find DEPS entry
deps_entry = []
old_deps_entry = []
for f in input_api.AffectedFiles(include_deletes=False):
if f.LocalPath() == 'DEPS':
new_deps = _ParseDeps('\n'.join(f.NewContents()))['deps']
deps_entry = new_deps['src/base/tracing/test/data']
old_deps = _ParseDeps('\n'.join(f.OldContents()))['deps']
old_deps_entry = old_deps['src/base/tracing/test/data']
if not deps_entry:
# TODO(312895063):Add back error when .sha256 files have been moved.
return [output_api.PresubmitNotifyResult(
Expand All @@ -3445,7 +3448,13 @@ def CheckEachPerfettoTestDataFileHasDepsEntry(input_api, output_api):
object_entry = next(
(item for item in objects if item["sha256sum"] == sha256_from_file),
None)
old_entry = next(
(item for item in old_deps_entry['objects'] if item["sha256sum"] == sha256_from_file),
None)
if object_entry:
# Allow renaming of objects with the same hash
if object_entry['object_name'] != old_entry['object_name']:
continue
output.append(output_api.PresubmitError(
'You deleted %s so you must also remove the corresponding DEPS entry.'
% f.LocalPath()
Expand Down
6 changes: 3 additions & 3 deletions PRESUBMIT_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def testNewSha256FileSuccess(self):
}""".splitlines()
input_api.files = [
MockFile('base/tracing/test/data_sha256/new.pftrace.sha256', ['a1b2c3f4']),
MockFile('DEPS', new_deps),
MockFile('DEPS', new_deps, ["deps={'src/base/tracing/test/data':{}}"]),
]
results = PRESUBMIT.CheckEachPerfettoTestDataFileHasDepsEntry(input_api, MockOutputApi())
self.assertEqual(0, len(results))
Expand All @@ -282,7 +282,7 @@ def testNewSha256FileWrongSha256(self):
f = MockFile('base/tracing/test/data_sha256/new.pftrace.sha256', ['a1b2c3f4'])
input_api.files = [
f,
MockFile('DEPS', new_deps),
MockFile('DEPS', new_deps, ["deps={'src/base/tracing/test/data':{}}"]),
]
results = PRESUBMIT.CheckEachPerfettoTestDataFileHasDepsEntry(input_api, MockOutputApi())
self.assertEqual((
Expand Down Expand Up @@ -311,7 +311,7 @@ def testDeleteSha256File(self):
f = MockFile('base/tracing/test/data_sha256/new.pftrace.sha256', [], ['a1b2c3f4'], action='D')
input_api.files = [
f,
MockFile('DEPS', old_deps),
MockFile('DEPS', old_deps, old_deps),
]
results = PRESUBMIT.CheckEachPerfettoTestDataFileHasDepsEntry(input_api, MockOutputApi())
self.assertEqual((
Expand Down

0 comments on commit 277cd66

Please sign in to comment.