Skip to content

Instantly share code, notes, and snippets.

@jacobq
Last active January 9, 2020 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobq/9d56dc9f8504cd2351651c9ee7b7d58a to your computer and use it in GitHub Desktop.
Save jacobq/9d56dc9f8504cd2351651c9ee7b7d58a to your computer and use it in GitHub Desktop.
Build electron from source
#!/bin/bash
ORIGINAL_DIR=${pwd}
# Optional caching step
#export GIT_CACHE_PATH="${HOME}/.git_cache"
#mkdir -p "${GIT_CACHE_PATH}"
# Use electron's build cache
export SCCACHE_BUCKET="electronjs-sccache-ci"
export SCCACHE_TWO_TIER=true
GN_DIR=${HOME}/tmp/electron-gn
mkdir -p "${GN_DIR}"
SRC_DIR=$GN_DIR/src
ELECTRON_REPO_URL=https://github.com/electron/electron
ELECTRON_REPO_BRANCH=master
# cd $HOME
# git clone https://chromium.googlesource.com/chromium/tools/depot_tools
DEPOT_TOOLS_DIR=${HOME}/tmp/depot_tools
# Add depot_tools to PATH if not already there (need gclient, gn, ninja, cipd, etc.)
[[ ":$PATH:" != *":${DEPOT_TOOLS_DIR}:"* ]] && export PATH="${PATH}:${DEPOT_TOOLS_DIR}"
export CHROMIUM_BUILDTOOLS_PATH=$SRC_DIR/buildtools
export GN_EXTRA_ARGS="${GN_EXTRA_ARGS} cc_wrapper=\"${SRC_DIR}/electron/external_binaries/sccache\""
echo "Configuring environment with gclient"
cd $GN_DIR
gclient config --name "src/electron" --unmanaged $ELECTRON_REPO_URL
gclient sync --with_branch_heads --with_tags #--delete_unversioned_trees
# To support push/pull
echo "Making sure electron repo is tracking with $ELECTRON_REPO_URL"
cd src/electron
git remote remove origin
git remote add origin $ELECTRON_REPO_URL
git fetch --all
git checkout $ELECTRON_REPO_BRANCH
git branch --set-upstream-to=origin/$ELECTRON_REPO_BRANCH
git reset --hard origin/$ELECTRON_REPO_BRANCH
#git pull
gclient sync -f
cd -
cd $SRC_DIR
BUILD_NAME=Testing # or Release
BUILD_CONFIG_FILE_NAME=`echo $BUILD_NAME| tr '[:upper:]' '[:lower:]'`
echo "Generating config (out/${BUILD_NAME}, ${BUILD_CONFIG_FILE_NAME}.gn)"
gn gen out/${BUILD_NAME} --args="import(\"//electron/build/args/${BUILD_CONFIG_FILE_NAME}.gn\") $GN_EXTRA_ARGS"
echo "Building"
ninja -C out/${BUILD_NAME} electron
echo "Building node headers"
ninja -C out/$BUILD_NAME third_party/electron_node:headers
echo "Running test suite"
cd electron
npm run test
cd $ORIGINAL_DIR
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment