electron 的depot_tools 工具下載構建源碼。這個工具是用nodejs寫的,封裝了chromium自身的depot_tools工具。非常方便易用。
主要是electron在下載完chromium源碼后會打自己的patch。如果用chromium的gclient下載會麻煩,報patch conflicts。這個electron自己用nodejs寫的工具就不會了。
參考自:https://github.com/electron/build-tools
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 https://github.com/electron/build-tools ~/.electron_build_tools && (cd ~/.electron_build_tools && npm install)
3,安裝python
sudo apt install python
windows上
1,可以用chocolate或者scoop安裝。安裝方法在 :https://classic.yarnpkg.com/en/docs/install/
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('https://chocolatey.org/install.ps1')) 4,測試安裝成功否 choco choco -?
choco安裝日志:https://www.cnblogs.com/bigben0123/p/13168140.html
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需要git.exe在路徑上,而不是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 http://ftp.gnu.org/gnu/glibc/glibc-2.18.tar.gz tar zxf glibc-2.18.tar.gz cd glibc-2.18/ mkdir build cd build/ ../configure --prefix=/usr make -j4 make install
報錯:確實bzip2:
windows上需要安裝vs 2019.
2, 源碼下載並且編譯構建
- e init --root=~/electron
參數構建時才有用:
-i, --import <name> Import build settings from $root/src/electron/build/args/$import.gn (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.com:electron/electron.git", "node": "git@github.com:electron/node.git" }, "gen": { "args": [ "import(\"//electron/build/args/testing.gn\")" ], "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] Resolving packages... 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 src/third_party/catapult src/tools' in 'C:\zhibin\electron9.2.1' ________ 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\6d205e765a23d3cbe0fcc8d1191ae406d8bf9c04.zip... Calculating hash of toolchain in vs_files\6d205e765a23d3cbe0fcc8d1191ae406d8bf9c04. Please wait... 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 https://commondatastorage.googleapis.com/chromium-browser-clang/Win/clang-n346557-4e0d9925-2.tgz .......... 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\bin 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/win/clang-format.exe.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/win/rc.exe.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_fonts.tar.gz.sha1' in 'C:\zhibin\electron9.2.1' 0> Downloading src/third_party/test_fonts/test_fonts.tar.gz@a22de844e32a3f720d219e3911c3da3478039f89... 0> Removed src/third_party/test_fonts/test_fonts... 0> Extracting 30 entries from src/third_party/test_fonts/test_fonts.tar.gz to src/third_party/test_fonts/test_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_fonts.tar.gz.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.1' 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_corpus.tar.gz.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/win/node.exe.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_modules.tar.gz.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_annotation_auditor.exe... 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\electron9.2.1' 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.1' 0> Downloading src/third_party/subresource-filter-ruleset/data/UnindexedRules... Downloading 1 files took 67.118000 second(s) Hook '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' took 73.81 secs ________ running 'vpython.bat -vpython-spec src/.vpython -vpython-tool install' in 'C:\zhibin\electron9.2.1'
示例:
# 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-release 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
用這個鏈接下載解決:https://github.com/mhammond/pywin32/releases/tag/b228。64位用pywin32-228.win-amd64-py3.8.exe。
- 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) { depot.ensure(); //console.log(evmConfig.outDir(config)); const gnPath = 'electron/script/strip-binaries.py'; const execArgs = ['-d', `out/${config.gen.out}` ]; const execOpts = { cwd: path.resolve(config.root, 'src') }; //delete dist.zip file const distfile = [path.resolve(evmConfig.outDir(config),'dist.zip')]; if (fs.existsSync(distfile[0])){ console.log('dist.zip delete.'); depot.execFileSync(config, 'rm', distfile, execOpts); }else{ console.log('dist.zip not found.'); } //strip electron depot.execFileSync(config, gnPath, execArgs, execOpts); }
|
mksnapshot | Builds the mksnapshot binary |
node:headers | Builds the node headers .tar.gz 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
chromium 編譯報錯 You must installWindows 10 SDK version 10.0.19041.0 including the "Debugging Tools for Windows" feature.
如果已經安裝了sdk,按下圖修改:
幫助:
or
e --helpe 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 lldb or gdb.
$ uname
Linux
$ e debug
Reading symbols from /home/yourname/electron/gn/master/src/out/Testing/electron...
(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 inRUN_AS_NODE
mode.--runners=<main|remote|native>
- The set of tests to run, can be eithermain
,remote
, ornative
.
單元測試一個用例,位於: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 of 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 of the built Electron executable |
e show root | The path of the root directory from e init --root . |
e show src [name] | The path of 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.
For example, e open 0920d01
will find the commit with an abbreviated sha1 of 0920d01
, see that it's associated with pull request #23450, and open https://github.com/electron/electron/pull/23450 in your browser. Since you can pass in a pull request or issue number as well, e open 23450
would have the same effect.
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 v8 | src/v8 |
src/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 evm-current.XXXXXXXX.txt)"
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.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" 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 "cmd.exe /c C:\Users\Administrator\.electron_build_tools\third_party\depot_tools\update_depot_tools.bat" Downloading CIPD client for windows-amd64 from https://chrome-infra-packages.appspot.com/client?platform=windows-amd64&version=git_revision:9f9afb5ef6ef9d4887e8aa2bb617dfdd798f8005... Running "python C:\Users\Administrator\.electron_build_tools\third_party\depot_tools\gclient.py config --name src/electron --unmanaged https://github.com/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\configs\evm.mymaster.json Now using config mymaster
Electron 打包執行
electron_dist_zip.runtime_deps

./electron resources.pak chrome_100_percent.pak chrome_200_percent.pak locales/am.pak locales/ar.pak locales/bg.pak locales/bn.pak locales/ca.pak locales/cs.pak locales/da.pak locales/de.pak locales/el.pak locales/en-GB.pak locales/en-US.pak locales/es.pak locales/et.pak locales/fa.pak locales/fi.pak locales/fil.pak locales/fr.pak locales/gu.pak locales/he.pak locales/hi.pak locales/hr.pak locales/hu.pak locales/id.pak locales/it.pak locales/ja.pak locales/kn.pak locales/ko.pak locales/lt.pak locales/lv.pak locales/ml.pak locales/mr.pak locales/ms.pak locales/nb.pak locales/nl.pak locales/pl.pak locales/pt-PT.pak locales/ro.pak locales/ru.pak locales/sk.pak locales/sl.pak locales/sr.pak locales/sv.pak locales/sw.pak locales/ta.pak locales/te.pak locales/th.pak locales/tr.pak locales/uk.pak locales/vi.pak locales/zh-CN.pak locales/zh-TW.pak locales/es-419.pak locales/pt-BR.pak resources/default_app.asar v8_context_snapshot.bin icudtl.dat swiftshader/libGLESv2.so swiftshader/libEGL.so ./libEGL.so ./libGLESv2.so ./libVkICD_mock_icd.so angledata/VkICD_mock_icd.json angledata/VkICD_mock_icd.json ./libffmpeg.so swiftshader/libvk_swiftshader.so natives_blob.bin snapshot_blob.bin natives_blob.bin snapshot_blob.bin LICENSE LICENSES.chromium.html version ./chrome_sandbox
添加sscache,加快以后編譯速度:
function runGNGen1(config) { depot.ensure(); const sscache = ' cc_wrapper = \\"D:/dev/electron7/src/electron/external_binaries/sccache\\" '; const gnExec = os.platform() === 'win32' ? 'gn.bat' : 'gn'; const gn_args = config.gen.args.join(' ').replace(/\"/g, '\\"'); // gn parses this part -- inner quotes must be escaped const exec = `${path.resolve(depot.path, gnExec)} gen "out/${ config.gen.out }" --args="${gn_args} ${sscache}"`; const opts = { cwd: path.resolve(config.root, 'src') }; depot.execSync(config, exec, opts); }
將離線git 倉庫連接上遠程
取回源碼文件和git cache文件(.git_cache)里面的。
以electron為例:
源碼和.git_cache目錄放好后,什么也別動,先做第一步:(否則總報錯:error: object directory /root/.git_cache/chromium.googlesource.com-chromium-src/objects does not exist; check .git/objects/info/alternates)
1,修改src/electron/.git/objects/info/alternates文件,指向本地存放路徑。
/home/admin/.git_cache/github.com-electron-electron/objects
2,如不想拷貝整個cache目錄,至少需要上面那個目錄下的pack底下的文件:
這個方案應該更好,以chromium為例:
直接將拷貝回的源碼,用git看會是detached游離狀態,因為是checkout的一個提交點。第一步先建立本地分支。第二步將分支提交到遠程。這就是我們要的分支了。第三步,附帶可以同步一下本地分支的tags和branch。否則遠程庫里面沒有。
根本不用在遠程還在建立一個分支取合並,太麻煩了。
如下示例:
在chromium的src目錄下:
1,$ git remote remove origin 2,$ git remote add origin https://github.com/electron/electron 本地倉庫中建立一個與遠程倉庫的別名,以便之后提交代碼而不是每次都要輸入遠程倉庫地址。
git remote -v 查看本地與遠程聯系
git branch -vv
查看本地分支與遠程的關聯。可以看到當前分支處於游離狀態:
* (HEAD detached from 83.0.4103.122)。
3,git branch tem //tem是新建分支的名字
4,git checkout tem
git branch 查看新建分支情況。是剛才的游離分支commit id。
5,git push origin tem 將本地分支提交到遠程,如果遠程沒有就創建一個同名的。
5.1 git push origin tem:master 或者指定提交到遠程某個分支:將本地分支tem提交到遠程origin上的master分支。
注意,雖然代碼同步到了遠程。但是tag並沒有。本地分支的tag要比遠程多。
git push origin --tags 將本地的tags同步到遠程。參考:https://www.cnblogs.com/bigben0123/p/13208286.html
一般到這里就可以結束了!!完
不建議做merge,沒用
$ git fetch 可以更新到遠程所有分支
git checkout master 分支 這個是真正的目標分支
git merge tem 合並剛才tem分支到目標master分支。可能有沖突解決。
解決沖突:
使用tem分支
git checkout --theirs $codefile $codefile是具體的沖突文件,可以用 git status 查看到
git add $codefile
git merge --continue
重新關聯track遠程分支
1,$ git remote remove origin 2,$ git remote add origin https://github.com/electron/electron
3,$ git branch --set-upstream-to=origin/<branch> 或者將當前分支與遠程已有分支關聯. 這里沒有寫本地分支,默認現在分支。 origin/<branch>這個是遠程分支
git branch --set-upstream-to=origin/my-remote-branch my-local-branch 將本地分支my-local-branch關聯到了遠程分支my-remote-branch
4,git fetch (git pull)
5,git push --set-upstream origin tistar-chrome-v9.2.1 將本地分支tistar-chrome-v9.2.1關聯到遠程同名分支並創建和push
5,git push --set-upstream origin mybranch:tistar-chrome-v9.2.1 將本地分支mybranch關聯到遠程分支tistar-chrome-v9.2.1 並 push
遠程分支與本地分支同名,才能省略成 git push!!!!
git checkout 78.0.3904.130 檢出的是tag,無法提交修改
git checkout -b branchElectron7 78.0.3904.130 為tag建立了本地分支
重新關聯遠程分支
1,克隆個本地副本,因為速度快: git clone coworker-machine:/path/to/repo 2,重新定向到真正的遠程: git set-url origin https://chromium.googlesource.com/chromium/src.git 3,更新: git fetch 4,刪除以前本地倉庫沒用的分支: git prune origin
多個遠程倉庫add后,直接切換同步與提交的代碼:
git.exe fetch -v --progress "mygithub" 7-3-x
git.exe push --set-upstream --progress "mygithub" bit-7-3-x:7-3-x 輸入用戶名與密碼
git強制覆蓋本地分支,慎用!!!
git fetch --all
git reset --hard origin/master
git pull
備注:
git fetch 只是下載遠程的庫的內容,不做任何的合並
git reset 把HEAD指向剛剛下載的最新的版本
-
git fetch origin newTestBranch:newTestBranch(newTestBranch 前面的分支為遠程分支名,后面是本地分支名)
然后git branch -v 查看分支
確認能自己新建的newDevelop分支的存在 -
git reflog show HEAD@{now} -10
這個命令會把HEAD指針所有的動作顯示出來。從中可以清楚的看到,在指針中提交對應的commit id
找到需要恢復的commit ,記下前面的commit id
chromium打印二進制函數:
#include "net/base/hex_utils.h"
auto sss = base::StringPiece(info.content_disposition);
LOG(INFO) << net::HexDump(sss);
Git Cookbook
A collection of git recipes to do common git tasks.
See also Git Tips.
Contents
- Introduction
- Chromium-specific Git Extensions
- Excluding file(s) from git-cl, while preserving them for later use
- Method #1: Reset your current branch, and selectively commit files
- Method #2: Create a new branch, reset, then commit files to preserve
- Method #3: Cherry-pick changes into review branches
- Sharing code between multiple machines
- Reverting commits
- Retrieving, or diffing against an old file revision
- Reusing a Git mirror
Introduction
This is designed to be a cookbook for common command sequences/tasks relating to git, git-cl, and how they work with Chromium development. It might be a little light on explanations.
If you are new to git, or do not have much experience with a distributed version control system, you should also check out The Git Community Book for an overview of basic git concepts and general git usage. Knowing what git means by branches, commits, reverts, and resets (as opposed to what SVN means by them) will help make the following much more understandable.
Chromium-specific Git Extensions
Chromium ships a large number of git extensions in depot_tools. Some (like git cl
) are required for the Chromium development workflow, while others (like git map-branches
) are simple utilities to make your life easier. Please take a look at the full depot_tools tutorial, and at the extensive man pages for all the extensions.
Excluding file(s) from git-cl, while preserving them for later use
Since git-cl assumes that the diff between your current branch and its tracking branch is what should be used for the CL, the goal is to remove the unwanted files from the current branch, and preserve them in another branch.
Method #1: Reset your current branch, and selectively commit files
git log
See the list of your commits. Find the hash of the last commit before your changes.git reset --soft abcdef
where abcdef is the hash found in the step above.git commit <files_for_this_cl> -m "files to upload"
commit the files you want included in the CL here.git new-branch new_branch_name
Create a new branch for the files that you want to exclude.git commit -a -m "preserved files"
Commit the rest of the files.
Method #2: Create a new branch, reset, then commit files to preserve
This method creates a new branch from your current one to preserve your changes. The commits on the new branch are undone, and then only the files you want to preserve are recommitted.
git checkout -b new_branch_name
This preserves your old files.git log
See the list of your commits. Find the hash of the last commit before your changes.git reset --soft abcdef
Where abcdef is the hash found in the step above.git commit <files_to_preserve> -m "preserved files"
Commit the found files into thenew_branch_name
.
Then revert your files however you'd like in your old branch. The files listed in step 4 will be saved in new_branch_name
Method #3: Cherry-pick changes into review branches
If you are systematic in creating separate local commits for independent changes, you can make a number of different changes in the same client and then cherry-pick each one into a separate review branch.
- Make and commit a set of independent changes.
git log
# see the hashes for each of your commits.- repeat checkout, cherry-pick, upload steps for each change1..n
git new-branch review-changeN
Create a new review branch tracking origingit cherry-pick <hash of change N>
git cl upload
If a change needs updating due to review comments, you can go back to your main working branch, update the commit, and re-cherry-pick it into the review branch.
git checkout <working branch>
- Make changes.
- If the commit you want to update is the most recent one:
git commit --amend <files>
- If not:
git commit <files>
git rebase -i origin
# use interactive rebase to squash the new commit into the old one.
git log
# observe new hash for the changegit checkout review-changeN
git reset --hard
# remove the previous version of the changecherry-pick <new hash of change N>
git cl upload
Sharing code between multiple machines
Assume Windows computer named vista, and a Linux one named penguin. Prerequisite: both machines have git clones of the main git tree.
vista$ git remote add linux ssh://penguin/path/to/git/repo vista$ git fetch linux vista$ git branch -a # should show "linux/branchname" vista$ git checkout -b foobar linux/foobar vista$ hack hack hack; git commit -a vista$ git push linux # push branch back to linux penguin$ git reset --hard # update with new stuff in branch
Note that, by default, gclient sync
will update all remotes. If your other machine (i.e., penguin
in the above example) is not always available, gclient sync
will timeout and fail trying to reach it. To fix this, you may exclude your machine from being fetched by default:
vista$ git config --bool remote.linux.skipDefaultUpdate true
Reverting commits
The command git revert X
patches in the inverse of a particular commit. Using this command is one way of making a revert:
git checkout origin # start with trunk git revert abcdef git cl upload
Retrieving, or diffing against an old file revision
Git works in terms of commits, not files. Thus, working with the history of a single file requires modified version of the show and diff commands.
# Find the commit you want in the file's commit log. git log path/to/file # This prints out the file contents at commit 123abc. git show 123abc:path/to/file # Diff the current version against path/to/file against the version at # path/to/file git diff 123abc -- path/to/file
When invoking git show
or git diff
, the path/to/file
is not relative the the current directory. It must be the full path from the directory where the .git directory lives. This is different from invoking git log
which understands relative paths.
Reusing a Git mirror
If you have a nearby copy of a Git repo, you can quickly bootstrap your copy from that one then adjust it to point it at the real upstream one.
- Clone a nearby copy of the code you want:
git clone coworker-machine:/path/to/repo
- Change the URL your copy fetches from to point at the real git repo:
git set-url origin https://chromium.googlesource.com/chromium/src.git
- Update your copy:
git fetch
- Delete any extra branches that you picked up in the initial clone:
git prune origin