Move environment set up to site_scons

This commit is contained in:
Eryn Wells 2015-09-22 14:44:30 -07:00
parent b9a582caf4
commit 2f1c86a793
5 changed files with 148 additions and 163 deletions

1
site_scons/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.pyc

84
site_scons/erw.py Normal file
View file

@ -0,0 +1,84 @@
# erw.py
# Eryn Wells <eryn@erynwells.me>
import sys
import SCons.Environment
import paths
#
# Environments
#
class Environment(SCons.Environment.Environment):
'''
Default SCons environment for building things.
'''
def __init__(self, name, modern=True, paranoid=True, colorful=True, succinct=True, **kwargs):
# Use clang if its available.
kwargs.setdefault('CC', self._toolchain_binary(('clang', 'gcc')))
kwargs.setdefault('CXX', self._toolchain_binary(('clang++', 'g++')))
kwargs.setdefault('LINK', self._toolchain_binary(('clang++')))
super(Environment, self).__init__(**kwargs)
self['_name'] = name
# Modern C/C++
if modern:
self.Append(CFLAGS=['-std=c99'])
self.Append(CXXFLAGS=['-std=c++11'])
# Paranoid C/C++
if paranoid:
self.Append(CCFLAGS=['-Wall', '-Wextra', '-pedantic'])
# Colorful C/C++
if colorful and sys.stdout.isatty():
if 'clang' in self['CC'] or 'clang' in self['CXX']:
self.Append(CCFLAGS=['-fcolor-diagnostics'])
self['ARCOMSTR'] = self._comstr('Archiving', succinct)
self['ASCOMSTR'] = self._comstr('Assembling', succinct)
self['ASPPCOMSTR'] = self._comstr('Assembling', succinct)
self['CCCOMSTR'] = self._comstr('Building (C)', succinct)
self['CXXCOMSTR'] = self._comstr('Building (C++)', succinct)
self['LINKCOMSTR'] = self._comstr('Linking', succinct)
self['RANLIBCOMSTR'] = self._comstr('Indexing', succinct)
self['SHCCCOMSTR'] = self._comstr('Building (C, Shared)', succinct)
self['SHCXXCOMSTR'] = self._comstr('Building (C++, Shared)', succinct)
self['SHLINKCOMSTR'] = self._comstr('Linking (Shared)', succinct)
def _toolchain_binary(self, binaries):
for b in binaries:
if b and paths.which(b):
return b
def _comstr(self, action, succinct=True):
if succinct:
return '{:>25}: $TARGET'.format(action)
else:
return ' [{:^6}] $TARGET'.format(action)
class DebugEnvironment(Environment):
def __init__(self, name='debug', **kwargs):
super(DebugEnvironment, self).__init__(name, **kwargs)
self.Append(CPPDEFINES=['NDEBUG'])
self.Append(CCFLAGS=['-O0', '-g'])
class BetaEnvironment(Environment):
def __init__(self, name='beta', **kwargs):
super(BetaEnvironment, self).__init__(name, **kwargs)
self.Append(CPPDEFINES=['NDEBUG'])
self.Append(CCFLAGS=['-O3', '-g'])
class ReleaseEnvironment(Environment):
def __init__(self, name='release', **kwargs):
super(ReleaseEnvironment, self).__init__(name, **kwargs)
self.Append(CPPDEFINES=['NRELEASE'])
self.Append(CCFLAGS=['-O3'])

30
site_scons/paths.py Normal file
View file

@ -0,0 +1,30 @@
# paths.py
# Eryn Wells <eryn@erynwells.me>
import os
import os.path
def is_executable(path):
return os.path.exists(path) and os.access(path, os.X_OK)
def which(program):
'''
Look for `program` in system path and return the full path to that binary if
it is found. Otherwise, return `None`.
'''
path, name = os.path.split(program)
if path:
if is_executable(program):
return program
else:
pathext = [''] + os.environ.get('PATHEXT', '').split(os.pathsep)
for path in os.environ.get('PATH', '').split(os.pathsep):
exe = os.path.join(path, program)
for ext in pathext:
candidate = exe + ext
if is_executable(candidate):
return candidate
return None

20
site_scons/site_init.py Normal file
View file

@ -0,0 +1,20 @@
# site_init.py
# Eryn Wells <eryn@erynwells.me>
import erw
#
# Argument utils
#
def get_bool_argument(arg):
'''
Convert the given argument value to a bool. True values are any integer that
is considered true by Python, and any string value that isn't a
capitalization variant of the word "false".
'''
try:
return bool(int(arg))
except ValueError:
pass
return str(arg).lower() != 'false'