diff options
author | Axel Waggershauser <awagger@gmail.com> | 2015-02-14 01:56:27 +0100 |
---|---|---|
committer | Axel Waggershauser <awagger@gmail.com> | 2015-02-14 01:56:27 +0100 |
commit | 0a95e4b4a929f848b81bd723124d3c9a774cbce0 (patch) | |
tree | 65cf0854e180d1b836fdac668d480006e244df2b /mesonlib.py | |
parent | 5a0cd64f9a0d6683dd542dd69e40f39dc0727cdd (diff) | |
download | meson-0a95e4b4a929f848b81bd723124d3c9a774cbce0.zip meson-0a95e4b4a929f848b81bd723124d3c9a774cbce0.tar.gz meson-0a95e4b4a929f848b81bd723124d3c9a774cbce0.tar.bz2 |
moved helper function detect_vcs into mesonlib.py
Diffstat (limited to 'mesonlib.py')
-rw-r--r-- | mesonlib.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/mesonlib.py b/mesonlib.py index 7e15770..f2d424c 100644 --- a/mesonlib.py +++ b/mesonlib.py @@ -14,7 +14,7 @@ """A library of random helper functionality.""" -import platform, subprocess, operator +import platform, subprocess, operator, os, shutil def is_osx(): return platform.system().lower() == 'darwin' @@ -42,6 +42,23 @@ def exe_exists(arglist): pass return False +def detect_vcs(source_dir): + vcs_systems = [ + dict(name = 'git', cmd = 'git', repo_dir = '.git', get_rev = 'git describe --dirty=+', rev_regex = '(.*)', dep = '.git/logs/HEAD'), + dict(name = 'mercurial', cmd = 'hg', repo_dir = '.hg', get_rev = 'hg id -n', rev_regex = '(.*)', dep = '.hg/dirstate'), + dict(name = 'subversion', cmd = 'svn', repo_dir = '.svn', get_rev = 'svn info', rev_regex = 'Revision: (.*)', dep = '.svn/wc.db'), + dict(name = 'bazaar', cmd = 'bzr', repo_dir = '.bzr', get_rev = 'bzr revno', rev_regex = '(.*)', dep = '.bzr'), + ] + + segs = source_dir.replace('\\', '/').split('/') + for i in range(len(segs), -1, -1): + curdir = '/'.join(segs[:i]) + for vcs in vcs_systems: + if os.path.isdir(os.path.join(curdir, vcs['repo_dir'])) and shutil.which(vcs['cmd']): + vcs['wc_dir'] = curdir + return vcs + return None + def version_compare(vstr1, vstr2): if vstr2.startswith('>='): cmpop = operator.ge |