def generate_caps_makefile(caps, caps_makefile, caps_cmakefile,
                           caps_sourcefile, caps_dir):
    """Generate makefile/cmakefile snippets for all caps."""
    logging.info('Generating caps makefile/cmakefile snippet ...')
    success = True
    makefile = CapsMakefile()
    makefile.filename = caps_makefile
    cmakefile = CapsCMakefile()
    cmakefile.filename = caps_cmakefile
    sourcefile = CapsSourcefile()
    sourcefile.filename = caps_sourcefile
    # Adjust relative file path to schemes from caps makefile
    caps_makefile_dir = os.path.split(os.path.abspath(caps_makefile))[0]
    relative_path = './{0}'.format(os.path.relpath(caps_dir,
                                                   caps_makefile_dir))
    caps_with_path = [os.path.join(relative_path, cap) for cap in caps]
    caps_with_abspath = [
        os.path.abspath(os.path.join(caps_dir, cap)) for cap in caps
    ]
    makefile.write(caps_with_abspath)
    cmakefile.write(caps_with_abspath)
    sourcefile.write(caps_with_abspath)
    logging.info('Added {0} auto-generated caps to {1} and {2}'.format(
        len(caps_with_path), makefile.filename, cmakefile.filename))
    return success
Exemple #2
0
def generate_caps_makefile(caps, caps_makefile, caps_cmakefile, caps_sourcefile, caps_dir):
    """Generate makefile/cmakefile snippets for all caps."""
    logging.info('Generating caps makefile/cmakefile snippet ...')
    success = True
    makefile = CapsMakefile()
    makefile.filename = caps_makefile + '.tmp'
    cmakefile = CapsCMakefile()
    cmakefile.filename = caps_cmakefile + '.tmp'
    sourcefile = CapsSourcefile()
    sourcefile.filename = caps_sourcefile + '.tmp'
    # Generate list of caps with absolute path
    caps_with_abspath = [ os.path.abspath(os.path.join(caps_dir, cap)) for cap in caps ]
    makefile.write(caps_with_abspath)
    cmakefile.write(caps_with_abspath)
    sourcefile.write(caps_with_abspath)
    if os.path.isfile(caps_makefile) and \
            filecmp.cmp(caps_makefile, makefile.filename):
        os.remove(makefile.filename)
        os.remove(cmakefile.filename)
        os.remove(sourcefile.filename)
    else:
        if os.path.isfile(caps_makefile):
            os.remove(caps_makefile)
        if os.path.isfile(caps_cmakefile):
            os.remove(caps_cmakefile)
        if os.path.isfile(caps_sourcefile):
            os.remove(caps_sourcefile)
        os.rename(makefile.filename, caps_makefile)
        os.rename(cmakefile.filename, caps_cmakefile)
        os.rename(sourcefile.filename, caps_sourcefile)
    #
    logging.info('Added {0} auto-generated caps to {1} and {2}, {3}'.format(
           len(caps_with_abspath), caps_makefile, caps_cmakefile, caps_sourcefile))
    return success