108 lines
3.5 KiB
Python
Executable File
108 lines
3.5 KiB
Python
Executable File
#!/usr/bin/python
|
|
# Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
|
# source code may only be used and distributed under the Widevine Master
|
|
# License Agreement.
|
|
|
|
"""Creates a self-contained static library of the CDM."""
|
|
|
|
from __future__ import print_function
|
|
|
|
import argparse
|
|
import glob
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
|
|
CDM_TOP = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
REQUIRED_LIBS = [
|
|
'device_files',
|
|
'license_protocol',
|
|
'metrics_proto',
|
|
'widevine_cdm_core',
|
|
'widevine_ce_cdm_static',
|
|
]
|
|
SSL_LIB_NAME = 'crypto'
|
|
PROTOBUF_NAME = 'protobuf_lite'
|
|
RESULT_LIB_NAME = 'widevine_cdm_complete'
|
|
|
|
|
|
def _CombineLinuxLibs(ar, result_path, libs):
|
|
# Extract each static library into the temporary directory.
|
|
temp_dir = os.path.join(os.path.dirname(result_path), 'bundle_dir')
|
|
shutil.rmtree(temp_dir, ignore_errors=True)
|
|
os.mkdir(temp_dir)
|
|
|
|
for lib in libs:
|
|
if subprocess.call([ar, 'x', lib], cwd=temp_dir) != 0:
|
|
return 1
|
|
|
|
# Create the combined static library.
|
|
if os.path.exists(result_path):
|
|
os.remove(result_path)
|
|
cmd = [ar, 'rcs', result_path] + glob.glob(os.path.join(temp_dir, '*.o'))
|
|
if subprocess.call(cmd) != 0:
|
|
return 1
|
|
|
|
shutil.rmtree(temp_dir, ignore_errors=True)
|
|
return 0
|
|
|
|
|
|
def main(args):
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument(
|
|
'platform',
|
|
help='The platform configuration to use (x86-64, ...). '
|
|
'Should be one of the folder names inside platforms/')
|
|
parser.add_argument('-r', '--release', dest='build_config', default='Debug',
|
|
action='store_const', const='Release',
|
|
help='Builds a release build (equivalent to -c Release)')
|
|
parser.add_argument('-c', '--config', dest='build_config', default='Debug',
|
|
help='Select a build config (Debug, Release). '
|
|
'Defaults to Debug.')
|
|
parser.add_argument('--ar', dest='ar', default='ar',
|
|
help='Use the given program as the archiver (defaults '
|
|
'to "ar").')
|
|
parser.add_argument('--lib', dest='lib', default='lib.exe',
|
|
help='Use the given lib.exe program (defaults to '
|
|
'lib.exe, which is normally not on PATH)')
|
|
parser.add_argument('--boringssl', dest='ssl', action='store_true',
|
|
help='Include BoringSSL in the bundle')
|
|
parser.add_argument('--protobuf', dest='protobuf', action='store_true',
|
|
help='Include protobuf in the bundle')
|
|
|
|
options = parser.parse_args(args)
|
|
|
|
is_win = sys.platform == 'win32'
|
|
lib_prefix = '' if is_win else 'lib'
|
|
lib_ext = '.lib' if is_win else '.a'
|
|
|
|
build_dir = os.path.join(CDM_TOP, 'out', options.platform,
|
|
options.build_config)
|
|
|
|
libs = REQUIRED_LIBS
|
|
if options.ssl:
|
|
libs += [SSL_LIB_NAME]
|
|
if options.protobuf:
|
|
libs += [PROTOBUF_NAME]
|
|
lib_paths = [os.path.join(build_dir, lib_prefix + lib + lib_ext)
|
|
for lib in libs]
|
|
result_path = os.path.join(build_dir, lib_prefix + RESULT_LIB_NAME + lib_ext)
|
|
|
|
not_found = [lib for lib in lib_paths if not os.path.exists(lib)]
|
|
if not_found:
|
|
print('Unable to find %s, be sure to run ./build.py first.' %
|
|
os.path.basename(not_found[0]))
|
|
return 1
|
|
|
|
if is_win:
|
|
return subprocess.call(
|
|
[options.lib, '/NOLOGO', '/OUT:' + result_path] + lib_paths)
|
|
else:
|
|
return _CombineLinuxLibs(options.ar, result_path, lib_paths)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main(sys.argv[1:]))
|