| Index: components/cronet/tools/cronet_licenses.py
|
| diff --git a/components/cronet/tools/cronet_licenses.py b/components/cronet/tools/cronet_licenses.py
|
| index 63a7b07e21d47f79294e7953dd6bbadbff55daf4..160d13928686b02cc43dd60efec79311df51b41f 100755
|
| --- a/components/cronet/tools/cronet_licenses.py
|
| +++ b/components/cronet/tools/cronet_licenses.py
|
| @@ -11,7 +11,10 @@ it depends. Based on android_webview/tools/webview_licenses.py.
|
|
|
| import optparse
|
| import os
|
| +import shutil
|
| +import subprocess
|
| import sys
|
| +import tempfile
|
| import textwrap
|
|
|
| REPOSITORY_ROOT = os.path.abspath(os.path.join(
|
| @@ -20,6 +23,15 @@ REPOSITORY_ROOT = os.path.abspath(os.path.join(
|
| sys.path.append(os.path.join(REPOSITORY_ROOT, 'tools'))
|
| import licenses
|
|
|
| +third_party_dirs = [
|
| + 'base/third_party/libevent',
|
| + 'third_party/ashmem',
|
| + 'third_party/boringssl',
|
| + 'third_party/modp_b64',
|
| + 'third_party/zlib',
|
| +]
|
| +
|
| +
|
| def _ReadFile(path):
|
| """Reads a file from disk.
|
| Args:
|
| @@ -35,15 +47,6 @@ def GenerateLicense():
|
| Returns:
|
| The contents of the LICENSE file.
|
| """
|
| - # TODO(mef): Generate list of third_party libraries using checkdeps.
|
| - third_party_dirs = [
|
| - 'base/third_party/libevent',
|
| - 'third_party/ashmem',
|
| - 'third_party/boringssl',
|
| - 'third_party/modp_b64',
|
| - 'third_party/zlib',
|
| - ]
|
| -
|
| # Start with Chromium's LICENSE file
|
| content = [_ReadFile('LICENSE')]
|
|
|
| @@ -52,7 +55,7 @@ def GenerateLicense():
|
| metadata = licenses.ParseDir(directory, REPOSITORY_ROOT,
|
| require_license_file=True)
|
| content.append('-' * 20)
|
| - content.append(directory)
|
| + content.append(directory.split("/")[-1])
|
| content.append('-' * 20)
|
| license_file = metadata['License File']
|
| if license_file and license_file != licenses.NOT_SHIPPED:
|
| @@ -61,6 +64,28 @@ def GenerateLicense():
|
| return '\n'.join(content)
|
|
|
|
|
| +def FindThirdPartyDeps(gn_out_dir):
|
| + # Generate gn project in temp directory and use it to find dependencies.
|
| + # Current gn directory cannot ba used because gn doesn't allow recursive
|
| + # invocations due to potential side effects.
|
| + try:
|
| + tmp_dir = tempfile.mkdtemp(dir = gn_out_dir)
|
| + shutil.copy(gn_out_dir + "/args.gn", tmp_dir)
|
| + subprocess.check_output(["gn", "gen", tmp_dir])
|
| + gn_deps = subprocess.check_output(["gn", "desc", tmp_dir, \
|
| + "//net", "deps", "--as=buildfile", "--all"])
|
| + finally:
|
| + if os.path.exists(tmp_dir):
|
| + shutil.rmtree(tmp_dir)
|
| +
|
| + third_party_deps = []
|
| + for build_dep in gn_deps.split():
|
| + if ("third_party" in build_dep and build_dep.endswith("/BUILD.gn")):
|
| + third_party_deps.append(build_dep.replace("/BUILD.gn", ""))
|
| + third_party_deps.sort()
|
| + return third_party_deps
|
| +
|
| +
|
| def main():
|
| class FormatterWithNewLines(optparse.IndentedHelpFormatter):
|
| def format_description(self, description):
|
| @@ -70,11 +95,18 @@ def main():
|
|
|
| parser = optparse.OptionParser(formatter=FormatterWithNewLines(),
|
| usage='%prog command [options]')
|
| + parser.add_option('--gn', help='Use gn deps to find third party dependencies',
|
| + action='store_true')
|
| parser.description = (__doc__ +
|
| '\nCommands:\n' \
|
| ' license [filename]\n' \
|
| ' Generate Cronet LICENSE to filename or stdout.\n')
|
| (_, args) = parser.parse_args()
|
| +
|
| + if _.gn:
|
| + global third_party_dirs
|
| + third_party_dirs = FindThirdPartyDeps(os.getcwd())
|
| +
|
| if not args:
|
| parser.print_help()
|
| return 1
|
|
|