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

Unified Diff: webrtc/build/ios/generate_licenses.py

Issue 1922363002: Script to generate licenses for prebuilt WebRTC. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: CR comments Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/build/ios/build_ios_libs.sh ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/build/ios/generate_licenses.py
diff --git a/webrtc/build/ios/generate_licenses.py b/webrtc/build/ios/generate_licenses.py
new file mode 100755
index 0000000000000000000000000000000000000000..e23056fb546d6fea3789634a86d69ca55664d99e
--- /dev/null
+++ b/webrtc/build/ios/generate_licenses.py
@@ -0,0 +1,152 @@
+#!/usr/bin/python
+
+# Copyright 2016 The WebRTC project authors. All Rights Reserved.
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS. All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+"""Generates license HTML for a prebuilt version of WebRTC for iOS."""
+
+import sys
+
+import argparse
+import cgi
+import fnmatch
+import os
+import re
+import textwrap
+
+
+LIB_TO_LICENSES_DICT = {
+ 'boringssl': ['third_party/boringssl/NOTICE'],
+ 'expat': ['third_party/expat/files/COPYING'],
+ 'jsoncpp': ['third_party/jsoncpp/LICENSE'],
+ 'opus': ['third_party/opus/src/COPYING'],
+ 'protobuf_lite': ['third_party/protobuf/COPYING.txt'],
+ 'srtp': ['third_party/libsrtp/srtp/LICENSE'],
+ 'usrsctplib': ['third_party/usrsctp/LICENSE'],
+ 'webrtc': ['webrtc/LICENSE', 'webrtc/LICENSE_THIRD_PARTY'],
+ 'vpx': ['third_party/libvpx/source/libvpx/LICENSE'],
+ 'yuv': ['third_party/libyuv/LICENSE'],
+}
+
+SCRIPT_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
kjellander_webrtc 2016/04/28 07:38:24 I prefer __file__ instead of sys.argv[0] but I'm O
+CHECKOUT_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir,
+ os.pardir))
+TALK_ROOT = os.path.join(CHECKOUT_ROOT, 'talk')
+WEBRTC_ROOT = os.path.join(CHECKOUT_ROOT, 'webrtc')
+
+webrtc_target_names = None
kjellander_webrtc 2016/04/28 07:38:24 I don't like the global variable here but I'll lea
+
+
+def GetWebRTCGypFilePaths():
+ gyp_filepaths = []
+ search_roots = [TALK_ROOT, WEBRTC_ROOT]
+ for search_root in search_roots:
+ for root, _, filenames in os.walk(search_root):
+ for filename in fnmatch.filter(filenames, '*.gyp*'):
+ gyp_filepaths.append(os.path.join(root, filename))
+ return gyp_filepaths
+
+
+def GetWebRTCTargetNames():
+ gyp_filepaths = GetWebRTCGypFilePaths()
+ target_names = []
+ for gyp_filepath in gyp_filepaths:
+ with open(gyp_filepath, 'r') as gyp_file:
+ for line in gyp_file:
+ match = re.search(r'\'target_name\'.*\'(\w+)\'', line)
+ if match:
+ target_name = match.group(1)
+ target_names.append(target_name)
+ return target_names
+
+
+def IsWebRTCLib(lib_name):
+ alternate_lib_name = 'lib' + lib_name
+ return (lib_name in webrtc_target_names or
+ alternate_lib_name in webrtc_target_names)
+
+
+def GetWebRTCPath():
+ # WebRTC path is script path down three directories.
+ path = os.path.dirname(os.path.realpath(sys.argv[0]))
+ i = 3
+ while i > 0:
+ path = os.path.dirname(path)
+ i -= 1
+ return path
+
+
+def GenerateLicenseText(static_lib_dir, output_dir):
+ # Get a list of libs from the files without their prefix and extension.
+ static_libs = []
+ for static_lib in os.listdir(static_lib_dir):
+ # Skip non libraries.
+ if not (static_lib.endswith('.a') and static_lib.startswith('lib')):
+ continue
+ # Extract library name.
+ static_libs.append(static_lib[3:-2])
+
+ # Generate amalgamated list of libraries. Mostly this just collapses the
+ # various WebRTC libs names into just 'webrtc'. Will exit with error if a
+ # lib is unrecognized.
+ license_libs = set()
+ for static_lib in static_libs:
+ license_lib = 'webrtc' if IsWebRTCLib(static_lib) else static_lib
+ license_path = LIB_TO_LICENSES_DICT.get(license_lib)
+ if license_path is None:
+ print 'Missing license path for lib: %s' % license_lib
+ sys.exit(1)
+ license_libs.add(license_lib)
+
+ # Put webrtc at the front of the list.
+ assert 'webrtc' in license_libs
+ license_libs.remove('webrtc')
+ license_libs = sorted(license_libs)
+ license_libs.insert(0, 'webrtc')
+
+ # Generate HTML.
+ output_license_file = open(os.path.join(output_dir, 'LICENSE.html'), 'w+')
+ output_license_file.write('<!DOCTYPE html>\n')
+ output_license_file.write('<html>\n<head>\n')
+ output_license_file.write('<meta charset="UTF-8">\n')
+ output_license_file.write('<title>Licenses</title>\n')
+ style_tag = textwrap.dedent('''\
+ <style>
+ body { margin: 0; font-family: sans-serif; }
+ pre { background-color: #eeeeee; padding: 1em; white-space: pre-wrap; }
+ p { margin: 1em; white-space: nowrap; }
+ </style>
+ ''')
+ output_license_file.write(style_tag)
+ output_license_file.write('</head>\n')
+
+ for license_lib in license_libs:
+ output_license_file.write('\n<p>\n%s<br/></p>\n' % license_lib)
+ output_license_file.write('<pre>\n')
+ for path in LIB_TO_LICENSES_DICT[license_lib]:
+ license_path = os.path.join(GetWebRTCPath(), path)
+ with open(license_path, 'r') as license_file:
+ license_text = cgi.escape(license_file.read(), quote=True)
+ output_license_file.write(license_text)
+ output_license_file.write('\n')
+ output_license_file.write('</pre>\n')
+
+ output_license_file.write('</body>\n')
+ output_license_file.write('</html>')
+ output_license_file.close()
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description='Generate WebRTC LICENSE.html')
+ parser.add_argument('static_lib_dir',
+ help='Directory with built static libraries.')
+ parser.add_argument('output_dir',
+ help='Directory to output LICENSE.html to.')
+ args = parser.parse_args()
+ webrtc_target_names = set(GetWebRTCTargetNames())
+ GenerateLicenseText(args.static_lib_dir, args.output_dir)
« no previous file with comments | « webrtc/build/ios/build_ios_libs.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698