""" Build support for geant4_ ========================= """ import os.path from ApeTools import Config, Build from ApeTools.Build import call, InstallError class Geant4(Build.Package): def __init__(self, name): """Add the :attr:`g4system` attribute and read it from the configuration.. """ Build.Package.__init__(self, name) self.setAttributes("g4system") def call_and_check(self, cmd, cwd, package, stage, log, env, append=False): """Execute command and check logfile for errors. The makefiles of Geant4 suppress non-zero exit codes. That means that the normal mechanism to detect build failure does not work. """ call(cmd, cwd=cwd, output=log, package=package, stage=stage, env=env, append=append) lf = open(log) for line in lf: if "error:" in line: raise InstallError(cwd=cwd, pack=package, stage=stage, log=log, cmd=cmd) def g4make(self, logFile, env): """Build and install geant4_. Set up the build environment with all :envvar:`G4...` environment variables required to run :command:`make` successfully. """ if not "CLHEPHOME" in env: raise InstallError(pack=self.name, args=["CLHEPHOME is not defined!"], stage="prepare make") env.update( CLHEP_BASE_DIR=env["CLHEPHOME"], G4SYSTEM=self.g4system, Geant4_DATA_DIR=os.path.join(self.prefix, "data"), G4INSTALL=os.path.dirname(self.buildDirectory), G4INCLUDE=os.path.join(self.prefix, "include"), G4LIB=os.path.join(self.prefix, "lib"), G4LISTS_BASE=os.path.join(self.prefix, "data"), G4LEDATA=os.path.join(self.prefix, "data/G4EMLOW"), G4LEVELGAMMADATA=os.path.join(self.prefix, "data/PhotonEvaporation"), G4RADIOACTIVEDATA=os.path.join(self.prefix, "data/RadiativeDecay"), G4ELASTICDATA=os.path.join(self.prefix, "data/Elastic"), G4TMP=os.path.join(self.buildDirectory, "tmp"), G4UI_NONE="1", G4LIB_BUILD_SHARED="1", ) buildCmd = ["make"] jobs = Config.getint("ape", "jobs") if jobs > 1: buildCmd += ["-j", str(jobs)] print " ... Building and installing" self.call_and_check(buildCmd, cwd=self.buildDirectory, log=logFile, env=env, package="geant4", stage="make") print " ... Installing headers" self.call_and_check(["make", "includes"], cwd=self.buildDirectory, log=logFile, append=True, env=env, package="geant4", stage="make includes") def make(self, logFile, env): try: self.g4make(logFile, env) except: self.removePrefixDir() raise