- ScmGit(repository, server=None, protocol=None, branch=None, tag=None, revision=None, patchfile=None, use_cache=None, **kw):
Will clone source from the provided location. An optional patch file can be provided to be applied after the code is cloned and checked out to the requested tag. ScmGit support SCM caching feature to make a local git mirror to be reused between different builds on the local box and to reduce bandwidth requirements on clone or update commands.
- Parameters:
repository (str) – The repository to use to get the source from the git server
server (Optional[str]) – The option server to be used. If not provided the value of
$GIT_SERVER
will be used.protocol (Optional[bool]) – The form of the URL to be used for cloning from the git server. If not provided the value of
$GIT_PROTOCOL
will be used. By default this ishttps
branch (Optional[str]) – The branch to checkout after clone. Defaults to default branch of the server. This has been classically the “master” branch. Cannot be mixed with tag or revision arguments
tag (Optional[str]) – The tag to checkout after clone. If not provided the default branch value is used Cannot be mixed with branch or revision arguments
revision (Optional[str]) – The revision to checkout after clone. If not provided the default branch value is used Cannot be mixed with branch or tag arguments
patchfile (Optional[str]) – If provided will point to a diff/patch file to apply to the source after the source is cloned and checked out correctly. This file must be in the format that git can handle via a
git am <patchfile>
use_cache (Optional[bool]) – Allow for manual control if Parts should use the git mirror cache when cloning. If not provided the value of
$USE_SCM_CACHE
will be used.**kw –
This value is ignored and provided as a way to help with future compatibility.
Examples¶
Checkout default source from git
Part("foo.part",vcs_t=ScmGit(server="git.mycorp.com",repository="group/foo"))
Normally you would checkout a number of components from a location such as github. In these cases it is useful to set the default server.
# default server for most of the components SetOptionDefault("GIT_SERVER", "github.com") Part("foo.part",vcs_t=ScmGit(repository="group/foo")) Part("boo.part",vcs_t=ScmGit(repository="group2/boo"))
Checkout a tag from git
Part( "foo.part", vcs_t=ScmGit(repository="group/foo", tag='v1.0') )
Checkout a branch, while only getting the last five commits. This can greatly speed up time and save space
Part( "foo.part", vcs_t=ScmGit(repository="group/foo", branch='9.0.x'), GIT_CLONE_ARGS="--depth=5" )
Same as above but do it globally
# default server for most of the components SetOptionDefault("GIT_CLONE_ARGS", "--depth=5") Part( "foo.part", vcs_t=ScmGit(repository="group/foo", branch='9.0.x'), )
- GitVersionFromTag(default, prefix='', regex=None, converter)¶
- env.GitVersionFromTag(default, prefix='', regex=None, converter)¶
Allows the getting the version based on the git tag used to retrieve the code. If the current commit is not on a tag or a tag does not match the a version, a default value can be provided to retrieve the version. The default regular expression used is
r'\d+\.\d+(?:\.\d+)*'
- Parameters:
default (str) – The version to use if there is no match for the tag.
prefix (str) – If there is a match, This prefix will be tested for in the result and removed.
regex (str) – A custom regex string to be used find a match on possible tag values.
converter (lambda) – A optional function that takes regex group that was matched and a Scons Environment It should return the final version value.
- Returns:
It will return the version based on the tags found, else default value. If there are more than one tag at this commit that matches, the highest sorted value will be returned.
Examples¶
A Part file that would build brotli. It retrieves it tries to retrieve the version from the git tag. If falls back to a special dev version to help make it easy to see that a modified version is being used.
Import('*') PartName("brotli") PartVersion(GitVersionFromTag("0.0.0.dev")) env.CMake()
- env.GitInfo(checkoutdir=None, patched=False)¶
retrieve various information and state about what is cloned on disk. Optional arguments allow checking for value in git submodule directory.
- Parameters:
checkoutdir (Optional[str]) – optional path to directory to check
patched (bool) – If set to True, the previous commit will be checked.
- Returns:
A dictionary with value for these keys
branch
tags
modified
untracked
server
revision
short_revision
Variables¶
ScmGit can be control via a number of variables.
- SCM_GIT_CACHE_DIR¶
Path to use for the git mirror cache
- GIT_SERVER¶
The default git server to use. Defaults to empty string and should be provided by the user.
- VCS_GIT_DIR¶
The location where git will clone source to. Defaults to
${CHECK_OUT_ROOT}/${PART_ALIAS}
- GIT_DEFAULT_BRANCH¶
The default branch to use when checking out a branch Defaults to
master
- GIT_IGNORE_UNTRACKED¶
Tell Parts when doing update check to ignore untracked files from being viewed as being a difference. normally these files would be defined in the .gitignore file. It is common however that files may not have been added for various reasons Defaults to False
- SCM_IGNORE_MODIFIED¶
General value that when set will allow git to ignore modified files when doing updates. Useful for cases when build a component has side effects of modifying sources. Normally these files should not have been checked in, however for various reason this can happen when building and calling scripts or third-party build systems.
- GIT_PROTOCOL¶
Support to clone via two different protocols is supported.
- https (default)
which is in the form of https://<server>/<repository>.git
example https://bitbucket.org/sconsparts/parts.git
- ssh
which is the form of git@<server>:<repository>.git
example git@bitbucket.org:sconsparts/parts.git
In both cases the “.git” will be added if not provided with the repository argument
- GIT_TAG_ARGS¶
Optional extra arguments when Parts tries to query for
git tag
.
- GIT_STATUS_ARGS¶
Optional extra arguments when Parts tries to query for
git status
.
- GIT_CLONE_ARGS¶
Optional extra arguments when Parts goes a
git clone
.
- GIT_CHECKOUT_ARGS¶
Optional extra arguments when Parts goes a
git checkout
.
- GIT_AM_ARGS¶
Optional extra arguments when Parts goes a
git as
as part of patching the source.
- GIT_FETCH_ARGS¶
Optional extra arguments when Parts goes a
git fetch
.
- GIT_PULL_ARGS¶
Optional extra arguments when Parts goes a
git pull
.
- GIT_RESET_ARGS¶
Optional extra arguments when Parts goes a
git reset
.