Merge pull request #14512 from electron/do-not-use-electron-gyp-for-verify-ffmpeg

refactor: do not use electron.gyp contents in the verify-ffmpeg script
This commit is contained in:
John Kleinschmidt 2018-09-10 09:34:16 -04:00 committed by GitHub
commit 2d2d1d2090
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 100 additions and 29 deletions

View file

@ -107,7 +107,7 @@ gn-build-steps: &gn-build-steps
name: Verify ffmpeg name: Verify ffmpeg
command: | command: |
if [ "$RUN_TESTS" != "false" ] && [ "$BUILD_FFMPEG" == "true" ]; then if [ "$RUN_TESTS" != "false" ] && [ "$BUILD_FFMPEG" == "true" ]; then
python src/electron/script/verify-ffmpeg.py -c Default --source-root "$PWD/src" --ffmpeg-path "$PWD/src/out/ffmpeg" python src/electron/script/verify-ffmpeg.py --build-dir out/Default --source-root "$PWD/src" --ffmpeg-path out/ffmpeg
fi fi
- run: - run:
name: Test name: Test

View file

@ -25,13 +25,13 @@ build_script:
- cd src - cd src
- gn gen out/Default "--args=import(\"//electron/build/args/%GN_CONFIG%.gn\") %GN_EXTRA_ARGS%" - gn gen out/Default "--args=import(\"//electron/build/args/%GN_CONFIG%.gn\") %GN_EXTRA_ARGS%"
- ninja -C out/Default electron:electron_app - ninja -C out/Default electron:electron_app
- gn gen out/ffmpeg "--args=import(\"//electron/build/args/ffmpeg.gn\")" - gn gen out/ffmpeg "--args=import(\"//electron/build/args/ffmpeg.gn\") %GN_EXTRA_ARGS%"
- ninja -C out/ffmpeg third_party/ffmpeg - ninja -C out/ffmpeg third_party/ffmpeg
- ninja -C out/Default electron:electron_dist_zip - ninja -C out/Default electron:electron_dist_zip
test_script: test_script:
- if "%GN_CONFIG%"=="testing" ( echo Verifying non proprietary ffmpeg & python electron\script\verify-ffmpeg.py --build-dir out\Default --source-root %cd% --ffmpeg-path out\ffmpeg )
- ps: >- - ps: >-
if ($env:GN_CONFIG -eq 'testing') { if ($env:GN_CONFIG -eq 'testing') {
python electron\script\verify-ffmpeg.py -c Default --source-root "$PWD" --ffmpeg-path "$PWD\out\ffmpeg"
ninja -C out/Default third_party/electron_node:headers ninja -C out/Default third_party/electron_node:headers
$env:npm_config_nodedir="$pwd/out/Default/gen/node_headers" $env:npm_config_nodedir="$pwd/out/Default/gen/node_headers"
$env:npm_config_msvs_version="2017" $env:npm_config_msvs_version="2017"
@ -43,7 +43,7 @@ test_script:
} else { } else {
echo "Skipping tests for $env:GN_CONFIG build" echo "Skipping tests for $env:GN_CONFIG build"
} }
- if "%GN_CONFIG%"=="testing" ( echo "Running test suite" & .\out\Default\electron.exe electron\spec --ci ) - if "%GN_CONFIG%"=="testing" ( echo Running test suite & .\out\Default\electron.exe electron\spec --ci )
artifacts: artifacts:
- path: src/out/Default/dist.zip - path: src/out/Default/dist.zip
name: dist.zip name: dist.zip

68
script/lib/gn.py Normal file
View file

@ -0,0 +1,68 @@
#!/usr/bin/env python
import subprocess
import sys
from util import scoped_cwd
class GNProject:
def __init__(self, out_dir):
self.out_dir = out_dir
def _get_executable_name(self):
if sys.platform == 'win32':
return 'gn.bat'
return 'gn'
def run(self, command_name, command_args):
with scoped_cwd(self.out_dir):
complete_args = [self._get_executable_name(), command_name, '.'] + command_args
return subprocess.check_output(complete_args)
def args(self):
return GNArgs(self)
class GNArgs:
def __init__(self, project):
self.project = project
def _get_raw_value(self, name):
# E.g. 'version = "1.0.0"\n'
raw_output = self.project.run('args',
['--list={}'.format(name), '--short'])
# E.g. 'version = "1.0.0"'
name_with_raw_value = raw_output[:-1]
# E.g. ['version', '"1.0.0"']
name_and_raw_value = name_with_raw_value.split(' = ')
raw_value = name_and_raw_value[1]
return raw_value
def get_string(self, name):
# Expects to get a string in double quotes, e.g. '"some_value"'.
raw_value = self._get_raw_value(name)
# E.g. 'some_value' (without enclosing quotes).
value = raw_value[1:-1]
return value
def get_boolean(self, name):
# Expects to get a 'true' or a 'false' string.
raw_value = self._get_raw_value(name)
if raw_value == 'true':
return True
if raw_value == 'false':
return False
return None
def gn(out_dir):
return GNProject(out_dir)

View file

@ -5,40 +5,42 @@ import shutil
import subprocess import subprocess
import sys import sys
from lib.util import electron_gyp, rm_rf from lib.gn import gn
from lib.util import rm_rf
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
FFMPEG_LIBCC_PATH = os.path.join(SOURCE_ROOT, 'vendor', 'download',
'libchromiumcontent', 'ffmpeg')
PROJECT_NAME = electron_gyp()['project_name%']
PRODUCT_NAME = electron_gyp()['product_name%']
def main(): def main():
args = parse_args() args = parse_args()
os.chdir(args.source_root)
app_path = create_app_copy(args) 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')
if sys.platform == 'darwin': if sys.platform == 'darwin':
electron = os.path.join(app_path, 'Contents', 'MacOS', PRODUCT_NAME) electron = os.path.join(app_path, 'Contents', 'MacOS', product_name)
ffmpeg_name = 'libffmpeg.dylib' ffmpeg_name = 'libffmpeg.dylib'
ffmpeg_app_path = os.path.join(app_path, 'Contents', 'Frameworks', ffmpeg_app_path = os.path.join(app_path, 'Contents', 'Frameworks',
'{0} Framework.framework'.format(PROJECT_NAME), '{0} Framework.framework'.format(product_name),
'Libraries') 'Libraries')
elif sys.platform == 'win32': elif sys.platform == 'win32':
electron = os.path.join(app_path, '{0}.exe'.format(PROJECT_NAME)) electron = os.path.join(app_path, '{0}.exe'.format(project_name))
ffmpeg_app_path = app_path ffmpeg_app_path = app_path
ffmpeg_name = 'ffmpeg.dll' ffmpeg_name = 'ffmpeg.dll'
else: else:
electron = os.path.join(app_path, PROJECT_NAME) electron = os.path.join(app_path, project_name)
ffmpeg_app_path = app_path ffmpeg_app_path = app_path
ffmpeg_name = 'libffmpeg.so' ffmpeg_name = 'libffmpeg.so'
# Copy ffmpeg without proprietary codecs into app # Copy ffmpeg without proprietary codecs into app.
shutil.copy(os.path.join(args.ffmpeg_path, ffmpeg_name), ffmpeg_app_path) 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)
returncode = 0 returncode = 0
try: try:
@ -56,13 +58,13 @@ def main():
# Create copy of app to install ffmpeg library without proprietary codecs into # Create copy of app to install ffmpeg library without proprietary codecs into
def create_app_copy(args): def create_app_copy(initial_app_path):
initial_app_path = os.path.join(args.source_root, 'out', args.config) app_path = os.path.join(os.path.dirname(initial_app_path),
app_path = os.path.join(args.source_root, 'out', os.path.basename(initial_app_path) + '-no-proprietary-codecs')
args.config + '-no-proprietary-codecs')
if sys.platform == 'darwin': if sys.platform == 'darwin':
app_name = '{0}.app'.format(PRODUCT_NAME) product_name = gn(initial_app_path).args().get_string('electron_product_name')
app_name = '{0}.app'.format(product_name)
initial_app_path = os.path.join(initial_app_path, app_name) initial_app_path = os.path.join(initial_app_path, app_name)
app_path = os.path.join(app_path, app_name) app_path = os.path.join(app_path, app_name)
@ -72,16 +74,17 @@ def create_app_copy(args):
def parse_args(): def parse_args():
parser = argparse.ArgumentParser(description='Test non-proprietary ffmpeg') parser = argparse.ArgumentParser(description='Test non-proprietary ffmpeg')
parser.add_argument('-c', '--config', parser.add_argument('-b', '--build-dir',
help='Test with Release or Debug configuration', help='Path to an Electron build folder. Relative to the --source-root.',
default='D', default=None,
required=False) required=True)
parser.add_argument('--source-root', parser.add_argument('--source-root',
default=SOURCE_ROOT, default=SOURCE_ROOT,
required=False) required=False)
parser.add_argument('--ffmpeg-path', parser.add_argument('--ffmpeg-path',
default=FFMPEG_LIBCC_PATH, help='Path to a folder with a ffmpeg lib. Relative to the --source-root.',
required=False) default=None,
required=True)
return parser.parse_args() return parser.parse_args()
if __name__ == '__main__': if __name__ == '__main__':