Commit 94f14abf authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Chromium LUCI CQ

Revert "[Android] Read DIR_METADATA in getowners.py"

This reverts commit b6f59baa.

Reason for revert: https://ci.chromium.org/p/chrome/builders/ci/lorenz-graph-dbg: No such file or directory: 'dirmd'

Original change's description:
> [Android] Read DIR_METADATA in getowners.py
>
> The getowners.py script periodically reads OWNERS files and git history
> and generates per-module data to be surfaced in go/clank-
>
> OWNERS files do not contain Monorail component, Team and OS information
> anymore, DIR_METADATA files have replaced them and broken the script
> since then.
>
> Bug: 1135347
> Change-Id: Ib88e9d576d94ad5484b6a3dbbfff156639275dea
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2634833
> Reviewed-by: Peter Wen <wnwen@chromium.org>
> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#845754}

TBR=wnwen@chromium.org,hnakashima@chromium.org,chromium-scoped@luci-project-accounts.iam.gserviceaccount.com

Change-Id: I5c1afaa0f5846f22db9e59fbc42438cca9aae68d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1135347
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2644528Reviewed-by: default avatarHenrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846229}
parent b6b047db
...@@ -21,7 +21,6 @@ import time ...@@ -21,7 +21,6 @@ import time
from typing import Dict, List, Optional, Tuple from typing import Dict, List, Optional, Tuple
import owners_data import owners_data
import owners_dir_metadata
import owners_exporter import owners_exporter
import owners_git import owners_git
import owners_input import owners_input
...@@ -54,12 +53,9 @@ def main(): ...@@ -54,12 +53,9 @@ def main():
paths_to_search = owners_input.get_android_folders(chromium_root, paths_to_search = owners_input.get_android_folders(chromium_root,
arguments.limit_to_dir) arguments.limit_to_dir)
all_dir_metadata = owners_dir_metadata.read_raw_dir_metadata(chromium_root)
with multiprocessing.Pool() as p: with multiprocessing.Pool() as p:
data = p.map( data = p.map(functools.partial(_process_requested_path, chromium_root),
functools.partial(_process_requested_path, chromium_root, paths_to_search)
all_dir_metadata), paths_to_search)
owners_exporter.to_json_file(data, arguments.output) owners_exporter.to_json_file(data, arguments.output)
print(f'Exported to {arguments.output}') print(f'Exported to {arguments.output}')
...@@ -68,18 +64,14 @@ def main(): ...@@ -68,18 +64,14 @@ def main():
def _process_requested_path( def _process_requested_path(
chromium_root: str, all_dir_metadata: Dict, chromium_root: str, requested_path: owners_data.RequestedPath
requested_path: owners_data.RequestedPath
) -> Tuple[owners_data.RequestedPath, owners_data.PathData]: ) -> Tuple[owners_data.RequestedPath, owners_data.PathData]:
'''Gets the necessary information from the git repository.''' '''Gets the necessary information from the git repository.'''
owners_file = _find_owners_file(chromium_root, requested_path.path) owners_file = _find_owners_file(chromium_root, requested_path.path)
owners = _build_owners_info(chromium_root, owners_file) owners = _build_owners_info(chromium_root, owners_file)
git_data = _fetch_git_data(chromium_root, requested_path) git_data = _fetch_git_data(chromium_root, requested_path)
dir_metadata = owners_dir_metadata.build_dir_metadata(chromium_root, path_data = owners_data.PathData(owners, git_data)
all_dir_metadata,
requested_path)
path_data = owners_data.PathData(owners, git_data, dir_metadata)
return (requested_path, path_data) return (requested_path, path_data)
...@@ -187,6 +179,12 @@ def _build_owners_info(chromium_root: str, ...@@ -187,6 +179,12 @@ def _build_owners_info(chromium_root: str,
continue continue
elif line.startswith('file://'): elif line.startswith('file://'):
owners.file_inherited = line[len('file://'):].strip() owners.file_inherited = line[len('file://'):].strip()
elif line.startswith('# COMPONENT:'):
owners.component = line[len('# COMPONENT:'):].strip()
elif line.startswith('# TEAM:'):
owners.team = line[len('# TEAM:'):].strip()
elif line.startswith('# OS:'):
owners.os = line[len('# OS:'):].strip()
elif line.startswith('#'): elif line.startswith('#'):
continue continue
elif line.startswith('per-file'): elif line.startswith('per-file'):
...@@ -218,7 +216,13 @@ def _propagate_down_owner_variables(chromium_root: str, ...@@ -218,7 +216,13 @@ def _propagate_down_owner_variables(chromium_root: str,
return return
if not owners.owners and parent_owners.owners: if not owners.owners and parent_owners.owners:
owners.owners.extend(parent_owners.owners) owners.owners.extend(parent_owners.owners)
if owners.owners: if not owners.component and parent_owners.component:
owners.component = parent_owners.component
if not owners.team and parent_owners.team:
owners.team = parent_owners.team
if not owners.os and parent_owners.os:
owners.os = parent_owners.os
if owners.owners and owners.component and owners.team and owners.os:
return return
visited.add(parent_owners.owners_file) visited.add(parent_owners.owners_file)
......
...@@ -8,23 +8,15 @@ import dataclasses ...@@ -8,23 +8,15 @@ import dataclasses
from typing import List, Optional from typing import List, Optional
@dataclasses.dataclass
class DirMetadata:
'''A synthetic representation of a DIR_METADATA file.'''
component: Optional[str] = None
team: Optional[str] = None
os: Optional[str] = None
def copy(self):
return dataclasses.replace(self)
@dataclasses.dataclass @dataclasses.dataclass
class Owners: class Owners:
'''A synthetic representation of an OWNERS file.''' '''A synthetic representation of an OWNERS file.'''
owners_file: str # Path to OWNERS file owners_file: str # Path to OWNERS file
file_inherited: Optional[str] = None # Referenced OWNERS file file_inherited: Optional[str] = None # Referenced OWNERS file
owners: List[str] = dataclasses.field(default_factory=list) # owners' emails owners: List[str] = dataclasses.field(default_factory=list) # owners' emails
component: Optional[str] = None
team: Optional[str] = None
os: Optional[str] = None
@dataclasses.dataclass @dataclasses.dataclass
...@@ -66,4 +58,3 @@ class PathData: ...@@ -66,4 +58,3 @@ class PathData:
'''Path to be searched for.''' '''Path to be searched for.'''
owner: Owners owner: Owners
git_data: GitData git_data: GitData
dir_metadata: DirMetadata
# Lint as: python3
# Copyright 2021 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import json
import os
import pathlib
import sys
from typing import Dict
import owners_data
_SRC_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
sys.path.append(
os.path.join(_SRC_PATH, 'tools', 'android', 'dependency_analysis'))
import subprocess_utils
def read_raw_dir_metadata(chromium_root: str) -> Dict:
'''Runs all DIR_METADATA files with dirmd and returns a dict of raw data.'''
raw_str: str = subprocess_utils.run_command(
['dirmd', 'export', '--root', chromium_root])
raw_dict: Dict = json.loads(raw_str)
return raw_dict['dirs']
def build_dir_metadata(chromium_root: str, all_dir_metadata: Dict,
requested_path: owners_data.RequestedPath
) -> owners_data.DirMetadata:
'''Creates a synthetic representation of an DIR_METADATA file.'''
return _build_dir_metadata_recursive(chromium_root, all_dir_metadata,
pathlib.Path(requested_path.path))
# Memoized synthetic dir_metadatas
synthetic_dir_metadatas: Dict[pathlib.Path, owners_data.DirMetadata] = {}
def _build_dir_metadata_recursive(chromium_root: str, all_dir_metadata: Dict,
path: pathlib.Path
) -> owners_data.DirMetadata:
# Use memoized value
if path in synthetic_dir_metadatas:
return synthetic_dir_metadatas[path]
# Clone parent synthetic dir_metadata as base
if len(path.parts) > 1:
parent_dir_metadata = _build_dir_metadata_recursive(chromium_root,
all_dir_metadata,
path.parent)
dir_metadata = parent_dir_metadata.copy()
else:
dir_metadata = owners_data.DirMetadata()
# Add data from all_dir_metadata, if there is a DIR_METADATA in the directory
# Be careful to keep values inherited from the parent dir.
raw_dict = all_dir_metadata.get(str(path), {})
monorail = raw_dict.get('monorail', {})
dir_metadata.component = monorail.get('component', dir_metadata.component)
dir_metadata.team = raw_dict.get('teamEmail', dir_metadata.team)
dir_metadata.os = raw_dict.get('os', dir_metadata.os)
# Memoize and return
synthetic_dir_metadatas[path] = dir_metadata
return dir_metadata
...@@ -33,7 +33,6 @@ def _to_data_dict(requested_path: owners_data.RequestedPath, ...@@ -33,7 +33,6 @@ def _to_data_dict(requested_path: owners_data.RequestedPath,
return r return r
owners = path_data.owner owners = path_data.owner
dir_metadata = path_data.dir_metadata
git_data = path_data.git_data git_data = path_data.git_data
return { return {
...@@ -41,9 +40,9 @@ def _to_data_dict(requested_path: owners_data.RequestedPath, ...@@ -41,9 +40,9 @@ def _to_data_dict(requested_path: owners_data.RequestedPath,
'feature': requested_path.feature, 'feature': requested_path.feature,
'owners_file': owners.owners_file, 'owners_file': owners.owners_file,
'owners_email': ', '.join(owners.owners), 'owners_email': ', '.join(owners.owners),
'team': dir_metadata.team if dir_metadata.team else '', 'team': owners.team if owners.team else '',
'component': dir_metadata.component if dir_metadata.component else '', 'component': owners.component if owners.component else '',
'os': dir_metadata.os if dir_metadata.os else '', 'os': owners.os if owners.os else '',
'lines_of_code': str(git_data.lines_of_code), 'lines_of_code': str(git_data.lines_of_code),
'number_of_files': str(git_data.number_of_files), 'number_of_files': str(git_data.number_of_files),
'latest_cl_date': git_data.latest_cl_date, 'latest_cl_date': git_data.latest_cl_date,
......
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