| OLD | NEW |
| 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 # Sample input: |
| 45 search_roots = [TALK_ROOT, WEBRTC_ROOT] | 43 # [" //third_party/usrsctp:usrsctp", " //webrtc:webrtc_common"] |
| 46 for search_root in search_roots: | 44 # Sample output: |
| 47 for root, _, filenames in os.walk(search_root): | 45 # ["usrsctp"] |
| 48 for filename in fnmatch.filter(filenames, '*.gyp*'): | 46 return re.sub(r'\(.*\)', '', s).strip().split(os.path.sep)[-1].split(':')[0] |
| 49 gyp_filepaths.append(os.path.join(root, filename)) | 47 output = subprocess.check_output( |
| 50 return gyp_filepaths | 48 ["gn", "desc", buildfile_dir, target_name, '--all']) .split(os.linesep) |
| 51 | 49 return [extractLibName(x) for x in output if re.search(r'third_party', x)] |
| 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 | 50 |
| 65 | 51 |
| 66 class LicenseBuilder(object): | 52 class LicenseBuilder(object): |
| 67 | 53 |
| 68 def __init__(self): | 54 def __init__(self, buildfile_dirs, target_name): |
| 69 self.webrtc_target_names = GetWebRTCTargetNames() | 55 self.buildfile_dirs = buildfile_dirs |
| 56 self.target_name = target_name |
| 70 | 57 |
| 71 def IsWebRTCLib(self, lib_name): | 58 def GenerateLicenseText(self, output_dir): |
| 72 alternate_lib_name = 'lib' + lib_name | 59 # Get a list of third_party libs from gn. For fat libraries we must consider |
| 73 return (lib_name in self.webrtc_target_names or | 60 # all architectures, hence the multiple buildfile directories. |
| 74 alternate_lib_name in self.webrtc_target_names) | 61 # The `sum` function flattens the 2d list. |
| 62 third_party_libs = sum([GetThirdPartyLibraries(buildfile, self.target_name) |
| 63 for buildfile in self.buildfile_dirs], []) |
| 75 | 64 |
| 76 def GenerateLicenseText(self, static_lib_dir, output_dir): | 65 # 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. | 66 # lib is unrecognized. |
| 89 license_libs = set() | 67 license_libs = set() |
| 90 for static_lib in static_libs: | 68 for static_lib in third_party_libs: |
| 91 license_lib = 'webrtc' if self.IsWebRTCLib(static_lib) else static_lib | 69 license_path = LIB_TO_LICENSES_DICT.get(static_lib) |
| 92 license_path = LIB_TO_LICENSES_DICT.get(license_lib) | 70 if static_lib == 'yasm': |
| 71 # yasm is a build-time dep only, and doesn't need a license. |
| 72 continue |
| 93 if license_path is None: | 73 if license_path is None: |
| 94 print 'Missing license path for lib: %s' % license_lib | 74 print 'Missing license path for lib: %s' % static_lib |
| 95 return 1 | 75 return 1 |
| 96 license_libs.add(license_lib) | 76 license_libs.add(static_lib) |
| 97 | 77 |
| 98 # Put webrtc at the front of the list. | 78 # 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) | 79 license_libs = sorted(license_libs) |
| 102 license_libs.insert(0, 'webrtc') | 80 license_libs.insert(0, 'webrtc') |
| 103 | 81 |
| 104 # Generate HTML. | 82 # Generate HTML. |
| 105 output_license_file = open(os.path.join(output_dir, 'LICENSE.html'), 'w+') | 83 output_license_file = open(os.path.join(output_dir, 'LICENSE.html'), 'w+') |
| 106 output_license_file.write('<!DOCTYPE html>\n') | 84 output_license_file.write('<!DOCTYPE html>\n') |
| 107 output_license_file.write('<html>\n<head>\n') | 85 output_license_file.write('<html>\n<head>\n') |
| 108 output_license_file.write('<meta charset="UTF-8">\n') | 86 output_license_file.write('<meta charset="UTF-8">\n') |
| 109 output_license_file.write('<title>Licenses</title>\n') | 87 output_license_file.write('<title>Licenses</title>\n') |
| 110 style_tag = textwrap.dedent('''\ | 88 style_tag = textwrap.dedent('''\ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 129 output_license_file.write('</pre>\n') | 107 output_license_file.write('</pre>\n') |
| 130 | 108 |
| 131 output_license_file.write('</body>\n') | 109 output_license_file.write('</body>\n') |
| 132 output_license_file.write('</html>') | 110 output_license_file.write('</html>') |
| 133 output_license_file.close() | 111 output_license_file.close() |
| 134 return 0 | 112 return 0 |
| 135 | 113 |
| 136 | 114 |
| 137 if __name__ == '__main__': | 115 if __name__ == '__main__': |
| 138 parser = argparse.ArgumentParser(description='Generate WebRTC LICENSE.html') | 116 parser = argparse.ArgumentParser(description='Generate WebRTC LICENSE.html') |
| 139 parser.add_argument('static_lib_dir', | 117 parser.add_argument('target_name', |
| 140 help='Directory with built static libraries.') | 118 help='Name of the GN target to generate a license for') |
| 141 parser.add_argument('output_dir', | 119 parser.add_argument('output_dir', |
| 142 help='Directory to output LICENSE.html to.') | 120 help='Directory to output LICENSE.html to.') |
| 121 parser.add_argument('buildfile_dirs', nargs="+", |
| 122 help='Directories containing gn generated ninja files') |
| 143 args = parser.parse_args() | 123 args = parser.parse_args() |
| 144 builder = LicenseBuilder() | 124 builder = LicenseBuilder(args.buildfile_dirs, args.target_name) |
| 145 sys.exit(builder.GenerateLicenseText(args.static_lib_dir, args.output_dir)) | 125 sys.exit(builder.GenerateLicenseText(args.output_dir)) |
| OLD | NEW |