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

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: Fix build from gyp project. Created 4 years, 6 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/tools/cr_cronet.py ('k') | net/test/run_all_unittests.cc » ('j') | 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
15 import subprocess
14 import sys 16 import sys
17 import tempfile
15 import textwrap 18 import textwrap
16 19
17 REPOSITORY_ROOT = os.path.abspath(os.path.join( 20 REPOSITORY_ROOT = os.path.abspath(os.path.join(
18 os.path.dirname(__file__), '..', '..', '..')) 21 os.path.dirname(__file__), '..', '..', '..'))
19 22
20 sys.path.append(os.path.join(REPOSITORY_ROOT, 'tools')) 23 sys.path.append(os.path.join(REPOSITORY_ROOT, 'tools'))
21 import licenses 24 import licenses
22 25
26 third_party_dirs = [
27 'base/third_party/libevent',
28 'third_party/ashmem',
29 'third_party/boringssl',
30 'third_party/modp_b64',
31 'third_party/zlib',
32 ]
33
34
23 def _ReadFile(path): 35 def _ReadFile(path):
24 """Reads a file from disk. 36 """Reads a file from disk.
25 Args: 37 Args:
26 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.
27 Returns: 39 Returns:
28 The contents of the file as a string. 40 The contents of the file as a string.
29 """ 41 """
30 return open(os.path.join(REPOSITORY_ROOT, path), 'rb').read() 42 return open(os.path.join(REPOSITORY_ROOT, path), 'rb').read()
31 43
32 44
33 def GenerateLicense(): 45 def GenerateLicense():
34 """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.
35 Returns: 47 Returns:
36 The contents of the LICENSE file. 48 The contents of the LICENSE file.
37 """ 49 """
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 50 # Start with Chromium's LICENSE file
48 content = [_ReadFile('LICENSE')] 51 content = [_ReadFile('LICENSE')]
49 52
50 # Add necessary third_party. 53 # Add necessary third_party.
51 for directory in sorted(third_party_dirs): 54 for directory in sorted(third_party_dirs):
52 metadata = licenses.ParseDir(directory, REPOSITORY_ROOT, 55 metadata = licenses.ParseDir(directory, REPOSITORY_ROOT,
53 require_license_file=True) 56 require_license_file=True)
54 content.append('-' * 20) 57 content.append('-' * 20)
55 content.append(directory) 58 content.append(directory.split("/")[-1])
56 content.append('-' * 20) 59 content.append('-' * 20)
57 license_file = metadata['License File'] 60 license_file = metadata['License File']
58 if license_file and license_file != licenses.NOT_SHIPPED: 61 if license_file and license_file != licenses.NOT_SHIPPED:
59 content.append(_ReadFile(license_file)) 62 content.append(_ReadFile(license_file))
60 63
61 return '\n'.join(content) 64 return '\n'.join(content)
62 65
63 66
67 def FindThirdPartyDeps(gn_out_dir):
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
70 # invocations due to potential side effects.
71 try:
72 tmp_dir = tempfile.mkdtemp(dir = gn_out_dir)
73 shutil.copy(gn_out_dir + "/args.gn", tmp_dir)
74 subprocess.check_output(["gn", "gen", tmp_dir])
75 gn_deps = subprocess.check_output(["gn", "desc", tmp_dir, \
76 "//net", "deps", "--as=buildfile", "--all"])
77 finally:
78 if os.path.exists(tmp_dir):
79 shutil.rmtree(tmp_dir)
80
81 third_party_deps = []
82 for build_dep in gn_deps.split():
83 if ("third_party" in build_dep and build_dep.endswith("/BUILD.gn")):
84 third_party_deps.append(build_dep.replace("/BUILD.gn", ""))
85 third_party_deps.sort()
86 return third_party_deps
87
88
64 def main(): 89 def main():
65 class FormatterWithNewLines(optparse.IndentedHelpFormatter): 90 class FormatterWithNewLines(optparse.IndentedHelpFormatter):
66 def format_description(self, description): 91 def format_description(self, description):
67 paras = description.split('\n') 92 paras = description.split('\n')
68 formatted_paras = [textwrap.fill(para, self.width) for para in paras] 93 formatted_paras = [textwrap.fill(para, self.width) for para in paras]
69 return '\n'.join(formatted_paras) + '\n' 94 return '\n'.join(formatted_paras) + '\n'
70 95
71 parser = optparse.OptionParser(formatter=FormatterWithNewLines(), 96 parser = optparse.OptionParser(formatter=FormatterWithNewLines(),
72 usage='%prog command [options]') 97 usage='%prog command [options]')
98 parser.add_option('--gn', help='Use gn deps to find third party dependencies',
99 action='store_true')
73 parser.description = (__doc__ + 100 parser.description = (__doc__ +
74 '\nCommands:\n' \ 101 '\nCommands:\n' \
75 ' license [filename]\n' \ 102 ' license [filename]\n' \
76 ' Generate Cronet LICENSE to filename or stdout.\n') 103 ' Generate Cronet LICENSE to filename or stdout.\n')
77 (_, args) = parser.parse_args() 104 (_, args) = parser.parse_args()
105
106 if _.gn:
107 global third_party_dirs
108 third_party_dirs = FindThirdPartyDeps(os.getcwd())
109
78 if not args: 110 if not args:
79 parser.print_help() 111 parser.print_help()
80 return 1 112 return 1
81 113
82 if args[0] == 'license': 114 if args[0] == 'license':
83 if len(args) > 1: 115 if len(args) > 1:
84 print 'Saving license to %s' % args[1] 116 print 'Saving license to %s' % args[1]
85 f = open(args[1], "w") 117 f = open(args[1], "w")
86 try: 118 try:
87 f.write(GenerateLicense()) 119 f.write(GenerateLicense())
88 finally: 120 finally:
89 f.close() 121 f.close()
90 else: 122 else:
91 print GenerateLicense() 123 print GenerateLicense()
92 return 0 124 return 0
93 125
94 parser.print_help() 126 parser.print_help()
95 return 1 127 return 1
96 128
97 129
98 if __name__ == '__main__': 130 if __name__ == '__main__':
99 sys.exit(main()) 131 sys.exit(main())
OLDNEW
« no previous file with comments | « components/cronet/tools/cr_cronet.py ('k') | net/test/run_all_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698