Merge changes Ie435db0f,Ib7db7e7d,I673a6804
* changes: vndk-def: Add namespaces to update_dataset_auto.py sourcedr: Support module namespace sourcedr: Cleanup os.path.abspath()
This commit is contained in:
@@ -41,6 +41,8 @@ def update_eligible_list_properties(path, build_top):
|
||||
|
||||
cmd = [sys.executable, LIST_VNDK_MODULE]
|
||||
cmd.extend(['--exclude', '(?:device/)|(?:vendor/)'])
|
||||
cmd.extend(['--namespace', 'hardware/google/av'])
|
||||
cmd.extend(['--namespace', 'hardware/google/interfaces'])
|
||||
cmd.extend(['-o', tmp_path])
|
||||
cmd.append(os.path.join(build_top, 'Android.bp'))
|
||||
|
||||
|
||||
@@ -825,7 +825,7 @@ class RecursiveParser(object):
|
||||
def _parse_file_recursive(self, path, env, evaluate, use_subdirs):
|
||||
"""Parse a blueprint file and recursively."""
|
||||
|
||||
self.visited.add(os.path.abspath(path))
|
||||
self.visited.add(path)
|
||||
|
||||
sub_env = self._parse_file(path, env, evaluate)
|
||||
|
||||
@@ -839,7 +839,7 @@ class RecursiveParser(object):
|
||||
sub_env.pop('optional_subdirs', None)
|
||||
|
||||
for sub_file_path in sub_file_paths:
|
||||
if os.path.abspath(sub_file_path) not in self.visited:
|
||||
if sub_file_path not in self.visited:
|
||||
self._parse_file_recursive(sub_file_path, sub_env, evaluate,
|
||||
use_subdirs)
|
||||
return sub_env
|
||||
@@ -849,6 +849,8 @@ class RecursiveParser(object):
|
||||
"""Scan all files with the specified name and parse them."""
|
||||
|
||||
rootdir = os.path.dirname(path)
|
||||
assert rootdir, 'rootdir is empty but must be non-empty'
|
||||
|
||||
envs = [(rootdir, env)]
|
||||
assert env is not None
|
||||
|
||||
@@ -888,6 +890,8 @@ class RecursiveParser(object):
|
||||
if env is None:
|
||||
env = {}
|
||||
|
||||
path = os.path.abspath(path)
|
||||
|
||||
sub_env = self._read_file(path, env)[1]
|
||||
|
||||
if 'subdirs' in sub_env or 'optional_subdirs' in sub_env:
|
||||
@@ -961,3 +965,31 @@ def evaluate_defaults(modules):
|
||||
attrs = evaluate_default(attrs, named_modules[default][1])
|
||||
modules[i] = (ident, attrs)
|
||||
return modules
|
||||
|
||||
|
||||
def fill_module_namespaces(root_bp, modules):
|
||||
"""Collect soong_namespace definition and set a `_namespace` property to
|
||||
each module definitions."""
|
||||
|
||||
# Collect all namespaces
|
||||
rootdir = os.path.dirname(os.path.abspath(root_bp))
|
||||
namespaces = {rootdir}
|
||||
for ident, attrs in modules:
|
||||
if ident == 'soong_namespace':
|
||||
namespaces.add(os.path.dirname(attrs['_path']))
|
||||
|
||||
# Build a path matcher for module namespaces
|
||||
namespaces = sorted(namespaces, reverse=True)
|
||||
path_matcher = re.compile(
|
||||
'|'.join('(' + re.escape(x) + '/.*)' for x in namespaces))
|
||||
|
||||
# Trim the root directory prefix
|
||||
rootdir_prefix_len = len(rootdir) + 1
|
||||
namespaces = [path[rootdir_prefix_len:] for path in namespaces]
|
||||
|
||||
# Fill in module namespaces
|
||||
for ident, attrs in modules:
|
||||
match = path_matcher.match(attrs['_path'])
|
||||
attrs['_namespace'] = namespaces[match.lastindex - 1]
|
||||
|
||||
return modules
|
||||
|
||||
@@ -94,6 +94,8 @@ def _parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('root_bp',
|
||||
help='path to Android.bp in ANDROID_BUILD_TOP')
|
||||
parser.add_argument('--namespace', action='append', default=[''],
|
||||
help='extra module namespaces')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@@ -102,7 +104,8 @@ def main():
|
||||
|
||||
args = _parse_args()
|
||||
|
||||
module_dicts = vndk.ModuleClassifier.create_from_root_bp(args.root_bp)
|
||||
module_dicts = vndk.ModuleClassifier.create_from_root_bp(
|
||||
args.root_bp, args.namespace)
|
||||
|
||||
all_bad_deps = _check_modules_deps(module_dicts)
|
||||
for name, bad_deps in all_bad_deps:
|
||||
|
||||
@@ -38,6 +38,8 @@ def _parse_args():
|
||||
help='regular expression for the excluded directories')
|
||||
parser.add_argument('--select',
|
||||
help='regular expression for the selected directories')
|
||||
parser.add_argument('--namespace', action='append', default=[''],
|
||||
help='extra module namespaces')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@@ -82,7 +84,8 @@ def main():
|
||||
exclude = re.compile(args.exclude) if args.exclude else None
|
||||
|
||||
# Parse Blueprint files and get VNDK libs
|
||||
module_dicts = vndk.ModuleClassifier.create_from_root_bp(args.root_bp)
|
||||
module_dicts = vndk.ModuleClassifier.create_from_root_bp(
|
||||
args.root_bp, args.namespace)
|
||||
|
||||
root_dir = os.path.dirname(args.root_bp)
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ correctness of dependencies."""
|
||||
|
||||
import copy
|
||||
|
||||
from blueprint import RecursiveParser, evaluate_defaults
|
||||
from blueprint import RecursiveParser, evaluate_defaults, fill_module_namespaces
|
||||
|
||||
|
||||
class Module(object):
|
||||
@@ -137,7 +137,7 @@ class ModuleClassifier(object):
|
||||
self.vendor_available_libs[name] = module
|
||||
|
||||
|
||||
def _add_modules_from_parsed_pairs(self, parsed_items):
|
||||
def _add_modules_from_parsed_pairs(self, parsed_items, namespaces):
|
||||
"""Add modules from the parsed (rule, attrs) pairs."""
|
||||
|
||||
for rule, attrs in parsed_items:
|
||||
@@ -145,6 +145,10 @@ class ModuleClassifier(object):
|
||||
if name is None:
|
||||
continue
|
||||
|
||||
namespace = attrs.get('_namespace')
|
||||
if namespace not in namespaces:
|
||||
continue
|
||||
|
||||
if rule == 'llndk_library':
|
||||
self.add_module(name, Module(rule, attrs))
|
||||
if rule in {'llndk_library', 'ndk_library'}:
|
||||
@@ -169,19 +173,22 @@ class ModuleClassifier(object):
|
||||
continue
|
||||
|
||||
|
||||
def parse_root_bp(self, root_bp_path):
|
||||
def parse_root_bp(self, root_bp_path, namespaces=None):
|
||||
"""Parse blueprint files and add module definitions."""
|
||||
|
||||
namespaces = {''} if namespaces is None else set(namespaces)
|
||||
|
||||
parser = RecursiveParser()
|
||||
parser.parse_file(root_bp_path)
|
||||
parsed_items = evaluate_defaults(parser.modules)
|
||||
parsed_items = fill_module_namespaces(root_bp_path, parsed_items)
|
||||
|
||||
self._add_modules_from_parsed_pairs(parsed_items)
|
||||
self._add_modules_from_parsed_pairs(parsed_items, namespaces)
|
||||
|
||||
|
||||
@classmethod
|
||||
def create_from_root_bp(cls, root_bp_path):
|
||||
def create_from_root_bp(cls, root_bp_path, namespaces=None):
|
||||
"""Create a ModuleClassifier from a root blueprint file."""
|
||||
result = cls()
|
||||
result.parse_root_bp(root_bp_path)
|
||||
result.parse_root_bp(root_bp_path, namespaces)
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user