Commit 5d465e52 authored by sergiyb's avatar sergiyb Committed by Commit bot

Add dir-to-team hack for layout tests

R=stgao@chromium.org, tandrii@chromium.org
CC=sshruthi@chromium.org
BUG=702202

Review-Url: https://codereview.chromium.org/2754063002
Cr-Commit-Position: refs/heads/master@{#457744}
parent 66f935ee
......@@ -172,29 +172,40 @@ class ExtractComponentsTest(unittest.TestCase):
@mock_file_tree(OrderedDict([
('chromium/src', 'boss@chromium.org\n'),
('chromium/src/dir1', 'dummy@chromium.org\n'
'# TEAM: dummy-team@chromium.org\n'
'# COMPONENT: Dummy>Component'),
'# TEAM: dummy-team@chromium.org\n'
'# COMPONENT: Dummy>Component'),
('chromium/src/dir2', 'dummy2@chromium.org\n'
'# TEAM: other-dummy-team@chromium.org\n'
'# COMPONENT: Dummy>Component2'),
'# TEAM: other-dummy-team@chromium.org\n'
'# COMPONENT: Dummy>Component2'),
('chromium/src/dir1/subdir', 'dummy@chromium.org'),
('chromium/src/dir2/subdir', None)]))
('chromium/src/dir2/subdir', None),
('third_party/WebKit/LayoutTests/foo',
'# TEAM: dummy-team-3@chromium.org\n'),
('third_party/WebKit/LayoutTests/bar',
'# TEAM: dummy-team-3@chromium.org\n'
'# COMPONENT: Dummy>Component3\n'),
]))
def testIncludesSubdirectoriesWithNoOwnersFileOrNoComponentTag(self):
self.maxDiff = None # This helps to see assertDictEqual errors in full.
saved_output = StringIO()
with mock.patch('sys.stdout', saved_output):
error_code = extract_components.main(['%prog', '--include-subdirs'])
error_code = extract_components.main(['%prog', '--include-subdirs', ''])
self.assertEqual(0, error_code)
result_minus_readme = json.loads(saved_output.getvalue())
del result_minus_readme['AAA-README']
self.assertDictEqual(result_minus_readme, {
u'component-to-team': {
u'Dummy>Component': u'dummy-team@chromium.org',
u'Dummy>Component2': u'other-dummy-team@chromium.org',
u'Dummy>Component': u'dummy-team@chromium.org'
u'Dummy>Component3': u'dummy-team-3@chromium.org',
},
u'dir-to-component': {
u'tools/checkteamtags/chromium/src/dir1': u'Dummy>Component',
u'tools/checkteamtags/chromium/src/dir1/subdir': u'Dummy>Component',
u'tools/checkteamtags/chromium/src/dir2': u'Dummy>Component2',
u'tools/checkteamtags/chromium/src/dir2/subdir': u'Dummy>Component2'
u'chromium/src/dir1': u'Dummy>Component',
u'chromium/src/dir1/subdir': u'Dummy>Component',
u'chromium/src/dir2': u'Dummy>Component2',
u'chromium/src/dir2/subdir': u'Dummy>Component2',
u'third_party/WebKit/LayoutTests/bar': u'Dummy>Component3',
},
u'dir-to-team': {
u'third_party/WebKit/LayoutTests/foo': u'dummy-team-3@chromium.org',
}})
......@@ -62,6 +62,9 @@ def aggregate_components_from_owners(root, include_subdirs=False):
warnings = []
component_to_team = defaultdict(set)
dir_to_component = {}
# TODO(sergiyb): Remove this mapping. Please do not use it as it is going to
# be removed in the future. See http://crbug.com/702202.
dir_to_team = {}
for dirname, _, files in os.walk(root):
# Proofing against windows casing oddities.
owners_file_names = [f for f in files if f.upper() == 'OWNERS']
......@@ -84,13 +87,22 @@ def aggregate_components_from_owners(root, include_subdirs=False):
else:
warnings.append('%s has no COMPONENT tag' % owners_rel_path)
# Add dir-to-team mapping unless there is also dir-to-component mapping.
if (include_subdirs and team and not component and
rel_dirname.startswith('third_party/WebKit/LayoutTests')):
dir_to_team[rel_dirname] = team
if include_subdirs and rel_dirname not in dir_to_component:
rel_parent_dirname = os.path.relpath(os.path.dirname(dirname), root)
if rel_parent_dirname in dir_to_component:
dir_to_component[rel_dirname] = dir_to_component[rel_parent_dirname]
if rel_parent_dirname in dir_to_team:
dir_to_team[rel_dirname] = dir_to_team[rel_parent_dirname]
mappings = {'component-to-team': component_to_team,
'dir-to-component': dir_to_component}
if include_subdirs:
mappings['dir-to-team'] = dir_to_team
errors = validate_one_team_per_component(mappings)
stats = {'OWNERS-count': num_total,
'OWNERS-with-component-only-count': num_with_component,
......
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