yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #02453
[Branch ~yade-dev/yade/trunk] Rev 1839: 1. Add scan&replace scons builder
------------------------------------------------------------
revno: 1839
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Tue 2009-12-01 23:24:00 +0100
message:
1. Add scan&replace scons builder
2. Get libstdc++ path from the compiler, embed it in main.py; it runs fine
3. Fix temporary filename in Omega (forgotten dir separator)
added:
scripts/scanreplace.py
renamed:
core/main/main.py => core/main/main.py.in
modified:
SConstruct
core/Omega.cpp
core/SConscript
core/main/main.py.in
--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk
Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription.
=== modified file 'SConstruct'
--- SConstruct 2009-11-30 08:48:32 +0000
+++ SConstruct 2009-12-01 22:24:00 +0000
@@ -70,7 +70,7 @@
Variables=Options
BoolVariable,ListVariable,EnumVariable=BoolOption,ListOption,EnumOption
-env=Environment(tools=['default'])
+env=Environment(tools=['default','scanreplace'],toolpath=['scripts'])
profileFile='scons.current-profile'
profOpts=Variables(profileFile)
@@ -302,9 +302,16 @@
ret=context.TryLink('#include<iostream>\nint main(int argc, char**argv){std::cerr<<std::endl;return 0;}\n','.cpp')
context.Result(ret)
return ret
+def CheckLibStdCxx(context):
+ context.Message('Finding libstdc++ library... ')
+ ret=os.popen(context.env['CXX']+' -print-file-name=libstdc++.so').readlines()[0][:-1]
+ context.env['libstdcxx']=ret
+ context.Result(ret)
+ return ret
+
if not env.GetOption('clean'):
- conf=env.Configure(custom_tests={'CheckQt':CheckQt,'CheckCXX':CheckCXX,'CheckPython':CheckPython,'CheckScientificPython':CheckScientificPython,'CheckIPython':CheckIPython},
+ conf=env.Configure(custom_tests={'CheckLibStdCxx':CheckLibStdCxx,'CheckQt':CheckQt,'CheckCXX':CheckCXX,'CheckPython':CheckPython,'CheckScientificPython':CheckScientificPython,'CheckIPython':CheckIPython},
conf_dir='$buildDir/.sconf_temp',log_file='$buildDir/config.log')
ok=True
@@ -312,6 +319,7 @@
if not ok:
print "\nYour compiler is broken, no point in continuing. See `%s' for what went wrong and use the CXX/CXXFLAGS parameters to change your compiler."%(buildDir+'/config.log')
Exit(1)
+ conf.CheckLibStdCxx()
# check essential libs
ok&=conf.CheckLibWithHeader('pthread','pthread.h','c','pthread_exit(NULL);',autoadd=1)
=== modified file 'core/Omega.cpp'
--- core/Omega.cpp 2009-12-01 14:56:39 +0000
+++ core/Omega.cpp 2009-12-01 22:24:00 +0000
@@ -81,7 +81,7 @@
std::string Omega::tmpFilename(){
if(tmpFileDir.empty()) throw runtime_error("tmpFileDir empty; Omega::initTemps not yet called()?");
boost::mutex::scoped_lock lock(tmpFileCounterMutex);
- return tmpFileDir+lexical_cast<string>(tmpFileCounter++);
+ return tmpFileDir+"/tmp-"+lexical_cast<string>(tmpFileCounter++);
}
void Omega::reset(){
=== modified file 'core/SConscript'
--- core/SConscript 2009-12-01 14:56:39 +0000
+++ core/SConscript 2009-12-01 22:24:00 +0000
@@ -1,14 +1,15 @@
Import('*')
pyMain='$PREFIX/bin/yade$SUFFIX-py'
-env.InstallAs(pyMain,env.File('main.py','main'))
+env.InstallAs(pyMain,env.ScanReplace('main/main.py.in'))
+
+env.InstallAs(pyMain,env.File(env.ScanReplace('main/main.py.in'),''))
env.AddPostAction(pyMain,Chmod(pyMain,0755))
env.Install('$PREFIX/lib/yade$SUFFIX/py/yade',[
env.SharedLibrary('boot',['main/pyboot.cpp'],SHLIBPREFIX='',LIBS=env['LIBS']+['yade-support','core'])
])
-
env.InstallAs('$PREFIX/bin/yade$SUFFIX',env.Program('yade',['main/main.cpp'],LIBS=env['LIBS']+['yade-support','core'],CPPDEFINES=env['CPPDEFINES']+[('YADE_VERSION','\\"'+env['realVersion']+'\\"'),]))
env.Install('$PREFIX/lib/yade$SUFFIX/lib',[
=== renamed file 'core/main/main.py' => 'core/main/main.py.in'
--- core/main/main.py 2009-12-01 14:56:39 +0000
+++ core/main/main.py.in 2009-12-01 22:24:00 +0000
@@ -1,16 +1,27 @@
#!/usr/bin/python
# syntax:python
+import sys,ctypes
+try:
+ import dl
+except ImportError:
+ import DLFCN as dl
# see file:///usr/share/doc/python2.6/html/library/sys.html#sys.setdlopenflags
# and various web posts on the topic, e.g.
# * http://gcc.gnu.org/faq.html#dso
# * http://www.code-muse.com/blog/?p=58
# * http://wiki.python.org/moin/boost.python/CrossExtensionModuleDependencies
-import sys, DLFCN
-sys.setdlopenflags(DLFCN.RTLD_NOW | DLFCN.RTLD_GLOBAL)
+sys.setdlopenflags(dl.RTLD_NOW | dl.RTLD_GLOBAL)
+# important: initialize c++ by importing libstdc++ directly
+# see http://www.abclinuxu.cz/poradna/programovani/show/286322
+# https://bugs.launchpad.net/bugs/490744
+libstdcxx='${libstdcxx}' # substituted by scons
+ctypes.cdll.LoadLibrary(libstdcxx)
+
# find what is our version, based on argv[0]
+# should be improved
import sys,re,os.path
m=re.match('(.*)/bin/yade(-.*)-py',sys.argv[0])
if not m: raise RuntimeError("Unable to find prefix and yade version from argv[0]=='%s'."%sys.argv[0])
@@ -19,6 +30,7 @@
pluginDirs=[libDir+dir for dir in ('','/plugins','/gui','/extra') if os.path.exists(libDir+dir)]
sys.path.append(libDir+'/py')
+# now we can import yade's c++ modules just fine
import yade.boot
yade.boot.initialize(pluginDirs,True)
@@ -29,9 +41,8 @@
from yade import runtime
from yade import utils
-
-
-__builtins__.O=Omega()
+# get some scons things here
+runtime.features='${features}'.split(',') # substituted by scons
runtime.prefix,runtime.suffix=prefix,suffix
runtime.argv=sys.argv
@@ -40,22 +51,27 @@
# todo
runtime.nonInteractive=False
# todo
-runtime.features=['openmp','opengl','vtk','gts','log4cxx']
-
runtime.simulation=''
runtime.script=''
for arg in sys.argv:
if arg.endswith('.xml') or arg.endswith('.xml.bz2'): runtime.simulation=arg
elif arg.endswith('.py'): runtime.script=arg
-
+#
+# this fills __builtins__ with wrapped types and proxy classes; it could be factored out, though
+#
execfile(prefix+'/lib/yade'+suffix+'/gui/PythonUI_rc.py')
+try:
+ import yade.qt
+ yade.qt.Controller()
+except ImportError: pass
+
#setupPythonRuntime()
#sys.argv[0]='<embedded python interpreter>'
if 0:
- if 1:
+ if 0:
from IPython.Shell import IPShellEmbed
ipshell=IPShellEmbed(exit_msg='Bye.',rc_override={'execfile':[runtime.prefix+'/lib/yade'+runtime.suffix+'/py/yade/ipython.py']})
ipshell()
=== added file 'scripts/scanreplace.py'
--- scripts/scanreplace.py 1970-01-01 00:00:00 +0000
+++ scripts/scanreplace.py 2009-12-01 22:24:00 +0000
@@ -0,0 +1,19 @@
+# source: http://www.scons.org/wiki/ReplacementBuilder
+# used internally by scons, do not delete
+
+from string import Template
+
+def replace_action(target, source, env):
+ open(str(target[0]),'w').write(Template(open(str(source[0]),'r').read()).safe_substitute(env))
+ return 0
+
+def replace_string(target, source, env):
+ return "R %s %s" % (str(source[0]), str(target[0]))
+
+def generate(env, **kw):
+ action = env.Action(replace_action, replace_string)
+ env['BUILDERS']['ScanReplace'] = env.Builder(action=action, src_suffix='.in', single_source=True)
+
+def exists(env):
+ return 1
+