0%

repo manifest 使用指南

使用 repo 管理工程源码及分支,需要对 manfiest.xml 有深入了解,本文记录主要关注点

repo

repo init -u $URL -b $BRANCH -m $MANIFEST 相当于执行如下命令队列

  mkdir .repo
  cd .repo
  git clone https://android.googlesource.com/tools/repo
  git clone --bare $URL manifests.git
  mkdir -p manifests/.git; cd manifests/.git
  for i in ../../manifests.git/*; do ln -s $ı .; done
  cd ..
  git checkout $BRANCH -- .
  cd ..
  ln -s manifests/$MANIFEST manifest.xml

manfiest.xml

repo v1.3

<!DOCTYPE manifest [
  <!ELEMENT manifest (remote*,
                      default?,
                      project*,
                      add-remote*)>
  <!ELEMENT remote (EMPTY)>
  <!ATTLIST remote name         ID    #REQUIRED>
  <!ATTLIST remote fetch        CDATA #REQUIRED>
  <!ATTLIST remote review       CDATA #IMPLIED>
  <!ATTLIST remote project-name CDATA #IMPLIED>
  <!ELEMENT default (EMPTY)>
  <!ATTLIST default remote   IDREF #IMPLIED>
  <!ATTLIST default revision CDATA #IMPLIED>
  <!ELEMENT project (remote*)>
  <!ATTLIST project name     CDATA #REQUIRED>
  <!ATTLIST project path     CDATA #IMPLIED>
  <!ATTLIST project remote   IDREF #IMPLIED>
  <!ATTLIST project revision CDATA #IMPLIED>
  <!ELEMENT add-remote (EMPTY)>
  <!ATTLIST add-remote to-project   ID    #REQUIRED>
  <!ATTLIST add-remote name         ID    #REQUIRED>
  <!ATTLIST add-remote fetch        CDATA #REQUIRED>
  <!ATTLIST add-remote review       CDATA #IMPLIED>
  <!ATTLIST add-remote project-name CDATA #IMPLIED>
]>

需要关注 remotedefaultproject

manfiest 示例

<manifest>
    <remote  name="aosp"
            fetch="https://android.googlesource.com/"/>
    <remote  name="udinic"
            fetch="https://github.com/udinic/"/>

    <default revision="master"
            remote="aosp"
            sync-j="4" />

    <project path="art" name="platform/art" />
    <project path="bionic" name="platform/bionic" groups="pdk" />
    <project path="dalvik" name="platform_dalvik” remote=“udinic”/>
    <project path="frameworks/base" name="platform_frameworks_base" remote=“udinic" revision=“statusbar_fixes"/>
    <project path="tools/adt/eclipse" name="platform/tools/adt/eclipse" groups="notdefault,tools" />
</manifest>

remote

<remote> 指定 remote 地址,可以有多个,可以使用 name 进行区分,主要参数如下

  • name,必须
  • fetch,必须,The Git URL prefix for all projects which use this remote.
  • review,代码评审地址

例如

    <remote  name="aosp"
            fetch="https://android.googlesource.com/"/>
            review="https://android.googlesource.com/review"/>
    <remote  name="udinic"
            fetch="https://github.com/udinic/"/>
            fetch="https://192.168.110.10/review"/>
    <remote  name="test"
            fetch="https://github.com/test/"/>

default

<default> 为可选项,指定默认 <remote>,主要设置参数如下:

  • remote 选择指定 <remote>
  • revision 指定默认 revision,包括 branchtag,例如 masterdevrefs/tags/v1.0.1

project

<project> 指定工程,主要参数如下

  • name 远程相对与 remote 地址的路径,必须项
  • path 本地相对路径,不指定的话表示和 name 相同
  • remote 选择 <remote>
  • revision 选择指定分支或 tag
  • copyfile 复制文件

将工程下的 make.sh 复制到根目录

<project path="tools"               name="test" >
  <copyfile src="make.sh" dest="make.sh" />
</project>

Example

实现意图, repo 管理两部分代码,一部分为私有代码,另外一部分为公共代码,位于不同的分支,修改 manfiest.xml 如下

<manifest>
    <remote  name="aosp"
            fetch="https://android.googlesource.com/"/>
    <remote  name="udinic"
            fetch="https://github.com/udinic/"/>

    <default revision="master"
            remote="aosp"
            sync-j="4" />

    <project path="art" name="platform/art" />
    <project path="bionic" name="platform/bionic" groups="pdk" />
    <project path="dalvik" name="platform_dalvik” remote=“udinic”/>
    <project path="frameworks/base" name="platform_frameworks_base" remote=“udinic" revision=“statusbar_fixes"/>
    <project path="tools/adt/eclipse" name="platform/tools/adt/eclipse" groups="notdefault,tools" />
</manifest>

未指定 revisionproject 下载 default 指定的 master 分支

建立分支或 tag

repo 管理下建立 branchtag,主要是管理 manfiest 以及 project 各个仓库

branch

  1. 管理 manfiest,克隆 git 仓库之后,根据 source 建立 release 分支,并修改 default.xml 跟踪 refs/tags/$RELEASE,推送 branchtag 到服务器
    git clone ssh://git@192.168.110.10/manifests.git
    git co origin/$SOURCE -b $RELEASE
    sed -i "s/\"$SOURCE\"/\"refs\/tags\/$RELEASE\"/g" ./default.xml
    git ci -m "$RELEASE" -a
    git push --all
  2. 管理 project,根据 SOURCE 迁出代码,然后上传 tag 信息
    git tag $RELEASE
    git push $SOURCE --tags

Ref

  1. 把已有的 repo 工程提交到服务器
  2. Learn about the repo tool , manifests and local manifests and 5 important tips !
  3. Get the code using the Manifest and Repo tool
  4. Repo Cheatsheet
  5. repo Manifest Format
  6. manifest-format.txt