Example #1
0
File: python.py Project: srp/mem
def _build_python_obj(target, source, CFLAGS, CPPPATH):
    includes = ["-I" + path for path in CPPPATH]
    if os.path.dirname(source) != '':
        includes.append("-I" + os.path.dirname(source))
    includes.append("-I" + get_config_var("CONFINCLUDEPY"))

    # Check for header dependencies
    mem = Mem.instance()
    mem.add_deps([nodes.File(f) for f in
                  make_depends(target, [ source ],
                               CFLAGS=CFLAGS,
                               CPPPATH=CPPPATH,
                               inc_dirs=includes
                  )
    ])

    cargs = get_config_var('BLDSHARED').split(' ')
    args = util.convert_cmd([cargs[0]] + cargs[1:] +
            CFLAGS + includes +
            target_inc_flag(target, [ source ]) +
            list(includes) +
            ["-c", "-o", target] + [ source ])

    util.ensure_file_dir(target)

    if util.run("GCC (Python Extension)", source, args) != 0:
        Mem.instance().fail()

    return [ nodes.File(target) ]
Example #2
0
File: gcc.py Project: srp/mem
def t_cpp_obj(target, source_list, CXXFLAGS, CPPPATH):
    inc_dirs = set()
    if len(source_list) > 1:
        combine_opt=['-combine']
    else:
        combine_opt=[]

    for source in source_list:
        inc_dirs.add("-I" + os.path.dirname(source))
        if not os.path.exists(str(source)):
            Mem.instance().fail("%s does not exist" % source)

            mem.add_dep(util.convert_to_file(source))

    mem.add_deps([nodes.File(f) for f in
                  make_depends(target, source_list,
                               CFLAGS=CXXFLAGS, CPPPATH=CPPPATH,
                               inc_dirs = list(inc_dirs))])

    includes = ["-I" + path for path in CPPPATH]
    args = util.convert_cmd(["g++"] +  CXXFLAGS + includes +
                                target_inc_flag(target, source_list) +
                                list(inc_dirs) +
                                combine_opt +
                                ["-c", "-o", target] + source_list)

    util.ensure_file_dir(target)

    if util.run("Compiling", source_list, args) != 0:
        Mem.instance().fail()

    return nodes.File(target)
Example #3
0
File: python.py Project: srp/mem
def _python_obj(source, env, build_dir, **kwargs):
    if not os.path.exists(str(source)):
        Mem.instance().fail("%s does not exist" % source)

    target = os.path.join(build_dir, os.path.splitext(source)[0] + '.o')

    return _build_python_obj(target, source,
            env.get("CFLAGS", []),
            env.get("CPPPATH", []),
    )
Example #4
0
File: python.py Project: srp/mem
def _link_python_ext(target, objs, CFLAGS, LDFLAGS):
    mem = Mem.instance()
    mem.add_deps(objs)

    cargs = get_config_var('BLDSHARED').split(' ')
    args = util.convert_cmd([cargs[0]] + cargs[1:] +
            CFLAGS + LDFLAGS + ["-o", target] + objs)

    if util.run("GCC Link (Python Extension)", objs, args) != 0:
        Mem.instance().fail()

    return nodes.File(target)
Example #5
0
def _link_python_ext(target, objs, CFLAGS, LINKFLAGS):
    mem = Mem.instance()
    mem.add_deps(objs)

    cargs = get_config_var('BLDSHARED').split() + get_config_var('BLDLIBRARY').split()
    args = util.convert_cmd(cargs[:1] + ["-o", target] + cargs[1:] + CFLAGS + objs + LINKFLAGS)

    (returncode, stdoutdata, stderrdata) = util.run_return_output("GCC Link (Python Extension)", objs, util._open_pipe_, args)
    if returncode != 0:
        Mem.instance().fail()

    return nodes.File(target)
Example #6
0
def build_obj(target, source, ext, env=None, **kwargs):
    if ext == ".c":
        t = util.Runable(t_c_obj, target, source, env=env, **kwargs)
        t.start()
        return t

    elif ext == ".cpp":
        t = util.Runable(t_cpp_obj, target, source, env=env, **kwargs)
        t.start()
        return t
    else:
        Mem.instance().fail("Don't know how to build %s" % source)

    return t
Example #7
0
def t_prog(target, objs, CFLAGS, LIBS, LIBPATH, LINKFLAGS):
    mem.add_deps(objs)

    npaths = map(lambda a: "-L" + str(a), LIBPATH)
    nlibs = map(lambda a: "-l" + str(a), LIBS)

    args = util.convert_cmd(["gcc", "-o", target] + CFLAGS + LINKFLAGS + npaths + objs + nlibs)

    util.ensure_file_dir(target)

    if util.run("Linking", target, args) != 0:
        Mem.instance().fail()

    return nodes.File(target)
Example #8
0
def obj(source_list, target=None, env=None, build_dir=None, **kwargs):
    """ Take a list of sources and convert them to a correct object file """

    BuildDir = util.get_build_dir(env, build_dir)
    threads = []

    if not type(source_list) == list:
        source_list = [source_list]

    nslist = util.flatten(source_list)

    # If a target is specified, build all the sources in the list into
    # a single target
    if target:
        buildext = None
        new_source_list = []
        for source in nslist:
            source = os.path.join(os.getcwd(), source)
            (name, ext) = os.path.splitext(str(source))
            if buildext == None:
                buildext = ext
            elif buildext != ext:
                Mem.instance().fail("Mixed extensions in a single build object")
            new_source_list.append(source)

        t = os.path.join(BuildDir, str(target))
        thread = build_obj(t, new_source_list, buildext, env, **kwargs)
        thread.join()
        return [thread.result]

    # No target specified.  Build each object individually
    for source in nslist:
        (name, ext) = os.path.splitext(str(source))
        target = os.path.join(BuildDir, name + ".o")

        source = os.path.join(os.getcwd(), str(source))
        if not ext == ".h":
            threads.append(build_obj(target, [source], ext, env, **kwargs))

    for t in threads:
        if t:
            t.join()

    return [t.result for t in threads if t]
Example #9
0
File: gcc.py Project: srp/mem
def t_prog(target, objs, CC, CFLAGS, LIBS, LIBPATH, LINKFLAGS):
    mem.add_deps(objs)

    npaths = map(lambda a: "-L" + str(a), LIBPATH)
    nlibs = []
    for l in LIBS:
        if type(l) is tuple:
            assert l[1] == 'static'
            nlibs.extend(["-Wl,-Bstatic", "-l" + l[0], "-Wl,-Bdynamic"])
        else:
            nlibs.append("-l" + l)

    args = util.convert_cmd([CC, "-o", target] + CFLAGS + LINKFLAGS +
                                npaths + objs + nlibs)

    util.ensure_file_dir(target)

    if util.run("Linking", target, args) != 0:
        Mem.instance().fail()

    return nodes.File(target)
Example #10
0
File: python.py Project: srp/mem
    def build(self, cfile, source):
        self.deps = set((source,))

        # We might also depend on our definition file
        # if it exists
        pxd = os.path.splitext(source)[0] + '.pxd'
        if os.path.exists(pxd):
            self.deps.add(pxd)
            self._find_deps(open(pxd, "r").read())

        self._find_deps(open(source,"r").read())
        self.deps = [ d for d in self.deps if os.path.exists(d) ]

        mem = Mem.instance()
        mem.add_deps([ nodes.File(f) for f in self.deps ])

        args = util.convert_cmd(["cython"] +
                ['-I' + path for path in self.include_paths ] +
                ["-o", cfile, source])

        if util.run("Cython", source, args) != 0:
            Mem.instance().fail()

        return nodes.File(cfile)
Example #11
0
def python_ext(target, sources, env={}, build_dir = "", inplace = False,
               **kwargs):
    """Turn the sources list into a python extension"""

    if not isinstance(sources, list):
        sources = [ sources ]

    mem = Mem.instance()

    build_dir = util.get_build_dir(env, build_dir)


    # Set our function specific config
    newenv = util.Env(env)
    newenv.update(kwargs)

    # Fill in the holes with sensible defaults
    # Is this C or C++?
    if 'CC' not in newenv:
        if 'CXXFLAGS' in newenv and 'CFLAGS' not in newenv:
            newenv.CC = 'g++'
        else:
            newenv.CC = 'gcc'


    all_objs = []
    for source in util.flatten(sources):
        ext = os.path.splitext(source)[1].lower()
        if ext not in _EXTENSION_DISPATCH:
            raise ValueError("Don't know how to build extension from source %s"
                    % source)

        objs = _EXTENSION_DISPATCH[ext](source, newenv or {}, build_dir, **kwargs)

        all_objs.extend(objs)

    target += '.so'

    if not inplace:
        ntarget = os.path.join(build_dir, target)
    else:
        ntarget = target

    return _link_python_ext(ntarget, all_objs, env=newenv)
Example #12
0
File: python.py Project: srp/mem
def python_ext(target, sources, env={}, build_dir = "", inplace = False,
               **kwargs):
    """Turn the sources list into a python extension"""

    if not isinstance(sources, list):
        sources = [ sources ]

    mem = Mem.instance()

    build_dir = util.get_build_dir(env, build_dir)

    all_objs = []
    for source in util.flatten(sources):
        ext = os.path.splitext(source)[1].lower()
        if ext not in _EXTENSION_DISPATCH:
            raise ValueError("Don't know how to build extension from source %s"
                    % source)

        objs = _EXTENSION_DISPATCH[ext](source, env or {}, build_dir, **kwargs)

        all_objs.extend(objs)

    target += '.so'

    if not inplace:
        ntarget = os.path.join(build_dir, target)
    else:
        ntarget = target


    if 'CFLAGS' in kwargs:
        CFLAGS = kwargs['CFLAGS'][:]
    elif env is not None:
        CFLAGS = env.get('CFLAGS', [])

    if 'LDFLAGS' in kwargs:
        LDFLAGS = kwargs['LDFLAGS'][:]
    elif env is not None:
        LDFLAGS = env.get('LDFLAGS', [])

    return _link_python_ext(ntarget, all_objs, CFLAGS, LDFLAGS)
Example #13
0
def install(source, DESTDIR):
    if DESTDIR is None:
        DESTDIR = Mem.instance().cwd
    mem.add_dep(source)

    target = os.path.join(DESTDIR, source.basename())
    source = mem.util.convert_cmd([source])[0]

    mem.util.ensure_dir(DESTDIR)

    def copier(*args, **kwargs):
        shutil.copy2(*args, **kwargs)
        return (0, "", "")


    if mem.util.run_return_output("Installing to %s" % DESTDIR,
                                  source,
                                  copier,
                                  source,
                                  target)[0]:
        mem.fail()

    return mem.nodes.File(target)