天天看點

建立repo倉庫管理Android源碼

前言

我們知道Android源碼是由很多個小的git組成,這樣可以隻clone我們需要修改的部分而不用關心其他,但編譯的時候需要整個源碼,這就需要将所有源碼都下載下傳并同步,這時候就需要使用repo來管理,尤其是當我們從晶片廠商拿到平台源碼之後,還需要搭建自己的gerrit伺服器管理源碼。

安裝gerrit

  1. 安裝gerrit伺服器,下載下傳gerrit-3.2.1.war或者其他版本
    mkdir gerrit
     cd gerrit
     java -jar gerrit-3.2.1.war init -d review_site
               
  2. 編輯review_site/etc/gerrit.config(修改伺服器ip)
    建立repo倉庫管理Android源碼
  3. 啟動/停止gerrit服務
    cd /gerrit/review_sites/bin
     ./gerrit.sh  start     #啟動gerrit服務
     ./gerrit.sh  stop      #停止gerrit服務
               
  4. 在用戶端的浏覽器中輸入伺服器網址進入通路:http://192.168.15.128:8080
    建立repo倉庫管理Android源碼
  5. 注冊登入後第一個使用者就是管理者,添加公鑰,友善後續使用
  6. gitweb安裝
    sudo apt-get install gitweb
     #/usr/share/gitweb/gitweb.cgi是為gitweb安裝目錄。
     #可通過find /usr - name gitweb.cgi查找
     git config --file /絕對路徑/gerrit/review_site/etc/gerrit.config gitweb.cgi /usr/share/gitweb/gitweb.cgi
     git config --file /絕對路徑/gerrit/review_site/etc/gerrit.config --unset gitweb.url
               

安裝repo

  1. 利用gerrit建立自己的repo庫
    ssh -p 29418 192.168.15.128 gerrit create-project --branch stable --empty-commit repo;
               
    建立repo倉庫管理Android源碼
  2. 送出自己的repo倉庫
    git clone https://gerrit-googlesource.lug.ustc.edu.cn/git-repo
     cd git-repo
     git checkout stable
     //将從google那裡clone的repo送出到自己的伺服器(在上一個步驟建立的)
     git push --mirror [email protected]:/home/lost/lost/tools/gerrit/review_site/git/repo.git
               
  3. 安裝repo
    curl https://storage.googleapis.com/git-repo-downloads/repo > /usr/bin/repo
     chmod a+x /usr/bin/repo
               
  4. 修改repo的預設url,這樣不用每次在repo init的時候指定url
    ## repo default configuration
     ##
     from __future__ import print_function
     REPO_URL='ssh://192.168.15.128:29418/repo.git'
     REPO_REV = 'stable'
               

建立Android源碼的所有小git工程倉庫

  1. 批量生成腳本create-gerrit-projects.sh
    #!/bin/bash
    
     if [ $# -lt 1 ] ; then
     	echo "usage : ./create-gerrit-projects.sh project.list";
     	exit 1;
     fi
    
     project_list=$1
    
     for i in  `cat ${project_list}`;
     do
     	echo $i
     	ssh -p 29418 192.168.15.128 gerrit create-project --branch Android-N/master --empty-commit Android-N/$i;
     done
               
    建立repo倉庫管理Android源碼
  2. 将所有需要生成的工程,放在同一檔案内project.list(一般擷取到的源碼的./repo/repo/有,可以直接拿來用)
    建立repo倉庫管理Android源碼
  3. 建立所有小git工程倉庫
    建立repo倉庫管理Android源碼
    ./create-gerrit-projects.sh project.list
               

建立manifest工程倉庫

  1. 建立倉庫
    ssh -p 29418 192.168.15.128 gerrit create-project --branch Android-N/master --empty-commit manifest;
               
  2. 添加default.xml(一般擷取到的源碼的./repo/repo/manifest有,可以直接拿來用)
    建立repo倉庫管理Android源碼
    git clone -bare ssh://192.168.15.128:29418/manifest -b Android-N/master
     cd manifest && scp -p -P 29418 [email protected]:hooks/commit-msg .git/hooks/
     
     cp ../share/default.xml .
     git commit -m "init default.xml"
     git push origin HEAD:refs/for/Android-N/master
               

同步代碼

repo init -u ssh://192.168.15.128:29418/manifest.git -b Android-N/master
repo sync
建立本地mater分支(必須)
repo start master --all
           

轉載請注明出處:http://www.wolfnx.com/2020/06/14/Android-Repo

作者 : wolfnx

郵箱 : [email protected]

郵箱2 : [email protected]