gclient-Google 多源碼管理工具

本文根據gclient幫助整理。

google的chromium項目是用gclient來管理源碼的checkout, update等。 gclient是google專門爲這種多源項目編寫的腳本,它可以將多個源碼管理系統中的代碼放在一起管理。甚至包括將Git和svn代碼放在一起。

gclient的sync,update等命令很容易學習和使用,不再多說,重點說明下和gclient密切相關的兩類文件.gclient和DEPS。

.gclient文件是gclient的控制文件,該文件放在工作目錄的最上層。”.gclient”文件是一個Python的腳本(google真是對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的代碼,如

 

"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,  
},

或者讓本地目錄從不同位置checkout一個新的代碼出來,或者checkout不同的分支、版本等。也可以用於增加在DEPS中不存在的新的項目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",  
} 

 

參考文章:http://blog.csdn.net/doon/article/details/9287693

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章