谷歌对android的源代码管理使用的是git。但是在git的基础上,谷歌开发出来了一套新的工具,python写的一套脚本,名字是repo。
Android源代码工程(AOSP)是非常多的git仓库组成的。目前估计有上百个独立的git仓库。
怎么管理这些仓库呢?使用一个清单文件(maniest.xml)来管理每个仓库。
这个xml也需要个仓库存放来管理,就是manifest.git 仓库。
那怎么来下载一套aosp的代码呢?就是使用repo工具,通过manifest.xml 来下载所有的仓库,所有的代码。
到目前为止,我们提到了三种类型的Git仓库,分别是Repo仓库、Manifest仓库和AOSP子项目仓库。Repo仓库通过Manifest仓库可以获得所有AOSP子项目仓库的元信息。有了这些元信息之后,我们就可以通过Repo仓库里面的Python脚本来操作AOSP的子项目。
repo是个工具仓库,这个工具仓库中有个一个文件,名字是repo。这个是一个引导脚本。我们一般会使用这个引导脚本来把整个repo仓库下载下来,整个仓库有了才会有整个功能。一个单一的repo文件里面代码有限的,功能有限的。
manifest是一个管理xml的仓库,每个xml里面都是列的谷歌各个子项目git的相关信息。
#安装Repo
一个repo文件,python写的。几百行代码。
可以从清华aosp镜像网站git clone下一个整个仓库。然后把仓库里面的repo文件复制到 /usr/local/bin 目录下面。
https://aosp.tuna.tsinghua.edu.cn/tools/repo
$ git clone https://aosp.tuna.tsinghua.edu.cn/tools/repo
Cloning into 'repo'...
remote: Counting objects: 3967, done.
remote: Compressing objects: 100% (1798/1798), done.
remote: Total 3967 (delta 2555), reused 3392 (delta 2108)
Receiving objects: 100% (3967/3967), 1.97 MiB | 820.00 KiB/s, done.
Resolving deltas: 100% (2555/2555), done.
我们可以看到repo仓库里面的所有的文件,其中有一个repo文件。
$ tree repo
repo
├── color.py
├── command.py
├── COPYING
├── docs
│ └── manifest-format.txt
├── editor.py
├── error.py
├── event_log.py
├── git_command.py
├── git_config.py
├── gitc_utils.py
├── git_refs.py
├── git_ssh
├── hooks
│ ├── commit-msg
│ └── pre-auto-gc
├── main.py
├── manifest_xml.py
├── pager.py
├── platform_utils.py
├── platform_utils_win32.py
├── progress.py
├── project.py
├── pyversion.py
├── README.md
├── repoM
├── subcmds
│ ├── abandon.py
│ ├── branches.py
│ ├── checkout.py
│ ├── cherry_pick.py
│ ├── diffmanifests.py
│ ├── diff.py
│ ├── download.py
│ ├── forall.py
│ ├── gitc_delete.py
│ ├── gitc_init.py
│ ├── grep.py
│ ├── help.py
│ ├── info.py
│ ├── __init__.py
│ ├── init.py
│ ├── list.py
│ ├── manifest.py
│ ├── overview.py
│ ├── prune.py
│ ├── rebase.py
│ ├── selfupdate.py
│ ├── smartsync.py
│ ├── stage.py
│ ├── start.py
│ ├── status.py
│ ├── sync.py
│ ├── upload.py
│ └── version.py
├── SUBMITTING_PATCHES.md
├── tests
│ ├── fixtures
│ │ ├── gitc_config
│ │ └── test.gitconfig
│ ├── test_git_config.py
│ └── test_wrapper.py
├── trace.py
└── wrapper.py
5 directories, 59 files
安装完成repo命令就可以执行一下。会输出一些帮助信息的。
$ repo
usage: repo COMMAND [ARGS]
The most commonly used repo commands are:
abandon Permanently abandon a development branch
branch View current topic branches
branches View current topic branches
checkout Checkout a branch for development
cherry-pick Cherry-pick a change.
diff Show changes between commit and working tree
diffmanifests Manifest diff utility
download Download and checkout a change
grep Print lines matching a pattern
info Get info on the manifest branch, current branch or unmerged branches
init Initialize repo in the current directory
list List projects and their associated directories
overview Display overview of unmerged project branches
prune Prune (delete) already merged topics
rebase Rebase local branches on upstream branch
smartsync Update working tree to the latest known good revision
stage Stage file(s) for commit
start Start a new branch for development
status Show the working tree status
sync Update working tree to the latest revision
upload Upload changes for code review
See 'repo help <command>' for more information on a specific command.
See 'repo help --all' for a complete list of recognized commands.
我们在一个已经repo init过的目录下面执行会显示帮助信息的,每个列出来的都是一个repo的子命令。
和git类似,git clone,其中clone是git的一个子命令,每个子命令又有许多选项参数等。repo 也是类似的。
一般的我们常用的就是 repo init 和 repo sync 2个命令。
#repo init
repo脚本安装好了我们就可以下载aosp代码。首先是新建个目录,然后执行repo init命令。也就是对这个空目录进行初始化。
在初始化过程中会把完整的repo仓库下载下来,完整的repo仓库会有更多其他功能,其他子命令,其他选项等。
$ repo
error: repo is not installed. Use "repo init" to install it here.
随便一个目录执行repo命令是会保持的,然后会提示你先 repo init 安装,这个安装就是会安装到当前目录,在当前目录下面的.repo 目录。一个隐藏目录。
建立工作目录:
mkdir aosp && cd aosp
初始化仓库:
一般的是这样一个简单的命令:
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
但是呢国内是不行的。这个命令中-u后面跟的就是一个manifest清单仓库。一般叫manifest名。这个仓库名可以是其他的,通常不会改。
repo init -u https://source.codeaurora.org/quic/la/platform/manifest.git \
-b release -m LA.UM.6.6.r1-02700-89xx.0.xml \
--repo-url=https://aosp.tuna.tsinghua.edu.cn/tools/repo \
--repo-branch=stable
#repo init的选项
$ repo init -h
Usage: repo init -u url [options]
Options:
-h, --help show this help message and exit
Logging options:
-q, --quiet be quiet
Manifest options:
-u URL, --manifest-url=URL
manifest repository location
-b REVISION, --manifest-branch=REVISION
manifest branch or revision
-m NAME.xml, --manifest-name=NAME.xml
initial manifest file
--mirror create a replica of the remote repositories rather
than a client working directory
--reference=DIR location of mirror directory
--depth=DEPTH create a shallow clone with given depth; see git clone
--archive checkout an archive instead of a git repository for
each project. See git archive.
-g GROUP, --groups=GROUP
restrict manifest projects to ones with specified
group(s) [default|all|G1,G2,G3|G4,-G5,-G6]
-p PLATFORM, --platform=PLATFORM
restrict manifest projects to ones with a specified
platform group [auto|all|none|linux|darwin|...]
--no-clone-bundle disable use of /clone.bundle on HTTP/HTTPS
repo Version options:
--repo-url=URL repo repository location
--repo-branch=REVISION
repo branch or revision
--no-repo-verify do not verify repo source code
Other options:
--config-name Always prompt for name/e-mail
我们还拿之前那个高通的下载代码的命令来讲。基本上常用的选项都用上了。
repo init -u https://source.codeaurora.org/quic/la/platform/manifest.git \
-b release -m LA.UM.6.6.r1-02700-89xx.0.xml \
--repo-url=https://aosp.tuna.tsinghua.edu.cn/tools/repo \
--repo-branch=stable