作者|户锐,何用单位:中国移动智慧家庭运营中心
Android源码是管理基于Linux的开源操作系统,目前Android ROM开发的代码代码管理工具基本上是采用Git。由于Android代码非常复杂,何用Google将其划分为多个git repo,管理这样不仅可以避免一个repo的代码代码太多,还可以根据repo的何用功能将其分配给不同团队进行管控。为了对Android代码质量进行管控,管理Google采用了Gerrit进行coderview,代码并利用jenkins做代码静态检测和自动化验证,当然还有集成CI工具。目前中国移动智慧家庭运营中心AOS-RM项目已经部署自己的Gerrit服务器,Gerrit对AOS-RM项目代码质量管理起到了非常重要的作用。
作为Android ROM相关的开发者,有必要了解什么是Gerrit,Gerrit的工作流程是怎么样的,Gerrit服务器怎么搭建,以及如何将Android codebase导入自己的Gerrit服务器。接下来本文将为大家详细解答以上问题。
Gerrit是Google为Android系统研发量身定制的一套免费开源的代码审核系统,使用网页界面。利用网页浏览器,同一个团队的软件开发者可以相互审阅彼此修改后的代码,决定是否提交,回退或是继续修改。它使用版本控制系统Git作为底层。目前Gerrit被广泛使用,与Android开发相关,尤其是做Android ROM开发的公司基本都使用Gerrit进行code review。根据统计使用Gerrit的top3领域是IOT,Software Development以及Big Data。
数据来源:https://www.slintel.com/tech/source-code-management/gerrit-market-share
sudo apt-get install git
sudo apt install openjdk-11-jdk
sudo apt-get install gitweb
wget https://gerrit-releases.storage.googleapis.com/gerrit-3.5.1.wa
cd ~/gerrit
mkdir review_site
java -jar gerrit-3.5.0.1.war init -d ./review_site/ (可以都选择默认,然后修改config文件)
sudo vim /home/gerrit/review_site/etc/gerrit.config
发送邮件配置的密码保存在secure.config,发送邮件的密码是授权码
sudo apt-get install apache2
sudo vim /etc/apache2/httpd.conf 内容如下图
sudo vim /etc/apache2/ports.conf 加入 Listen 8081(如果80端口没有被占用,不用修改)
sudo vi /etc/apache2/apache2.conf 加入 Include httpd.conf
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests
htpasswd -b /xxx/passwords account xxxx
如果passwords文件不存在,第一次需要加-c,
htpasswd -c -b /xxxx/passwords account xxxx
sudo systemctl start apache2
sudo systemctl restart apache2
/xxxx/bin/gerrit.sh start
/xxxx/bin/gerrit.sh restart
http://IP地址:端口号/
利用浏览器在Gerrit服务器上创建AOSP仓库,将Only server as parent for other repositories设置为True
repo init -u https://android.googlesource.com/platform/manifest --mirror
repo sync
repo forall -c 'echo $REPO_PROJECT; ssh -p 29418 account@IP gerrit create-project --owner AOSP_account $REPO_PROJECT;
repo forall -c 'echo $REPO_PROJECT; ssh -p 29418 account@IP gerrit set-project-parent --parent AOSP $REPO_PROJECT;
repo forall -c 'echo $REPO_PROJECT; git push
ssh://account@IP:29418/$REPO_PROJECT +refs/heads/* +refs/tags/*
git clone "ssh://account@IP:29418/platform/manifest" && scp -p -P 29418 account@IP:hooks/commit-msg "manifest/.git/hooks/
一定要设置review字段,否则repo sync后的代码不会产生change id
如果要增加自己特有的仓库,则增加一个project节点,并配置name,path和revision即可,最后将新的xml文件提交到gerrit服务器,完成review后merge到远程仓库。
repo init -u ssh://account@IP:29418/platform/manifest.git -b branch_name --repo-url=ssh://account@IP:29418/repo.git -m mymanifest.xml
repo sync -j4
详细说明可以参考:
https://gerrit-documentation.storage.googleapis.com/Documentation/3.5.0/access-control.htm
配置中,需要根据实际情况进行修改,不同组对不同仓库具有不同的访问权限,切记不要开放对refs/*的push权限,否则开发人员可以跳过Gerrit,直接push到git服务器。
责任编辑:未丽燕 来源: 移动Labs AndroidGerrit代码审核(责任编辑:知识)
今年一季度我国企业海外并购明显降温 企业“走出去”渐渐回归理性
资管过渡期尾页的“攻坚战”(上):倒计时吧,抹平波动的“摊余成本法”
大别山革命老区正式迎来“高铁时代” 黄黄高铁正线全长126.85公里
高盛收购复星旅文旗下2个度假酒店品牌;环球影城旁将再添3座酒店
中欧班列(西安)2021年累计运输车数突破3万车 同比增长24.36%