目录

一,背景介绍

二,repo配置

2.1 创建仓库

2.2  gerrit服务器上创建manifests仓库

三,aosp代码上传

四,代码下载


一,背景介绍

        Android源码是基于Linux的开源操作系统,目前Android ROM开发的代码管理工具基本上是采用Git。由于Android代码非常复杂,Google将其划分为多个git repo,这样不仅可以避免一个repo的代码太多,还可以根据repo的功能将其分配给不同团队进行管控。为了对Android代码质量进行管控,Google采用了Gerrit进行coderview,并利用jenkins做代码静态检测和自动化验证,当然还有集成CI工具。
        作为Android ROM相关的开发者,有必要了解什么是Gerrit,Gerrit的工作流程是怎么样的,Gerrit服务器怎么搭建,以及如何将Android codebase导入自己的Gerrit服务器。接下来本文将为大家详细解答以上问题。

二,repo配置

2.1 创建仓库

在gerrit的ubuntu服务器上,执行以下脚本,前提是gerrit本地服务已正常启动,说明文档见《Gerrit搭建》

#!/bin/bash

USER_NAME="admin"

SERVER_IP="10.119.*.*"

SERVER_PORT="29418"

PROJECT_DIR="test-test"

function creatEmptyGerritProject()

{

for i in `cat pro_path.log`;

do

echo $i

echo "ssh -p $SERVER_PORT $USER_NAME@$SERVER_IP gerrit create-project --empty-commit $PROJECT_DIR/$i"

ssh -p $SERVER_PORT $USER_NAME@$SERVER_IP gerrit create-project --empty-commit $PROJECT_DIR/$i

done

}

creatEmptyGerritProject

参数说明,

USER_NAME="admin",为gerrit账户名

SERVER_IP="10.119.*.*",为gerrit的ip服务器

SERVER_PORT="29418",为gerrit服务固定端口

PROJECT_DIR="test-test",为gerrit仓库名字

2.2  gerrit服务器上创建manifests仓库

  1,通过下面命令,在gerrit服务器上创建manifests仓库,命令既可以在服务器本地执行,也可以在远端客户端执行。

$ ssh -p 29418 username@ipaddress gerrit create-project --empty-commit projectName/manifests

        其中,username为gerrit账户,ipaddress为gerrit服务器地址,projectName为gerrit上创建的repo库。

2,gerrit服务器的根目录下创建bin文件夹,

$ mkdir ~/bin

3,在bin目录下将刚创建的远程manifests仓库拉取下来

$ git clone ssh://username@ipaddress:29418/projectName/manifests

4,将现有目录(aosp源码)下的aosp_common和default.xml复制到拉取下来的manifests

$ cp * ~/bin/manifests
$ cd ~/bin/manifests
$ git add .
$ git commit –m 'add manifests'
$ git push origin master

5,在~/bin目录下载repo

$ curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
$ chmod +x repo

6,修改repo文件中的REPO_URL

$ export REPO_URL=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo

7,gerrit添加公钥

$ git config –global user.name 用户名
$ git config –global user.email 邮箱地址
$ ssh-keygen -t rsa -C 邮箱地址  (一路回车啥也别输入)
拷贝 .ssh/id_rsa.pub 里面内容,粘贴到gerrit的Settings SSH Public Keys

三,aosp代码上传

        在aosp源码的根目录下,执行以下命令,

#!/bin/bash

USER_NAME="admin"

SERVER_IP="10.119.*.*"

SERVER_PORT="29418"

PROJECT_DIR="test-test"

function pushGerritProject()

{

file="pro_path.log"

lines=`cat $file | wc -l`

for ((i=1;i<=$lines;i++))

do

line=`awk 'NR=="'$i'"{print $0}' $file`

cd $line

echo `pwd`

rm -rf .git

git init

git remote add aosp ssh://$USER_NAME@$SERVER_IP:$SERVER_PORT/$PROJECT_DIR/$line.git

git pull aosp master

git add -A .

git commit -am "init commit"

git push aosp master

cd -

done

}

pushGerritProject

        其中,pro_path.log文件为aosp源码的 /.repo/project.list文件,为repo管理的git地址库列表,

art
bionic
bootable/recovery
build/blueprint
build/make
build/soong
compatibility/cdd
cts
dalvik
developers/build
developers/demos
developers/samples/android
development
device/amlogic/yukawa
device/amlogic/yukawa-kernel
device/common
device/generic/arm64
device/generic/armv7-a-neon
device/generic/art
device/generic/car
device/generic/common
device/generic/goldfish
device/generic/goldfish-opengl
device/generic/mini-emulator-arm64
device/generic/mini-emulator-armv7-a-neon
device/generic/mini-emulator-x86
device/generic/mini-emulator-x86_64
device/generic/opengl-transport
device/generic/qemu
device/generic/trusty
device/generic/uml
device/generic/x86
device/generic/x86_64
device/google/atv
device/google/bonito
device/google/bonito-kernel
device/google/bonito-sepolicy
device/google/bramble
device/google/bramble-sepolicy
device/google/contexthub
device/google/coral
device/google/coral-kernel
device/google/coral-sepolicy
device/google/crosshatch
device/google/crosshatch-kernel
device/google/crosshatch-sepolicy
device/google/cuttlefish
device/google/cuttlefish_kernel
device/google/cuttlefish_vmm
device/google/fuchsia
device/google/redbull
device/google/redbull-kernel
device/google/redbull-sepolicy
device/google/redfin
device/google/redfin-sepolicy
device/google/sunfish
device/google/sunfish-kernel
device/google/sunfish-sepolicy
device/google/trout
device/google/vrservices
device/google_car
device/linaro/bootloader/OpenPlatformPkg
device/linaro/bootloader/arm-trusted-firmware
device/linaro/bootloader/edk2
device/linaro/dragonboard
device/linaro/dragonboard-kernel
device/linaro/hikey
device/linaro/hikey-kernel
device/linaro/poplar
device/linaro/poplar-kernel
device/mediatek/wembley-sepolicy
device/sample
device/ti/beagle_x15
device/ti/beagle_x15-kernel
external/FP16
external/FXdiv
external/ImageMagick
external/OpenCL-CTS
external/OpenCSD
external/Reactive-Extensions/RxCpp
external/XNNPACK
external/aac
external/adeb
external/adhd
external/android-clat
external/androidplot
external/angle
external/ant-glob
external/antlr
external/apache-commons-bcel
external/apache-commons-compress
external/apache-commons-math
external/apache-harmony
external/apache-http
external/apache-xml
external/arm-neon-tests
external/arm-optimized-routines
external/arm-trusted-firmware
external/autotest
external/avb
external/bc
external/bcc
external/blktrace
external/boringssl
external/bouncycastle
external/brotli
external/bsdiff
external/bzip2
external/caliper
external/capstone
external/catch2
external/cblas
external/cbor-java
external/chromium-libpac
external/chromium-trace
external/chromium-webview
external/clang
external/cldr
external/cn-cbor
external/compiler-rt
external/conscrypt
external/cpu_features
external/cpuinfo
external/crcalc
external/cros/system_api
external/crosvm
external/curl
external/dagger2
external/deqp
external/deqp-deps/SPIRV-Headers
external/deqp-deps/SPIRV-Tools
external/deqp-deps/amber
external/deqp-deps/glslang
external/desugar
external/dexmaker
external/dlmalloc
external/dng_sdk
external/dnsmasq
external/doclava
external/dokka
external/drm_hwcomposer
external/drrickorang
external/dtc
external/dynamic_depth
external/e2fsprogs
external/easymock
external/eigen
external/elfutils
external/emma
external/error_prone
external/ethtool
external/exoplayer
external/expat
external/f2fs-tools
external/fastrpc
external/fdlibm
external/fec
external/flac
external/flatbuffers
external/fmtlib
external/fonttools
external/freetype
external/fsck_msdos
external/fsverity-utils
external/gemmlowp
external/gflags
external/giflib
external/glide
external/golang-protobuf
external/google-benchmark
external/google-breakpad
external/google-fonts/arbutus-slab
external/google-fonts/arvo
external/google-fonts/barlow
external/google-fonts/big-shoulders-text
external/google-fonts/carrois-gothic-sc
external/google-fonts/coming-soon
external/google-fonts/cutive-mono
external/google-fonts/dancing-script
external/google-fonts/fraunces
external/google-fonts/karla
external/google-fonts/lato
external/google-fonts/lustria
external/google-fonts/rubik
external/google-fonts/source-sans-pro
external/google-fonts/zilla-slab
external/google-fruit
external/google-styleguide
external/googletest
external/gptfdisk
external/grpc-grpc
external/grpc-grpc-java
external/guava
external/guice
external/gwp_asan
external/hamcrest
external/harfbuzz_ng
external/honggfuzz
external/hyphenation-patterns
external/icu
external/igt-gpu-tools
external/image_io
external/ims
external/iperf3
external/iproute2
external/ipsec-tools
external/iptables
external/iputils
external/iw
external/jacoco
external/jarjar
external/javaparser
external/javapoet
external/javasqlite
external/jcommander
external/jdiff
external/jemalloc
external/jemalloc_new
external/jline
external/jsilver
external/jsmn
external/jsoncpp
external/jsr305
external/jsr330
external/junit
external/junit-params
external/kernel-headers
external/kmod
external/kotlinc
external/kotlinx.coroutines
external/ksoap2
external/libaom
external/libavc
external/libbackup
external/libbrillo
external/libcap
external/libcap-ng
external/libchrome
external/libcups
external/libcxx
external/libcxxabi
external/libdaemon
external/libdivsufsort
external/libdrm
external/libepoxy
external/libese
external/libevent
external/libexif
external/libffi
external/libfuse
external/libgav1
external/libgsm
external/libhevc
external/libiio
external/libjpeg-turbo
external/libkmsxx
external/libldac
external/libmpeg2
external/libnetfilter_conntrack
external/libnfnetlink
external/libnl
external/libogg
external/libopus
external/libpcap
external/libphonenumber
external/libpng
external/libprotobuf-mutator
external/libsrtp2
external/libtextclassifier
external/libunwind
external/libunwind_llvm
external/libusb
external/libutf
external/libvpx
external/libvterm
external/libxaac
external/libxkbcommon
external/libxml2
external/libyuv
external/linux-kselftest
external/llvm
external/lmfit
external/ltp
external/lua
external/lz4
external/lzma
external/markdown
external/mdnsresponder
external/mesa3d
external/mime-support
external/minigbm
external/minijail
external/mksh
external/mockftpserver
external/mockito
external/mockwebserver
external/modp_b64
external/mp4parser
external/mtpd
external/nanohttpd
external/nanopb-c
external/naver-fonts
external/neon_2_sse
external/neven
external/newfs_msdos
external/nfacct
external/nist-pkits
external/nist-sip
external/nos/host/generic
external/noto-fonts
external/oauth
external/objenesis
external/oj-libjdwp
external/okhttp
external/one-true-awk
external/opencensus-java
external/openssh
external/oss-fuzz
external/owasp/sanitizer
external/parameter-framework
external/pcre
external/pdfium
external/perfetto
external/piex
external/ply
external/ppp
external/proguard
external/protobuf
external/psimd
external/pthreadpool
external/puffin
external/python/apitools
external/python/asn1crypto
external/python/cffi
external/python/cpython2
external/python/cpython3
external/python/cryptography
external/python/dateutil
external/python/enum34
external/python/funcsigs
external/python/futures
external/python/google-api-python-client
external/python/httplib2
external/python/ipaddress
external/python/mock
external/python/oauth2client
external/python/parse_type
external/python/pyasn1
external/python/pyasn1-modules
external/python/pybind11
external/python/pycparser
external/python/pyopenssl
external/python/rsa
external/python/setuptools
external/python/six
external/python/uritemplates
external/rappor
external/replicaisland
external/rmi4utils
external/robolectric-shadows
external/roboto-fonts
external/rootdev
external/rust/crates/byteorder
external/rust/crates/libc
external/rust/crates/proc-macro2
external/rust/crates/quote
external/rust/crates/remain
external/rust/crates/syn
external/rust/crates/unicode-xid
external/scapy
external/scrypt
external/scudo
external/seccomp-tests
external/selinux
external/setupcompat
external/setupdesign
external/sfntly
external/shaderc/spirv-headers
external/shflags
external/skia
external/skqp
external/sl4a
external/slf4j
external/smali
external/snakeyaml
external/sonic
external/sonivox
external/speex
external/sqlite
external/squashfs-tools
external/strace
external/stressapptest
external/subsampling-scale-image-view
external/swiftshader
external/tagsoup
external/tcpdump
external/tensorflow
external/testng
external/tinyalsa
external/tinycompress
external/tinyxml
external/tinyxml2
external/toolchain-utils
external/toybox
external/tremolo
external/turbine
external/u-boot
external/ukey2
external/unicode
external/universal-tween-engine
external/v4l2_codec2
external/v8
external/vboot_reference
external/virglrenderer
external/vixl
external/vogar
external/volley
external/vulkan-headers
external/vulkan-validation-layers
external/walt
external/wayland
external/wayland-protocols
external/webp
external/webrtc
external/wpa_supplicant_8
external/wycheproof
external/xmp_toolkit
external/xz-embedded
external/xz-java
external/yapf
external/zlib
external/zopfli
external/zxing
frameworks/av
frameworks/base
frameworks/compile/libbcc
frameworks/compile/mclinker
frameworks/compile/slang
frameworks/ex
frameworks/hardware/interfaces
frameworks/layoutlib
frameworks/libs/modules-utils
frameworks/libs/native_bridge_support
frameworks/libs/net
frameworks/libs/systemui
frameworks/minikin
frameworks/ml
frameworks/multidex
frameworks/native
frameworks/opt/bitmap
frameworks/opt/calendar
frameworks/opt/car/services
frameworks/opt/car/setupwizard
frameworks/opt/chips
frameworks/opt/colorpicker
frameworks/opt/localepicker
frameworks/opt/net/ethernet
frameworks/opt/net/ims
frameworks/opt/net/voip
frameworks/opt/net/wifi
frameworks/opt/photoviewer
frameworks/opt/setupwizard
frameworks/opt/telephony
frameworks/opt/timezonepicker
frameworks/opt/tv/tvsystem
frameworks/opt/vcard
frameworks/rs
frameworks/wilhelm
hardware/broadcom/libbt
hardware/broadcom/wlan
hardware/google/apf
hardware/google/av
hardware/google/camera
hardware/google/easel
hardware/google/interfaces
hardware/google/pixel
hardware/google/pixel-sepolicy
hardware/interfaces
hardware/invensense
hardware/knowles/athletico/sound_trigger_hal
hardware/libhardware
hardware/libhardware_legacy
hardware/nxp/nfc
hardware/nxp/secure_element
hardware/qcom/audio
hardware/qcom/bootctrl
hardware/qcom/bt
hardware/qcom/camera
hardware/qcom/data/ipacfg-mgr
hardware/qcom/display
hardware/qcom/gps
hardware/qcom/keymaster
hardware/qcom/media
hardware/qcom/msm8960
hardware/qcom/msm8994
hardware/qcom/msm8996
hardware/qcom/msm8x09
hardware/qcom/msm8x26
hardware/qcom/msm8x27
hardware/qcom/msm8x84
hardware/qcom/power
hardware/qcom/sdm845/bt
hardware/qcom/sdm845/data/ipacfg-mgr
hardware/qcom/sdm845/display
hardware/qcom/sdm845/gps
hardware/qcom/sdm845/media
hardware/qcom/sdm845/thermal
hardware/qcom/sdm845/vr
hardware/qcom/sm7150/gps
hardware/qcom/sm7250/display
hardware/qcom/sm7250/gps
hardware/qcom/sm7250/media
hardware/qcom/sm8150/data/ipacfg-mgr
hardware/qcom/sm8150/display
hardware/qcom/sm8150/gps
hardware/qcom/sm8150/media
hardware/qcom/sm8150/thermal
hardware/qcom/sm8150/vr
hardware/qcom/sm8150p/gps
hardware/qcom/wlan
hardware/ril
hardware/st/nfc
hardware/st/secure_element
hardware/ti/am57x
kernel/configs
kernel/prebuilts/4.19/arm64
kernel/tests
libcore
libnativehelper
packages/apps/BasicSmsReceiver
packages/apps/Bluetooth
packages/apps/Browser2
packages/apps/Calendar
packages/apps/Camera2
packages/apps/Car/Calendar
packages/apps/Car/Cluster
packages/apps/Car/Dialer
packages/apps/Car/Hvac
packages/apps/Car/LatinIME
packages/apps/Car/Launcher
packages/apps/Car/LinkViewer
packages/apps/Car/LocalMediaPlayer
packages/apps/Car/Media
packages/apps/Car/Messenger
packages/apps/Car/Notification
packages/apps/Car/Radio
packages/apps/Car/RotaryController
packages/apps/Car/Settings
packages/apps/Car/SystemUpdater
packages/apps/Car/libs
packages/apps/Car/tests
packages/apps/CarrierConfig
packages/apps/CellBroadcastReceiver
packages/apps/CertInstaller
packages/apps/Contacts
packages/apps/DeskClock
packages/apps/DevCamera
packages/apps/Dialer
packages/apps/DocumentsUI
packages/apps/EmergencyInfo
packages/apps/Gallery
packages/apps/Gallery2
packages/apps/HTMLViewer
packages/apps/KeyChain
packages/apps/Launcher3
packages/apps/LegacyCamera
packages/apps/ManagedProvisioning
packages/apps/Messaging
packages/apps/Music
packages/apps/MusicFX
packages/apps/Nfc
packages/apps/OnDeviceAppPrediction
packages/apps/OneTimeInitializer
packages/apps/PermissionController
packages/apps/PhoneCommon
packages/apps/Protips
packages/apps/Provision
packages/apps/QuickAccessWallet
packages/apps/QuickSearchBox
packages/apps/SafetyRegulatoryInfo
packages/apps/SampleLocationAttribution
packages/apps/SecureElement
packages/apps/Settings
packages/apps/SettingsIntelligence
packages/apps/SoundRecorder
packages/apps/SpareParts
packages/apps/Stk
packages/apps/StorageManager
packages/apps/TV
packages/apps/Tag
packages/apps/Terminal
packages/apps/Test/connectivity
packages/apps/ThemePicker
packages/apps/TimeZoneData
packages/apps/TimeZoneUpdater
packages/apps/Traceur
packages/apps/TvSettings
packages/apps/UniversalMediaPlayer
packages/apps/WallpaperPicker
packages/apps/WallpaperPicker2
packages/inputmethods/LatinIME
packages/inputmethods/LeanbackIME
packages/modules/ArtPrebuilt
packages/modules/CaptivePortalLogin
packages/modules/CellBroadcastService
packages/modules/Cronet
packages/modules/DnsResolver
packages/modules/ExtServices
packages/modules/IPsec
packages/modules/ModuleMetadata
packages/modules/NetworkPermissionConfig
packages/modules/NetworkStack
packages/modules/SdkExtensions
packages/modules/TestModule
packages/modules/vndk
packages/providers/BlockedNumberProvider
packages/providers/BookmarkProvider
packages/providers/CalendarProvider
packages/providers/CallLogProvider
packages/providers/ContactsProvider
packages/providers/DownloadProvider
packages/providers/MediaProvider
packages/providers/PartnerBookmarksProvider
packages/providers/TelephonyProvider
packages/providers/TvProvider
packages/providers/UserDictionaryProvider
packages/screensavers/Basic
packages/screensavers/PhotoTable
packages/services/AlternativeNetworkAccess
packages/services/BuiltInPrintService
packages/services/Car
packages/services/Mms
packages/services/Mtp
packages/services/Telecomm
packages/services/Telephony
packages/wallpapers/ImageWallpaper
packages/wallpapers/LivePicker
pdk
platform_testing
prebuilts/abi-dumps/ndk
prebuilts/abi-dumps/platform
prebuilts/abi-dumps/vndk
prebuilts/android-emulator
prebuilts/asuite
prebuilts/build-tools
prebuilts/bundletool
prebuilts/checkcolor
prebuilts/checkstyle
prebuilts/clang-tools
prebuilts/clang/host/darwin-x86
prebuilts/clang/host/linux-x86
prebuilts/cmdline-tools
prebuilts/devtools
prebuilts/fuchsia_sdk
prebuilts/gcc/darwin-x86/aarch64/aarch64-linux-android-4.9
prebuilts/gcc/darwin-x86/arm/arm-linux-androideabi-4.9
prebuilts/gcc/darwin-x86/host/i686-apple-darwin-4.2.1
prebuilts/gcc/darwin-x86/mips/mips64el-linux-android-4.9
prebuilts/gcc/darwin-x86/x86/x86_64-linux-android-4.9
prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9
prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8
prebuilts/gcc/linux-x86/host/x86_64-w64-mingw32-4.8
prebuilts/gcc/linux-x86/mips/mips64el-linux-android-4.9
prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9
prebuilts/gdb/darwin-x86
prebuilts/gdb/linux-x86
prebuilts/go/darwin-x86
prebuilts/go/linux-x86
prebuilts/gradle-plugin
prebuilts/jdk/jdk11
prebuilts/jdk/jdk8
prebuilts/jdk/jdk9
prebuilts/ktlint
prebuilts/manifest-merger
prebuilts/maven_repo/android
prebuilts/maven_repo/bumptech
prebuilts/misc
prebuilts/module_sdk/art
prebuilts/ndk
prebuilts/python/darwin-x86/2.7.5
prebuilts/python/linux-x86/2.7.5
prebuilts/qemu-kernel
prebuilts/r8
prebuilts/remoteexecution-client
prebuilts/runtime
prebuilts/rust
prebuilts/sdk
prebuilts/tools
prebuilts/vndk/v27
prebuilts/vndk/v28
prebuilts/vndk/v29
sdk
system/apex
system/bpf
system/bpfprogs
system/bt
system/ca-certificates
system/chre
system/connectivity/wificond
system/connectivity/wifilogd
system/core
system/extras
system/gatekeeper
system/gsid
system/hardware/interfaces
system/hwservicemanager
system/incremental_delivery
system/iorap
system/keymaster
system/libartpalette
system/libfmq
system/libhidl
system/libhwbinder
system/libsysprop
system/libufdt
system/libvintf
system/linkerconfig
system/media
system/memory/libion
system/memory/libmeminfo
system/memory/libmemtrack
system/memory/libmemunreachable
system/memory/lmkd
system/netd
system/nfc
system/nvram
system/security
system/sepolicy
system/server_configurable_flags
system/teeui
system/testing/gtest_extras
system/timezone
system/tools/aidl
system/tools/hidl
system/tools/mkbootimg
system/tools/sysprop
system/tools/xsdc
system/update_engine
system/vold
test/app_compat/csuite
test/framework
test/mlts/benchmark
test/mlts/models
test/mts
test/suite_harness
test/vti/dashboard
test/vti/fuzz_test_serving
test/vti/test_serving
test/vts
test/vts-testcase/fuzz
test/vts-testcase/hal
test/vts-testcase/hal-trace
test/vts-testcase/kernel
test/vts-testcase/nbu
test/vts-testcase/performance
test/vts-testcase/security
test/vts-testcase/vndk
toolchain/benchmark
toolchain/pgo-profiles
tools/acloud
tools/apifinder
tools/apksig
tools/apkzlib
tools/asuite
tools/carrier_settings
tools/currysrc
tools/dexter
tools/doc_generation
tools/external/fat32lib
tools/external_updater
tools/loganalysis
tools/metalava
tools/ndkports
tools/platform-compat
tools/repohooks
tools/security
tools/test/connectivity
tools/test/graphicsbenchmark
tools/tradefederation/contrib
tools/tradefederation/core
tools/treble
tools/trebuchet

四,代码下载

        在第三部分上传完aosp后,在工作目录~/aosp_repo

#在工作目录~/aosp_repo下,repo初始化

$ mkdir aosp_repo
$ repo init -u ssh://username@ipaddress:29418/projectname/manifests
$ repo sync


​

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐