def build(module, options, log, origEnviron, exitOnFailure=True): """ Build the software """ spec = module["spec"] print_msg("processing EasyBuild easyconfig %s" % spec, log) ## Restore original environment log.info("Resetting environment") filetools.errorsFoundInLog = 0 if not filetools.modifyEnv(os.environ, origEnviron): error("Failed changing the environment back to original") cwd = os.getcwd() ## Load easyblock easyblock = options.easyblock if not easyblock: ## Try to look in .eb file reg = re.compile(r"^\s*easyblock\s*=(.*)$") for line in open(spec).readlines(): match = reg.search(line) if match: easyblock = eval(match.group(1)) break name = module["module"][0] try: app_class = get_class(easyblock, log, name=name) app = app_class(spec, debug=options.debug) log.info("Obtained application instance of for %s (easyblock: %s)" % (name, easyblock)) except EasyBuildError, err: error("Failed to get application instance for %s (easyblock: %s): %s" % (name, easyblock, err.msg))
def get_instance(package, log): """ Get an instance for this package package is in the format provided by processEasyConfig log is a logger object returns an instance of Application (or subclass thereof) """ spec = package['spec'] name = package['module'][0] # handle easyconfigs with custom easyblocks easyblock = None reg = re.compile(r"^\s*easyblock\s*=(.*)$") for line in open(spec).readlines(): match = reg.search(line) if match: easyblock = eval(match.group(1)) break app_class = get_class(easyblock, log, name=name) return app_class(spec, debug=True)
def main(): """ Main function: - parse command line options - initialize logger - read easyconfig - build software """ # disallow running EasyBuild as root if os.getuid() == 0: sys.stderr.write( "ERROR: You seem to be running EasyBuild with root priveleges.\n" "That's not wise, so let's end this here.\n" "Exiting.\n" ) sys.exit(1) # options parser parser = OptionParser() parser.usage = "%prog [options] easyconfig [..]" parser.description = ( "Builds software package based on easyconfig (or parse a directory)\n" "Provide one or more easyconfigs or directories, use -h or --help more information." ) add_build_options(parser) (options, paths) = parser.parse_args() ## mkstemp returns (fd,filename), fd is from os.open, not regular open! fd, logFile = tempfile.mkstemp(suffix=".log", prefix="easybuild-") os.close(fd) if options.stdoutLog: os.remove(logFile) logFile = None global LOGDEBUG LOGDEBUG = options.debug configOptions = {} if options.pretend: configOptions["installPath"] = os.path.join(os.environ["HOME"], "easybuildinstall") if options.only_blocks: blocks = options.only_blocks.split(",") else: blocks = None ## Initialize logger logFile, log, hn = initLogger(filename=logFile, debug=options.debug, typ="build") ## Show version if options.version: print_msg("This is EasyBuild %s" % easybuild.VERBOSE_VERSION, log) ## Initialize configuration # - check environment variable EASYBUILDCONFIG # - then, check command line option # - last, use default config file easybuild_config.py in build.py directory config_file = options.config if not config_file and os.getenv("EASYBUILDCONFIG"): config_file = os.getenv("EASYBUILDCONFIG") else: appPath = os.path.dirname(os.path.realpath(sys.argv[0])) config_file = os.path.join(appPath, "easybuild_config.py") config.init(config_file, **configOptions) # Dump possible options if options.avail_easyconfig_params: app = get_class(options.easyblock, log) extra = app.extra_options() default = EasyBlock.default_config print "DEFAULT OPTIONS:" for key in sorted(default): tabs = "\t" * (3 - (len(key) + 1) / 8) print "%s:%s%s" % (key, tabs, default[key][1]) if extra: print "EXTRA OPTIONS:" for key in sorted(extra): tabs = "\t" * (3 - (len(key) + 1) / 8) print "%s:%s%s" % (key, tabs, extra[key][1]) ## Dump available classes if options.dump_classes: dumpClasses("easybuild.easyblocks") ## Search for modules if options.search: if not options.robot: error("Please provide a search-path to --robot when using --search") searchModule(options.robot, options.search) if options.avail_easyconfig_params or options.dump_classes or options.search or options.version: if logFile: os.remove(logFile) sys.exit(0) # set strictness of filetools module if options.strict: filetools.strictness = options.strict ## Read easyconfig files packages = [] if len(paths) == 0: error("Please provide one or more easyconfig files", optparser=parser) for path in paths: path = os.path.abspath(path) if not (os.path.exists(path)): error("Can't find path %s" % path) try: files = findEasyconfigs(path, log) for eb_file in files: packages.extend(processEasyconfig(eb_file, log, blocks)) except IOError, err: log.error("Processing easyconfigs in path %s failed: %s" % (path, err))