import sys, os.path as p wdir = p.abspath(p.dirname(__file__)) topdir = p.normpath(p.join(wdir, p.pardir, p.pardir)) srcdir = p.join(topdir, 'src') sys.path.insert(0, p.join(topdir, 'conf')) from mpiscanner import Scanner scanner = Scanner() libmpi_pxd = p.join(srcdir, 'include', 'mpi4py', 'libmpi.pxd') scanner.parse_file(libmpi_pxd) libmpi_h = p.join(wdir, 'libmpi.h') scanner.dump_header_h(libmpi_h) #try: # from cStringIO import StringIO #except ImportError: # from io import StringIO #libmpi_h = StringIO() #scanner.dump_header_h(libmpi_h) #print libmpi_h.read() libmpi_c = p.join(wdir, 'libmpi.c') with open(libmpi_c, 'w') as f: f.write("""\ #include <mpi.h> #include "%(srcdir)s/config.h" #include "%(srcdir)s/missing.h" #include "%(srcdir)s/fallback.h" #include "%(srcdir)s/compat.h" """ % vars())
import sys, os.path as p wdir = p.abspath(p.dirname(__file__)) topdir = p.normpath(p.join(wdir, p.pardir, p.pardir)) srcdir = p.join(topdir, 'src') sys.path.insert(0, p.join(topdir, 'conf')) from mpiscanner import Scanner scanner = Scanner() libmpi_pxd = p.join(srcdir, 'mpi4py', 'libmpi.pxd') scanner.parse_file(libmpi_pxd) libmpi_h = p.join(wdir, 'libmpi.h') scanner.dump_header_h(libmpi_h) #from io import StringIO #libmpi_h = StringIO() #scanner.dump_header_h(libmpi_h) #print libmpi_h.read() libmpi_c = p.join(wdir, 'libmpi.c.in') with open(libmpi_c, 'w') as f: f.write(f"""\ #include <mpi.h> #include "{srcdir}/lib-mpi/config.h" #include "{srcdir}/lib-mpi/missing.h" #include "{srcdir}/lib-mpi/fallback.h" #include "{srcdir}/lib-mpi/compat.h" """)
def __init__(self): Scanner.__init__(self) for filename in self.SOURCES: fullname = os.path.join(self.SRCDIR, filename) self.parse_file(fullname)
def __init__(self, config_cmd): self.scanner = Scanner() for filename in self.SOURCES: fullname = os.path.join(self.SRCDIR, filename) self.scanner.parse_file(fullname) self.config_cmd = config_cmd
class ConfigureMPI(object): SRCDIR = 'src' SOURCES = [os.path.join('mpi4py', 'libmpi.pxd')] DESTDIR = os.path.join('src', 'lib-mpi') CONFIG_H = os.path.join('config', 'config.h') MISSING_H = 'missing.h' CONFIGTEST_H = """\ /* _configtest.h */ #if !defined(MPIAPI) # define MPIAPI #endif """ def __init__(self, config_cmd): self.scanner = Scanner() for filename in self.SOURCES: fullname = os.path.join(self.SRCDIR, filename) self.scanner.parse_file(fullname) self.config_cmd = config_cmd def run(self): results = [] with open('_configtest.h', 'w') as f: f.write(self.CONFIGTEST_H) for node in self.scanner: name = node.name testcode = node.config() confcode = node.missing(guard=False) log.info("checking for '%s' ..." % name) ok = self.run_test(testcode) if not ok: log.info("**** failed check for '%s'" % name) with open('_configtest.h', 'a') as f: f.write(confcode) results.append((name, ok)) try: os.remove('_configtest.h') except OSError: pass return results def gen_test(self, code): body = ['#include "_configtest.h"', 'int main(int argc, char **argv) {', '\n'.join([' ' + line for line in code.split('\n')]), ' (void)argc; (void)argv;', ' return 0;', '}'] body = '\n'.join(body) + '\n' return body def run_test(self, code, lang='c'): level = log.set_threshold(log.WARN) log.set_threshold(level) if not self.config_cmd.noisy: level = log.set_threshold(log.WARN) try: body = self.gen_test(code) headers = ['stdlib.h', 'mpi.h'] ok = self.config_cmd.try_link(body, headers=headers, lang=lang) return ok finally: log.set_threshold(level) def dump(self, results): destdir = self.DESTDIR config_h = os.path.join(destdir, self.CONFIG_H) missing_h = os.path.join(destdir, self.MISSING_H) log.info("writing '%s'", config_h) self.scanner.dump_config_h(config_h, results) log.info("writing '%s'", missing_h) self.scanner.dump_missing_h(missing_h, None)