From 8e525f965da4323ee73f8c5f9548e898983f208b Mon Sep 17 00:00:00 2001 From: Aleksei Kuzmin Date: Fri, 31 Aug 2018 13:48:21 +0200 Subject: [PATCH 1/3] build: add a helper script to retreive data from a GN project --- script/lib/gn.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 script/lib/gn.py diff --git a/script/lib/gn.py b/script/lib/gn.py new file mode 100644 index 000000000000..ccd8cc666155 --- /dev/null +++ b/script/lib/gn.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +import subprocess + +from util import scoped_cwd + + +class GNProject: + def __init__(self, out_dir): + self.out_dir = out_dir + + def run(self, command_name, command_args): + with scoped_cwd(self.out_dir): + complete_args = ['gn', 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) From 57a4d8666931ca76014e31f9dd4922d7c52e2c81 Mon Sep 17 00:00:00 2001 From: Aleksei Kuzmin Date: Fri, 31 Aug 2018 13:52:21 +0200 Subject: [PATCH 2/3] refactor: do not use electron.gyp contents in the verify-ffmpeg script Also run verify ffmpeg with cmd instead of powershell --- .circleci/config.yml | 2 +- appveyor-gn.yml | 4 ++-- script/lib/gn.py | 9 ++++++- script/verify-ffmpeg.py | 53 ++++++++++++++++++++++------------------- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index daf0b4cbd71e..d0bc75ac3257 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -107,7 +107,7 @@ gn-build-steps: &gn-build-steps name: Verify ffmpeg command: | 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 - run: name: Test diff --git a/appveyor-gn.yml b/appveyor-gn.yml index eaba7b06218c..4783b5418562 100644 --- a/appveyor-gn.yml +++ b/appveyor-gn.yml @@ -29,9 +29,9 @@ build_script: - ninja -C out/ffmpeg third_party/ffmpeg - ninja -C out/Default electron:electron_dist_zip 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: >- 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 $env:npm_config_nodedir="$pwd/out/Default/gen/node_headers" $env:npm_config_msvs_version="2017" @@ -43,7 +43,7 @@ test_script: } else { 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: - path: src/out/Default/dist.zip name: dist.zip diff --git a/script/lib/gn.py b/script/lib/gn.py index ccd8cc666155..0d192bcd909e 100644 --- a/script/lib/gn.py +++ b/script/lib/gn.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import subprocess +import sys from util import scoped_cwd @@ -9,9 +10,15 @@ 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 = ['gn', command_name, '.'] + command_args + complete_args = [self._get_executable_name(), command_name, '.'] + command_args return subprocess.check_output(complete_args) def args(self): diff --git a/script/verify-ffmpeg.py b/script/verify-ffmpeg.py index d5d30889aa09..f6cea8a95e85 100755 --- a/script/verify-ffmpeg.py +++ b/script/verify-ffmpeg.py @@ -5,40 +5,42 @@ import shutil import subprocess 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__))) -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(): 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': - 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_app_path = os.path.join(app_path, 'Contents', 'Frameworks', - '{0} Framework.framework'.format(PROJECT_NAME), + '{0} Framework.framework'.format(product_name), 'Libraries') 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_name = 'ffmpeg.dll' else: - electron = os.path.join(app_path, PROJECT_NAME) + electron = os.path.join(app_path, project_name) ffmpeg_app_path = app_path ffmpeg_name = 'libffmpeg.so' - # Copy ffmpeg without proprietary codecs into app - shutil.copy(os.path.join(args.ffmpeg_path, ffmpeg_name), ffmpeg_app_path) + # 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) returncode = 0 try: @@ -56,13 +58,13 @@ def main(): # Create copy of app to install ffmpeg library without proprietary codecs into -def create_app_copy(args): - initial_app_path = os.path.join(args.source_root, 'out', args.config) - app_path = os.path.join(args.source_root, 'out', - args.config + '-no-proprietary-codecs') +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') 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) app_path = os.path.join(app_path, app_name) @@ -72,16 +74,17 @@ def create_app_copy(args): def parse_args(): parser = argparse.ArgumentParser(description='Test non-proprietary ffmpeg') - parser.add_argument('-c', '--config', - help='Test with Release or Debug configuration', - default='D', - required=False) + parser.add_argument('-b', '--build-dir', + help='Path to an Electron build folder. Relative to the --source-root.', + default=None, + required=True) parser.add_argument('--source-root', default=SOURCE_ROOT, required=False) parser.add_argument('--ffmpeg-path', - default=FFMPEG_LIBCC_PATH, - required=False) + help='Path to a folder with a ffmpeg lib. Relative to the --source-root.', + default=None, + required=True) return parser.parse_args() if __name__ == '__main__': From b16bf6a95d663a0979df7621ed8619a8360a96e6 Mon Sep 17 00:00:00 2001 From: Aleksei Kuzmin Date: Mon, 3 Sep 2018 12:33:23 +0200 Subject: [PATCH 3/3] ci: pass GN_EXTRA_ARGS to the ffmpeg build Both Electron and ffmpeg should have the same value of the `target_cpu` build flag. --- appveyor-gn.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor-gn.yml b/appveyor-gn.yml index 4783b5418562..81155f488aa0 100644 --- a/appveyor-gn.yml +++ b/appveyor-gn.yml @@ -25,7 +25,7 @@ build_script: - cd src - gn gen out/Default "--args=import(\"//electron/build/args/%GN_CONFIG%.gn\") %GN_EXTRA_ARGS%" - 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/Default electron:electron_dist_zip test_script: