Google multi-source code management tool gclient

Source: Internet
Author: User

This article is based on gclient help.

Google's Chromium project uses gclient to manage source code checkout and update. Gclient is a script specially written by Google for such multi-source projects. It can manage the code in multiple source code management systems. It even includes putting git and SVN Code together.

Gclient sync, update, and other commands are easy to learn and use. I will not talk about them any more. The two types of files. gclient and deps that are closely related to gclient are highlighted.

The. gclient file is the control file of gclient, which is placed at the top of the working directory. The ". gclient" file is a Python script (Google has a special liking for Python). It defines a set of "solutions" in a format similar to the following:

    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: name of the source code output by checkout
  • URL: directory where the source code is located. gclient wants to include a deps file in the source code generated by checkout. This file contains the source code that must be checkout to the working directory;
  • Deps_file this is a file name (excluding paths). It refers to a file that contains a dependency list in the project directory. This parameter is optional and the default value is "deps"
  • Custom_deps: an optional dictionary object that overwrites the entries defined in the project's "deps" file. It is generally used as the code that does not require checkout in the local directory, such

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

Or let the local directory checkout a new code from different locations, or different branches and versions of checkout. It can also be used to add new items that do not exist in deps.

  • Target_ OS: This optional entry indicates a special platform. Different codes are generated for checkout based on the platform, as shown in figure

target_os = ['android']

If the target_ OS _only value is true, then only the corresponding code is checkout, as shown in

   target_os = [ "ios" ]   target_os_only = True

In each checkout project, gclient expects to find a deps file (defined by deps_file), which defines how different parts of the project are checkout.

"Deps" is also a Python script, which is the simplest, as follows:

    deps = {      "src/outside" : "http://outside-server/trunk@1234",      "src/component" : "svn://svnserver/component/trunk/src@77829",      "src/relative" : "/trunk/src@77829",    }

Each deps entry contains a key-value pair. The key is the local directory of the checkout, and the value is the corresponding remote URL.

If the path starts with '/', it is a relative URL, relative to the URL address in. gclient.

A URL usually contains a version number to lock the source code in a specific version. Of course, this is optional. If not, it obtains the latest version of the specified branch.

Deps can also contain other types of data, such as 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 defines a set of variables inBack, Which can be accessed through VAR (XXX. VaR (XXX) returns a string. Therefore, you can perform operations, as shown in figure

      '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',

The second is self-reliant. var ("webkit_trunk") [:-6] is a python expression that indicates obtaining the last six strings represented by "webkit_trunk"

Hooks: deps contains optional content hooks, which also plays an important role. It indicates to execute a hook operation after sync, update, or recert.

If you use the -- nohooks option (Hook is executed by default), the hook will not be executed after gclient sync or other operations. You can use gclient runhooks for separate execution. If gclient sync -- force exists, the hook will be executed no matter whether sync is successful or not.

The method of hook in deps is generally:

    hooks = [      { "pattern": "\\.(gif|jpe?g|pr0n|png)$",        "action":  ["python", "image_indexer.py", "--all"]},      { "pattern": ".",        "name": "gyp",        "action":  ["python", "src/build/gyp_chromium"]},    ]

Hooks contains a set of hooks. Each Hook has several important items:

  • Pattern is a regular expression used to match files in the project directory. Once the matching is successful, the action item is executed.
  • Action describes a command line that is run according to a specific parameter. This command can be run at most once no matter how many files match each time on the gclient. This command is run in the same directory as. gclient. If the first parameter is "Python", the current Python interpreter will be used. If the string "$ matching_files" is included, it expands the string to a list of matched files.
  • Name (optional) indicates the group to which the hook belongs. It can be used to overwrite and reorganize.

Deps_ OS: items in deps that define dependencies between different platforms, as shown in figure

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 specifies the dependencies between different platforms. It can contain multiple platforms and correspond to target_ OS in. gclient. The corresponding relationship is as follows:

  DEPS_OS_CHOICES = {    "win32": "win",    "win": "win",    "cygwin": "win",    "darwin": "mac",    "mac": "mac",    "unix": "unix",    "linux": "unix",    "linux2": "unix",    "linux3": "unix",    "android": "android",  }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.