From ffe0d330262338e16ab66c3c0a89ff8849e9ec7f Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 7 Dec 2016 09:51:05 -0400 Subject: [PATCH] chore: require MinGW to build Etcher on Windows (#948) Using MinGW allows us to re-use the build scripts we've been developing for GNU/Linux and OS X, which are much more robust than their `*.bat` counterparts (due to Batch limitations). This commit does the following changes: - Documents MinGW as a requirement in `RUNNING-LOCALLY.md` - It setups MinGW in Appveyor CI - Transforms `windows/sign.bat` into `windows/electron-sign-exe.sh` - Re-uses `dependencies-npm.sh` and `dependencies-bower.sh` in `build/windows.bat` Signed-off-by: Juan Cruz Viotti --- appveyor.yml | 2 + docs/RUNNING-LOCALLY.md | 8 ++ scripts/build/windows.bat | 19 +++-- scripts/windows/dependencies.bat | 118 --------------------------- scripts/windows/electron-sign-exe.sh | 81 ++++++++++++++++++ scripts/windows/sign.bat | 64 --------------- 6 files changed, 103 insertions(+), 189 deletions(-) delete mode 100644 scripts/windows/dependencies.bat create mode 100755 scripts/windows/electron-sign-exe.sh delete mode 100644 scripts/windows/sign.bat diff --git a/appveyor.yml b/appveyor.yml index 95bd259e..7d86b64b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -29,6 +29,8 @@ install: - set PATH=C:\Program Files (x86)\Windows Kits\8.1\bin\x86;%PATH% - set PATH=C:\Program Files (x86)\NSIS;%PATH% - set PATH=C:\Ruby22\bin;%PATH% + - set PATH=C:\MinGW\bin;%PATH% + - set PATH=C:\MinGW\msys\1.0\bin;%PATH% - gem install scss_lint - .\scripts\build\windows.bat install x64 diff --git a/docs/RUNNING-LOCALLY.md b/docs/RUNNING-LOCALLY.md index ff56bd3e..4f48a357 100644 --- a/docs/RUNNING-LOCALLY.md +++ b/docs/RUNNING-LOCALLY.md @@ -22,6 +22,14 @@ Prerequisites - [NSIS v2.51](http://nsis.sourceforge.net/Main_Page) (v3.x won't work) - [Visual Studio Community 2013](https://www.visualstudio.com/en-us/news/vs2013-community-vs.aspx) - [7z](http://www.7-zip.org) (command line version) +- [MinGW](http://www.mingw.org) + +The following MinGW packages are required: + +- `msys-make` +- `msys-unzip` +- `msys-wget` +- `msys-bash` ### OS X diff --git a/scripts/build/windows.bat b/scripts/build/windows.bat index fa47201d..8a49b7bc 100644 --- a/scripts/build/windows.bat +++ b/scripts/build/windows.bat @@ -148,7 +148,12 @@ set package_name=Etcher-%etcher_version%-win32-%arch% ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: if not "%command%"=="package" ( - call scripts\windows\dependencies.bat -r %arch% -v %electron_version% -t electron + call bash.exe scripts\unix\dependencies-npm.sh^ + -r %arch%^ + -v %electron_version%^ + -t electron^ + -s win32 + call bash.exe scripts\unix\dependencies-bower.sh ) if "%command%"=="install" ( @@ -188,13 +193,13 @@ if not "%arch%"=="%electron_arch%" ( move %output_build_directory%\Etcher-win32-%arch% %package_output% -:: Omit *.dll and *.node files from the asar package, otherwise -:: `process.dlopen` and `module.require` can't load them correctly. -call asar pack %package_output%\resources\app %package_output%\resources\app.asar^ - --unpack "{*.dll,*.node}" +call bash.exe scripts\unix\electron-create-asar.sh^ + -d %package_output%\resources\app^ + -o %package_output%\resources\app.asar + call rimraf %package_output%\resources\app -call scripts\windows\sign.bat^ +call bash.exe scripts\windows\electron-sign-exe.sh^ -c %certificate_file%^ -p %certificate_pass%^ -f %package_output%\Etcher.exe^ @@ -221,7 +226,7 @@ mkdir "%output_directory%" move "%installer_tmp_output%\%application_name% Setup.exe" "%installer_output%" rd /s /q "%installer_tmp_output%" -call scripts\windows\sign.bat^ +call bash.exe scripts\windows\electron-sign-exe.sh^ -c %certificate_file%^ -p %certificate_pass%^ -f %installer_output%^ diff --git a/scripts/windows/dependencies.bat b/scripts/windows/dependencies.bat deleted file mode 100644 index 1796d9f9..00000000 --- a/scripts/windows/dependencies.bat +++ /dev/null @@ -1,118 +0,0 @@ -@echo off -setlocal EnableDelayedExpansion - -:ParameterLoop -if x%1 equ x goto :ParameterDone -set parameter=%1 -if %parameter:~0,1% equ - goto CheckParameter -:Usage -echo Usage: %0 -echo. -echo Options -echo. -echo -r ^ -echo -v ^ -echo -t ^ -echo -f force install -echo -p production install -exit /b 1 -:NextParameter -shift /1 -goto ParameterLoop -:CheckParameter -if "%1" equ "-r" goto ARGV_R -if "%1" equ "-v" goto ARGV_V -if "%1" equ "-t" goto ARGV_T -if "%1" equ "-f" goto ARGV_F -if "%1" equ "-p" goto ARGV_P -goto Usage -:ARGV_R - shift /1 - set argv_architecture=%1 - goto NextParameter -:ARGV_V - shift /1 - set argv_target_version=%1 - goto NextParameter -:ARGV_T - shift /1 - set argv_target_platform=%1 - goto NextParameter -:ARGV_F - shift /1 - set argv_force=true - goto NextParameter -:ARGV_P - shift /1 - set argv_production=true - goto NextParameter -:ParameterDone -if not defined argv_architecture (goto Usage) -if not defined argv_target_version (goto Usage) -if not defined argv_target_platform (goto Usage) - -:: Check that rimraf is installed. -:: We make use of this command line tool to clear -:: saved dependencies since doing so with `del` -:: might return errors due to long paths. -where rimraf >nul 2>nul -if %ERRORLEVEL% neq 0 ( - echo Dependency missing: rimraf 1>&2 - exit /b 1 -) - -:: Check that npm is installed. -where npm >nul 2>nul -if %ERRORLEVEL% neq 0 ( - echo Dependency missing: npm 1>&2 - exit /b 1 -) - -:: Check that bower is installed. -where bower >nul 2>nul -if %ERRORLEVEL% neq 0 ( - echo Dependency missing: bower 1>&2 - exit /b 1 -) - -:: Check that python is installed. -where python >nul 2>nul -if %ERRORLEVEL% neq 0 ( - echo Dependency missing: python 1>&2 - exit /b 1 -) - -:: We require Visual Studio 2013 specifically since newer versions -:: lack command line build tools such as `lib.exe` and `cl.exe`. -set GYP_MSVS_VERSION=2013 - -if "%argv_target_platform%"=="electron" ( - set npm_config_disturl=https://atom.io/download/atom-shell - set npm_config_runtime=electron -) - -set npm_config_target=%argv_target_version% - -if "%argv_architecture%"=="x86" ( - set npm_config_arch=ia32 -) else ( - set npm_config_arch=%electron_arch% -) - -set npm_install_opts=--build-from-source - -if "%argv_force%"=="true" ( - set npm_install_opts=%npm_install_opts% --force -) - -if "%argv_production%"=="true" ( - set npm_install_opts=%npm_install_opts% --production -) - -call rimraf node_modules -call npm install %npm_install_opts% - -if "%argv_target_platform%"=="electron" ( - call rimraf bower_components - call bower install --production -) diff --git a/scripts/windows/electron-sign-exe.sh b/scripts/windows/electron-sign-exe.sh new file mode 100755 index 00000000..6b72be0c --- /dev/null +++ b/scripts/windows/electron-sign-exe.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +### +# Copyright 2016 resin.io +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +### + +set -u +set -e + +function check_dep() { + if ! command -v $1 2>/dev/null 1>&2; then + echo "Dependency missing: $1" 1>&2 + exit 1 + fi +} + +OS=$(uname -o 2>/dev/null || true) +if [[ "$OS" != "Msys" ]]; then + echo "This script is only meant to be run in Windows" 1>&2 + exit 1 +fi + +check_dep signtool + +function usage() { + echo "Usage: $0" + echo "" + echo "Options" + echo "" + echo " -f " + echo " -c " + echo " -p " + echo " -d " + exit 1 +} + +ARGV_FILE="" +ARGV_CERTIFICATE_FILE="" +ARGV_CERTIFICATE_PASSWORD="" +ARGV_SIGNATURE_DESCRIPTION="" + +while getopts ":f:c:p:d:" option; do + case $option in + f) ARGV_FILE="$OPTARG" ;; + c) ARGV_CERTIFICATE_FILE="$OPTARG" ;; + p) ARGV_CERTIFICATE_PASSWORD="$OPTARG" ;; + d) ARGV_SIGNATURE_DESCRIPTION="$OPTARG" ;; + *) usage ;; + esac +done + +if [ -z "$ARGV_FILE" ] || + [ -z "$ARGV_CERTIFICATE_FILE" ] || + [ -z "$ARGV_CERTIFICATE_PASSWORD" ] || + [ -z "$ARGV_SIGNATURE_DESCRIPTION" ] +then + usage +fi + +TIMESTAMP_SERVER=http://timestamp.comodoca.com + +signtool sign \ + /t "$TIMESTAMP_SERVER" \ + /d "$ARGV_SIGNATURE_DESCRIPTION" \ + /f "$ARGV_CERTIFICATE_FILE" \ + /p "$ARGV_CERTIFICATE_PASSWORD" \ + "$ARGV_FILE" + +signtool verify /pa /v "$ARGV_FILE" diff --git a/scripts/windows/sign.bat b/scripts/windows/sign.bat deleted file mode 100644 index a438e069..00000000 --- a/scripts/windows/sign.bat +++ /dev/null @@ -1,64 +0,0 @@ -@echo on -setlocal EnableDelayedExpansion - -:ParameterLoop -if x%1 equ x goto :ParameterDone -set parameter=%1 -if %parameter:~0,1% equ - goto CheckParameter -:Usage -echo Usage: %0 -echo. -echo Options -echo. -echo -c ^ -echo -p ^ -echo -f ^ -echo -d ^ -exit /b 1 -:NextParameter -shift /1 -goto ParameterLoop -:CheckParameter -if "%1" equ "-c" goto ARGV_C -if "%1" equ "-p" goto ARGV_P -if "%1" equ "-f" goto ARGV_F -if "%1" equ "-d" goto ARGV_D -goto Usage -:ARGV_C - shift /1 - set argv_certificate=%1 - goto NextParameter -:ARGV_P - shift /1 - set argv_password=%1 - goto NextParameter -:ARGV_F - shift /1 - set argv_file=%1 - goto NextParameter -:ARGV_D - shift /1 - set argv_description=%1 - goto NextParameter -:ParameterDone - -if not defined argv_certificate (goto Usage) -if not defined argv_password (goto Usage) -if not defined argv_file (goto Usage) -if not defined argv_description (goto Usage) - -:: Check that signtool is installed. -where signtool >nul 2>nul -if %ERRORLEVEL% neq 0 ( - echo Dependency missing: signtool 1>&2 - exit /b 1 -) - -signtool sign^ - /t http://timestamp.comodoca.com^ - /d %argv_description%^ - /f %argv_certificate%^ - /p %argv_password%^ - %argv_file% - -signtool verify /pa /v %argv_file%