赞
踩
操作系统:Ubuntu18.04 x86
cef版本:79.0.3945.130
注:本文使用特定历史版本,和cef wiki里面使用最新master分支构建略有不同,请注意区别!!
“~” 可以是任意不带空格和特殊字符的路径
~/code/
automate/
automate-git.py <-- CEF build script
chromium_git/
cef/ <-- CEF source checkout
chromium/
src/ <-- Chromium source checkout
update.[bat|sh] <-- Bootstrap script for automate-git.py
depot_tools/ <-- Chromium build tools
mkdir ~/code
mkdir ~/code/automate
mkdir ~/code/chromium_git
cd ~/code
sudo apt-get install curl
curl 'https://chromium.googlesource.com/chromium/src/+/master/build/install-build-deps.sh?format=TEXT' | base64 -d > install-build-deps.sh
chmod 755 install-build-deps.sh
sudo ./install-build-deps.sh --no-arm --no-chromeos-fonts --no-nacl
在 ~/code
目录下执行命令,实际运行79版本的install-build-deps79.sh
sudo apt-get install curl
curl 'https://chromium.googlesource.com/chromium/src/+/refs/tags/79.0.3945.130/build/install-build-deps.sh?format=TEXT' | base64 -d > install-build-deps79.sh
chmod 755 install-build-deps79.sh
sudo ./install-build-deps79.sh --no-arm --no-chromeos-fonts
第2条指令执行报错,连接不上
解决办法:网络问题,挂vpn解决。
第4步执行,缺少python
Depends, python2.7-minimal (= 2.7.15_rc1-1) 问题解决方法使用 aptitude 安装以及与 apt-get 的区别_wohu1104的博客-CSDN博客
第4步执行,依赖包出现问题
部分报错信息如下:
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
尝试:先卸载掉已有包,sudo apt-get purge xxx然后再重新安装。没有解决
解决:重装Ubuntu,软件源默认用官方的软件源,使用国内镜像问题太多了orz。官方源的缺点就是要架梯子。
sudo apt-get install libgtkglext1-dev
官方指令/实际执行
cd ~/code
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
注意:如果构建较老版本的 cef 需要下载版本相近的工具依赖包,不然容易出现同步源码失败的情况(如下)。
#工具包版本不对的错误
gclient.py: error: no such option: --disable-syntax-validation
Traceback (most recent call last):
File "../automate/automate-git.py", line 1364, in <module>
chromium_dir, depot_tools_dir)
File "../automate/automate-git.py", line 70, in run
args, cwd=working_dir, env=env, shell=(sys.platform == 'win32'))
File "/usr/lib/python2.7/subprocess.py", line 190, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['gclient', 'sync', '--nohooks', '--with_branch_heads', '--disable-syntax-validation', '--jobs', '16']' returned non-zero exit status 2
解决办法:
克隆代码后切换到旧版本分支
git branch -a
git checkout -b 3904 origin/chrome/3904
注意:要使用绝对路径,请根据自己实际目录填写命令!
export PATH=/home/qihao/work/cef/code/depot_tools:$PATH
cd ~/code/automate
#官方文档默认是最新分支
wget https://bitbucket.org/chromiumembedded/cef/raw/master/tools/automate/automate-git.py
#3945版本(实际执行)
wget https://bitbucket.org/chromiumembedded/cef/raw/ecefb59aa8184ae35f99837dd83b46a78488d763/tools/automate/automate-git.py
文件目录:~/code/chromium_git/update.sh
运行“update.sh“脚本用于下载CEF和Chromium源代码。
CEF源代码将下载到~/code/chromium_git/cef
Chromium源代码将下载到~/code/chromium_git/chromium/src
下载完成后,CEF源代码将被复制到~/code/chromium_git/chromium/src/cef
。
注意:--download-dir
--depot-tools-dir
的值需要需要用户根据情况自己填写。
官方指令:
#!/bin/bash
python ../automate/automate-git.py --download-dir=/home/marshall/code/chromium_git --depot-tools-dir=/home/marshall/code/depot_tools --no-distrib --no-build
实际内容:
#!/bin/bash
python ../automate/automate-git.py --download-dir=/home/qihao/work/cef/code/chromium_git --depot-tools-dir=/home/qihao/work/cef/code/depot_tools --no-distrib --branch=3945 --no-debug-build
给文件添加权限
cd ~/code/chromium_git
chmod 755 update.sh
运行脚本
cd ~/code/chromium_git
./update.sh
报错内容:
gclient.py: error: no such option: --disable-syntax-validation
Traceback (most recent call last):
File "../automate/automate-git.py", line 1364, in <module>
chromium_dir, depot_tools_dir)
File "../automate/automate-git.py", line 70, in run
args, cwd=working_dir, env=env, shell=(sys.platform == 'win32'))
File "/usr/lib/python2.7/subprocess.py", line 190, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['gclient', 'sync', '--nohooks', '--with_branch_heads', '--disable-syntax-validation', '--jobs', '16']' returned non-zero exit status 2
尝试1:修改update.sh文件
export DEPOT_TOOLS_UPDATE=0
export GCLIENT_PY3=0
export CEF_USE_GN=1
export GN_DEFINES="is_official_build=true use_sysroot=true use_allocator=none symbol_level=1"
export CEF_ARCHIVE_FORMAT=tar.bz2
python ../automate/automate-git.py --download-dir=/home/qihao/work/cef/code/chromium_git --depot-tools-dir=/home/qihao/work/cef/code/depot_tools --no-distrib --branch=3945 --no-debug-build
再次执行
cd ~/code/chromium_git
./update.sh
还是报错
尝试2:切换depot_tools版本,并重新执行update.sh
qihao@qihao-virtual-machine:~/work/cef/code/depot_tools$ git branch -a
* (HEAD detached at origin/main)
main
remotes/origin/HEAD -> origin/main
remotes/origin/chrome/3865
remotes/origin/chrome/3904
remotes/origin/chrome/3987
remotes/origin/chrome/4147
remotes/origin/infra/config
remotes/origin/main
qihao@qihao-virtual-machine:~/work/cef/code/depot_tools$ git checkout -b 3904 origin/chrome/3904
Previous HEAD position was 252b1986 Redirect cros calls to py2.7 scripts to the vpython2.7 package.
Branch '3904' set up to track remote branch 'chrome/3904' from 'origin'.
Switched to a new branch '3904'
qihao@qihao-virtual-machine:~/work/cef/code/depot_tools$ git branch
* 3904
main
然后修改文件 update.sh文件
export DEPOT_TOOLS_UPDATE=0
export GCLIENT_PY3=0
export CEF_USE_GN=1
export GN_DEFINES="is_official_build=true use_sysroot=true use_allocator=none symbol_level=0 proprietary_codecs=true ffmpeg_branding=Chrome"
python ../automate/automate-git.py --download-dir=/home/qihao/work/cef/code/chromium_git --depot-tools-dir=/home/qihao/work/cef/code/depot_tools --no-distrib --branch=3945 --no-debug-build --build-log-file --force-clean
export变量函数说明
DEPOT_TOOLS_UPDATE=0
:不更新depot_toolsGCLIENT_PY3=0
:不使用python3CEF_USE_GN=1
:启用GNGN_DEFINES
:参考GN Quick Start guide
is_official_build=true
:是否是编译正式版本,指定该参数为true基本上都是为了产品发布使用use_sysroot=true
:设置了该参数为true之后将不能直接构建 cefclient,可以构建 cefsimpleuse_allocator=none
:设置use_allocator为none,默认就会编译系统(glibc)的符号表。symbol_level=1
:加速链接。symbol_level=1时编译器发出文件名和行号信息,仍然可以进行源代码级调试,但是没有局部变量或类型信息。(后期备注:这里因为项目要使用沙箱应该设置为0,设置为1将禁用沙箱)proprietary_codecs=true
:指明支持H264编码,编译时,自动H264相关组件,打包PE文件中。ffmpeg_branding=Chrome
:作用于Chromium所依赖的第三方ffmpeg工程的代码,使之编译相关的支持代码。automate-git.py参数说明
参数 | 含义 |
---|---|
–download-dir | 下载的源码目录 |
–depot-tools-dir | depot_tools的下载目录。 |
–no-distrib | 不执行打包项目,只下载代码。 |
–branch | 表示你要下载和编译哪个版本的代码,Chromium和CEF的版本对应关系可以看这个链接 |
–no-debug-build | 编译时用,不编译debug只要release |
–build-log-file | 生成编译的日志文件,出错可以看下 |
–force-clean | 如果你曾经执行过这个脚本,可能会出错,则加上这个参数,它执行清理残留文件 |
核心是网络问题。
尝试1:修改git相关配置(无效)
sudo apt-get install gnutls-bin
git config --global http.sslVerify false
git config --global http.postBuffer 1048576000
实际操作
qihao@qihao-virtual-machine:~/work/cef/code/chromium_git/chromium$ git init
已初始化空的 Git 仓库于 /home/qihao/work/cef/code/chromium_git/chromium/.git/
qihao@qihao-virtual-machine:~/work/cef/code/chromium_git/chromium$ git config --global http.sslVerify false
qihao@qihao-virtual-machine:~/work/cef/code/chromium_git/chromium$ git config --global http.postBuffer 1048576000
或者
ifconfig eth0 mtu 14000
还是报错
1>error: RPC failed; curl 56 GnuTLS recv error (-9): A TLS packet with unexpected length was received.
1>fatal: The remote end hung up unexpectedly
1>fatal: early EOF
1>fatal: index-pack failed
尝试2:换了个VPN【解决】
网络才是根本问题!!!!!
update.sh文件的作用是下载cef和Chromium源码。之前参考同事的步骤将update.sh内容弄得比较复杂。同时设置了GN变量,和下载代码。具体内容如下。
#!/bin/bash
#Disable updating depot_tools
export DEPOT_TOOLS_UPDATE=0
#Use python2 instead of python3.
export GCLIENT_PY3=0
export CEF_USE_GN=1
#After "use_sysroot=true" is set in GN_DEFINES, cefclient cannot be built directly, but cefsimple can be built.
export GN_DEFINES="is_official_build=true use_sysroot=true use_allocator=none symbol_level=1 enable_vr=false proprietary_codecs=true ffmpeg_branding=Chrome"
#export CEF_ARCHIVE_FORMAT=tar.bz2
#"--force-clean "
python ../automate/automate-git.py --download-dir=/home/qihao/work/cef/code/chromium_git --depot-tools-dir=/home/qihao/work/cef/code/depot_tools --x86-64-build --no-distrib --branch=3945 --no-debug-build --build-log-file
现在考虑把update.sh文件内容简化,GN变量设置单独一步,便于排错。
新版本update.sh:
#!/bin/bash
python ../automate/automate-git.py --download-dir=/home/qihao/work/cef/code/chromium_git --depot-tools-dir=/home/qihao/work/cef/code/depot_tools --no-distrib --branch=3945 --no-debug-build --build-log-file
给予它可执行权限。
cd ~/code/chromium_git
chmod 755 update.sh
运行“update.sh“脚本并等待下载CEF和Chromium源代码。
cd ~/code/chromium_git
./update.sh
0.是否是编译正式版本
is_official_build=true
1.使用sysroot映像
Chromium提供了sysroot映像,以实现跨Linux发行版的一致构建。必要的文件将作为上个步骤(运行update.sh)的一部分自动下载。如果您不想处理由于与本地安装的包或内核版本不兼容而导致的潜在构建中断,建议使用Chromium的sysroot。要使用sysroot映像,请配置以下GN_DEFINES:
use_sysroot=true use_allocator=none symbol_level=1 is_cfi=false use_thin_lto=false
实际采用
use_sysroot=true use_allocator=none symbol_level=0
注意:symbol_level=0
如果symbol_level不为0,则会禁用SUID沙箱。(浏览器要使用沙箱)is_cfi=false use_thin_lto=false
默认就是false可以不设置。
2.音视频支持:
CEF的默认版本不启用专有的音频和视频编解码器。要在启用Chrome专有音频和视频编解码器的情况下构建CEF,请将以下内容添加到 GN_DEFINES 环境变量:
ffmpeg_branding=Chrome proprietary_codecs=true
参考文档:Chromium Embedded Framework Build Instructions for Google products
综上所诉。实际GN变量设置如下:
export GN_DEFINES="is_official_build=true use_sysroot=true use_allocator=none symbol_level=1 proprietary_codecs=true ffmpeg_branding=Chrome"
上一步的update.sh执行automate.py 中已经包含了ninja cef的步骤。
但如果编译很容易半截出现问题,有两个办法解决。
删除编译的内容
# rm -rf /<yourcefpath>/cef/chromium_git/chromium/src/out
# 例如我的实际目录
rm -rf ~/Desktop/work/cef/code/chromium_git/chromium/src/out
再重新编译
不删除,用ninja继续(重新)编译,修改了GN变量也要重新执行此步。
注意在/cef/chromium_git/chromium/src/out
目录下有四个文件夹,分别对应不同版本,如下图所示:
此处我们选用 release 64位版本,即在Release_GN_x64
目录下执行ninja。
(提示:如果在上一步,即使用automate-git.py完成编译,如果没有设置特定参数,会默认编译x86版本)
cd ./cef/chromium_git/chromium/src
./third_party/depot_tools/ninja -C out/Release_GN_x64 cefsimple chrome_sandbox
执行结果(编译成功)
qihao@qihao-virtual-machine:~/Desktop/work/cef/code/chromium_git/chromium/src$ ./third_party/depot_tools/ninja -C out/Release_GN_x64 cefsimple chrome_sandbox
ninja: Entering directory `out/Release_GN_x64'
[1/1] Regenerating ninja files
[24358/34002] ACTION //cef:make_pack_header_resources(//build/toolchain/linux:clang_x64)
File includes/include/cef_pack_resources.h updated.
[24360/34002] ACTION //cef:make_pack_header_strings(//build/toolchain/linux:clang_x64)
File includes/include/cef_pack_strings.h updated.
[34002/34002] LINK ./cefsimple
release 32位版本编译运行记录:
qihao@qihao-virtual-machine:~/Desktop/work/cef/code/chromium_git/chromium/src$ ./third_party/depot_tools/ninja -C out/Release_GN_x86 cefsimple chrome_sandbox
ninja: Entering directory `out/Release_GN_x86'
[1/1] Regenerating ninja files
[14173/37279] ACTION //cef:make_pack_h...ces(//build/toolchain/linux:clang_x86)
File includes/include/cef_pack_resources.h is already up to date.
[14177/37278] ACTION //cef:make_pack_h...ngs(//build/toolchain/linux:clang_x86)
File includes/include/cef_pack_strings.h is already up to date.
[37276/37276] LINK ./cefsimple
直接运行
#32位
ninja -C out/Release_GN_x86 cefsimple chrome_sandbox
#64位
ninja -C out/Release_GN_x64 cefsimple chrome_sandbox
会报错
Error: could not find depot_tools in PATH.
改成下面这样就ok了
#32bit
./third_party/depot_tools/ninja -C out/Release_GN_x86 cefsimple chrome_sandbox
#64bit
./third_party/depot_tools/ninja -C out/Release_GN_x64 cefsimple chrome_sandbox
构建调试和发布配置后,您可以使用make_distrib工具(Windows上为.bat,macOS和Linux上为.sh)创建二进制分发版。
cd /path/to/chromium/src/cef/tools
./make_distrib.sh --ninja-build
如果该过程成功,将在/path/to/chromium/src/cef/binary_distrib目录中创建一个二进制分发包。
有关其他使用选项,请参见make_distrib.py脚本。
然后可以使用CMake和平台工具链构建生成的二进制分布。有关详细信息,请参阅二进制分发包中包含的README.txt文件
打包过程报错:
Traceback (most recent call last):
File "make_distrib.py", line 1185, in <module>
copy_files_list(build_dir, dst_dir, binaries)
File "make_distrib.py", line 316, in copy_files_list
raise Exception('Missing required path: %s' % source_path)
Exception: Missing required path: /home/qihao/work/cef/code/chromium_git/chromium/src/out/Debug_GN_x86/chrome_sandbox
核心意思就是缺少chrome_sandbox
chatgpt回答:
这个错误提示是在打包 CEF 时出现的,它指出缺少了 chrome_sandbox 这个文件。这个文件通常会被编译到 cef_binary 文件夹下的子目录中。这个错误的原因可能是在编译 CEF 时没有正确地设置 GN 变量或者编译过程中出现了错误。为了解决这个问题,可以尝试以下步骤:
- 确认在编译 CEF 时设置了正确的 GN 变量,包括设置了 sandbox 相关的变量。
- 确认编译过程中没有出现错误,并且 chrome_sandbox 文件确实存在于编译好的 CEF 二进制文件夹中。
- 如果 chrome_sandbox 文件确实存在于 CEF 二进制文件夹中,那么可以尝试手动将这个文件拷贝到缺失的位置中。
如果这些步骤都没有解决问题,建议检查一下编译 CEF 的文档或者参考其他开发者的编译配置,看看是否有遗漏的设置或者步骤。
问题出在前面设置GN变量时
问:GN 变量中哪些是 sandbox 相关的变量?
答:下面是一些与sandbox相关的GN变量:
- is_debug: 是否启用调试模式。如果启用了调试模式,那么将禁用SUID沙箱。
- symbol_level: 编译时符号级别。如果symbol_level不为0,则会禁用SUID沙箱。
- treat_warnings_as_errors: 是否将编译器警告视为错误。如果启用此选项,则编译时将禁用SUID沙箱。
- enable_sandbox: 是否启用SUID沙箱。默认情况下启用,可以通过将其设置为false来禁用SUID沙箱。
- use_sandbox_linux_seccomp: 是否使用Linux Seccomp策略来限制SUID沙箱。默认情况下启用,可以通过将其设置为false来禁用Seccomp。
- use_custom_sandbox_path: 是否使用自定义沙箱路径。默认情况下,使用Chromium的默认沙箱路径。如果您希望使用不同的沙箱路径,则可以将此变量设置为您想要使用的路径。
这只是其中的一部分,更多与Sandbox相关的GN变量,请参考官方文档。
为了加速编译设置了symbol_level=1
导致禁用沙箱(难怪前同事设置的0和官方文档建议的不一样),需要改成symbol_level=0
后再使用ninja重新构建项目
$ python automate-git.py --help
Usage: automate-git.py [options]
This utility implements automation for the download, update, build and
distribution of CEF.
Options:
-h, --help show this help message and exit
--download-dir=DIR Download directory with no spaces [required].
--depot-tools-dir=DIR
Download directory for depot_tools.
--depot-tools-archive=DEPOTTOOLSARCHIVE
Zip archive file that contains a single top-level
depot_tools directory.
--branch=BRANCH Branch of CEF to build (trunk, 1916, ...). This will
be used to name the CEF download directory and to
identify the correct URL if --url is not specified.
The default value is trunk.
--url=URL CEF download URL. If not specified the default URL
will be used.
--chromium-url=CHROMIUMURL
Chromium download URL. If not specified the default
URL will be used.
--checkout=CHECKOUT Version of CEF to checkout. If not specified the most
recent remote version of the branch will be used.
--chromium-checkout=CHROMIUMCHECKOUT
Version of Chromium to checkout (Git branch/hash/tag).
This overrides the value specified by CEF in
CHROMIUM_BUILD_COMPATIBILITY.txt.
--chromium-channel=CHROMIUMCHANNEL
Chromium channel to check out (canary, dev, beta or
stable). This overrides the value specified by CEF in
CHROMIUM_BUILD_COMPATIBILITY.txt.
--chromium-channel-distance=CHROMIUMCHANNELDISTANCE
The target number of commits to step in the channel,
or 0 to use the newest channel version. Used in
combination with --chromium-channel.
--force-config Force creation of a new gclient config file.
--force-clean Force a clean checkout of Chromium and CEF. This will
trigger a new update, build and distribution.
--force-clean-deps Force a clean checkout of Chromium dependencies. Used
in combination with --force-clean.
--dry-run Output commands without executing them.
--dry-run-platform=DRYRUNPLATFORM
Simulate a dry run on the specified platform (windows,
macosx, linux). Must be used in combination with the
--dry-run flag.
--force-update Force a Chromium and CEF update. This will trigger a
new build and distribution.
--no-update Do not update Chromium or CEF. Pass --force-build or
--force-distrib if you desire a new build or
distribution.
--no-cef-update Do not update CEF. Pass --force-build or --force-
distrib if you desire a new build or distribution.
--force-cef-update Force a CEF update. This will cause local changes in
the CEF checkout to be discarded and patch files to be
reapplied.
--no-chromium-update Do not update Chromium.
--no-depot-tools-update
Do not update depot_tools.
--fast-update Update existing Chromium/CEF checkouts for fast
incremental builds by attempting to minimize the
number of modified files. The update will fail if
there are unstaged CEF changes or if Chromium changes
are not included in a patch file.
--force-patch-update Force update of patch files.
--resave Resave patch files.
--log-chromium-changes
Create a log of the Chromium changes.
--force-build Force CEF debug and release builds. This builds
[build-target] on all platforms and chrome_sandbox on
Linux.
--no-build Do not build CEF.
--build-target=BUILDTARGET
Target name(s) to build (defaults to "cefclient").
--build-tests Also build the test target specified via --test-
target.
--no-debug-build Don't perform the CEF debug build.
--no-release-build Don't perform the CEF release build.
--verbose-build Show all command lines while building.
--build-failure-limit=BUILDFAILURELIMIT
Keep going until N jobs fail.
--build-log-file Write build logs to file. The file will be named
"build-[branch]-[debug|release].log" in the download
directory.
--x64-build Create a 64-bit build.
--arm-build Create an ARM build.
--arm64-build Create an ARM64 build.
--run-tests Run the ceftests target.
--no-debug-tests Don't run debug build tests.
--no-release-tests Don't run release build tests.
--test-target=TESTTARGET
Test target name to build (defaults to "ceftests").
--test-prefix=TESTPREFIX
Prefix for running the test executable (e.g. `xvfb-
run` on Linux).
--test-args=TESTARGS Arguments that will be passed to the test executable.
--force-distrib Force creation of a CEF binary distribution.
--no-distrib Don't create a CEF binary distribution.
--minimal-distrib Create a minimal CEF binary distribution.
--minimal-distrib-only
Create a minimal CEF binary distribution only.
--client-distrib Create a client CEF binary distribution.
--client-distrib-only
Create a client CEF binary distribution only.
--sandbox-distrib Create a cef_sandbox static library distribution.
--sandbox-distrib-only
Create a cef_sandbox static library distribution only.
--no-distrib-docs Don't create CEF documentation.
--no-distrib-archive Don't create archives for output directories.
--clean-artifacts Clean the artifacts output directory.
--distrib-subdir=DISTRIBSUBDIR
CEF distrib dir name, child of
chromium/src/cef/binary_distrib
Chromium浏览器不支持MP3、MP4格式,而Chrome却支持。根本原因是浏览器内核所依赖的 FFmpeg 编译开关不一样导致的的。
在Chromium代码工程的生成gn工程的时候加上以上两个值: ffmpeg_branding="Chrome" proprietary_codecs=true
就可以让Chromium编译出来的浏览器像Chrome一样支持MP3、MP4格式格式了。
proprietary_codecs
的作用是开启代码中的USE_PROPRIETARY_CODECS
宏,使Chromium的代码支持更多的音视频解码格式。
ffmpeg_branding
则是作用于Chromium所依赖的第三方ffmpeg工程的代码,使之编译相关的支持代码。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。