build: create a symlink to src/buildtools during sync

Assisted-by: Claude Opus 4.6
This commit is contained in:
David Sanders
2026-05-01 14:26:36 -07:00
parent 7adb8b0d3f
commit d212bc7170
13 changed files with 72 additions and 62 deletions

View File

@@ -54,7 +54,6 @@ if [ ! -f $buildtools/configs/evm.testing.json ]; then
\"out\": \"Testing\"
},
\"env\": {
\"CHROMIUM_BUILDTOOLS_PATH\": \"/workspaces/gclient/src/buildtools\",
\"GIT_CACHE_PATH\": \"/workspaces/gclient/.git-cache\"
},
\"\$schema\": \"file:///home/builduser/.electron_build_tools/evm-config.schema.json\",

View File

@@ -57,9 +57,6 @@ jobs:
@Subdir src/buildtools/linux64
gn/gn/linux-amd64 $gn_version
CIPD
buildtools_path="$(pwd)/src/buildtools"
echo "CHROMIUM_BUILDTOOLS_PATH=$buildtools_path" >> $GITHUB_ENV
- name: Download clang-format Binary
shell: bash
run: |
@@ -80,11 +77,10 @@ jobs:
- name: Run Lint
shell: bash
run: |
# gn.py tries to find a gclient root folder starting from the current dir.
# When it fails and returns "None" path, the whole script fails. Let's "fix" it.
touch .gclient
# Another option would be to checkout "buildtools" inside the Electron checkout,
# but then we would lint its contents (at least gn format), and it doesn't pass it.
# Clean things up so `depot_tools/gclient_paths.py` finds src/buildtools properly
echo '' > .gclient
rm -f .gclient_entries
ln -s src/buildtools buildtools
cd src/electron
node script/yarn.js install --immutable

View File

@@ -189,8 +189,6 @@ jobs:
run: |
(cd src/electron && git checkout .) && node src/electron/script/generate-deps-hash.js
echo "DEPSHASH=$(cat src/electron/.depshash)" >> $GITHUB_ENV
- name: Add CHROMIUM_BUILDTOOLS_PATH to env
run: echo "CHROMIUM_BUILDTOOLS_PATH=$(pwd)/src/buildtools" >> $GITHUB_ENV
- name: Free up space (macOS)
if: ${{ inputs.target-platform == 'macos' }}
uses: ./src/electron/.github/actions/free-space-macos

View File

@@ -111,8 +111,6 @@ jobs:
run: |
(cd src/electron && git checkout .) && node src/electron/script/generate-deps-hash.js
echo "DEPSHASH=$(cat src/electron/.depshash)" >> $GITHUB_ENV
- name: Add CHROMIUM_BUILDTOOLS_PATH to env
run: echo "CHROMIUM_BUILDTOOLS_PATH=$(pwd)/src/buildtools" >> $GITHUB_ENV
- name: Checkout Electron
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:

View File

@@ -112,8 +112,6 @@ jobs:
run: |
(cd src/electron && git checkout .) && node src/electron/script/generate-deps-hash.js
echo "DEPSHASH=$(cat src/electron/.depshash)" >> $GITHUB_ENV
- name: Add CHROMIUM_BUILDTOOLS_PATH to env
run: echo "CHROMIUM_BUILDTOOLS_PATH=$(pwd)/src/buildtools" >> $GITHUB_ENV
- name: Checkout Electron
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
@@ -128,6 +126,11 @@ jobs:
git pack-refs
- name: Run GN Check for ${{ inputs.target-archs }}
run: |
# `depot_tools/gclient_paths.py` tries to find a gclient root folder starting from the current dir.
# We also need to set up a symlink to src/buildtools so that `build-tools` can find it properly.
touch .gclient
ln -s src/buildtools buildtools
for target_cpu in ${{ inputs.target-archs }}
do
e init -f --root=$(pwd) --out=Default ${{ inputs.gn-build-type }} --import ${{ inputs.gn-build-type }} --target-cpu $target_cpu --remote-build none

View File

@@ -202,8 +202,6 @@ jobs:
src/electron/script/generate-deps-hash.js
echo "DEPSHASH=$(cat src/electron/.depshash)" >> $GITHUB_ENV
- name: Add CHROMIUM_BUILDTOOLS_PATH to env
run: echo "CHROMIUM_BUILDTOOLS_PATH=$(pwd)/src/buildtools" >> $GITHUB_ENV
- name: Free up space (macOS)
if: ${{ inputs.target-platform == 'macos' }}
uses: ./src/electron/.github/actions/free-space-macos

9
DEPS
View File

@@ -155,6 +155,15 @@ hooks = [
'import os, subprocess; os.chdir(os.path.join("src", "electron")); subprocess.check_call(["node", ".yarn/releases/yarn-4.12.0.cjs", "install", "--immutable"]);',
],
},
{
'name': 'buildtools_symlink',
'condition': 'checkout_chromium and process_deps',
'pattern': 'src/electron',
'action': [
'python3',
'src/electron/script/create-buildtools-symlink.py',
],
},
{
'name': 'sysroot_arm',
'pattern': '.',

View File

@@ -173,27 +173,6 @@ $ gclient sync -f
### Building
**Set the environment variable for chromium build tools**
On Linux & MacOS
```sh
$ cd src
$ export CHROMIUM_BUILDTOOLS_PATH=`pwd`/buildtools
```
On Windows:
```sh
# cmd
$ cd src
$ set CHROMIUM_BUILDTOOLS_PATH=%cd%\buildtools
# PowerShell
$ cd src
$ $env:CHROMIUM_BUILDTOOLS_PATH = "$(Get-Location)\buildtools"
```
**To generate Testing build config of Electron:**
On Linux & MacOS

View File

@@ -0,0 +1,50 @@
#!/usr/bin/env python3
"""Create a buildtools symlink in the gclient root directory.
This enables gclient_paths.py to locate buildtools without needing the
CHROMIUM_BUILDTOOLS_PATH environment variable.
"""
import os
import sys
def main():
electron_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
src_dir = os.path.dirname(electron_dir)
gclient_root = os.path.dirname(src_dir)
source = os.path.join(src_dir, 'buildtools')
link_name = os.path.join(gclient_root, 'buildtools')
if not os.path.isdir(source):
print(f'buildtools not found at {source}', file=sys.stderr)
return 1
# Already a symlink - verify it points to the right place.
if os.path.islink(link_name):
if os.path.realpath(link_name) == os.path.realpath(source):
return 0
os.remove(link_name)
elif os.path.exists(link_name):
# A real file or directory we shouldn't clobber.
print(f'{link_name} already exists and is not a symlink',
file=sys.stderr)
return 1
rel = os.path.relpath(source, gclient_root)
try:
os.symlink(rel, link_name, target_is_directory=True)
except OSError as e:
print(f'Failed to create symlink {link_name} -> {rel}: {e}',
file=sys.stderr)
if sys.platform == 'win32':
print('On Windows, creating symlinks requires Developer Mode '
'or administrator privileges.', file=sys.stderr)
return 1
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@@ -7,14 +7,11 @@ $ node ./script/gn-check.js [--outDir=dirName]
const minimist = require('minimist');
const cp = require('node:child_process');
const path = require('node:path');
const args = minimist(process.argv.slice(2), { string: ['outDir'] });
const { getDepotToolsEnv, getOutDir } = require('./lib/utils');
const SOURCE_ROOT = path.normalize(path.dirname(__dirname));
const OUT_DIR = getOutDir({ outDir: args.outDir });
if (!OUT_DIR) {
throw new Error('No viable out dir: one of Debug, Testing, or Release must exist.');
@@ -22,7 +19,6 @@ if (!OUT_DIR) {
const env = {
...getDepotToolsEnv(),
CHROMIUM_BUILDTOOLS_PATH: path.resolve(SOURCE_ROOT, '..', 'buildtools'),
DEPOT_TOOLS_WIN_TOOLCHAIN: '0'
};

View File

@@ -233,9 +233,4 @@ def get_depot_tools_env():
if depot_tools_env is None:
raise RuntimeError("Couldn't find depot_tools, ensure it's on your PATH")
if 'CHROMIUM_BUILDTOOLS_PATH' not in depot_tools_env:
raise RuntimeError(
'CHROMIUM_BUILDTOOLS_PATH environment variable must be set'
)
return depot_tools_env

View File

@@ -194,10 +194,6 @@ function getDepotToolsEnv() {
throw new Error("Couldn't find depot_tools, ensure it's on your PATH");
}
if (!('CHROMIUM_BUILDTOOLS_PATH' in depotToolsEnv)) {
throw new Error('CHROMIUM_BUILDTOOLS_PATH environment variable must be set');
}
return depotToolsEnv;
}

View File

@@ -116,13 +116,11 @@ const LINTERS = [
roots: ['shell'],
test: (filename) => filename.endsWith('.cc') || (filename.endsWith('.h') && !isObjCHeader(filename)),
run: (opts, filenames) => {
const env = {
...getDepotToolsEnv(),
CHROMIUM_BUILDTOOLS_PATH: path.resolve(ELECTRON_ROOT, '..', 'buildtools')
};
const clangFormatFlags = opts.fix ? ['--fix'] : [];
for (const chunk of chunkFilenames(filenames)) {
spawnAndCheckExitCode('python3', ['script/run-clang-format.py', ...clangFormatFlags, ...chunk], { env });
spawnAndCheckExitCode('python3', ['script/run-clang-format.py', ...clangFormatFlags, ...chunk], {
env: getDepotToolsEnv()
});
cpplint([`--filter=${CPPLINT_FILTERS.join(',')}`, ...chunk]);
}
}
@@ -132,13 +130,9 @@ const LINTERS = [
roots: ['shell'],
test: (filename) => filename.endsWith('.mm') || (filename.endsWith('.h') && isObjCHeader(filename)),
run: (opts, filenames) => {
const env = {
...getDepotToolsEnv(),
CHROMIUM_BUILDTOOLS_PATH: path.resolve(ELECTRON_ROOT, '..', 'buildtools')
};
const clangFormatFlags = opts.fix ? ['--fix'] : [];
spawnAndCheckExitCode('python3', ['script/run-clang-format.py', '-r', ...clangFormatFlags, ...filenames], {
env
env: getDepotToolsEnv()
});
const filter = [...CPPLINT_FILTERS, '-readability/braces'];
cpplint(['--extensions=mm,h', `--filter=${filter.join(',')}`, ...filenames]);
@@ -175,7 +169,6 @@ const LINTERS = [
.map((filename) => {
const env = {
...getDepotToolsEnv(),
CHROMIUM_BUILDTOOLS_PATH: path.resolve(ELECTRON_ROOT, '..', 'buildtools'),
DEPOT_TOOLS_WIN_TOOLCHAIN: '0'
};
const args = ['format', filename];