google的chromium項目是用gclient來管理源碼的checkout, update等。 gclient是google專門為這種多源項目編寫的腳本,它可以將多個源碼管理系統中的代碼放在一起管理。甚至包括將Git和svn代碼放在一起。
webrtc也是使用gclient管理代碼.
gclient的sync,update等命令密切相關的兩類文件.gclient和DEPS。
.gclient文件是gclient的控制文件,該文件放在工作目錄的最上層(webrtc環境下與src統計目錄)。".gclient"文件是一個Python的腳本,定義了一組"solutions",格式類似如下
solutions = [
{ "name" : "src",
"url" : "svn://svnserver/component/trunk/src",
"custom_deps" : {
# To use the trunk of a component instead of what's in DEPS:
#"component": "https://svnserver/component/trunk/",
# To exclude a component from your working copy:
#"data/really_large_component": None,
}
},
]
- name:checkout出源碼的名字
- url:源碼所在的目錄,gclient希望checkout出的源碼中包括一個DEPS的文件,這個文件包含了必須checkout到工作目錄的源碼信息;
- deps_file:這是一個文件名(不包括路徑),指在工程目錄中包含依賴列表的文件,該項可選,默認值為"DEPS"
-
custom_deps:這是一個可選的字典對象,會覆蓋工程的"DEPS"文件定義的條目.一般它用作本地目錄中,那些不用checkout的代碼,或者讓本地目錄從不同位置checkout一個新的代碼出來,或者checkout不同的分支,版本等.也可以用於增加在DEPS中不存在的新的項目.如:
"custom_deps": { "src/content/test/data/layout_tests/LayoutTests": None, "src/chrome/tools/test/reference_build/chrome_win": None, "src/chrome_frame/tools/test/reference_build/chrome_win": None, "src/chrome/tools/test/reference_build/chrome_linux": None, "src/chrome/tools/test/reference_build/chrome_mac": None, "src/third_party/hunspell_dictionaries": None, }, -
target_os:這個可選的條目可以指出特殊的平台,根據平台類checkout出不同代碼,如:
target_os = ['android']如果target_os_only值為True的話,那麼,僅僅checkout出對應的代碼,如:
target_os = [ "ios" ] target_os_only = True
在每個checkout出的工程中,gclient期望發現一個DEPS文件(由deps_file來給定),它定義了工程不同部分都是如何checkout出來。
“DEPS”也是一個python腳本,最簡單的,如下:
deps = {
"src/outside" : "http://outside-server/trunk@1234",
"src/component" : "svn://svnserver/component/trunk/src@77829",
"src/relative" : "/trunk/src@77829",
}
deps的每個條目都包含一個key-value對,key是被checkout的本地目錄,而value就是對應的遠程URL。如果路徑是以'/'開頭的,那麼它是一個相對URL,相對與.gclient中URL地址。
URL通常包含一個版本號,以便鎖定源碼在特定版本上。當然,這是可選的。如果沒有,那麼它將獲取指定分支上最新的版本。
DEPS還可以包含其他類型的數據,如vars,
vars = {
'pymox':
'http://pymox.googlecode.com/svn',
'sfntly':
'http://sfntly.googlecode.com/svn',
'eyes-free':
'http://eyes-free.googlecode.com/svn',
'rlz':
'http://rlz.googlecode.com/svn',
'smhasher':
'http://smhasher.googlecode.com/svn',
...
}
vars定義了一組變量,在後面,可以通過Var(xxx)來訪問。Var(xxx)返回一個字符串,故此,也可以進行操作,如
'src/third_party/cros_dbus_cplusplus/source':
Var("git.chromium.org") + '/chromiumos/third_party/dbus-cplusplus.git@5e8f6d9db5c2abfb91d91f751184f25bb5cd0900',
'src/third_party/WebKit':
Var("webkit_trunk")[:-6] + '/branches/chromium/1548@153044',
第二個自立,Var("webkit_trunk")[:-6]是一個python表達式,表示取得"webkit_trunk"表示的字符串的最後6個
Hooks:DEPS包含可選的內容 hooks,也有重要的作用,它表示在sync, update或者recert後,執行一個hook操作。
如果使用 --nohooks選項(hook默認執行),那麼在gclient sync或者其他操作後,不會執行hook。你可以通過gclient runhooks來單獨執行; 如果有 gclient sync --force,那麼,無論sync是否成功,都會執行hook。
hook在DEPS中的寫法,一般是:
hooks = [
{ "pattern": "\\.(gif|jpe?g|pr0n|png)$",
"action": ["python", "image_indexer.py", "--all"]},
{ "pattern": ".",
"name": "gyp",
"action": ["python", "src/build/gyp_chromium"]},
]
hooks包含一組hook,每個hook有幾個重要項:
- pattern 是一個正則表達式,用來匹配工程目錄下的文件,一旦匹配成功,action項就會執行
- action 描述一個根據特定參數運行的命令行。這個命令在每次gclient時,無論多少文件匹配,至多運行一次。這個命令和.gclient在同一目錄下運行。如果第一個參數是"python",那麼,當前的python解釋器將被使用。如果包含字符串 "$matching_files",它將該字符串擴展為匹配出的文件列表。
- name 可選,標記出hook所屬的組,可以被用來覆蓋和重新組織。
deps_os: DEPS中定義不同平台依賴關係的項目,如
deps_os = {
"win": {
"src/chrome/tools/test/reference_build/chrome_win":
"/trunk/deps/reference_builds/chrome_win@197743",
"src/third_party/cygwin":
"/trunk/deps/third_party/cygwin@133786",
.....
},
"ios": {
"src/third_party/GTM":
(Var("googlecode_url") % "google-toolbox-for-mac") + "/trunk@" +
Var("gtm_revision"),
"src/third_party/nss":
"/trunk/deps/third_party/nss@" + Var("nss_revision"),
....
},
...
}
deps_os指定不同平台的依賴,它可以包含多種平台,和.gclient中的target_os對應。這種對應關係如下:
DEPS_OS_CHOICES = {
"win32": "win",
"win": "win",
"cygwin": "win",
"darwin": "mac",
"mac": "mac",
"unix": "unix",
"linux": "unix",
"linux2": "unix",
"linux3": "unix",
"android": "android",
}
下載webrtc android代碼的.gclient文件(與src同級目錄):
solutions = [
{
"url": "https://chromium.googlesource.com/external/webrtc.git",
"managed": False,
"name": "src",
"deps_file": "DEPS",
"custom_deps": {},
},
]
target_os = ["android", "unix"]
src同級目錄下.gclient_entries定義了各模塊及對應地址
entries = {
'src': 'https://chromium.googlesource.com/external/webrtc.git',
'src/base': 'https://chromium.googlesource.com/chromium/src/base@413df39df4640665d7ee1e8c198be1e91cedb4d9',
'src/build': 'https://chromium.googlesource.com/chromium/src/build@98f2769027214c848094d0d58156474eada3bc1b',
'src/buildtools': 'https://chromium.googlesource.com/chromium/buildtools.git@98f00fa10dbad2cdbb2e297a66c3d6d5bc3994f3',
'src/testing': 'https://chromium.googlesource.com/chromium/src/testing@3eab1a4b0951ac1fcb2be8bf9cb24143b509ea52',
'src/testing/gmock': 'https://chromium.googlesource.com/external/googlemock.git@0421b6f358139f02e102c9c332ce19a33faf75be',
'src/testing/gtest': 'https://chromium.googlesource.com/external/github.com/google/googletest.git@6f8a66431cb592dad629028a50b3dd418a408c87',
'src/third_party': 'https://chromium.googlesource.com/chromium/src/third_party@939f3a2eae486dd7cf3b31eae38642d2bc243737',
'src/third_party/android_tools': 'https://chromium.googlesource.com/android_tools.git@b65c4776dac2cf1b80e969b3b2d4e081b9c84f29',
'src/third_party/boringssl/src': 'https://boringssl.googlesource.com/boringssl.git@777fdd6443d5f01420b67137118febdf56a1c8e4',
'src/third_party/catapult': 'https://chromium.googlesource.com/external/github.com/catapult-project/catapult.git@6939b1db033bf35f4adf1ee55824b6edb3e324d6',
'src/third_party/ced/src': 'https://chromium.googlesource.com/external/github.com/google/compact_enc_det.git@e21eb6aed10b9f6e2727f136c52420033214d458',
'src/third_party/colorama/src': 'https://chromium.googlesource.com/external/colorama.git@799604a1041e9b3bc5d2789ecbd7e8db2e18e6b8',
'src/third_party/ffmpeg': 'https://chromium.googlesource.com/chromium/third_party/ffmpeg.git@28a5cdde5c32bcf66715343c10f74e85713f7aaf',
'src/third_party/gflags': 'https://chromium.googlesource.com/external/webrtc/deps/third_party/gflags@892576179b45861b53e04a112996a738309cf364',
'src/third_party/gflags/src': 'https://chromium.googlesource.com/external/github.com/gflags/gflags@03bebcb065c83beff83d50ae025a55a4bf94dfca',
'src/third_party/gtest-parallel': 'https://chromium.googlesource.com/external/github.com/google/gtest-parallel@7eb02a6415979ea59e765c34fe9da6c792f53e26',
'src/third_party/icu': 'https://chromium.googlesource.com/chromium/deps/icu.git@b34251f8b762f8e2112a89c587855ca4297fed96',
'src/third_party/jsoncpp/source': 'https://chromium.googlesource.com/external/github.com/open-source-parsers/jsoncpp.git@f572e8e42e22cfcf5ab0aea26574f408943edfa4',
'src/third_party/jsr-305/src': 'https://chromium.googlesource.com/external/jsr-305.git@642c508235471f7220af6d5df2d3210e3bfc0919',
'src/third_party/junit/src': 'https://chromium.googlesource.com/external/junit.git@64155f8a9babcfcf4263cf4d08253a1556e75481',
'src/third_party/libFuzzer/src': 'https://chromium.googlesource.com/chromium/llvm-project/llvm/lib/Fuzzer.git@16f5f743c188c836d32cdaf349d5d3effb8a3518',
'src/third_party/libjpeg_turbo': 'https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@7260e4d8b8e1e40b17f03fafdf1cd83296900f76',
'src/third_party/libsrtp': 'https://chromium.googlesource.com/chromium/deps/libsrtp.git@ccf84786f8ef803cb9c75e919e5a3976b9f5a672',
'src/third_party/libvpx/source/libvpx': 'https://chromium.googlesource.com/webm/libvpx.git@f22b828d685adee4c7a561990302e2d21b5e0047',
'src/third_party/libyuv': 'https://chromium.googlesource.com/libyuv/libyuv.git@fc02cc3806a394a6b887979ba74aa49955f3199b',
'src/third_party/lss': 'https://chromium.googlesource.com/linux-syscall-support.git@63f24c8221a229f677d26ebe8f3d1528a9d787ac',
'src/third_party/mockito/src': 'https://chromium.googlesource.com/external/mockito/mockito.git@de83ad4598ad4cf5ea53c69a8a8053780b04b850',
'src/third_party/openh264/src': 'https://chromium.googlesource.com/external/github.com/cisco/openh264@0fd88df93c5dcaf858c57eb7892bd27763f0f0ac',
'src/third_party/openmax_dl': 'https://chromium.googlesource.com/external/webrtc/deps/third_party/openmax.git@7acede9c039ea5d14cf326f44aad1245b9e674a7',
'src/third_party/requests/src': 'https://chromium.googlesource.com/external/github.com/kennethreitz/requests.git@f172b30356d821d180fa4ecfa3e71c7274a32de4',
'src/third_party/robolectric/robolectric': 'https://chromium.googlesource.com/external/robolectric.git@2a0b6ba221c14f3371813a676ce06143353e448d',
'src/third_party/ub-uiautomator/lib': 'https://chromium.googlesource.com/chromium/third_party/ub-uiautomator.git@00270549ce3161ae72ceb24712618ea28b4f9434',
'src/third_party/usrsctp/usrsctplib': 'https://chromium.googlesource.com/external/github.com/sctplab/usrsctp@8679f2b0bf063ac894dc473debefd61dbbebf622',
'src/third_party/yasm/source/patched-yasm': 'https://chromium.googlesource.com/chromium/deps/yasm/patched-yasm.git@7da28c6c7c6a1387217352ce02b31754deb54d2a',
'src/tools': 'https://chromium.googlesource.com/chromium/src/tools@4718dd2b6d53fb68819b3fd23676b40935f4f31e',
'src/tools/gyp': 'https://chromium.googlesource.com/external/gyp.git@eb296f67da078ec01f5e3a9ea9cdc6d26d680161',
'src/tools/swarming_client': 'https://chromium.googlesource.com/external/swarming.client.git@11e31afa5d330756ff87aa12064bb5d032896cb5',
'src/buildtools/clang_format/script': 'https://chromium.googlesource.com/chromium/llvm-project/cfe/tools/clang-format.git@c09c8deeac31f05bd801995c475e7c8070f9ecda',
'src/buildtools/third_party/libc++/trunk': 'https://chromium.googlesource.com/chromium/llvm-project/libcxx.git@b1ece9c037d879843b0b0f5a2802e1e9d443b75a',
'src/buildtools/third_party/libc++abi/trunk': 'https://chromium.googlesource.com/chromium/llvm-project/libcxxabi.git@0edb61e2e581758fc4cd4cd09fc588b3fc91a653',
'src/third_party/android_tools/ndk': 'https://chromium.googlesource.com/android_ndk.git@26d93ec07f3ce2ec2cdfeae1b21ee6f12ff868d8',
}