Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Generates the contents of an Cronet LICENSE file for the third-party code. | 6 """Generates the contents of an Cronet LICENSE file for the third-party code. |
| 7 | 7 |
| 8 It makes use of src/tools/licenses.py and the README.chromium files on which | 8 It makes use of src/tools/licenses.py and the README.chromium files on which |
| 9 it depends. Based on android_webview/tools/webview_licenses.py. | 9 it depends. Based on android_webview/tools/webview_licenses.py. |
| 10 """ | 10 """ |
| 11 | 11 |
| 12 import optparse | 12 import optparse |
| 13 import os | 13 import os |
| 14 import shutil | 14 import shutil |
| 15 import subprocess | 15 import subprocess |
| 16 import sys | 16 import sys |
| 17 import tempfile | 17 import tempfile |
| 18 import textwrap | 18 import textwrap |
| 19 | 19 |
| 20 REPOSITORY_ROOT = os.path.abspath(os.path.join( | 20 REPOSITORY_ROOT = os.path.abspath(os.path.join( |
| 21 os.path.dirname(__file__), '..', '..', '..')) | 21 os.path.dirname(__file__), '..', '..', '..')) |
| 22 | 22 |
| 23 sys.path.append(os.path.join(REPOSITORY_ROOT, 'tools')) | 23 sys.path.append(os.path.join(REPOSITORY_ROOT, 'tools')) |
| 24 import licenses | 24 import licenses |
| 25 | 25 |
| 26 third_party_dirs = [ | 26 third_party_dirs = [ |
|
xunjieli
2016/07/18 21:33:12
Can this be removed now? since the dependencies ar
mef
2016/07/18 22:01:04
Exactly, I would wait until GYP support is depreca
xunjieli
2016/07/18 22:03:58
Acknowledged.
| |
| 27 'base/third_party/libevent', | 27 'base/third_party/libevent', |
| 28 'third_party/ashmem', | 28 'third_party/ashmem', |
| 29 'third_party/boringssl', | 29 'third_party/boringssl', |
| 30 'third_party/modp_b64', | 30 'third_party/modp_b64', |
| 31 'third_party/zlib', | 31 'third_party/zlib', |
| 32 ] | 32 ] |
| 33 | 33 |
| 34 | 34 |
| 35 def _ReadFile(path): | 35 def _ReadFile(path): |
| 36 """Reads a file from disk. | 36 """Reads a file from disk. |
| 37 Args: | 37 Args: |
| 38 path: The path of the file to read, relative to the root of the repository. | 38 path: The path of the file to read, relative to the root of the repository. |
| 39 Returns: | 39 Returns: |
| 40 The contents of the file as a string. | 40 The contents of the file as a string. |
| 41 """ | 41 """ |
| 42 return open(os.path.join(REPOSITORY_ROOT, path), 'rb').read() | 42 return open(os.path.join(REPOSITORY_ROOT, path), 'rb').read() |
| 43 | 43 |
| 44 | 44 |
| 45 def GenerateLicense(): | 45 def GenerateLicense(): |
| 46 """Generates the contents of an Cronet LICENSE file for the third-party code. | 46 """Generates the contents of an Cronet LICENSE file for the third-party code. |
| 47 Returns: | 47 Returns: |
| 48 The contents of the LICENSE file. | 48 The contents of the LICENSE file. |
| 49 """ | 49 """ |
| 50 # Start with Chromium's LICENSE file | 50 # Start with Chromium's LICENSE file |
| 51 content = [_ReadFile('LICENSE')] | 51 content = [_ReadFile('LICENSE')] |
| 52 | 52 |
| 53 # Add necessary third_party. | 53 # Add necessary third_party. |
| 54 for directory in sorted(third_party_dirs): | 54 for directory in sorted(third_party_dirs, key=os.path.basename): |
| 55 metadata = licenses.ParseDir(directory, REPOSITORY_ROOT, | 55 metadata = licenses.ParseDir(directory, REPOSITORY_ROOT, |
| 56 require_license_file=True) | 56 require_license_file=True) |
| 57 content.append('-' * 20) | 57 content.append('-' * 20) |
| 58 content.append(directory.split("/")[-1]) | 58 content.append(directory.split("/")[-1]) |
| 59 content.append('-' * 20) | 59 content.append('-' * 20) |
| 60 license_file = metadata['License File'] | 60 license_file = metadata['License File'] |
| 61 if license_file and license_file != licenses.NOT_SHIPPED: | 61 if license_file and license_file != licenses.NOT_SHIPPED: |
| 62 content.append(_ReadFile(license_file)) | 62 content.append(_ReadFile(license_file)) |
| 63 | 63 |
| 64 return '\n'.join(content) | 64 return '\n'.join(content) |
| 65 | 65 |
| 66 | 66 |
| 67 def FindThirdPartyDeps(gn_out_dir): | 67 def FindThirdPartyDeps(gn_out_dir): |
| 68 # Generate gn project in temp directory and use it to find dependencies. | 68 # Generate gn project in temp directory and use it to find dependencies. |
| 69 # Current gn directory cannot ba used because gn doesn't allow recursive | 69 # Current gn directory cannot ba used because gn doesn't allow recursive |
| 70 # invocations due to potential side effects. | 70 # invocations due to potential side effects. |
| 71 try: | 71 try: |
| 72 tmp_dir = tempfile.mkdtemp(dir = gn_out_dir) | 72 tmp_dir = tempfile.mkdtemp(dir = os.path.join(gn_out_dir, "..")) |
| 73 shutil.copy(gn_out_dir + "/args.gn", tmp_dir) | 73 shutil.copy(os.path.join(gn_out_dir, "args.gn"), tmp_dir) |
| 74 subprocess.check_output(["gn", "gen", tmp_dir]) | 74 subprocess.check_output(["gn", "gen", tmp_dir]) |
| 75 gn_deps = subprocess.check_output(["gn", "desc", tmp_dir, \ | 75 gn_deps = subprocess.check_output(["gn", "desc", tmp_dir, \ |
| 76 "//net", "deps", "--as=buildfile", "--all"]) | 76 "//net", "deps", "--as=buildfile", "--all"]) |
| 77 finally: | 77 finally: |
| 78 if os.path.exists(tmp_dir): | 78 if os.path.exists(tmp_dir): |
| 79 shutil.rmtree(tmp_dir) | 79 shutil.rmtree(tmp_dir) |
| 80 | 80 |
| 81 third_party_deps = [] | 81 third_party_deps = [] |
| 82 for build_dep in gn_deps.split(): | 82 for build_dep in gn_deps.split(): |
| 83 if ("third_party" in build_dep and build_dep.endswith("/BUILD.gn")): | 83 # Look for third party deps that have separate license. |
| 84 third_party_deps.append(build_dep.replace("/BUILD.gn", "")) | 84 if ("third_party" in build_dep and not "android_tools" in build_dep and |
| 85 third_party_deps.sort() | 85 os.path.basename(build_dep) == "BUILD.gn"): |
| 86 third_party_deps.append(os.path.dirname(build_dep)) | |
| 86 return third_party_deps | 87 return third_party_deps |
| 87 | 88 |
| 88 | 89 |
| 89 def main(): | 90 def main(): |
| 90 class FormatterWithNewLines(optparse.IndentedHelpFormatter): | 91 class FormatterWithNewLines(optparse.IndentedHelpFormatter): |
| 91 def format_description(self, description): | 92 def format_description(self, description): |
| 92 paras = description.split('\n') | 93 paras = description.split('\n') |
| 93 formatted_paras = [textwrap.fill(para, self.width) for para in paras] | 94 formatted_paras = [textwrap.fill(para, self.width) for para in paras] |
| 94 return '\n'.join(formatted_paras) + '\n' | 95 return '\n'.join(formatted_paras) + '\n' |
| 95 | 96 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 122 else: | 123 else: |
| 123 print GenerateLicense() | 124 print GenerateLicense() |
| 124 return 0 | 125 return 0 |
| 125 | 126 |
| 126 parser.print_help() | 127 parser.print_help() |
| 127 return 1 | 128 return 1 |
| 128 | 129 |
| 129 | 130 |
| 130 if __name__ == '__main__': | 131 if __name__ == '__main__': |
| 131 sys.exit(main()) | 132 sys.exit(main()) |
| OLD | NEW |