importEnv externalized
This commit is contained in:
parent
565258d9bb
commit
b173933248
43
SConstruct
43
SConstruct
|
|
@ -12,36 +12,30 @@ VERSION='2.8.1b25'
|
|||
EFENCE=False
|
||||
|
||||
env = Environment(CPPPATH='#/include', LIBPATH=['/usr/lib','/usr/local/lib'])
|
||||
# Turn CPPFLAGS to list
|
||||
env.Append( CPPFLAGS = [])
|
||||
|
||||
################### Functions ######################
|
||||
def importEnv(list=None, prefix=None):
|
||||
if list:
|
||||
for i in list:
|
||||
if os.environ.get(i):
|
||||
kw={}
|
||||
kw[i]=os.environ.get(i)
|
||||
kw={ 'ENV': kw }
|
||||
env.Append(**kw)
|
||||
if prefix:
|
||||
for i in os.environ.keys():
|
||||
if i.startswith(prefix):
|
||||
kw={}
|
||||
kw[i]=os.environ.get(i)
|
||||
kw={ 'ENV': kw }
|
||||
env.Append(**kw)
|
||||
|
||||
#import environment
|
||||
importEnv(['HOME','CC'])
|
||||
importEnv(prefix='DISTCC_')
|
||||
importEnv(prefix='CCACHE_')
|
||||
if env['ENV'].get('CC'):
|
||||
env.Replace( CC = env['ENV'].get('CC'))
|
||||
from importer import ImportEnvironment,ImportVariable
|
||||
importEnvironment(env,'HOME')
|
||||
importVariable(env,'CC')
|
||||
importVariable(env,'CFLAGS','CCFLAGS')
|
||||
importEnvironment(env,prefix='DISTCC_')
|
||||
importEnvironment(env,prefix='CCACHE_')
|
||||
|
||||
# Turn CPPFLAGS to list, so we can add values to it
|
||||
env.Append( CPPFLAGS = [])
|
||||
|
||||
# Get CC from commandline
|
||||
if ARGUMENTS.get('CC', 0):
|
||||
env.Replace(CC = ARGUMENTS.get('CC'))
|
||||
|
||||
if ARGUMENTS.get('CFLAGS',0):
|
||||
env.Replace(CCFLAGS = ARGUMENTS.get('CFLAGS'))
|
||||
if ARGUMENTS.get('CCFLAGS',0):
|
||||
env.Replace(CCFLAGS = ARGUMENTS.get('CCFLAGS'))
|
||||
|
||||
# Convert CCFLAGS into list
|
||||
env.Replace(CCFLAGS = str(env['CCFLAGS']).split(' '))
|
||||
|
||||
#################### Tests ###################
|
||||
|
||||
# check for other GCC options
|
||||
|
|
@ -114,7 +108,6 @@ main ()
|
|||
############ Start configuration ##############
|
||||
|
||||
from maintainer import checkForMaintainerMode
|
||||
|
||||
conf = Configure(env,{'checkForGCCOption':checkForGCCOption,
|
||||
'MAINTAINER_MODE':checkForMaintainerMode,
|
||||
'checkForLockPrefix':checkForLockPrefix,
|
||||
|
|
|
|||
95
site_scons/importer.py
Normal file
95
site_scons/importer.py
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
#
|
||||
# Scons variable importer
|
||||
#
|
||||
# Version 1.0
|
||||
# 16-Jun-2009
|
||||
#
|
||||
import os
|
||||
|
||||
def _setvariable(env,name,value):
|
||||
"""Sets SCons variable.
|
||||
|
||||
Sets Scons variable name in environment env to value
|
||||
|
||||
"""
|
||||
kw={}
|
||||
kw[name]=value
|
||||
env.Replace(**kw)
|
||||
|
||||
def _setenvvariable(env,name,value):
|
||||
"""Sets SCons environment variable.
|
||||
|
||||
Sets Scons environment variable name in environment env to value.
|
||||
This variable will be used as environment variable for
|
||||
external jobs started by SCons.
|
||||
|
||||
"""
|
||||
env['ENV'][name]=value
|
||||
|
||||
def importVariable(env,varlist=None,target=None,prefix=None):
|
||||
"""Imports variables from OS to SCons environment.
|
||||
|
||||
Imports environment variables from Operation System into SCons
|
||||
variable.
|
||||
|
||||
keyword arguments:
|
||||
env -- SCons environment to be imported into
|
||||
varlist -- list or environment variable name to be imported
|
||||
target -- output variable names (optional)
|
||||
prefix -- import all variables starting with this prefix
|
||||
|
||||
"""
|
||||
_importcore(env,varlist,target,prefix,_setvariable)
|
||||
|
||||
def importEnvironment(env,varlist=None,target=None,prefix=None):
|
||||
"""Imports variables from OS to SCons environment.
|
||||
|
||||
Imports environment variables from Operation System into SCons
|
||||
variable.
|
||||
|
||||
keyword arguments:
|
||||
env -- SCons environment to be imported into
|
||||
varlist -- list or environment variable name to be imported
|
||||
target -- output variable names (optional)
|
||||
prefix -- import all variables starting with this prefix
|
||||
|
||||
"""
|
||||
_importcore(env,varlist,target,prefix,_setenvvariable)
|
||||
|
||||
def _importcore(env,varlist,targets,prefix,setter):
|
||||
"""Imports env. variables from OS using setter.
|
||||
|
||||
keyword arguments:
|
||||
env -- SCons environment to be imported into
|
||||
varlist -- list or environment variable name to be imported
|
||||
targets -- target variable names if you want to import variable
|
||||
using different name
|
||||
prefix -- import all variables starting with this prefix
|
||||
setter -- function for setting variable in env
|
||||
|
||||
"""
|
||||
if varlist:
|
||||
if not isinstance(varlist, list):
|
||||
if isinstance(varlist, str):
|
||||
varlist=[varlist]
|
||||
else:
|
||||
raise TypeError,"varlist must be list or string"
|
||||
if targets:
|
||||
if not isinstance(targets, list):
|
||||
if isinstance(targets, str):
|
||||
targets=[targets]
|
||||
else:
|
||||
raise TypeError,"targets must be list of string"
|
||||
for i in range(0,len(varlist)):
|
||||
value=os.environ.get(varlist[i])
|
||||
if value:
|
||||
if targets:
|
||||
setter(*[env,targets[i],value])
|
||||
else:
|
||||
setter(*[env,varlist[i],value])
|
||||
if prefix:
|
||||
if not isinstance(prefix, str):
|
||||
raise TypeError,"prefix must be string"
|
||||
for i in os.environ.keys():
|
||||
if i.startswith(prefix):
|
||||
setter(*[env,i,os.environ.get(i)])
|
||||
Loading…
Reference in New Issue
Block a user