Exemplo n.º 1
0
def generate_schemes_makefile(schemes, schemes_makefile, schemes_cmakefile,
                              schemes_sourcefile):
    """Generate makefile/cmakefile snippets for all schemes."""
    logging.info('Generating schemes makefile/cmakefile snippet ...')
    success = True
    makefile = SchemesMakefile()
    makefile.filename = schemes_makefile
    cmakefile = SchemesCMakefile()
    cmakefile.filename = schemes_cmakefile
    sourcefile = SchemesSourcefile()
    sourcefile.filename = schemes_sourcefile
    # Adjust relative file path to schemes from caps makefile
    schemes_with_path = []
    schemes_with_abspath = []
    schemes_makefile_dir = os.path.split(os.path.abspath(schemes_makefile))[0]
    for scheme in schemes:
        (scheme_filepath,
         scheme_filename) = os.path.split(os.path.abspath(scheme))
        relative_path = './{0}'.format(
            os.path.relpath(scheme_filepath, schemes_makefile_dir))
        schemes_with_path.append(os.path.join(relative_path, scheme_filename))
        schemes_with_abspath.append(os.path.abspath(scheme))
    makefile.write(schemes_with_abspath)
    cmakefile.write(schemes_with_abspath)
    sourcefile.write(schemes_with_abspath)
    logging.info('Added {0} schemes to {1}, {2}, {3}'.format(
        len(schemes_with_path), makefile.filename, cmakefile.filename,
        sourcefile.filename))
    return success
Exemplo n.º 2
0
def generate_schemes_makefile(schemes, schemes_makefile, schemes_cmakefile,
                              schemes_sourcefile):
    """Generate makefile/cmakefile snippets for all schemes."""
    logging.info('Generating schemes makefile/cmakefile snippet ...')
    success = True
    makefile = SchemesMakefile()
    makefile.filename = schemes_makefile + '.tmp'
    cmakefile = SchemesCMakefile()
    cmakefile.filename = schemes_cmakefile + '.tmp'
    sourcefile = SchemesSourcefile()
    sourcefile.filename = schemes_sourcefile + '.tmp'
    # Sort schemes so that the order remains the same (for cmake to avoid) recompiling
    schemes.sort()
    # Generate list of schemes with absolute path
    schemes_with_abspath = [os.path.abspath(scheme) for scheme in schemes]
    makefile.write(schemes_with_abspath)
    cmakefile.write(schemes_with_abspath)
    sourcefile.write(schemes_with_abspath)
    if os.path.isfile(schemes_makefile) and \
            filecmp.cmp(schemes_makefile, makefile.filename):
        os.remove(makefile.filename)
        os.remove(cmakefile.filename)
        os.remove(sourcefile.filename)
    else:
        if os.path.isfile(schemes_makefile):
            os.remove(schemes_makefile)
        if os.path.isfile(schemes_cmakefile):
            os.remove(schemes_cmakefile)
        if os.path.isfile(schemes_sourcefile):
            os.remove(schemes_sourcefile)
        os.rename(makefile.filename, schemes_makefile)
        os.rename(cmakefile.filename, schemes_cmakefile)
        os.rename(sourcefile.filename, schemes_sourcefile)
    #
    logging.info('Added {0} schemes to {1}, {2}, {3}'.format(
        len(schemes_with_abspath), schemes_makefile, schemes_cmakefile,
        schemes_sourcefile))
    return success