The Meson Build System
http://mesonbuild.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
3.0 KiB
88 lines
3.0 KiB
# Copyright 2012-2014 The Meson development team |
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
# you may not use this file except in compliance with the License. |
|
# You may obtain a copy of the License at |
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
# See the License for the specific language governing permissions and |
|
# limitations under the License. |
|
|
|
"""A library of random helper functionality.""" |
|
|
|
import platform, subprocess, operator, os, shutil |
|
|
|
def is_osx(): |
|
return platform.system().lower() == 'darwin' |
|
|
|
def is_linux(): |
|
return platform.system().lower() == 'linux' |
|
|
|
def is_windows(): |
|
return platform.system().lower() == 'windows' |
|
|
|
def is_debianlike(): |
|
try: |
|
open('/etc/debian_version', 'r') |
|
return True |
|
except FileNotFoundError: |
|
return False |
|
|
|
def exe_exists(arglist): |
|
try: |
|
p = subprocess.Popen(arglist, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
p.communicate() |
|
if p.returncode == 0: |
|
return True |
|
except FileNotFoundError: |
|
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 |
|
vstr2 = vstr2[2:] |
|
elif vstr2.startswith('<='): |
|
cmpop = operator.le |
|
vstr2 = vstr2[2:] |
|
elif vstr2.startswith('!='): |
|
cmpop = operator.ne |
|
vstr2 = vstr2[2:] |
|
elif vstr2.startswith('=='): |
|
cmpop = operator.eq |
|
vstr2 = vstr2[2:] |
|
elif vstr2.startswith('='): |
|
cmpop = operator.eq |
|
vstr2 = vstr2[1:] |
|
elif vstr2.startswith('>'): |
|
cmpop = operator.gt |
|
vstr2 = vstr2[1:] |
|
elif vstr2.startswith('<'): |
|
cmpop = operator.lt |
|
vstr2 = vstr2[1:] |
|
else: |
|
cmpop = operator.eq |
|
varr1 = [int(x) for x in vstr1.split('.')] |
|
varr2 = [int(x) for x in vstr2.split('.')] |
|
return cmpop(varr1, varr2)
|
|
|