Example #1
0
def handle_cfg(transform, filepath):
    # if there is a .cfg file, disable it
    stem, ext = os.path.splitext(filepath)
    cfg_orig = stem + ".cfg"
    cfg_orig = io.iglob(cfg_orig)
    if cfg_orig:
        cfg_orig = cfg_orig[0]
        cfg_disable = cfg_orig + ".disable"
        io.rename(cfg_orig, cfg_disable)
        transform[cfg_orig] = cfg_disable

        # XXX write new .cfg with filtered flags
        s = open(cfg_disable).read()
        s = re.sub("(?i)-M", "", s)  # writes dcus to disk
        s = re.sub("(?i)-GD", "", s)  # writes .map file to disk
        s = re.sub("(?i)-cg", "", s)  # writes .drc file to disk
        # kill whitespace only lines
        s = "\n".join(filter(lambda l: not re.match("^\s*$", l), s.splitlines()))
        open(cfg_orig, "w").write(s)
Example #2
0
def do_preprocess(filelist, is_directive_on, dipp_conditionals):
    dipp_bin = get_dipp()

    for fp in filelist:
        filename = os.path.basename(fp)
        directory = os.path.dirname(fp)

        tmpfile = io.get_tmpfile(filename)
        if io.platform_is_cygwin():
            tmpfile = io.path_cygwin_to_win(tmpfile)

        ### PASS 1
        flags = ['-o', '-PD2006', '-li']

        exitcode = io.run_win32app('Preprocessing includes in %s' % fp,
                                   directory,
                                   [dipp_bin, filename, tmpfile]
                                   + flags)
        if not exitcode:
            io.rename(tmpfile, fp)
        else:
            return exitcode

        ### PASS 1.5
        prepare_to_preprocess(is_directive_on, fp)

        ### PASS 2
        flags = ['-o', '-PD2006', '-c', '-h', dipp_conditionals]

        exitcode = io.run_win32app('Preprocessing conditionals in %s' % fp,
                                   directory,
                                   [dipp_bin, filename, tmpfile]
                                   + flags)
        if not exitcode:
            io.rename(tmpfile, fp)
        else:
            return exitcode

        ### PASS 2.5
        do_after_preprocess(fp)

    return exitcode
Example #3
0
def build(filepath, use_graph=None, target_dir=None):
    transform = {}

    if not DelphiGraph.filepath_is_graph(filepath):
        fpabs = os.path.abspath(filepath)
        abspath = os.path.dirname(fpabs)
        relpath = "."
        filename = os.path.basename(fpabs)
        stdlibpath = DelphiCompiler.get_stdlibpath(libonly=True, relative_to=abspath)
        includepath = ";".join(stdlibpath)

        if use_graph:
            dg = DelphiGraph.from_file(use_graph)
            df = dg.rootnode
            includepath = prepare_path(dg, use_abspath=abspath)

        return do_compile(transform, abspath, relpath, filename, includepath, target_dir=target_dir)

    else:
        # load from file
        dg = DelphiGraph.from_file(filepath)
        df = dg.rootnode
        targets = df.collect_nodes(lambda n: n.filetype in (FileTypes.Program, FileTypes.Library, FileTypes.Package))
        target = targets[0]

        includepath = prepare_path(dg)

        try:
            # XXX seems to be redundant at times, not understood when
            do_dfm_conversion(transform, dg)
            exitcode = do_compile(
                transform, dg.abspath, target.path, target.filename, includepath, target_dir=target_dir
            )
        finally:
            for (orig, new) in transform.items():
                io.rename(new, orig)

        return exitcode