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

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

Issue 1934083002: [Cronet] Use gn desc deps to find third_party licenses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add components/cronet/ios/BUILD.gn Created 4 years, 7 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
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 subprocess
14 import sys 15 import sys
15 import textwrap 16 import textwrap
16 17
17 REPOSITORY_ROOT = os.path.abspath(os.path.join( 18 REPOSITORY_ROOT = os.path.abspath(os.path.join(
18 os.path.dirname(__file__), '..', '..', '..')) 19 os.path.dirname(__file__), '..', '..', '..'))
19 20
20 sys.path.append(os.path.join(REPOSITORY_ROOT, 'tools')) 21 sys.path.append(os.path.join(REPOSITORY_ROOT, 'tools'))
21 import licenses 22 import licenses
22 23
24 third_party_dirs = [
25 'base/third_party/libevent',
26 'third_party/ashmem',
27 'third_party/boringssl',
28 'third_party/modp_b64',
29 'third_party/zlib',
30 ]
31
23 def _ReadFile(path): 32 def _ReadFile(path):
24 """Reads a file from disk. 33 """Reads a file from disk.
25 Args: 34 Args:
26 path: The path of the file to read, relative to the root of the repository. 35 path: The path of the file to read, relative to the root of the repository.
27 Returns: 36 Returns:
28 The contents of the file as a string. 37 The contents of the file as a string.
29 """ 38 """
30 return open(os.path.join(REPOSITORY_ROOT, path), 'rb').read() 39 return open(os.path.join(REPOSITORY_ROOT, path), 'rb').read()
31 40
32 41
33 def GenerateLicense(): 42 def GenerateLicense():
34 """Generates the contents of an Cronet LICENSE file for the third-party code. 43 """Generates the contents of an Cronet LICENSE file for the third-party code.
35 Returns: 44 Returns:
36 The contents of the LICENSE file. 45 The contents of the LICENSE file.
37 """ 46 """
38 # TODO(mef): Generate list of third_party libraries using checkdeps.
39 third_party_dirs = [
40 'base/third_party/libevent',
41 'third_party/ashmem',
42 'third_party/boringssl',
43 'third_party/modp_b64',
44 'third_party/zlib',
45 ]
46
47 # Start with Chromium's LICENSE file 47 # Start with Chromium's LICENSE file
48 content = [_ReadFile('LICENSE')] 48 content = [_ReadFile('LICENSE')]
49 49
50 # Add necessary third_party. 50 # Add necessary third_party.
51 for directory in sorted(third_party_dirs): 51 for directory in sorted(third_party_dirs):
52 metadata = licenses.ParseDir(directory, REPOSITORY_ROOT, 52 metadata = licenses.ParseDir(directory, REPOSITORY_ROOT,
53 require_license_file=True) 53 require_license_file=True)
54 content.append('-' * 20) 54 content.append('-' * 20)
55 content.append(directory) 55 content.append(directory.split("/")[-1])
56 content.append('-' * 20) 56 content.append('-' * 20)
57 license_file = metadata['License File'] 57 license_file = metadata['License File']
58 if license_file and license_file != licenses.NOT_SHIPPED: 58 if license_file and license_file != licenses.NOT_SHIPPED:
59 content.append(_ReadFile(license_file)) 59 content.append(_ReadFile(license_file))
60 60
61 return '\n'.join(content) 61 return '\n'.join(content)
62 62
63 63
64 def FindThirdPartyDeps(gn_out_dir):
65 gn_deps = subprocess.check_output(["gn", "desc", gn_out_dir, \
66 "net", "deps", "--as=buildfile", "--all"])
67 third_party_deps = []
68 for build_dep in gn_deps.split():
69 if ("third_party" in build_dep and build_dep.endswith("/BUILD.gn")):
70 third_party_deps.append(build_dep.replace("/BUILD.gn", ""))
brettw 2016/05/03 17:59:00 The BUILD file in a third party directory isn't ne
mef 2016/05/03 21:50:20 Argh, that's unfortunate! Luckily Cronet's set of
71 third_party_deps.sort()
72 return third_party_deps
73
74
64 def main(): 75 def main():
65 class FormatterWithNewLines(optparse.IndentedHelpFormatter): 76 class FormatterWithNewLines(optparse.IndentedHelpFormatter):
66 def format_description(self, description): 77 def format_description(self, description):
67 paras = description.split('\n') 78 paras = description.split('\n')
68 formatted_paras = [textwrap.fill(para, self.width) for para in paras] 79 formatted_paras = [textwrap.fill(para, self.width) for para in paras]
69 return '\n'.join(formatted_paras) + '\n' 80 return '\n'.join(formatted_paras) + '\n'
70 81
71 parser = optparse.OptionParser(formatter=FormatterWithNewLines(), 82 parser = optparse.OptionParser(formatter=FormatterWithNewLines(),
72 usage='%prog command [options]') 83 usage='%prog command [options]')
84 parser.add_option('--gn_out_dir', help='Directory of gn output.')
73 parser.description = (__doc__ + 85 parser.description = (__doc__ +
74 '\nCommands:\n' \ 86 '\nCommands:\n' \
75 ' license [filename]\n' \ 87 ' license [filename]\n' \
76 ' Generate Cronet LICENSE to filename or stdout.\n') 88 ' Generate Cronet LICENSE to filename or stdout.\n')
77 (_, args) = parser.parse_args() 89 (_, args) = parser.parse_args()
90
91 if _.gn_out_dir:
92 global third_party_dirs
93 third_party_dirs = FindThirdPartyDeps(_.gn_out_dir)
94
78 if not args: 95 if not args:
79 parser.print_help() 96 parser.print_help()
80 return 1 97 return 1
81 98
82 if args[0] == 'license': 99 if args[0] == 'license':
83 if len(args) > 1: 100 if len(args) > 1:
84 print 'Saving license to %s' % args[1] 101 print 'Saving license to %s' % args[1]
85 f = open(args[1], "w") 102 f = open(args[1], "w")
86 try: 103 try:
87 f.write(GenerateLicense()) 104 f.write(GenerateLicense())
88 finally: 105 finally:
89 f.close() 106 f.close()
90 else: 107 else:
91 print GenerateLicense() 108 print GenerateLicense()
92 return 0 109 return 0
93 110
94 parser.print_help() 111 parser.print_help()
95 return 1 112 return 1
96 113
97 114
98 if __name__ == '__main__': 115 if __name__ == '__main__':
99 sys.exit(main()) 116 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698