Commit f4fa98d2 authored by Hiroshi Ichikawa's avatar Hiroshi Ichikawa Committed by Commit Bot

Apply git cl format to //tools/licenses.py.

//tools has its own custom styling configuration to use 2-space indent:
https://source.chromium.org/chromium/chromium/src/+/master:tools/.style.yapf?originalUrl=https:%2F%2Fcs.chromium.org%2F
So it is expected that this CL converts the file to use 2-space indent
even though it's not compatible with the latest style guide.

Change-Id: I5fd40493eba702f5ffcc5aa932841a509554c665
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2132649
Auto-Submit: Hiroshi Ichikawa <ichikawa@chromium.org>
Reviewed-by: default avatarDavid Jean <djean@chromium.org>
Commit-Queue: David Jean <djean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756209}
parent 4c420c42
...@@ -369,6 +369,7 @@ class LicenseError(Exception): ...@@ -369,6 +369,7 @@ class LicenseError(Exception):
fully filled out.""" fully filled out."""
pass pass
def AbsolutePath(path, filename, root): def AbsolutePath(path, filename, root):
"""Convert a path in README.chromium to be absolute based on the source """Convert a path in README.chromium to be absolute based on the source
root.""" root."""
...@@ -382,6 +383,7 @@ def AbsolutePath(path, filename, root): ...@@ -382,6 +383,7 @@ def AbsolutePath(path, filename, root):
return absolute_path return absolute_path
return None return None
def ParseDir(path, root, require_license_file=True, optional_keys=None): def ParseDir(path, root, require_license_file=True, optional_keys=None):
"""Examine a third_party/foo component and extract its metadata.""" """Examine a third_party/foo component and extract its metadata."""
# Parse metadata fields out of README.chromium. # Parse metadata fields out of README.chromium.
...@@ -466,7 +468,7 @@ def FindThirdPartyDirs(prune_paths, root): ...@@ -466,7 +468,7 @@ def FindThirdPartyDirs(prune_paths, root):
"""Find all third_party directories underneath the source root.""" """Find all third_party directories underneath the source root."""
third_party_dirs = set() third_party_dirs = set()
for path, dirs, files in os.walk(root): for path, dirs, files in os.walk(root):
path = path[len(root)+1:] # Pretty up the path. path = path[len(root) + 1:] # Pretty up the path.
if path in prune_paths: if path in prune_paths:
dirs[:] = [] dirs[:] = []
...@@ -483,15 +485,15 @@ def FindThirdPartyDirs(prune_paths, root): ...@@ -483,15 +485,15 @@ def FindThirdPartyDirs(prune_paths, root):
# Add all subdirectories that are not marked for skipping. # Add all subdirectories that are not marked for skipping.
for dir in dirs: for dir in dirs:
dirpath = os.path.join(path, dir) dirpath = os.path.join(path, dir)
additional_paths_file = os.path.join( additional_paths_file = os.path.join(root, dirpath,
root, dirpath, ADDITIONAL_PATHS_FILENAME) ADDITIONAL_PATHS_FILENAME)
if dirpath not in prune_paths: if dirpath not in prune_paths:
third_party_dirs.add(dirpath) third_party_dirs.add(dirpath)
if os.path.exists(additional_paths_file): if os.path.exists(additional_paths_file):
with open(additional_paths_file) as paths_file: with open(additional_paths_file) as paths_file:
extra_paths = json.load(paths_file) extra_paths = json.load(paths_file)
third_party_dirs.update([ third_party_dirs.update(
os.path.join(dirpath, p) for p in extra_paths]) [os.path.join(dirpath, p) for p in extra_paths])
# Don't recurse into any subdirs from here. # Don't recurse into any subdirs from here.
dirs[:] = [] dirs[:] = []
...@@ -542,8 +544,7 @@ def GetThirdPartyDepsFromGNDepsOutput(gn_deps, target_os): ...@@ -542,8 +544,7 @@ def GetThirdPartyDepsFromGNDepsOutput(gn_deps, target_os):
""" """
third_party_deps = set() third_party_deps = set()
for absolute_build_dep in gn_deps.split(): for absolute_build_dep in gn_deps.split():
relative_build_dep = os.path.relpath( relative_build_dep = os.path.relpath(absolute_build_dep, _REPOSITORY_ROOT)
absolute_build_dep, _REPOSITORY_ROOT)
m = re.search( m = re.search(
r'^((.+[/\\])?third_party[/\\][^/\\]+[/\\])(.+[/\\])?BUILD\.gn$', r'^((.+[/\\])?third_party[/\\][^/\\]+[/\\])(.+[/\\])?BUILD\.gn$',
relative_build_dep) relative_build_dep)
...@@ -552,8 +553,8 @@ def GetThirdPartyDepsFromGNDepsOutput(gn_deps, target_os): ...@@ -552,8 +553,8 @@ def GetThirdPartyDepsFromGNDepsOutput(gn_deps, target_os):
third_party_path = m.group(1) third_party_path = m.group(1)
if any(third_party_path.startswith(p + os.sep) for p in PRUNE_PATHS): if any(third_party_path.startswith(p + os.sep) for p in PRUNE_PATHS):
continue continue
if (target_os == 'ios' and if (target_os == 'ios' and any(
any(third_party_path.startswith(p + os.sep) third_party_path.startswith(p + os.sep)
for p in KNOWN_NON_IOS_LIBRARIES)): for p in KNOWN_NON_IOS_LIBRARIES)):
# Skip over files that are known not to be used on iOS. # Skip over files that are known not to be used on iOS.
continue continue
...@@ -571,12 +572,13 @@ def FindThirdPartyDeps(gn_out_dir, gn_target, target_os): ...@@ -571,12 +572,13 @@ def FindThirdPartyDeps(gn_out_dir, gn_target, target_os):
# effects. # effects.
tmp_dir = None tmp_dir = None
try: try:
tmp_dir = tempfile.mkdtemp(dir = gn_out_dir) tmp_dir = tempfile.mkdtemp(dir=gn_out_dir)
shutil.copy(os.path.join(gn_out_dir, "args.gn"), tmp_dir) shutil.copy(os.path.join(gn_out_dir, "args.gn"), tmp_dir)
subprocess.check_output([_GnBinary(), "gen", tmp_dir]) subprocess.check_output([_GnBinary(), "gen", tmp_dir])
gn_deps = subprocess.check_output([ gn_deps = subprocess.check_output([
_GnBinary(), "desc", tmp_dir, gn_target, _GnBinary(), "desc", tmp_dir, gn_target, "deps", "--as=buildfile",
"deps", "--as=buildfile", "--all"]) "--all"
])
if isinstance(gn_deps, bytes): if isinstance(gn_deps, bytes):
gn_deps = gn_deps.decode("utf-8") gn_deps = gn_deps.decode("utf-8")
finally: finally:
...@@ -657,9 +659,10 @@ def GenerateCredits( ...@@ -657,9 +659,10 @@ def GenerateCredits(
chromium_license_metadata = { chromium_license_metadata = {
'Name': 'The Chromium Project', 'Name': 'The Chromium Project',
'URL': 'http://www.chromium.org', 'URL': 'http://www.chromium.org',
'License File': os.path.join(_REPOSITORY_ROOT, 'LICENSE') } 'License File': os.path.join(_REPOSITORY_ROOT, 'LICENSE')
entries.append(MetadataToTemplateEntry(chromium_license_metadata, }
entry_template)) entries.append(
MetadataToTemplateEntry(chromium_license_metadata, entry_template))
for path in third_party_dirs: for path in third_party_dirs:
try: try:
...@@ -686,9 +689,8 @@ def GenerateCredits( ...@@ -686,9 +689,8 @@ def GenerateCredits(
entries_contents = '\n'.join([entry['content'] for entry in entries]) entries_contents = '\n'.join([entry['content'] for entry in entries])
file_template = open(file_template_file).read() file_template = open(file_template_file).read()
template_contents = "<!-- Generated by licenses.py; do not edit. -->" template_contents = "<!-- Generated by licenses.py; do not edit. -->"
template_contents += EvaluateTemplate(file_template, template_contents += EvaluateTemplate(
{'entries': entries_contents}, file_template, {'entries': entries_contents}, escape=False)
escape=False)
if output_file: if output_file:
changed = True changed = True
...@@ -747,8 +749,7 @@ def GenerateLicenseFile(output_file, gn_out_dir, gn_target, target_os): ...@@ -747,8 +749,7 @@ def GenerateLicenseFile(output_file, gn_out_dir, gn_target, target_os):
# Add necessary third_party. # Add necessary third_party.
for directory in sorted(third_party_dirs): for directory in sorted(third_party_dirs):
metadata = ParseDir( metadata = ParseDir(directory, _REPOSITORY_ROOT, require_license_file=True)
directory, _REPOSITORY_ROOT, require_license_file=True)
content.append('-' * 20) content.append('-' * 20)
content.append(directory.split(os.sep)[-1]) content.append(directory.split(os.sep)[-1])
content.append('-' * 20) content.append('-' * 20)
...@@ -768,18 +769,16 @@ def GenerateLicenseFile(output_file, gn_out_dir, gn_target, target_os): ...@@ -768,18 +769,16 @@ def GenerateLicenseFile(output_file, gn_out_dir, gn_target, target_os):
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--file-template', parser.add_argument(
help='Template HTML to use for the license page.') '--file-template', help='Template HTML to use for the license page.')
parser.add_argument('--entry-template', parser.add_argument(
help='Template HTML to use for each license.') '--entry-template', help='Template HTML to use for each license.')
parser.add_argument('--target-os', parser.add_argument('--target-os', help='OS that this build is targeting.')
help='OS that this build is targeting.') parser.add_argument(
parser.add_argument('--gn-out-dir', '--gn-out-dir', help='GN output directory for scanning dependencies.')
help='GN output directory for scanning dependencies.') parser.add_argument('--gn-target', help='GN target to scan for dependencies.')
parser.add_argument('--gn-target', parser.add_argument(
help='GN target to scan for dependencies.') 'command', choices=['help', 'scan', 'credits', 'license_file'])
parser.add_argument('command',
choices=['help', 'scan', 'credits', 'license_file'])
parser.add_argument('output_file', nargs='?') parser.add_argument('output_file', nargs='?')
build_utils.AddDepfileOption(parser) build_utils.AddDepfileOption(parser)
args = parser.parse_args() args = parser.parse_args()
...@@ -789,13 +788,12 @@ def main(): ...@@ -789,13 +788,12 @@ def main():
return 1 return 1
elif args.command == 'credits': elif args.command == 'credits':
if not GenerateCredits(args.file_template, args.entry_template, if not GenerateCredits(args.file_template, args.entry_template,
args.output_file, args.target_os, args.output_file, args.target_os, args.gn_out_dir,
args.gn_out_dir, args.gn_target, args.depfile): args.gn_target, args.depfile):
return 1 return 1
elif args.command == 'license_file': elif args.command == 'license_file':
try: try:
GenerateLicenseFile( GenerateLicenseFile(args.output_file, args.gn_out_dir, args.gn_target,
args.output_file, args.gn_out_dir, args.gn_target,
args.target_os) args.target_os)
except LicenseError as e: except LicenseError as e:
print("Failed to parse README.chromium: {}".format(e)) print("Failed to parse README.chromium: {}".format(e))
......
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