webrtc之源码管理工具gclient

google的chromium项目是用gclient来管理源码的checkout, update等。 gclient是google专门为这种多源项目编写的脚本,它可以将多个源码管理系统中的代码放在一起管理。甚至包括将Git和svn代码放在一起。

webrtc也是使用gclient管理代码.

gclient的sync,update等命令密切相关的两类文件.gclient和DEPS。

.gclient文件是gclient的控制文件,该文件放在工作目录的最上层(webrtc环境下与src统计目录)。”.gclient”文件是一个Python的脚本,定义了一组”solutions”,格式类似如下

1
2
3
4
5
6
7
8
9
10
11
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中不存在的新的项目.如:

    1
    2
    3
    4
    5
    6
    7
    8
    "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出不同代码,如:

    1
    target_os = ['android']

如果target_os_only值为True的话,那么,仅仅checkout出对应的代码,如:

1
2
target_os = [ "ios" ]  
target_os_only = True

在每个checkout出的工程中,gclient期望发现一个DEPS文件(由deps_file来给定),它定义了工程不同部分都是如何checkout出来。 “DEPS”也是一个python脚本,最简单的,如下:

1
2
3
4
5
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,

1
2
3
4
5
6
7
8
9
10
11
12
13
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)返回一个字符串,故此,也可以进行操作,如

1
2
3
4
'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中的写法,一般是:

1
2
3
4
5
6
7
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中定义不同平台依赖关系的项目,如

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

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对应。这种对应关系如下:

1
2
3
4
5
6
7
8
9
10
11
12
13

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同级目录):

1
2
3
4
5
6
7
8
9
10
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定义了各模块及对应地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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',
}
坚持原创技术分享,您的支持将鼓励我继续创作!