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

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

Issue 2246573002: Pass path to gn binary to cronet_licenses.py when building for iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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/ios/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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_path, 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 = gn_out_dir)
73 shutil.copy(gn_out_dir + "/args.gn", tmp_dir) 73 shutil.copy(gn_out_dir + "/args.gn", tmp_dir)
74 subprocess.check_output(["gn", "gen", tmp_dir]) 74 subprocess.check_output([gn_path, "gen", tmp_dir])
75 gn_deps = subprocess.check_output(["gn", "desc", tmp_dir, \ 75 gn_deps = subprocess.check_output([gn_path, "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 build_dep.endswith("/BUILD.gn")):
84 third_party_deps.append(build_dep.replace("/BUILD.gn", "")) 84 third_party_deps.append(build_dep.replace("/BUILD.gn", ""))
85 third_party_deps.sort() 85 third_party_deps.sort()
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',
99 action='store_true') 99 action='store_true')
100 parser.add_option('--gn-path', default='gn',
101 help='Path to gn executable (default: %(default)s)')
100 parser.description = (__doc__ + 102 parser.description = (__doc__ +
101 '\nCommands:\n' \ 103 '\nCommands:\n' \
102 ' license [filename]\n' \ 104 ' license [filename]\n' \
103 ' Generate Cronet LICENSE to filename or stdout.\n') 105 ' Generate Cronet LICENSE to filename or stdout.\n')
104 (_, args) = parser.parse_args() 106 (flags, args) = parser.parse_args()
107 print flags
105 108
106 if _.gn: 109 if flags.gn:
107 global third_party_dirs 110 global third_party_dirs
108 third_party_dirs = FindThirdPartyDeps(os.getcwd()) 111 third_party_dirs = FindThirdPartyDeps(flags.gn_path, os.getcwd())
109 112
110 if not args: 113 if not args:
111 parser.print_help() 114 parser.print_help()
112 return 1 115 return 1
113 116
114 if args[0] == 'license': 117 if args[0] == 'license':
115 if len(args) > 1: 118 if len(args) > 1:
116 f = open(args[1], "w") 119 f = open(args[1], "w")
117 try: 120 try:
118 f.write(GenerateLicense()) 121 f.write(GenerateLicense())
119 finally: 122 finally:
120 f.close() 123 f.close()
121 else: 124 else:
122 print GenerateLicense() 125 print GenerateLicense()
123 return 0 126 return 0
124 127
125 parser.print_help() 128 parser.print_help()
126 return 1 129 return 1
127 130
128 131
129 if __name__ == '__main__': 132 if __name__ == '__main__':
130 sys.exit(main()) 133 sys.exit(main())
OLDNEW
« no previous file with comments | « components/cronet/ios/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698