electron源码下载与编译构建compile
electron 的depot_tools ⼯具下载构建源码。这个⼯具是⽤nodejs写的,封装了chromium⾃⾝的depot_tools⼯具。⾮常⽅便易⽤。
主要是electron在下载完chromium源码后会打⾃⼰的patch。如果⽤chromium的gclient下载会⿇烦,报patch conflicts。这个electron⾃⼰⽤nodejs写的⼯具就不会了。
1,预先安装:
linux下:
git必须2.2版本以上。
1,安装nodejs
sudo apt-get install -y nodejs 或者 yum install nodejs
node -v 看版本低
sudo npm i -g n 安装n⼯具
sudo n lts node更新到了最新
2,下载eletron构建⼯具:
npm i -g @electron/build-tools (总有权限问题,不⽤-g安装在了当前⽬录)
也可⽤yarn安装:sudo yarn global add @electron/build-tools
如若报错,须运⾏如下,解决nodejs缺失很多包:
git clone github/electron/build-tools ~/.electron_build_tools && (cd ~/.electron_build_tools && npm install)
3,安装python
sudo apt install python
windows上
安装
1,启动 powsershell ⽤管理员权限
2,运⾏ Get-ExecutionPolicy
如果返回Restricted
执⾏:
Set-ExecutionPolicy AllSigned or Set-ExecutionPolicy Bypass -Scope Process
3,运⾏下⾯命令会安装choco软件
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('h 4,测试安装成功否
choco
choco -?
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\xxx\AppData\Roaming
ChocolateyInstall=C:\ProgramData\chocolatey
ChocolateyLastPathUpdate=132366682081775967
2,
choco必须在cmd⾥⾯运⾏:
choco install git python nodejs yarn
refreshenv
安装 git,python,nodejs,yarn(linux下⽤)或者npm。
(git需要在路径上,⽽不是google的depot tools⾥⾯的git.bat。那样python就不能运⾏git了,需要加上shell=ture)
下载eletron构建⼯具:
npm i -g @electron/build-tools
需要安装glibc编译库在linux。如果报错:
vpython src/buildtools/ensure_gn_version.py git_revision:e002e68a48d1c82648eadde2f6aafa20d08c36f2' in '/root/electron/e11'
`/root/electron/e11/src/buildtools/linux64/gn --version` returned 1:
/root/electron/e11/src/buildtools/linux64/gn: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by /root/electron/e11/src/buildtools/linux64/gn)
解决⽅法
yum install gcc
wget /gnu/glibc/glibc-2.
tar zxf glibc-2.
cd glibc-2.18/
mkdir build
cd build/
../configure --prefix=/usr
make -j4
make install
报错:确实bzip2:
yum search bzip2
yum install bzip2.x86_64
windows上需要安装vs 2019.
2, 源码下载并且编译构建
e init --root=~/electron
-
i, --import <name> Import build settings from $root/src/electron/build/args/$ (default: "testing")
--bootstrap 会全做,包括同步,构建。
如果想做多个分⽀版本:
`--root=~/electron/branch` (e.g. `~/electron-gn/master`)
喝咖啡去吧。
不构建的话,分三步⾛:
1,e init 这个会看⽬录下有没有chromium的depot_tools,没有的话会去下载。
实例: e init e11 --root ./e11
命令⾏参数有
1)给这次构建起个名字,如branch7,chocolate,随意。后⾯接release 或者 testing。以后切换构建⽤: e use branch7.
2)设定源码存放的根⽬录,多个构建tesing,debug,release可以重复⽤它。
⽰例:master-testing,master-release都是起的名字配置
命令执⾏后会⽣成配置⽂件,操作系统的环境变量可以放在json⽂件的env⾥⾯。(存放⽬录C:\Users\Administrator\.electron_build_tools\configs):
{
"goma": "none",
"root": "C:\\dev\\electron7",
"origin": {
"electron": "git@github:electron/electron.git",
"node": "git@github:electron/node.git"
},
"gen": {
"args": [
"import(\"//electron/build/\")"
],
"out": "Testing"
},
"env": {
"CHROMIUM_BUILDTOOLS_PATH": "C:\\dev\\electron7\\src\\buildtools",
"GIT_CACHE_PATH": "C:\\Users\\Administrator\\.git_cache",
"DEPOT_TOOLS_WIN_TOOLCHAIN": 0 #只适⽤于windows。如果下载机器上没有装vs2019,这个值需要置1,下载⾕歌内部的vs,只有内部⼈员才有权限使⽤。编译时置0,⽤⾃⼰本机的。
}
}
和depot_tools 使⽤⽬录有关的源码在 .electron_build_tools\src\下:
evm-config.js
\utils\depot-tools.js
DEPOT_TOOLS_WIN_TOOLCHAIN为1时,log输出:
[1/4]
success Already up-to-date.
Done in 3.50s.
Hook 'vpython.bat -c 'import os, subprocess; os.chdir(os.path.join("src", "electron")); subprocess.check_call(["python", "script/lib/npx.py", "yarn@1.15.2", "install", "--frozen-lockfile"]);'' took 12.70 secs
________ running 'vpython.bat src/build/landmines.py' in 'C:\zhibin\electron9.2.1'
________ running 'vpython.bat src/third_party/depot_tools/update_depot_tools_toggle.py --disable' in '
C:\zhibin\electron9.2.1'
________ running 'vpython.bat src/tools/remove_stale_pyc_files.py src/android_webview/tools src/build/android src/gpu/gles2_conform_support src/infra src/ppapi src/printing src/third_party/blink/renderer/build/scripts src/third_party/blink/tools sr ________ running 'vpython.bat src/buildtools/ensure_gn_version.py git_revision:5ed3c9cc67b090d5e311e4bd2aba072173e82db9' in 'C:\zhibin\electron9.2.1'
________ running 'vpython.bat src/build/vs_toolchain.py update --force' in 'C:\zhibin\electron9.2.1'
Windows toolchain out of date or doesn't exist, updating (Pro)...
current_hashes:
desired_hash: 6d205e765a23d3cbe0fcc8d1191ae406d8bf9c04
Extracting c:\users\administrator\appdata\local\temp\tmp8nmtsz\
Calculating hash of toolchain in vs_files\6d205e765a23d3cbe0fcc8d1191ae406d8bf9c04.
Hook 'vpython.bat src/build/vs_toolchain.py update --force' took 686.70 secs
________ running 'vpython.bat src/tools/clang/scripts/update.py' in 'C:\zhibin\electron9.2.1'
Downloading leapis/chromium-browser-clang/ .......... Done.
Copying C:\zhibin\electron9.2.1\src\third_party\depot_tools\win_toolchain\vs_files\6d205e765a23d3cbe0fcc8d1191ae406d8bf9c04\win_sdk\..\DIA SDK\bin\amd64\msdia140.dll to C:\zhibin\electron9.2.1\src\third_party\llvm-build\Release+Asserts\b Hook 'vpython.bat src/tools/clang/scripts/update.py' took 23.48 secs
________ running 'vpython.bat src/build/util/lastchange.py -o src/build/util/LASTCHANGE' in 'C:\zhibin\electron9.2.1'
Hook 'vpython.bat src/build/util/lastchange.py -o src/build/util/LASTCHANGE' took 10.01 secs
________ running 'vpython.bat src/build/util/lastchange.py -m GPU_LISTS_VERSION --revision-id-only --header src/gpu/config/gpu_lists_version.h' in 'C:\zhibin\electron9.2.1'
________ running 'vpython.bat src/build/util/lastchange.py -m SKIA_COMMIT_HASH -s src/third_party/skia --header src/skia/ext/skia_commit_hash.h' in 'C:\zhibin\electron9.2.1'
________ running 'vpython.bat src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_auth --bucket chromium-clang-format -s src/buildtools/sha1' in 'C:\zhibin\electron9.2.1'
________ running 'vpython.bat src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_auth --bucket chromium-browser-clang/rc -s src/build/toolchain/win/rc/sha1' in 'C:\zhibin\electron9.2.1'
________ running 'download_from_google_storage --no_resume --extract --no_auth --bucket chromium-fonts -s src/third_party/test_fonts/test_sha1' in 'C:\zhibin\electron9.2.1'
0> Downloading src/third_party/test_fonts/test_@
0> Removed src/third_party/test_fonts/
0> Extracting 30 entries from src/third_party/test_fonts/test_ to src/third_party/test_fonts/tes
t_fonts
Downloading 1 files took 68.306000 second(s)
Hook 'download_from_google_storage --no_resume --extract --no_auth --bucket chromium-fonts -s src/third_party/test_fonts/test_sha1' took 71.11 secs
________ running 'download_from_google_storage --no_auth --quiet --bucket chromium-webrtc-resources -d src/third_party/opus/tests/resources' in 'C:\zhibin\electron9.2.1'
________ running 'vpython.bat src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_auth --num_threads=4 --bucket chromium-browser-clang/orderfiles -d src/chrome/build' in 'C:\zhibin\electron9.2.1'
________ running 'vpython.bat src/third_party/depot_tools/download_from_google_storage.py --no_resume --directory --recursive --no_auth --num_threads=16 --bucket chromium-apache-win32 src/third_party/apache-win32' in 'C:\zhibin\electron9.2 Hook 'vpython.bat src/third_party/depot_tools/download_from_google_storage.py --no_resume --directory --recursive --no_auth --num_threads=16 --bucket chromium-apache-win32 src/third_party/apache-win32' took 16.20 secs
________ running 'vpython.bat src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_auth -u --bucket v8-wasm-fuzzer -s src/v8/test/fuzzer/wasm_sha1' in 'C:\zhibin\electron9.2.1'
________ running 'vpython.bat src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_auth --bucket chromium-nodejs/12.14.1 -s src/third_party/node/sha1' in 'C:\zhibin\electron9.2.1'
________ running 'vpython.bat src/third_party/depot_tools/download_from_google_storage.py --no_resume --extract --no_auth --bucket chromium-nodejs -s src/third_party/node/node_sha1' in 'C:\zhibin\electron9.2.1'
________ running 'vpython.bat src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_auth --num_threads=4 --bucket chromium-tools-traffic_annotation -d src/tools/traffic_annotation/bin/win32' in 'C:\zhibin\electron9.2.1' 0> Downloading src/tools/traffic_annotation/bin/win32\traffic_
Downloading 1 files took 55.001000 second(s)
Hook 'vpython.bat src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_auth --num_threads=4 --bucket chromium-tools-traffic_annotation -d src/tools/traffic_annotation/bin/win32' took 63.31 secs
________ running 'vpython.bat src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_auth --num_threads=4 --bucket chromium-binary-patching/zucchini_testdata --recursive -d src/components/zucchini' in 'C:\zhibin\elec Hook 'vpython.bat src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_auth --num_threads=4 --bucket chromium-binary-patching/zucchini_testdata --recursive -d src/components/zucchini' took 10.18 secs
________ running 'vpython.bat src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_auth --bucket chromium-ads-detection -s src/third_party/subresource-filter-ruleset/data/UnindexedRules.sha1' in 'C:\zhibin\electron9.2 0> Downloading src/third_party/subresource-filter-ruleset/
Downloading 1 files took 67.118000 second(s)
Hook 'vpython.bat src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_a
uth --bucket chromium-ads-detection -s src/third_party/subresource-filter-ruleset/data/UnindexedRules.sha1' took 73.81 secs
________ running 'vpython.bat -vpython-spec src/.vpython -vpython-tool install' in 'C:\zhibin\electron9.2.1'
View Code
⽰例:
# making 'release' and 'testing' builds from master
$ e init master-testing --root=~/src/electron
Creating '~/src/electron'
New build config 'master-testing' created
Now using config 'master-testing'
$ e show current
master-testing
$ e init master-release --root=~/src/electron
INFO Root '~/src/electron' already exists.
INFO (OK if you are sharing $root between multiple build configs)
New build config 'master-release' created
Now using config 'master-release'
$ e show configs
master-testing
$ e show current
master-release
$ e show root
~
/src/electron
$ e use master-testicdng
Now using config 'master-testing'
$ e show current
master-testing
$ e show root
~/src/electron
报错下载链接不到pywin32
2、e sync
e sync -vvvv --revision 11-x-y
等同gclient sync。同步源码,依赖。
⽬前不⽀持版本切换,下载其他分⽀只能这么做:
进⼊src/electron⽬录下:
$ git checkout x-y-z
$ e sync -vvvv
$ e build
直接⽤nodejs的 http-server,⾮常容易实现http的断点传输。⽤360浏览器等,直接下载,很快。npm install -g i http-server
http-server electron-dir
下载想要的分⽀,⽤
git branch -vv
可以看到本地分⽀关联的是哪个远程分⽀。
修改 .gclient ⾥⾯的url:
https//github/electron/electron@7-3-x
删除掉已经下载的src⽬录。重新同步代码:
e sync -vvvv
可以看到是指定的分⽀下载了。
因为⽤的unmanaged,所以切换分⽀是不⾏的,以前unmanaged就丢掉了。
是不是需要先upstream到远程分⽀。再操作。
gclient参数同样可以加⼊
$ e sync
Running "gclient sync --with_branch_heads --with_tags"in'~/src/electron/src'
[sync output omitted]
-v 或者 -vvvv输出更多信息。
e build [target] -v
e build --gen 强制做gn操作,重新⽣成ninja项⽬
Target Description
breakpad Builds the breakpad dump_syms binary
chromedriver Builds the chromedriver binary
electron Builds the Electron binary (Default)
electron:dist Builds the Electron binary and generates a dist zip file
打包。可以在e-build.js中加⼊⾃动删除zip⽂件和移除调试信息,缩减dist包到100m:function runStrip(config) {
//console.log(evmConfig.outDir(config));
const gnPath = 'electron/script/strip-binaries.py';
const execArgs = ['-d', `out/${ut}` ];
const execOpts = { cwd: , 'src') };
//delete dist.zip file
const distfile = [solve(evmConfig.outDir(config),'dist.zip')];
if (fs.existsSync(distfile[0])){
console.log('dist.zip delete.');
}else{
console.log('dist.zip not found.');
}
//strip electron
}
mksnapshot Builds the mksnapshot binary
node:headers Builds the node headers . file
如果源码是从别⼈那⾥拷贝过来,需要设置:
rem set PATH=D:\dev\electron7\src\out\Testing;%PATH%
set DEPOT_TOOLS_DIR=D:\dev\electron-master\electron\depot_tools
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
set GIT_CACHE_PATH=D:\\dev\\.git_cache
set depot-tools=D:\dev\electron-master\electron\depot_tools
set PATH=%depot-tools%\bootstrap-3_8_0_chromium_8_bin\python\bin\scripts;%PATH% electron7编译⽤到pip,安装了pywin32
如果已经安装了sdk,按下图修改:
帮助:
e --helpor e help <cmd>
e命令类似git,mvn:
nvm e Description
nvm ls e show configs显⽰配置Show the available configurations
nvm current e show current显⽰版本Show which configuration is currently in use
nvm use <name>e use <name>切换分⽀Change which configuration is currently in use
运⾏于调试:
Using Electron
After you've built Electron, it's time to use it!
Command Description
e start Run the Electron build
e node Run the Electron build as Node
e debug Run the Electron build in a debugger
e test Run Electron's spec runner
As usual, any extra args are passed along to the executable. For example, e node --version will print out Electron's node version.
e debug
Runs your local Electron build inside of or .
$ uname
Linux
$ e debug
Reading symbols from /home/yourname/electron/gn/master/src/out/
(gdb)
$ uname
Darwin
$ e debug
target create "/Users/yourname/electron-gn/src/out/Testing/Electron.app/Contents/MacOS/Electron"
(lldb)
e test
-g webRequest
Starts the local Electron build's test runner. Any extra args are passed along to the runner.
# run all tests
e test
# run main process tests
e test --runners=main
Possible extra arguments to pass:
--node - Run Node.js' own tests with Electron in RUN_AS_NODE mode.
--runners=<main|remote|native> - The set of tests to run, can be either main, remote, or native.
单元测试⼀个⽤例,位于:D:\dev\electron\src\electron\spec-main\api-web-request-spec.ts
e test --runners=remote -g webRequest
e test -- -g webRequest
Getting Information
e show shows information about the current build config.
Command Description
e show current The name o
android11系统更新包下载f the active build config
e show configs Lists all build configs
e show env Show environment variables injected by the active build config
e show exe The path o
f the built Electron executable
e show root The path o
f the root directory from e init --root.
e show src [name]The path o
f the named (default: electron) source dir
e show stats Build statistics
Example usage:
$ uname
Darwin
$ e show exe
/Users/username/electron-gn-root/src/out/Testing/Electron.app/Contents/MacOS/Electron
$ uname
Linux
$ e show exe
/home/username/electron-gn-root/src/out/Testing/electron
$ e show out
Testing
$ e show src
/home/username/electron-gn-root/src/electron
$ cd `e show src base` && pwd
/home/username/electron-gn-root/src/base
$ ripgrep --t h TakeHeapSnapshot `e show src`
e open <commit | issue | PR>
Opens the GitHub page for the specified commit, pull request, or issue.
e patches [patch-dir]
Exports patches to the desired patch folder in Electron source tree.
Valid patch directories can include:
node
v8
boringssl
chromium
perfetto
icu
Command Source Directory Patch Directory
e patches node src/third_party/electron_node src/electron/patches/node
e patches chromium src src/electron/patches/chromium
e patches boringssl src/third_party/boringssl/src src/electron/patches/boringssl
e patches v8src/v8src/electron/patches/v8
e patches perfetto src/third_party/perfetto src/electron/patches/perfetto
e patches icu src/third_party/icu src/electron/patches/icu
应⽤patch:
git am ~/dev0/e9.2.1/patch/0001-pdf-viewer-feature-disabled.patch
有时候莫名其妙不成功,也没有冲突,检查:
git apply --check ~/dev0/e9.2.1/patch/0002-update-version-from-9.2.1-to-109.2.1.patch
git apply --stat ~/dev0/e9.2.1/patch/0002-update-version-from-9.2.1-to-109.2.1.patch
放弃:
git am --abort
改⽤:
git apply ~/dev0/e9.2.1/patch/0002-update-version-from-9.2.1-to-109.2.1.patch
git add xxx.file 或者 .
然后commit
Advanced Usage
Per-Session Active Configs
If you want your shell sessions to each have different active configs, try this in your ~/.profile or ~/.zshrc or ~/.bashrc:
export EVM_CURRENT_FILE="$(mktemp --tmpdir )"
This will create per-shell temporary files in which he active config file can be changed with e use.
C:\dev>e init --root=\dev\electron mymaster
WARN A fixable error has occurred
--> git config --global core.filemode must be set to false.
Do you want build-tools to try fix this for you? [y/n]: y
Running "git config --global core.filemode false"
WARN A fixable error has occurred
--> git config --global core.autocrlf must be set to false.
Do you want build-tools to try fix this for you? [y/n]: y
Running "git config --global core.autocrlf false"
WARN A fixable error has occurred
--> git config --global branch.autosetuprebase must be set to always.
Do you want build-tools to try fix this for you? [y/n]: y
Running "git config --global branch.autosetuprebase always"
WARN A fixable error has occurred
--> A required dependency "choco" could not be located, it probably has to be installed.
Do you want build-tools to try fix this for you? [y/n]: y
Running "powershell -Command Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebCli WARN A fixable error has occurred
--> A required dependency "python" could not be located, it probably has to be installed.
Do you want build-tools to try fix this for you? [y/n]: y
Running "choco install python2 --yes"
WARN A fixable error has occurred
--> A required dependency "pywin32" could not be located, it probably has to be installed.
Do you want build-tools to try fix this for you? [y/n]: y
Running "choco install pywin32 --yes"
需要装nodejs对应版本的pywin32
C:\dev>e init --root=\dev\electron mymaster
Creating \dev\electron
Cloning "depot_tools" into C:\Users\Administrator\.electron_build_tools\third_party\depot_tools
Updating C:\Users\Administrator\.electron_build_tools\third_party\depot_tools
Running " /c C:\Users\Administrator\.electron_build_tools\third_party\depot_tools\update_depot_tools.bat"
Downloading CIPD client for windows-amd64 from chrome-infra-packages.appspot/client?platform=windows-amd64&version=git_
Running "python C:\Users\Administrator\.electron_build_tools\third_party\depot_tools\gclient.py config --name src/electron --unmanaged github/electron/electron"in \dev\electron
Creating C:\Users\Administrator\.electron_build_tools\configs
New build config mymaster created in C:\Users\Administrator\.electron_build_tools\aster.json
Now using config mymaster
Electron 打包执⾏
electron_dist_zip.runtime_deps
./electron
resources.pak
chrome_100_percent.pak
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论