用electron自己的nodejs写的depot_tools 工具下载 构建源码

主要是electron在下载完chromium源码后会打自己的patch。如果用chromium的gclient下载会麻烦,报patch conflicts。这个electron自己用nodejs写的工具就不会了。

参考自:https://github.com/electron/build-tools 

1,预先安装

需要git,python,nodejs,yarn。

(git需要git.exe在路径上,而不是google的depot tools里面的git.bat。那样python就不能运行git了,需要加上shell=ture)

可以用chocolate或者scoop安装。安装方法在 :https://classic.yarnpkg.com/en/docs/install/

2,windows要在cmd里面运行: 

npm i -g @electron/build-tools

3, 源码下载并且编译构建

  • e init --root=~/electron --bootstrap testing
如果想做多个分支版本:
`--root=~/electron/branch` (e.g. `~/electron-gn/master`)
喝咖啡去吧。

一般可以分三步:
e init
一般都要起个名字,如branch7,chocolate,随意。以后切换版本用: e use branch7.
设定个root目录,多个构建debug,release会重复用它。
示例:master-testing,master-release都是起的名字配置
# making 'release' and 'testing' builds from master

$ e init master-testing -i 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 -i 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-testing
Now using config 'master-testing'
$ e show current
master-testing
$ e show root
~/src/electron

e init --bootstrap 会全做,包括同步,构建。

  • e sync
注意sync前看看生成的配置文件,操作系统环境变量在这个json文件的env里面设置(存放目录C:\Users\Administrator\.electron_build_tools\configs):
{
  "goma": "none",
  "root": "C:\\dev\\electron7",
  "origin": {
    "electron": "[email protected]:electron/electron.git",
    "node": "[email protected]: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
  }
}


和depot_tools 使用目录有关的源码在 .electron_build_tools\src\下:
evm-config.js
\utils\depot-tools.js

 

等同gclient sync。同步源码,依赖。可以切换分支????不知道怎么做。 
下载想要的分支,用
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 sync -vvvv --revision 7-3-x 

  • e build [target] -v
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
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


帮助:
e --help
or e help

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 e use 切换分支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

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= - The set of tests to run, can be either mainremote, or native.

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

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

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"

 

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自己的nodejs写的depot_tools 工具下载 构建源码)