Scons

Une alternative à CMT ?

Laurent Garnier

15 Avril 2007

Devdu

État de l'art

What is Scons ? 1/2 (copier-collé de leur site ;-)

What is Scons ? 2/2 (copier-collé de leur site ;-)

Scons Pro/Cons (copier-collé de leur site ;-)

Comment ça marche? Les bases

Comment ça marche? Hello world

 

Comment ça marche? Libraries

Principes de CMT par rapport à Scons

CMT / Scons

Gestion des packages "à la CMT" :

|-- interfaces
|   |-- CLHEP
|   |   |-- SConscript
|   |-- HDF5
|   |   |-- SConscript
|   |-- dld
|   |   |-- SConscript
|   `-- zlib
|       |-- SConscript
      

Exemple de fichier SConscript

#
# File Interface/HDF5/SConcript
#
import os.path
import sys
Import('env')
# for HDF5 :
env.Replace(HDF5_native_version='1.6.5')
if (sys.platform == 'win32') :
env.Replace(HDF5_home='C:\usr\local\HDF5\$HDF5_native_version')
elif (sys.platform == 'darwin'):
env.Replace(HDF5_home='/usr/local/hdf5/')
else :
env.Replace(HDF5_home='/usr/local/hdf5-$HDF5_native_version')

env.Append(CPPPATH = ['$HDF5_home/$HDF5_native_version/include'])
env.Prepend(LIBPATH = ['$HDF5_home/$HDF5_native_version/lib'])
env.Prepend(LIBS = ['hdf5'])

if (sys.platform != 'win32') :
env.PrependENVPath('LD_LIBRARY_PATH', env.Dir('$HDF5_home/lib').abspath)

if (sys.platform == 'darwin') :
env.PrependENVPath('DYLD_LIBRARY_PATH', env.Dir('$HDF5_home/lib').abspath)

if (sys.platform != 'win32') :
env.PrependENVPath('PATH', env.Dir('$HDF5_home/bin').abspath)
else :
env.PrependENVPath('PATH', env.Dir('$HDF5_home\bin').abspath)

#
# File bhep/SConcript
#


import os.path
import glob
import sys

import SCons.Tool

#import version
#Export('version')

#EnsurePythonVersion(2,3)

# List of Interfaces
interfaces = ['CLHEP','HDF5','zlib','dld']



env = Environment()

# no DEBUG
debug=0

# Get Interfaces scripts

for dict in interfaces :
  print "Reading Interfaces %s" % (dict)
  SConscript('platform'+os.sep+'interfaces'+os.sep+'%s'%dict+os.sep+'SConscript', exports=['env','debug'])


env.Replace(BUILDTOP=['#Release'+os.sep+'${PLATFORM}'])
env.Replace(BINDIR = ['${BUILDTOP}'+os.sep+'bin'])
env.Replace(LIBDIR = ['${BUILDTOP}'+os.sep+'lib'])
env.Replace(INCDIR = ['${BUILDTOP}'+os.sep+'include'])
env.Replace(OBJDIR = ['${BUILDTOP}'+os.sep+'obj'])

# Set the sources to 'source directory
env.Replace(SRCDIR = ['sources'])

# set the cache dir
CacheDir('cache')




# Set the build dir of all cpp files in build directory
for projects in [
                '.',
                'base',
                'util',
                'converters',
                'manager',
                'examples',
                'tutorials',
                'histos',
                'tools'] :
   BuildDir(env.Dir('$OBJDIR').abspath+os.sep+projects,projects, duplicate=0)


# CPPPATH for my files
env.Append(CPPPATH = [env.Dir('$SRCDIR').abspath+os.sep+'.',
                      env.Dir('$SRCDIR').abspath+os.sep+'bhep',
                      env.Dir('$SRCDIR').abspath+os.sep+'examples',
                      env.Dir('$SRCDIR').abspath+os.sep+'tutorials'])
# REPOSITORY :
# but very strange comportment, dir 'base' will be checkout correctly, but 'util' won't...
# and a dir call 'bu' will and 'bus' won't... WHY ???
 
#svn = SCons.Tool.Tool('Subversion')
#svn(env)
#env.SourceCode('.', env.Subversion('svn://neutrinos1.ific.uv.es:/usr/local/svn/nautilus/bhep/tags/bhepv1r5p2'))

# PRINT EVERYTHING
#for key, val in env.items():
#    print "    %-20s %s" % (key, val)

print "CPPPATH =", env['CPPPATH']
print "CXXFLAGS =", env['CXXFLAGS']
print "CCFLAGS =", env['CCFLAGS']
print "CFLAGS =", env['CFLAGS']

# sources
bhep_sources = [
  'version.cpp',
  'base/event.cpp',
  'base/hit.cpp',
  'base/mparticle.cpp',
  'base/particle.cpp',
  'base/sparticle.cpp',
  'base/track.cpp',
  'util/particle_definition.cpp',
  'util/ray.cpp',
  'util/material.cpp',
  'converters/event_cvt.cpp',
  'converters/hit_cvt.cpp',
  'converters/mparticle_cvt.cpp',
  'converters/particle_cvt.cpp',
  'converters/sparticle_cvt.cpp',
  'converters/track_cvt.cpp',
  'manager/base_reader.cpp',
  'manager/bhep_svc.cpp',
  'manager/brw.cpp',
  'manager/converter_svc.cpp',
  'manager/random_reader.cpp',
  'manager/random_writer.cpp',
  'manager/reader_gz.cpp',
  'manager/reader_hdf5.cpp',
  'manager/reader_txt.cpp',
  'manager/sequential_reader.cpp',
  'manager/sequential_writer.cpp',
  'manager/writer_gz.cpp',
  'manager/writer_hdf5.cpp',
  'manager/writer_txt.cpp',
  'examples/generate_event.cpp',
  'tutorials/gevent.cpp',
  'histos/axis.cpp',
  'histos/histogram.cpp',
  'tools/EventManager.cpp']
# 'tools/EventManager.cpp2']

bhep_sources = [os.path.join(env.Dir('$OBJDIR').abspath+os.sep, x) for x in bhep_sources]
bhep_sources = [x.replace('/',os.sep) for x in bhep_sources]

# name of the library
bhep_libname = 'bhep'

# shared lib :
env.SharedLibrary(target=bhep_libname,
 source = bhep_sources)

# install the library
env['BHEP_LIBNAME'] = env.subst(env['SHLIBPREFIX'])+bhep_libname+env.subst(env['SHLIBSUFFIX'])
env.Install(env['LIBDIR'], env['BHEP_LIBNAME'])

CMT / Scons

Pour aller plus loin

Quelques références

Questions ?