-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from fredboudon/util
Create a util module for simple detection useful in SConstruct
- Loading branch information
Showing
8 changed files
with
189 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
|
||
def fix_custom_buildprefix(env, standardprefix = 'build-scons'): | ||
""" | ||
A function that create a symlink in case build_prefix is different from standardprefix. | ||
Usefull to make the link with python setup.py configuration. | ||
Args: | ||
env (SCons.environment or str): The actual prefix. | ||
standardprefix (str): The name of the standart prefix used by setup.py. | ||
""" | ||
import os, shutil | ||
if os.name == 'posix' : | ||
if type(env) == str: | ||
prefix = env | ||
else: | ||
# A | ||
prefix = env['build_prefix'] | ||
if os.path.basename(prefix) != standardprefix: | ||
if os.path.exists(standardprefix): | ||
if os.path.isdir(standardprefix) and not os.path.islink(standardprefix): | ||
shutil.rmtree(standardprefix) | ||
else: | ||
os.remove(standardprefix) | ||
os.symlink(prefix, standardprefix) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#------------------------------------------------------------------------------ | ||
# Conda detection | ||
import os | ||
|
||
|
||
def is_conda(): | ||
""" Check if sconsx is run in a conda environment. """ | ||
return ("CONDA_PREFIX" in os.environ) | ||
|
||
def conda_prefix(): | ||
""" Returns the PREFIX where lib, include are installed. """ | ||
if is_conda(): | ||
if 'CONDA_BUILD' in os.environ: | ||
return os.environ.get('PREFIX', os.environ.get('CONDA_PREFIX')) | ||
else: | ||
return os.environ['CONDA_PREFIX'] | ||
|
||
def conda_library_prefix(): | ||
if os.name == 'posix' : | ||
return conda_prefix() | ||
elif is_conda(): | ||
library_prefix= os.path.join(os.environ.get('CONDA_PREFIX'),'Library') | ||
if 'CONDA_BUILD' in os.environ: | ||
return os.environ.get('LIBRARY_PREFIX', library_prefix) | ||
else: | ||
return library_prefix | ||
#------------------------------------------------------------------------------ | ||
# system detection | ||
|
||
def is_32bit_environment(): | ||
return not is_64bit_environment() | ||
|
||
def is_64bit_environment(): | ||
import sys | ||
return sys.maxsize.bit_length() == 63 | ||
|
||
#------------------------------------------------------------------------------ | ||
# CI detection | ||
|
||
def is_continuous_integration(): | ||
import os | ||
return 'CI' in os.environ | ||
|
||
def is_on_travis(): | ||
import os | ||
return 'TRAVIS' in os.environ | ||
|
||
def is_on_appveyor(): | ||
import os | ||
return 'APPVEYOR' in os.environ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# -- locate executables in the path, use with caution -- | ||
def find_executable_path_from_env(exe, strip_bin=True): | ||
import os | ||
from os.path import exists, join | ||
|
||
paths = os.environ["PATH"].split(os.pathsep) | ||
okPath = None | ||
for p in paths: | ||
if exists(join(p,exe)): | ||
okPath = p | ||
break | ||
|
||
if okPath is None : return None | ||
bin = okPath[-4:] | ||
if strip_bin and okPath and "bin" in bin and os.sep in bin: | ||
return okPath[:-4] | ||
else: | ||
return okPath | ||
|
||
|
||
def detect_posix_project_installpath(filepattern, potentialdirs = []): | ||
""" Detect the installation of include of lib in the system. | ||
Potential dirs can be added to test on the system. | ||
By default, '/usr','/usr/local','/opt/local' are tested. | ||
If nothing is found, it return the default value /usr | ||
Exemple of use will be: | ||
detect_posix_project_installpath('GL', ['/usr/X11R6']) | ||
""" | ||
from os.path import join, exists | ||
from .env_check import is_conda | ||
|
||
mpotentialdirs = potentialdirs+['/opt/local','/usr/local','/usr'] | ||
if is_conda(): | ||
mpotentialdirs.prepend(conda_library_prefix()) | ||
for potentialdir in mpotentialdirs: | ||
if exists(join(potentialdir,filepattern)) : | ||
return potentialdir | ||
return '/usr' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
def detect_qt_includepath(): | ||
from .lib_check import detect_posix_project_installpath, find_executable_path_from_env | ||
import os | ||
from os.path import join, abspath | ||
|
||
defaultdirs = ['/opt/local/libexec'] | ||
qt_dir = os.getenv("QTDIR") | ||
if qt_dir : defaultdirs.append(qt_dir) | ||
qt_dir = find_executable_path_from_env("moc.exe", strip_bin=True) | ||
if qt_dir : defaultdirs.append(abspath(join(qt_dir,os.pardir))) | ||
|
||
for pattern in ['qt4/include','qt5/include','qt/include','include/qt4','include/qt5','include/qt']: | ||
defdir = os.path.join(detect_posix_project_installpath(join(pattern,'QtCore'),defaultdirs),pattern) | ||
if os.path.exists(defdir): | ||
break | ||
return defdir | ||
|
||
|
||
def detect_installed_qt_version(default = 4): | ||
import os | ||
from .versionreader import read_variable, version_from_hex | ||
|
||
QT_VERSION = None | ||
library_inc = detect_qt_includepath() | ||
|
||
qversionconfig = os.path.join(library_inc,'QtCore','qconfig.h') | ||
if os.path.exists(qversionconfig): | ||
variable = 'QT_VERSION_MAJOR' | ||
QT_VERSION = read_variable(variable, qversionconfig) | ||
if QT_VERSION is None: | ||
qversionconfig = os.path.join(library_inc,'QtCore','qglobal.h') | ||
if os.path.exists(qversionconfig): | ||
variable = 'QT_VERSION' | ||
QT_VERSION = read_variable(variable, qversionconfig) | ||
if QT_VERSION is None: | ||
print ('Autodetect qt error in',repr(library_inc)) | ||
QT_VERSION = default | ||
|
||
return QT_VERSION | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
|
||
def read_variable(varname, fname): | ||
import re | ||
stream = file(fname, 'r') | ||
text = stream.read() | ||
pattern = '#define\s+?'+varname+'\s+?(.+?)\s*?$' | ||
res = re.findall(pattern, text, re.M) | ||
if not res is None and len(res) > 0: | ||
res = res[0] | ||
try: | ||
res = eval(res) | ||
except: | ||
pass | ||
else : return None | ||
return res | ||
|
||
def version_from_hex(hex_version): | ||
major = ((hex_version & 0xff0000) >> 16) | ||
minor = ((hex_version & 0x00ff00) >> 8) | ||
rev = (hex_version & 0x0000ff) | ||
return major, minor, rev | ||
|
||
def strversion_from_hex(hex_version): | ||
major, minor, rev = version_from_hex(hex_version) | ||
return str(major)+'.'+str(minor)+'.'+str(rev) |