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

Side by Side Diff: tools-webrtc/ios/generate_licenses.py

Issue 2735173002: Update licence generation script after GYP->GN migration. (Closed)
Patch Set: actually exit on error Created 3 years, 9 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 2
3 # Copyright 2016 The WebRTC project authors. All Rights Reserved. 3 # Copyright 2016 The WebRTC project authors. All Rights Reserved.
4 # 4 #
5 # Use of this source code is governed by a BSD-style license 5 # Use of this source code is governed by a BSD-style license
6 # that can be found in the LICENSE file in the root of the source 6 # that can be found in the LICENSE file in the root of the source
7 # tree. An additional intellectual property rights grant can be found 7 # tree. An additional intellectual property rights grant can be found
8 # in the file PATENTS. All contributing project authors may 8 # in the file PATENTS. All contributing project authors may
9 # be found in the AUTHORS file in the root of the source tree. 9 # be found in the AUTHORS file in the root of the source tree.
10 10
11 """Generates license HTML for a prebuilt version of WebRTC for iOS.""" 11 """Generates license HTML for a prebuilt version of WebRTC for iOS."""
12 12
13 import sys 13 import sys
14 14
15 import argparse 15 import argparse
16 import cgi 16 import cgi
17 import fnmatch
18 import os 17 import os
19 import re 18 import re
20 import textwrap 19 import textwrap
20 import subprocess
21 21
22 22
23 LIB_TO_LICENSES_DICT = { 23 LIB_TO_LICENSES_DICT = {
24 'boringssl': ['third_party/boringssl/src/LICENSE'], 24 'boringssl': ['third_party/boringssl/src/LICENSE'],
25 'expat': ['third_party/expat/files/COPYING'], 25 'expat': ['third_party/expat/files/COPYING'],
26 'jsoncpp': ['third_party/jsoncpp/LICENSE'], 26 'jsoncpp': ['third_party/jsoncpp/LICENSE'],
27 'opus': ['third_party/opus/src/COPYING'], 27 'opus': ['third_party/opus/src/COPYING'],
28 'protobuf_lite': ['third_party/protobuf/LICENSE'], 28 'protobuf': ['third_party/protobuf/LICENSE'],
29 'srtp': ['third_party/libsrtp/srtp/LICENSE'], 29 'libsrtp': ['third_party/libsrtp/LICENSE'],
30 'usrsctplib': ['third_party/usrsctp/LICENSE'], 30 'usrsctp': ['third_party/usrsctp/LICENSE'],
31 'webrtc': ['webrtc/LICENSE', 'webrtc/LICENSE_THIRD_PARTY'], 31 'webrtc': ['webrtc/LICENSE', 'webrtc/LICENSE_THIRD_PARTY'],
32 'vpx': ['third_party/libvpx/source/libvpx/LICENSE'], 32 'libvpx': ['third_party/libvpx/source/libvpx/LICENSE'],
33 'yuv': ['third_party/libyuv/LICENSE'], 33 'libyuv': ['third_party/libyuv/LICENSE'],
34 } 34 }
35 35
36 SCRIPT_DIR = os.path.dirname(os.path.realpath(sys.argv[0])) 36 SCRIPT_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
37 CHECKOUT_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, 37 CHECKOUT_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir))
38 os.pardir))
39 TALK_ROOT = os.path.join(CHECKOUT_ROOT, 'talk')
40 WEBRTC_ROOT = os.path.join(CHECKOUT_ROOT, 'webrtc') 38 WEBRTC_ROOT = os.path.join(CHECKOUT_ROOT, 'webrtc')
41 39
42 40 def GetThirdPartyLibraries(buildfile_dir, target_name):
43 def GetWebRTCGypFilePaths(): 41 def extractLibName(s):
44 gyp_filepaths = [] 42 return re.sub(r'\(.*\)', '', s).strip().split(os.path.sep)[-1].split(':')[0]
magjed_webrtc 2017/03/09 13:23:34 Can you add a comment giving an example input and
kthelgason 2017/03/09 14:45:54 Done.
45 search_roots = [TALK_ROOT, WEBRTC_ROOT] 43 output = subprocess.check_output(
46 for search_root in search_roots: 44 ["gn", "desc", buildfile_dir, target_name, '--all']) .split(os.linesep)
47 for root, _, filenames in os.walk(search_root): 45 return [extractLibName(x) for x in output if re.search(r'third_party', x)]
48 for filename in fnmatch.filter(filenames, '*.gyp*'):
49 gyp_filepaths.append(os.path.join(root, filename))
50 return gyp_filepaths
51
52
53 def GetWebRTCTargetNames():
54 gyp_filepaths = GetWebRTCGypFilePaths()
55 target_names = []
56 for gyp_filepath in gyp_filepaths:
57 with open(gyp_filepath, 'r') as gyp_file:
58 for line in gyp_file:
59 match = re.search(r'\'target_name\'.*\'(\w+)\'', line)
60 if match:
61 target_name = match.group(1)
62 target_names.append(target_name)
63 return target_names
64 46
65 47
66 class LicenseBuilder(object): 48 class LicenseBuilder(object):
67 49
68 def __init__(self): 50 def __init__(self, buildfile_dir, target_name):
69 self.webrtc_target_names = GetWebRTCTargetNames() 51 self.buildfile_dir = buildfile_dir
52 self.target_name = target_name
70 53
71 def IsWebRTCLib(self, lib_name): 54 def GenerateLicenseText(self, output_dir):
72 alternate_lib_name = 'lib' + lib_name 55 # Get a list of third_party libs from gn.
73 return (lib_name in self.webrtc_target_names or 56 third_party_libs = GetThirdPartyLibraries(self.buildfile_dir,
74 alternate_lib_name in self.webrtc_target_names) 57 self.target_name)
75 58
76 def GenerateLicenseText(self, static_lib_dir, output_dir): 59 # Generate amalgamated list of libraries. Will exit with error if a
77 # Get a list of libs from the files without their prefix and extension.
78 static_libs = []
79 for static_lib in os.listdir(static_lib_dir):
80 # Skip non libraries.
81 if not (static_lib.endswith('.a') and static_lib.startswith('lib')):
82 continue
83 # Extract library name.
84 static_libs.append(static_lib[3:-2])
85
86 # Generate amalgamated list of libraries. Mostly this just collapses the
87 # various WebRTC libs names into just 'webrtc'. Will exit with error if a
88 # lib is unrecognized. 60 # lib is unrecognized.
89 license_libs = set() 61 license_libs = set()
90 for static_lib in static_libs: 62 for static_lib in third_party_libs:
91 license_lib = 'webrtc' if self.IsWebRTCLib(static_lib) else static_lib 63 license_path = LIB_TO_LICENSES_DICT.get(static_lib)
92 license_path = LIB_TO_LICENSES_DICT.get(license_lib)
93 if license_path is None: 64 if license_path is None:
94 print 'Missing license path for lib: %s' % license_lib 65 print 'Missing license path for lib: %s' % static_lib
95 return 1 66 return 1
96 license_libs.add(license_lib) 67 license_libs.add(static_lib)
97 68
98 # Put webrtc at the front of the list. 69 # Put webrtc at the front of the list.
99 assert 'webrtc' in license_libs
100 license_libs.remove('webrtc')
101 license_libs = sorted(license_libs) 70 license_libs = sorted(license_libs)
102 license_libs.insert(0, 'webrtc') 71 license_libs.insert(0, 'webrtc')
103 72
104 # Generate HTML. 73 # Generate HTML.
105 output_license_file = open(os.path.join(output_dir, 'LICENSE.html'), 'w+') 74 output_license_file = open(os.path.join(output_dir, 'LICENSE.html'), 'w+')
106 output_license_file.write('<!DOCTYPE html>\n') 75 output_license_file.write('<!DOCTYPE html>\n')
107 output_license_file.write('<html>\n<head>\n') 76 output_license_file.write('<html>\n<head>\n')
108 output_license_file.write('<meta charset="UTF-8">\n') 77 output_license_file.write('<meta charset="UTF-8">\n')
109 output_license_file.write('<title>Licenses</title>\n') 78 output_license_file.write('<title>Licenses</title>\n')
110 style_tag = textwrap.dedent('''\ 79 style_tag = textwrap.dedent('''\
(...skipping 18 matching lines...) Expand all
129 output_license_file.write('</pre>\n') 98 output_license_file.write('</pre>\n')
130 99
131 output_license_file.write('</body>\n') 100 output_license_file.write('</body>\n')
132 output_license_file.write('</html>') 101 output_license_file.write('</html>')
133 output_license_file.close() 102 output_license_file.close()
134 return 0 103 return 0
135 104
136 105
137 if __name__ == '__main__': 106 if __name__ == '__main__':
138 parser = argparse.ArgumentParser(description='Generate WebRTC LICENSE.html') 107 parser = argparse.ArgumentParser(description='Generate WebRTC LICENSE.html')
139 parser.add_argument('static_lib_dir', 108 parser.add_argument('target_name',
140 help='Directory with built static libraries.') 109 help='Name of the GN target to generate a license for')
110 parser.add_argument('buildfile_dir',
111 help='Directory containing gn generated ninja files')
141 parser.add_argument('output_dir', 112 parser.add_argument('output_dir',
142 help='Directory to output LICENSE.html to.') 113 help='Directory to output LICENSE.html to.')
143 args = parser.parse_args() 114 args = parser.parse_args()
144 builder = LicenseBuilder() 115 builder = LicenseBuilder(args.buildfile_dir, args.target_name)
145 sys.exit(builder.GenerateLicenseText(args.static_lib_dir, args.output_dir)) 116 sys.exit(builder.GenerateLicenseText(args.output_dir))
OLDNEW
« tools-webrtc/ios/build_ios_libs.py ('K') | « tools-webrtc/ios/build_ios_libs.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698