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