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 # TODO(mef): Remove hard-coded list once GYP support is deprecated. | |
27 third_party_dirs = [ | 26 third_party_dirs = [ |
28 'base/third_party/libevent', | 27 'base/third_party/libevent', |
29 'third_party/ashmem', | 28 'third_party/ashmem', |
30 'third_party/boringssl', | 29 'third_party/boringssl', |
31 'third_party/modp_b64', | 30 'third_party/modp_b64', |
32 'third_party/zlib', | 31 'third_party/zlib', |
33 ] | 32 ] |
34 | 33 |
35 | 34 |
36 def _ReadFile(path): | 35 def _ReadFile(path): |
37 """Reads a file from disk. | 36 """Reads a file from disk. |
38 Args: | 37 Args: |
39 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. |
40 Returns: | 39 Returns: |
41 The contents of the file as a string. | 40 The contents of the file as a string. |
42 """ | 41 """ |
43 return open(os.path.join(REPOSITORY_ROOT, path), 'rb').read() | 42 return open(os.path.join(REPOSITORY_ROOT, path), 'rb').read() |
44 | 43 |
45 | 44 |
46 def GenerateLicense(): | 45 def GenerateLicense(): |
47 """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. |
48 Returns: | 47 Returns: |
49 The contents of the LICENSE file. | 48 The contents of the LICENSE file. |
50 """ | 49 """ |
51 # Start with Chromium's LICENSE file | 50 # Start with Chromium's LICENSE file |
52 content = [_ReadFile('LICENSE')] | 51 content = [_ReadFile('LICENSE')] |
53 | 52 |
54 # Add necessary third_party. | 53 # Add necessary third_party. |
55 for directory in sorted(third_party_dirs, key=os.path.basename): | 54 for directory in sorted(third_party_dirs): |
56 metadata = licenses.ParseDir(directory, REPOSITORY_ROOT, | 55 metadata = licenses.ParseDir(directory, REPOSITORY_ROOT, |
57 require_license_file=True) | 56 require_license_file=True) |
58 content.append('-' * 20) | 57 content.append('-' * 20) |
59 content.append(directory.split("/")[-1]) | 58 content.append(directory.split("/")[-1]) |
60 content.append('-' * 20) | 59 content.append('-' * 20) |
61 license_file = metadata['License File'] | 60 license_file = metadata['License File'] |
62 if license_file and license_file != licenses.NOT_SHIPPED: | 61 if license_file and license_file != licenses.NOT_SHIPPED: |
63 content.append(_ReadFile(license_file)) | 62 content.append(_ReadFile(license_file)) |
64 | 63 |
65 return '\n'.join(content) | 64 return '\n'.join(content) |
66 | 65 |
67 | 66 |
68 def FindThirdPartyDeps(gn_out_dir): | 67 def FindThirdPartyDeps(gn_out_dir): |
69 # 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. |
70 # 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 |
71 # invocations due to potential side effects. | 70 # invocations due to potential side effects. |
72 try: | 71 try: |
73 tmp_dir = tempfile.mkdtemp(dir = os.path.join(gn_out_dir, "..")) | 72 tmp_dir = tempfile.mkdtemp(dir = gn_out_dir) |
74 shutil.copy(os.path.join(gn_out_dir, "args.gn"), tmp_dir) | 73 shutil.copy(gn_out_dir + "/args.gn", tmp_dir) |
75 subprocess.check_output(["gn", "gen", tmp_dir]) | 74 subprocess.check_output(["gn", "gen", tmp_dir]) |
76 gn_deps = subprocess.check_output(["gn", "desc", tmp_dir, \ | 75 gn_deps = subprocess.check_output(["gn", "desc", tmp_dir, \ |
77 "//net", "deps", "--as=buildfile", "--all"]) | 76 "//net", "deps", "--as=buildfile", "--all"]) |
78 finally: | 77 finally: |
79 if os.path.exists(tmp_dir): | 78 if os.path.exists(tmp_dir): |
80 shutil.rmtree(tmp_dir) | 79 shutil.rmtree(tmp_dir) |
81 | 80 |
82 third_party_deps = [] | 81 third_party_deps = [] |
83 for build_dep in gn_deps.split(): | 82 for build_dep in gn_deps.split(): |
84 # Look for third party deps that have separate license. | 83 if ("third_party" in build_dep and build_dep.endswith("/BUILD.gn")): |
85 if ("third_party" in build_dep and not "android_tools" in build_dep and | 84 third_party_deps.append(build_dep.replace("/BUILD.gn", "")) |
86 os.path.basename(build_dep) == "BUILD.gn"): | 85 third_party_deps.sort() |
87 third_party_deps.append(os.path.dirname(build_dep)) | |
88 return third_party_deps | 86 return third_party_deps |
89 | 87 |
90 | 88 |
91 def main(): | 89 def main(): |
92 class FormatterWithNewLines(optparse.IndentedHelpFormatter): | 90 class FormatterWithNewLines(optparse.IndentedHelpFormatter): |
93 def format_description(self, description): | 91 def format_description(self, description): |
94 paras = description.split('\n') | 92 paras = description.split('\n') |
95 formatted_paras = [textwrap.fill(para, self.width) for para in paras] | 93 formatted_paras = [textwrap.fill(para, self.width) for para in paras] |
96 return '\n'.join(formatted_paras) + '\n' | 94 return '\n'.join(formatted_paras) + '\n' |
97 | 95 |
(...skipping 26 matching lines...) Expand all Loading... |
124 else: | 122 else: |
125 print GenerateLicense() | 123 print GenerateLicense() |
126 return 0 | 124 return 0 |
127 | 125 |
128 parser.print_help() | 126 parser.print_help() |
129 return 1 | 127 return 1 |
130 | 128 |
131 | 129 |
132 if __name__ == '__main__': | 130 if __name__ == '__main__': |
133 sys.exit(main()) | 131 sys.exit(main()) |
OLD | NEW |