2017-03-29 23:23:30 +00:00
|
|
|
#!/usr/bin/env python
|
2018-08-22 15:41:25 +00:00
|
|
|
import argparse
|
2017-03-29 23:23:30 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
2018-08-31 11:52:21 +00:00
|
|
|
from lib.gn import gn
|
|
|
|
from lib.util import rm_rf
|
2017-03-29 23:23:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2018-08-22 15:41:25 +00:00
|
|
|
args = parse_args()
|
2017-03-29 23:23:30 +00:00
|
|
|
|
2018-08-31 11:52:21 +00:00
|
|
|
initial_app_path = os.path.join(os.path.abspath(args.source_root), args.build_dir)
|
|
|
|
app_path = create_app_copy(initial_app_path)
|
|
|
|
|
|
|
|
# Those are the same in the original app and its copy.
|
|
|
|
# So it is ok to retrieve them from the original build dir and use in the copy.
|
|
|
|
product_name = gn(initial_app_path).args().get_string('electron_product_name')
|
|
|
|
project_name = gn(initial_app_path).args().get_string('electron_project_name')
|
2017-03-29 23:23:30 +00:00
|
|
|
|
|
|
|
if sys.platform == 'darwin':
|
2018-08-31 11:52:21 +00:00
|
|
|
electron = os.path.join(app_path, 'Contents', 'MacOS', product_name)
|
2017-03-29 23:23:30 +00:00
|
|
|
ffmpeg_name = 'libffmpeg.dylib'
|
|
|
|
ffmpeg_app_path = os.path.join(app_path, 'Contents', 'Frameworks',
|
2018-08-31 11:52:21 +00:00
|
|
|
'{0} Framework.framework'.format(product_name),
|
2017-03-29 23:23:30 +00:00
|
|
|
'Libraries')
|
|
|
|
elif sys.platform == 'win32':
|
2018-08-31 11:52:21 +00:00
|
|
|
electron = os.path.join(app_path, '{0}.exe'.format(project_name))
|
2017-03-29 23:23:30 +00:00
|
|
|
ffmpeg_app_path = app_path
|
2017-03-30 00:01:25 +00:00
|
|
|
ffmpeg_name = 'ffmpeg.dll'
|
2017-03-29 23:23:30 +00:00
|
|
|
else:
|
2018-08-31 11:52:21 +00:00
|
|
|
electron = os.path.join(app_path, project_name)
|
2017-03-29 23:23:30 +00:00
|
|
|
ffmpeg_app_path = app_path
|
|
|
|
ffmpeg_name = 'libffmpeg.so'
|
|
|
|
|
2018-08-31 11:52:21 +00:00
|
|
|
# Copy ffmpeg without proprietary codecs into app.
|
|
|
|
ffmpeg_lib_path = os.path.join(os.path.abspath(args.source_root), args.ffmpeg_path, ffmpeg_name)
|
|
|
|
shutil.copy(ffmpeg_lib_path, ffmpeg_app_path)
|
2017-03-29 23:23:30 +00:00
|
|
|
|
|
|
|
returncode = 0
|
|
|
|
try:
|
2018-08-22 15:41:25 +00:00
|
|
|
test_path = os.path.join(SOURCE_ROOT, 'spec', 'fixtures',
|
|
|
|
'no-proprietary-codecs.js')
|
2017-03-29 23:23:30 +00:00
|
|
|
subprocess.check_call([electron, test_path] + sys.argv[1:])
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
returncode = e.returncode
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
returncode = 0
|
|
|
|
|
2018-08-24 14:49:01 +00:00
|
|
|
if returncode == 0:
|
|
|
|
print 'ok Non proprietary ffmpeg does not contain proprietary codes.'
|
2017-03-29 23:23:30 +00:00
|
|
|
return returncode
|
|
|
|
|
|
|
|
|
|
|
|
# Create copy of app to install ffmpeg library without proprietary codecs into
|
2018-08-31 11:52:21 +00:00
|
|
|
def create_app_copy(initial_app_path):
|
|
|
|
app_path = os.path.join(os.path.dirname(initial_app_path),
|
|
|
|
os.path.basename(initial_app_path) + '-no-proprietary-codecs')
|
2017-03-29 23:23:30 +00:00
|
|
|
|
|
|
|
if sys.platform == 'darwin':
|
2018-08-31 11:52:21 +00:00
|
|
|
product_name = gn(initial_app_path).args().get_string('electron_product_name')
|
|
|
|
app_name = '{0}.app'.format(product_name)
|
2017-03-29 23:23:30 +00:00
|
|
|
initial_app_path = os.path.join(initial_app_path, app_name)
|
|
|
|
app_path = os.path.join(app_path, app_name)
|
|
|
|
|
|
|
|
rm_rf(app_path)
|
|
|
|
shutil.copytree(initial_app_path, app_path, symlinks=True)
|
|
|
|
return app_path
|
|
|
|
|
2018-08-22 15:41:25 +00:00
|
|
|
def parse_args():
|
|
|
|
parser = argparse.ArgumentParser(description='Test non-proprietary ffmpeg')
|
2018-08-31 11:52:21 +00:00
|
|
|
parser.add_argument('-b', '--build-dir',
|
|
|
|
help='Path to an Electron build folder. Relative to the --source-root.',
|
|
|
|
default=None,
|
|
|
|
required=True)
|
2018-08-22 15:41:25 +00:00
|
|
|
parser.add_argument('--source-root',
|
|
|
|
default=SOURCE_ROOT,
|
|
|
|
required=False)
|
|
|
|
parser.add_argument('--ffmpeg-path',
|
2018-08-31 11:52:21 +00:00
|
|
|
help='Path to a folder with a ffmpeg lib. Relative to the --source-root.',
|
|
|
|
default=None,
|
|
|
|
required=True)
|
2018-08-22 15:41:25 +00:00
|
|
|
return parser.parse_args()
|
2017-03-29 23:23:30 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|