Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 1bd0e29

Browse files
author
Justin Yun
committed
Fix license_collector
This fixes a bug for the VNDK license collector that fails to get the license kinds when a path is given. Bug: 192434786 Test: python3 development/vndk/snapshot/gen_buildfiles.py -vv 29 Change-Id: I101b08b97cfc1229f4e0c67fa66341d4b49fa201
1 parent 4b4779a commit 1bd0e29

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

vndk/snapshot/collect_licenses.py

+23-16
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,35 @@ def read_and_check_licenses(self, license_text, license_keywords):
8484
found = True
8585
return found
8686

87-
def read_and_check_dir_for_licenses(self, path):
88-
""" Check licenses for all files under the directory
87+
def check_licenses(self, filepath):
88+
""" Read a license text file and find the license_kinds.
8989
"""
90-
for (root, _, files) in os.walk(path):
91-
for f in files:
92-
with open(os.path.join(root, f), 'r') as file_to_check:
93-
file_string = file_to_check.read()
94-
self.read_and_check_licenses(file_string, LICENSE_KEYWORDS)
95-
if self.read_and_check_licenses(file_string, RESTRICTED_LICENSE_KEYWORDS):
96-
self.restricted.add(f)
97-
98-
def run(self, license_text=''):
90+
with open(filepath, 'r') as file_to_check:
91+
file_string = file_to_check.read()
92+
self.read_and_check_licenses(file_string, LICENSE_KEYWORDS)
93+
if self.read_and_check_licenses(file_string, RESTRICTED_LICENSE_KEYWORDS):
94+
self.restricted.add(os.path.basename(filepath))
95+
96+
def run(self, license_text_path=''):
9997
""" search licenses in vndk snapshots
98+
99+
Args:
100+
license_text_path: path to the license text file to check.
101+
If empty, check all license files.
100102
"""
101-
if license_text == '':
103+
if license_text_path == '':
102104
for path in self._paths_to_check:
103105
logging.info('Reading {}'.format(path))
104-
self.read_and_check_dir_for_licenses(path)
106+
for (root, _, files) in os.walk(path):
107+
for f in files:
108+
self.check_licenses(os.path.join(root, f))
109+
self.license_kinds.update(LICENSE_INCLUDE)
105110
else:
106-
logging.info('Reading {}'.format(license_text))
107-
self.read_and_check_dir_for_licenses(license_text)
108-
self.license_kinds.update(LICENSE_INCLUDE)
111+
logging.info('Reading {}'.format(license_text_path))
112+
self.check_licenses(os.path.join(self._install_dir, utils.COMMON_DIR_PATH, license_text_path))
113+
if not self.license_kinds:
114+
# Add 'legacy_permissive' if no licenses are found for this file.
115+
self.license_kinds.add('legacy_permissive')
109116

110117
def get_args():
111118
parser = argparse.ArgumentParser()

vndk/snapshot/gen_buildfiles.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,15 @@ def _gen_license_package(self):
301301
ind=self.INDENT,
302302
version=self._vndk_version))
303303

304-
def _get_license_kinds(self, license_text=''):
305-
""" Returns a set of license kinds """
304+
def _get_license_kinds(self, license_text_path=''):
305+
""" Returns a set of license kinds
306+
307+
Args:
308+
license_text_path: path to the license text file to check.
309+
If empty, check all license files.
310+
"""
306311
license_collector = collect_licenses.LicenseCollector(self._install_dir)
307-
license_collector.run(license_text)
312+
license_collector.run(license_text_path)
308313
return license_collector.license_kinds
309314

310315
def _gen_license(self):
@@ -547,7 +552,7 @@ def is_prebuilts_in_list(prebuilts, vndk_list):
547552
return False
548553

549554
def get_notice_file(prebuilts):
550-
"""Returns build rule for notice file (attribute 'notice').
555+
"""Returns build rule for notice file (attribute 'licenses').
551556
552557
Args:
553558
prebuilts: list, names of prebuilt objects

0 commit comments

Comments
 (0)