首页 > 解决方案 > 如何使用 gclient 获取电子分支代码?

问题描述

如何获得像 electron v3.1.6 和 Dependency chromium 代码这样的分支代码?</p>

这是关于 Electron 官方给出的获取代码。但它是获取最新的代码。

mkdir electron-gn && cd electron-gn gclient config \ --name "src/electron" \ --unmanaged \ https://github.com/electron/electron gclient sync --with_branch_heads --with_tags

标签: electron-builder

解决方案


请注意,该--unmanaged选项使您可以更改远程(repo)和/或分支,gclient并且不会对此做任何事情。(如果我理解正确的话。)

来自gclient config --help

--unmanaged 覆盖默认行为,以使 gclient 可以不触及主要解决方案(gclient 将检查非托管依赖项但永远不会同步它们)

因此,您可以进入src/electron文件夹并签出您喜欢的任何分支。下面是我根据官方构建说明(YMMV) 为此编写的脚本。

#!/bin/bash

GN_DIR=${HOME}/tmp/electron-gn
SRC_DIR=$GN_DIR/src
ELECTRON_REPO_URL=https://github.com/user/electron
ELECTRON_REPO_BRANCH=some_branch

# mkdir -p $HOME/tmp
# cd $HOME/tmp
# 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 GIT_CACHE_PATH="${HOME}/.git_cache"
export SCCACHE_BUCKET="electronjs-sccache-ci"
export SCCACHE_TWO_TIER=true
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

echo "Making sure electron repo is tracking with $ELECTRON_REPO_URL"
cd src/electron
git checkout $ELECTRON_REPO_BRANCH
#git branch --set-upstream-to=origin/$ELECTRON_REPO_BRANCH
git pull
cd -

echo "Making sure electron repo is up to date"
cd src/electron
git pull
gclient sync -f
cd -

cd $SRC_DIR
echo "Generating config"
gn gen out/Debug --args="import(\"//electron/build/args/debug.gn\") $GN_EXTRA_ARGS"
echo "Building"
ninja -C out/Debug electron

推荐阅读