Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(913)

Side by Side Diff: components/cronet/tools/cronet_licenses.py

Issue 2150933007: [Cronet] Use gn desc to find third party licenses on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass gn-path for gn inside of //buildtools. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/cronet/android/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
26 third_party_dirs = [ 27 third_party_dirs = [
27 'base/third_party/libevent', 28 'base/third_party/libevent',
28 'third_party/ashmem', 29 'third_party/ashmem',
29 'third_party/boringssl', 30 'third_party/boringssl',
30 'third_party/modp_b64', 31 'third_party/modp_b64',
31 'third_party/zlib', 32 'third_party/zlib',
32 ] 33 ]
33 34
34 35
35 def _ReadFile(path): 36 def _ReadFile(path):
36 """Reads a file from disk. 37 """Reads a file from disk.
37 Args: 38 Args:
38 path: The path of the file to read, relative to the root of the repository. 39 path: The path of the file to read, relative to the root of the repository.
39 Returns: 40 Returns:
40 The contents of the file as a string. 41 The contents of the file as a string.
41 """ 42 """
42 return open(os.path.join(REPOSITORY_ROOT, path), 'rb').read() 43 return open(os.path.join(REPOSITORY_ROOT, path), 'rb').read()
43 44
44 45
45 def GenerateLicense(): 46 def GenerateLicense():
46 """Generates the contents of an Cronet LICENSE file for the third-party code. 47 """Generates the contents of an Cronet LICENSE file for the third-party code.
47 Returns: 48 Returns:
48 The contents of the LICENSE file. 49 The contents of the LICENSE file.
49 """ 50 """
50 # Start with Chromium's LICENSE file 51 # Start with Chromium's LICENSE file
51 content = [_ReadFile('LICENSE')] 52 content = [_ReadFile('LICENSE')]
52 53
53 # Add necessary third_party. 54 # Add necessary third_party.
54 for directory in sorted(third_party_dirs): 55 for directory in sorted(third_party_dirs, key=os.path.basename):
55 metadata = licenses.ParseDir(directory, REPOSITORY_ROOT, 56 metadata = licenses.ParseDir(directory, REPOSITORY_ROOT,
56 require_license_file=True) 57 require_license_file=True)
57 content.append('-' * 20) 58 content.append('-' * 20)
58 content.append(directory.split("/")[-1]) 59 content.append(directory.split("/")[-1])
59 content.append('-' * 20) 60 content.append('-' * 20)
60 license_file = metadata['License File'] 61 license_file = metadata['License File']
61 if license_file and license_file != licenses.NOT_SHIPPED: 62 if license_file and license_file != licenses.NOT_SHIPPED:
62 content.append(_ReadFile(license_file)) 63 content.append(_ReadFile(license_file))
63 64
64 return '\n'.join(content) 65 return '\n'.join(content)
65 66
66 67
67 def FindThirdPartyDeps(gn_path, gn_out_dir): 68 def FindThirdPartyDeps(gn_path, gn_out_dir):
68 # Generate gn project in temp directory and use it to find dependencies. 69 # 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 70 # Current gn directory cannot ba used because gn doesn't allow recursive
70 # invocations due to potential side effects. 71 # invocations due to potential side effects.
71 try: 72 try:
72 tmp_dir = tempfile.mkdtemp(dir = gn_out_dir) 73 tmp_dir = tempfile.mkdtemp(dir = gn_out_dir)
73 shutil.copy(gn_out_dir + "/args.gn", tmp_dir) 74 shutil.copy(gn_out_dir + "/args.gn", tmp_dir)
74 subprocess.check_output([gn_path, "gen", tmp_dir]) 75 subprocess.check_output([gn_path, "gen", tmp_dir])
75 gn_deps = subprocess.check_output([gn_path, "desc", tmp_dir, 76 gn_deps = subprocess.check_output([gn_path, "desc", tmp_dir,
76 "//net", "deps", "--as=buildfile", "--all"]) 77 "//net", "deps", "--as=buildfile", "--all"])
77 finally: 78 finally:
78 if os.path.exists(tmp_dir): 79 if os.path.exists(tmp_dir):
79 shutil.rmtree(tmp_dir) 80 shutil.rmtree(tmp_dir)
80 81
81 third_party_deps = [] 82 third_party_deps = []
82 for build_dep in gn_deps.split(): 83 for build_dep in gn_deps.split():
83 if ("third_party" in build_dep and build_dep.endswith("/BUILD.gn")): 84 # Look for third party deps that have separate license.
84 third_party_deps.append(build_dep.replace("/BUILD.gn", "")) 85 if ("third_party" in build_dep and not "android_tools" in build_dep and
85 third_party_deps.sort() 86 os.path.basename(build_dep) == "BUILD.gn"):
87 third_party_deps.append(os.path.dirname(build_dep))
86 return third_party_deps 88 return third_party_deps
87 89
88 90
89 def main(): 91 def main():
90 class FormatterWithNewLines(optparse.IndentedHelpFormatter): 92 class FormatterWithNewLines(optparse.IndentedHelpFormatter):
91 def format_description(self, description): 93 def format_description(self, description):
92 paras = description.split('\n') 94 paras = description.split('\n')
93 formatted_paras = [textwrap.fill(para, self.width) for para in paras] 95 formatted_paras = [textwrap.fill(para, self.width) for para in paras]
94 return '\n'.join(formatted_paras) + '\n' 96 return '\n'.join(formatted_paras) + '\n'
95 97
(...skipping 27 matching lines...) Expand all
123 else: 125 else:
124 print GenerateLicense() 126 print GenerateLicense()
125 return 0 127 return 0
126 128
127 parser.print_help() 129 parser.print_help()
128 return 1 130 return 1
129 131
130 132
131 if __name__ == '__main__': 133 if __name__ == '__main__':
132 sys.exit(main()) 134 sys.exit(main())
OLDNEW
« no previous file with comments | « components/cronet/android/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698