zoukankan      html  css  js  c++  java
  • Appium 本地编译 chromedriver 历程记录

    本地编译 chromedriver 历程记录

    原因:尝试编译 fix chromedriver bug('chrome not reachable') for wechat webview57.0.2987.132
    结果:编译成功啦,哈哈哈,分享下成功的喜悦
    过程记录:共耗时5天,除了正常工作外,大部分时间都在等,以及处理编译前遇到的各种问题,真正编译时间很短

     

    一、先说下总体正常的流程

    前提:terminal scientific internet(终端),希望你能在所有同步代码类命令前都加上http_proxy or https_proxy

    1、配置 depot_tools
    2、fetch chromium(耗时较长)
    3、切分支(如果编译最新版不需此步)
    4、gclient sync 同步相关工程代码(耗时较长)
    5、构建依赖项 build/install-build-deps.sh(如果是 linux)
    6、运行钩子 gclient runhooks(印象中 mac 会在第 4 步同时做好)
    7、gn 设置构建
    8、ninja 构建(如果只构建 chromedriver,编译过程 3000 多个文件,大约 10 分钟或者更快)

    二、接下来是这几天遇到的一些问题记录,如果你也遇到,希望可以有参考的价值

    第一天和第二天主要处理环境、依赖问题

    1、第一天下午开始决定要尝试一下,于是各种查资料,看了几篇文章后蠢蠢欲动,于是在本机 Mac 上开始拉代码

    问题 1、刚开始从 github 搜 chromedriver 相关源码,倒是找到了相应版本源码,可是后面不知道如何处理(建议还是参考官方方式)

    问题 2、fetch --nohooks chromium过程卡住,等不下去 control+c 了(必须要 terminal scientific internet,只 proxychains 不行的)

    问题 3、脑残执行了build/install-build-deps.sh,报错ERROR: lsb_release not found in $PATH,结果查这个报错查了半天,发现这个错别人都是 Linux 下出的问题,撞了南墙墙没破不得已,想着换 Linux 编译吧那就,很蓝瘦,安慰自己 Linux 服务器毕竟配置高,应该很快,公司 Mac 是机械硬盘,后面确实体会到了它的 “威力”(后几日看了官方文档,发现 Mac 下不需要执行这个命令的 )

    2、换了 Linux,先配置环境,depot_tools 弄好后,开始拉代码,这时我的 terminal scientific internet 还没解决,看了一下 build 目录拉下来了,于是想着先执行 build/install-build-deps.sh 解决依赖吧,结果又出现了新的问题

    问题 1、ImportError: No module named gyp
    https://chromium.googlesource.com/external/gyp/+/master
    https://blog.csdn.net/kangear/article/details/38777015
    git clone https://chromium.googlesource.com/external/gyp
    cd gyp
    sudo ./setup.py install

    问题 2、No module named setuptools,一度怀疑是 Python 环境问题,切回了 2.7,还换了一个其他 2.7 的小版本
    wget https://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
    (这一步又被网上小坑一下,网上是http,这里需https)
    tar zxvf setuptools-0.6c11.tar.gz
    cd setuptools-0.6c11
    sudo python setup.py install

    第三天 Linux 编译 master 版本

    切指定版本肯定会有一堆问题,于是想着先构建最新版本,找下感觉

    1、build/install-build-deps.sh 解决后,继续 gclient runhooks,可能是由于代码之前没有同步完整,报错了又

    问题 1、gclient runhooks 报错
    running '/usr/bin/python src/tools/clang/scripts/update.py'
    Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Linux_x64/clang-340925-2.tgz
    <urlopen error [Errno 110] Connection timed out>
    Failed to download prebuilt clang clang-340925-2.tgz
    Use --force-local-build if you want to build locally.
    Exiting.

    手动 build
    ./update.py --force-local-build --without-android --without-fuchsia

    问题 2、gclient runhooks 报错

    Running hooks: 29% (22/75) gn_linux64
    ________ running '/usr/bin/python src/third_party/depot_tools/download_from_google_storage.py --no_resume --no_auth --bucket chromium-gn -s src/buildtools/linux64/gn.sha1' in '/home/chen/chromium'
    NOTICE: You have PROXY values set in your environment, but gsutil in depot_tools does not (yet) obey them.
    Also, --no_auth prevents the normal BOTO_CONFIG environment variable from being used.
    To use a proxy in this situation, please supply those settings in a .boto file pointed to by the NO_AUTH_BOTO_CONFIG environment var.
    Failed to fetch file gs://chromium-gn/1756964fe6b9f0a865accdf577ae46345847de3b for src/buildtools/linux64/gn. [Err: Traceback (most recent call last):
    [Err: |DNS-request| storage.googleapis.com

    这个要保证上网环境,进行设置 dns 8.8.8.8 或者重启网卡解决

    问题 3、gn gen out/Release 报错
    /home/chen/chromium/.gclient_entries missing, .gclient file in parent directory /home/chen/chromium might not be the file you want to use.
    /home/chen/chromium/.gclient_entries missing, .gclient file in parent directory /home/chen/chromium might not be the file you want to use.
    ERROR at //build_overrides/build.gni:5:1: Can't load input file.

    居然少了文件,看来还是要一次性同步完所有文件,再进行后面操作更为妥当,好吧,rm -rf ~/chromium,重新来过

    2、重新来过

    fetch --nohooks --no-history chromium进入漫长的等待,
    如果中途断了gclient sync --force进入漫长的等待,
    如果之前没有执行build/install-build-deps.sh则需再执行一次
    上一步 ok 后gclient runhooks进入漫长的等待,
    上一步 ok 后,恭喜,迈出了一大步,后面基本不会报错了,至少我没遇到,执行gn gen out/Release
    上一步一分钟内 ok,执行ninja -C out/Release chromedriver
    约 10 分钟内编译完成,切到 out/Release 目录下,看到了明晃晃的那个文件

    第四天 Linux 编译指定版本

    1、从昨天编译 master 成功后,精神为之一振,赶紧搜寻编译指定版本方法,看到网上 2 种方式

    1、修改 chromium 目录下.gclient 文件的 url,后面加上 @ 版本提交记录

    2、在 master 基础上,git checkout -b

    一开始我采用了第一种方法,又遇到无数问题,弄了大半天,代码没 down 下来,最终失败告终,此间遇到的问题不一一列举了,不推荐此方式
    后来采用第二种方法,也遇到了很多问题,下午很烦躁,萌生了放弃的想法,想想都走到这一步了,可能再坚持一下就看到曙光了

    2、于是又有了神奇的操作rm -rf ~/chromium57 #我的指定版本目录,以下为重点

    fetch --nohooks chromium #不要加--no-history
    cd src
    git fetch --tags
    # 根据57.0.2987.132版本建立一个你自己的分支
    git checkout -b your_release_branch 57.0.2987.132
    // 同步所有相关工程代码 
    gclient sync --with_branch_heads --jobs 16
    build/install-build-deps.sh #linux
    gclient runhooks
    gn gen out/Release
    ninja -C out/Release chromedriver
    

    3、经过上一步一系列操作,最终成功编译

    这时可能喜悦搞得头有点晕了,赶紧 scp 把包搞到 Mac 上,跑了一个脚本,结果不出意外的报错了,有预感。。
    报错Exec format error: 'chromedriver',于是手动到/usr/local/bin/chromedriver一样报错了,去 Linux 下执行,可以正常启动
    忽然想起,Linux 的怎么能在 Mac 上用呢。。尴尬

    第五天 Mac 编译指定版本

    1、Mac 下编译和 Linux 大同小异,开始有提到

    fetch --nohooks chromium
    cd src
    git fetch --tags
    git checkout -b your_release_branch 57.0.2987.132
    gclient sync --with_branch_heads --jobs 16
    gclient runhooks #如果上一步有提示runhooks成功,则不需执行
    gn gen out/Release #当你看到单行输出结果的时候,那么已经胜利在望了
    ninja -C out/Release chromedriver #不如去冲一杯咖啡,因为Time for a true display of skill
    

    2、编译成功,测试一下

    将产物 cp 到对应目录,这里要吐槽的是,公司 Mac 的机械硬盘,只要进 src 目录,就会巨卡,没米啊,有米自己上了
    执行脚本,报错,需要依赖动态库,将.dylib 文件也拷贝到/usr/local/bin/,再次执行脚本,成功打印 page_source

    3、想不明白为什么必须要依赖库,官方的怎么不需要

    晚上回去路上特意问了下 C 的朋友,一直没有回复
    晚上睡觉都在想,想着要么第二天把整个 chromium 都编译一下
    第二天又好好查了一下资料,发现可以设置 gn 为--args="is_debug=false",问题得到解决

    参考资料

    1、官方文档
    https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md
    https://chromium.googlesource.com/chromium/src/+/master/docs/mac_build_instructions.md
    http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html
    2、官方代码库
    https://chromium.googlesource.com/chromium/src/+/master/chrome
    https://chromium.googlesource.com/chromium/src/+refs

    3、docker 构建
    https://stackoverflow.com/questions/43841415/build-chromedriver-for-linux

    4、其他博客资料
    https://www.jianshu.com/p/e637044df961
    https://blog.csdn.net/bobozhangyx/article/details/78014425
    https://blog.csdn.net/yyinhai/article/details/53517873
    https://blog.csdn.net/bbmjja0000/article/details/45870891
    https://www.jianshu.com/p/bd7d3a19adbb
    https://www.jianshu.com/p/07a281ff57d3

    三、后记

    此次过程遇到很多问题,中途也曾想要放弃,可想想心有不甘,还是坚持下来
    坚持到底,永不放弃!

  • 相关阅读:
    简单工厂、工厂方法、抽象工厂
    c#之反射总结
    设计模式Builder(建造者)模式
    c#之委托和事件的区别
    c#之委托总结
    javascript之流程控制 和函数的容易忽略点
    javascript之六种数据类型以及特殊注意点
    Sublime Text 快捷键
    链接中获取文件名
    js 获取当天23点59分59秒 时间戳 (最简单的方法)
  • 原文地址:https://www.cnblogs.com/interdrp/p/14370646.html
Copyright © 2011-2022 走看看