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
This commit is contained in:
@@ -84,28 +84,35 @@ class LicenseCollector(object):
|
||||
found = True
|
||||
return found
|
||||
|
||||
def read_and_check_dir_for_licenses(self, path):
|
||||
""" Check licenses for all files under the directory
|
||||
def check_licenses(self, filepath):
|
||||
""" Read a license text file and find the license_kinds.
|
||||
"""
|
||||
for (root, _, files) in os.walk(path):
|
||||
for f in files:
|
||||
with open(os.path.join(root, f), 'r') as file_to_check:
|
||||
file_string = file_to_check.read()
|
||||
self.read_and_check_licenses(file_string, LICENSE_KEYWORDS)
|
||||
if self.read_and_check_licenses(file_string, RESTRICTED_LICENSE_KEYWORDS):
|
||||
self.restricted.add(f)
|
||||
with open(filepath, 'r') as file_to_check:
|
||||
file_string = file_to_check.read()
|
||||
self.read_and_check_licenses(file_string, LICENSE_KEYWORDS)
|
||||
if self.read_and_check_licenses(file_string, RESTRICTED_LICENSE_KEYWORDS):
|
||||
self.restricted.add(os.path.basename(filepath))
|
||||
|
||||
def run(self, license_text=''):
|
||||
def run(self, license_text_path=''):
|
||||
""" search licenses in vndk snapshots
|
||||
|
||||
Args:
|
||||
license_text_path: path to the license text file to check.
|
||||
If empty, check all license files.
|
||||
"""
|
||||
if license_text == '':
|
||||
if license_text_path == '':
|
||||
for path in self._paths_to_check:
|
||||
logging.info('Reading {}'.format(path))
|
||||
self.read_and_check_dir_for_licenses(path)
|
||||
for (root, _, files) in os.walk(path):
|
||||
for f in files:
|
||||
self.check_licenses(os.path.join(root, f))
|
||||
self.license_kinds.update(LICENSE_INCLUDE)
|
||||
else:
|
||||
logging.info('Reading {}'.format(license_text))
|
||||
self.read_and_check_dir_for_licenses(license_text)
|
||||
self.license_kinds.update(LICENSE_INCLUDE)
|
||||
logging.info('Reading {}'.format(license_text_path))
|
||||
self.check_licenses(os.path.join(self._install_dir, utils.COMMON_DIR_PATH, license_text_path))
|
||||
if not self.license_kinds:
|
||||
# Add 'legacy_permissive' if no licenses are found for this file.
|
||||
self.license_kinds.add('legacy_permissive')
|
||||
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
@@ -301,10 +301,15 @@ class GenBuildFile(object):
|
||||
ind=self.INDENT,
|
||||
version=self._vndk_version))
|
||||
|
||||
def _get_license_kinds(self, license_text=''):
|
||||
""" Returns a set of license kinds """
|
||||
def _get_license_kinds(self, license_text_path=''):
|
||||
""" Returns a set of license kinds
|
||||
|
||||
Args:
|
||||
license_text_path: path to the license text file to check.
|
||||
If empty, check all license files.
|
||||
"""
|
||||
license_collector = collect_licenses.LicenseCollector(self._install_dir)
|
||||
license_collector.run(license_text)
|
||||
license_collector.run(license_text_path)
|
||||
return license_collector.license_kinds
|
||||
|
||||
def _gen_license(self):
|
||||
@@ -547,7 +552,7 @@ class GenBuildFile(object):
|
||||
return False
|
||||
|
||||
def get_notice_file(prebuilts):
|
||||
"""Returns build rule for notice file (attribute 'notice').
|
||||
"""Returns build rule for notice file (attribute 'licenses').
|
||||
|
||||
Args:
|
||||
prebuilts: list, names of prebuilt objects
|
||||
|
||||
Reference in New Issue
Block a user