Ejemplo n.º 1
0
def genTengilFile(outputFile = str(), viewDir = str(), outputName = str(), inputName = str(), buildItems = list(), bcFile = str()):
    launch_path = posixpath.abspath('.')
    view_dir = ctx2_common.get_view_dir(viewDir)
    obj_dir = view_dir + os.sep + '.ctx/obj'

    envLayout = None
    oldEnv = None

    contexo_config_path = posixpath.join( ctx_common.getUserCfgDir(), ctx_sysinfo.CTX_CONFIG_FILENAME )
    cfgFile = ctx_cfg.CFGFile( contexo_config_path )

    cview = ctx_view.CTXView(view_dir, validate=False)
    bc = ctx2_common.getBuildConfiguration(cview, bcFile, cfgFile)

    comps = ctx2_common.expand_list_files(cview, buildItems)

    components = list()
    modules = list()
    components = ctx2_common.create_components(comps, cview.getItemPaths('comp'), obj_dir, launch_path)
    for comp in components:
        for library, compModules in comp.libraries.items():
            modules.extend(compModules)

    buildTests = True
    librarySources, includes = ctx2_common.parseComps(cview, view_dir, buildTests, bc, components)
    tempdir = tempfile.mkdtemp(prefix='ctx2tengil')

    for file in includes:
        shutil.copy(file, tempdir)
    for sources in librarySources.values():
        for file in sources:
            shutil.copy(file, tempdir)

    args = " ".join(['grep', '-h', inputName, tempdir + os.sep + '*',  '|', 'grep', '-v', '"#define"' + '>', outputFile])
    print args
    if subprocess.call(args, shell=True) != 0:
        sys.exit()
    
    args = " ".join(['sed', '-i', 's/' + inputName + '/' + outputName + '/g', outputFile])
    print args
    if subprocess.Popen(args, shell=True) != 0:
        sys.exit()
 
    shutil.rmtree(tempdir)