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..62f75ade0978dd086265104f1a82f903ecdf0de3 |
--- /dev/null |
+++ b/webrtc/build/ios/generate_licenses.py |
@@ -0,0 +1,160 @@ |
+#!/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 |
kjellander_webrtc
2016/04/27 12:58:05
sort this among the other standard library modules
tkchin_webrtc
2016/04/27 21:43:28
linter told me to place this above
kjellander_webrtc
2016/04/28 07:38:24
hmm, that never happened to me, odd. I guess we'll
tkchin_webrtc
2016/04/28 22:38:10
using gpylint maybe that makes a difference
kjellander_webrtc
2016/04/29 05:27:59
I dunno, it seems this passed git cl presubmit (wh
|
+ |
+import argparse |
+import cgi |
+import os |
+import re |
+ |
+ |
+WEBRTC_LIBS = [ |
kjellander_webrtc
2016/04/27 12:58:05
Ouch, you're signing up for painful maintenance he
tkchin_webrtc
2016/04/27 21:43:29
Yes, the goal was to cause breakage if license cha
kjellander_webrtc
2016/04/28 07:38:24
That sounds great. I guess you'll get test and too
tkchin_webrtc
2016/04/28 22:38:10
The tools won't actually be built since only depen
kjellander_webrtc
2016/04/29 05:27:59
Acknowledged.
|
+ 'audio_coding_module', |
+ 'audio_conference_mixer', |
+ 'audio_decoder_interface', |
+ 'audio_device', |
+ 'audio_encoder_interface', |
+ 'audio_processing', |
+ 'audioproc_debug_proto', |
+ 'bitrate_controller', |
+ 'cng', |
+ 'common_audio', |
+ 'common_video', |
+ 'congestion_controller', |
+ 'field_trial_default', |
+ 'g711', |
+ 'g722', |
+ 'ilbc', |
+ 'isac', |
+ 'isac_common', |
+ 'jingle_peerconnection_objc', |
+ 'jingle_peerconnection', |
+ 'media_file', |
+ 'metrics_default', |
+ 'neteq', |
+ 'paced_sender', |
+ 'pcm16b', |
+ 'red', |
+ 'remote_bitrate_estimator', |
+ 'rent_a_codec', |
+ 'rtp_rtcp', |
+ 'system_wrappers', |
+ 'video_capture_module_internal_impl', |
+ 'video_capture_module', |
+ 'video_coding_utility', |
+ 'video_processing', |
+ 'video_render_module_internal_impl', |
+ 'video_render_module', |
+ 'voice_engine', |
+] |
+ |
+ |
+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'], |
+} |
+ |
+ |
+def IsWebRTCLib(lib): |
+ if (lib in WEBRTC_LIBS or |
+ re.search('rtc_.*', lib) is not None or |
+ re.search('webrtc.*', lib) is not None): |
+ return True |
+ return False |
+ |
+ |
+def GetWebRTCPath(): |
+ # WebRTC path is script path down three directories. |
+ path = os.path.dirname(os.path.realpath(sys.argv[0])) |
kjellander_webrtc
2016/04/27 12:58:05
Define a constant like checkout_root instead (see
tkchin_webrtc
2016/04/27 21:43:29
Done.
|
+ 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><head>\n') |
+ output_license_file.write(' <meta charset="UTF-8">\n') |
+ style_tag = ''' <style> |
kjellander_webrtc
2016/04/27 12:58:05
Use textwrap.dedent instead, like https://chromium
tkchin_webrtc
2016/04/27 21:43:29
Done.
|
+ body { margin: 0; font-family: sans-serif; } |
+ pre { background-color: #eeeeee; padding: 1em; white-space: pre-wrap; } |
+ li { list-style: none; } |
+ p { margin: 1em; white-space: nowrap; } |
+ </style>''' |
+ output_license_file.write(style_tag) |
+ output_license_file.write('\n <title>Licenses</title>\n') |
kjellander_webrtc
2016/04/27 12:58:05
Put this leading newline in the end of the style_t
tkchin_webrtc
2016/04/27 21:43:28
Done.
|
+ output_license_file.write('</head>\n') |
+ |
+ for license_lib in license_libs: |
+ output_license_file.write('<p>\n%s<br/></p>\n' % license_lib) |
kjellander_webrtc
2016/04/27 12:58:05
newline in the beginning of the paragraph?
tkchin_webrtc
2016/04/27 21:43:29
Done.
kjellander_webrtc
2016/04/28 07:38:24
I meant I was surprised to see the newline at the
tkchin_webrtc
2016/04/28 22:38:10
Oh, nope, removed.
|
+ 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() |
+ GenerateLicenseText(args.static_lib_dir, args.output_dir) |