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

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: Created 4 years, 5 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 """
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if ("third_party" in build_dep and not "android_tools" in build_dep and
xunjieli 2016/07/18 14:54:50 Could you add a brief comment here on why we are e
mef 2016/07/18 15:45:20 Done. There is no license in build/secondary/third
84 third_party_deps.append(build_dep.replace("/BUILD.gn", "")) 84 os.path.basename(build_dep) == "BUILD.gn"):
85 third_party_deps.sort() 85 third_party_deps.append(os.path.dirname(build_dep))
86 return third_party_deps 86 return third_party_deps
87 87
88 88
89 def main(): 89 def main():
90 class FormatterWithNewLines(optparse.IndentedHelpFormatter): 90 class FormatterWithNewLines(optparse.IndentedHelpFormatter):
91 def format_description(self, description): 91 def format_description(self, description):
92 paras = description.split('\n') 92 paras = description.split('\n')
93 formatted_paras = [textwrap.fill(para, self.width) for para in paras] 93 formatted_paras = [textwrap.fill(para, self.width) for para in paras]
94 return '\n'.join(formatted_paras) + '\n' 94 return '\n'.join(formatted_paras) + '\n'
95 95
96 parser = optparse.OptionParser(formatter=FormatterWithNewLines(), 96 parser = optparse.OptionParser(formatter=FormatterWithNewLines(),
97 usage='%prog command [options]') 97 usage='%prog command [options]')
98 parser.add_option('--gn', help='Use gn deps to find third party dependencies', 98 parser.add_option('--gn', help='Use gn deps to find third party dependencies',
xunjieli 2016/07/18 14:54:50 The "--gn" option is added here, why do we need it
mef 2016/07/18 15:45:20 It is added here to option parser, so it is recogn
xunjieli 2016/07/18 21:33:12 You are right! I missed that part of the code. Tha
99 action='store_true') 99 action='store_true')
100 parser.description = (__doc__ + 100 parser.description = (__doc__ +
101 '\nCommands:\n' \ 101 '\nCommands:\n' \
102 ' license [filename]\n' \ 102 ' license [filename]\n' \
103 ' Generate Cronet LICENSE to filename or stdout.\n') 103 ' Generate Cronet LICENSE to filename or stdout.\n')
104 (_, args) = parser.parse_args() 104 (_, args) = parser.parse_args()
105 105
106 if _.gn: 106 if _.gn:
107 global third_party_dirs 107 global third_party_dirs
108 third_party_dirs = FindThirdPartyDeps(os.getcwd()) 108 third_party_dirs = FindThirdPartyDeps(os.getcwd())
(...skipping 13 matching lines...) Expand all
122 else: 122 else:
123 print GenerateLicense() 123 print GenerateLicense()
124 return 0 124 return 0
125 125
126 parser.print_help() 126 parser.print_help()
127 return 1 127 return 1
128 128
129 129
130 if __name__ == '__main__': 130 if __name__ == '__main__':
131 sys.exit(main()) 131 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