快速下载chromium源码
文档说明: 只记录关键的地方; 发布时间: 2022-08-11
环境: debian 11 docker
状态: 已完成
备注:
第一步:准备服务
一句命令即可使用准备好的服务
使用代理方式一:
socat -d -d TCP4-LISTEN:8016,reuseaddr,fork ssl:http-proxy.xiaoshuogeng.com:8017,verify=1,snihost=http-proxy.xiaoshuogeng.com,commonname=http-proxy.xiaoshuogeng.com,openssl-min-proto-version=TLS1.3,openssl-max-proto-version=TLS1.3
# 备注: 服务端就是一个 实现了 connect 方法的 nginx ,仅此而已
# socat 需要支持TLSv1.3
# 如果你的socat 不支持相关参数,请使用下面容器的方式
使用代理方式二:
version: "3"
services:
socat-http-proxy-8016:
image: registry.cn-beijing.aliyuncs.com/jingjingxyk-public/app:socat-alpine-20221018T1839Z
restart: always
container_name: socat-http-proxy-8016
ports:
- "8016:8016"
command:
- /bin/sh
- -c
- |
socat -d -d TCP4-LISTEN:8016,reuseaddr,fork ssl:http-proxy.xiaoshuogeng.com:8017,verify=1,snihost=http-proxy.xiaoshuogeng.com,commonname=http-proxy.xiaoshuogeng.com,openssl-min-proto-version=TLS1.3,openssl-max-proto-version=TLS1.3
# 启动
docker-compose -f docker-compose.yaml up -d
# 关闭
docker-compose -f docker-compose.yaml down --remove-orphans
# 查看日志
docker-compose -f docker-compose.yaml logs -f
第二步: 安装必要依赖
test ! -f /etc/apt/source.list.save && cp /etc/apt/sources.list /etc/apt/sources.list.save
sed -i "s@deb.debian.org@mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list && \
sed -i "s@security.debian.org@mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
apt update -y && apt install -y git curl python3 python3-pip python3-dev wget ninja-build ffmpeg sudo file
apt install -y libssl-dev ca-certificates make cmake gcc g++ zip
apt install -y lsb-release locales
apt install -y tcpdump nmap traceroute net-tools dnsutils iproute2 procps iputils-ping rsync
apt install -y libegl-mesa0
第三步:准备 depot_tools
脚本
# vi depot_tools.sh
#!/bin/bash
set -exu
__DIR__=$(
cd "$(dirname "$0")"
pwd
)
cd ${__DIR__}
export http_proxy=http://127.0.0.1:8016
export https_proxy=http://127.0.0.1:8016
if [ -f depot_tools/.gitignore ];then
git -C depot_tools pull --depth=1 --progress --rebase=true
else
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git --depth=1 --progress
fi
export PATH="$PATH:${__DIR__}/depot_tools"
第四步:准备chromium
同步脚本
vi download-chromium.sh
#!/bin/env bash
set -eux
__CURRENT__=$(pwd)
__DIR__=$(
cd "$(dirname "$0")"
pwd
)
cd ${__DIR__}
cat > ${__DIR__}/.boto <<EOF
[Boto]
proxy = 127.0.0.1
proxy_port = 8016
proxy_type = http
# README https://gist.github.com/nickdiego/2b2faa35f5ab48e7438ee434d2756765
EOF
proxy_server_url=http://127.0.0.1:8016
export http_proxy=$proxy_server_url
export https_proxy=$proxy_server_url
export PATH=${__DIR__}/depot_tools:$PATH
export DEPOT_TOOLS_UPDATE=0
gclient metrics --opt-out
export NO_AUTH_BOTO_CONFIG=${__DIR__}/.boto
# 显示git下载详细信息
#export GIT_TRACE_PACKET=1
#export GIT_TRACE=1
export GIT_CURL_VERBOSE=1
curl -I https://chromium.googlesource.com
mkdir -p ${__DIR__}/chromium/chromium
# 从这里才开始下载代码哈
# 前面都是准备工作
cd ${__DIR__}/chromium/chromium
pwd
# show tag
# https://chromium.googlesource.com/chromium/src/+refs
# git log --pretty=format:"%h %s" --graph
# shellcheck disable=SC2107
if [ -f '.gclient' ] && [ -d ${__DIR__}/chromium/chromium/src/ ]; then
{
# 写着里的目的,是为了多次拉取更新。如果只拉取一次,这里就不需要
sed -i 's/"custom_vars": {}/"custom_vars": { \n "checkout_pgo_profiles": True, \n }/' ${__DIR__}/chromium/chromium/.gclient
cd ${__DIR__}/chromium/chromium/src/
git clean -fd
git checkout main
# git rebase-update
# git pull origin main --depth=1 --rebase=true --progress --allow-unrelated-histories
git pull origin main --depth=1 --rebase=true --progress
cd ${__DIR__}/chromium/chromium/
gclient sync -D --verbose --nohooks --no-history --auto_rebase -R --shallow
cd ${__DIR__}/chromium/chromium/src/
git checkout main
git merge origin/main
git branch
cd ${__DIR__}/chromium/chromium/
gclient runhooks --verbose
cd ${__DIR__}/chromium/chromium/src/
git clean -fd
}
else
{
test -d ${__DIR__}/chromium/chromium/src/ && rm -rf ${__DIR__}/chromium/chromium/src/
fetch --nohooks --no-history chromium
gclient sync --nohooks --no-history
gclient runhooks --verbose
}
fi
cd ${__DIR__}/chromium/chromium/src
git branch
cd ${__DIR__}/
第四步:执行同步chromium
工程源代码
sh download-chromium.sh
写这个脚本的初衷。源于四年前,回看下面的事。现在终于能自个实现了
参考文档
- nginx 的http_proxy_connect_module模块使用
- http 代理的服务端实现
- 构建能让socat支持TLSv.13特性的容器环境
- github chromium Source repository
- chromium Source repository
- chromium docs