def cmd_build(args): launch_path = os.path.abspath('.') view_dir = get_view_dir(args.view) obj_dir = view_dir + os.sep + '.ctx/obj' # test if not absolute path if args.output[0] != '/' and args.output[0] != '\\' and args.output[1:3] != ':\\': lib_output = os.path.join(view_dir,args.output) else: lib_output = args.output lib_dirs = map(os.path.abspath, args.libdirs) from contexo import ctx_cmod from contexo import ctx_base from contexo import ctx_envswitch from contexo.ctx_depmgr import CTXDepMgr from contexo.ctx_export import CTXExportData envLayout = None oldEnv = None if args.env != None: envLayout = EnvironmentLayout( cfgFile, args.env ) oldEnv = switchEnvironment( envLayout, True ) absIncDirs = map(os.path.abspath, args.incdirs) # Prepare all deprecated_nra_warning( args ) deprecated_repo_validation_warning(args) cview = ctx_view.CTXView( view_dir, validate=False ) bc = getBuildConfiguration( cview, args ) bc.buildParams.incPaths.extend( absIncDirs ) #TODO: accessing 'private' data? bc.buildParams.ldDirs.extend(lib_dirs) bc.buildParams.ldLibs.extend(args.libs) archPath = list() archPath = bc.getArchPath() deprecated_tolerate_missing_headers_warning(args) depmgr = CTXDepMgr ( codeModulePaths = cview.getItemPaths('modules'), failOnMissingHeaders = args.fail_on_missing_headers, archPath = bc.getArchPath(), additionalIncDirs = absIncDirs, legacyCompilingMod = args.legacy_compiling_mod, legacyDuplicateSources = args.legacy_duplicate_sources, globalOutputDir = obj_dir, bc = bc ) session = ctx_base.CTXBuildSession( bc ) session.setDependencyManager( depmgr ) items = expand_list_files( cview, args.items ) # Make sure we have only one type of item to export #TODO:make a more robust recognition than file extention for .comp component_build = True for item in items: if item.endswith( '.comp' ): if component_build == False: userErrorExit("The operation can either work on a list of components OR a list of modules, not both.") else: component_build = False # Register build configuration in log handler ctx_log.ctxlogSetBuildConfig( bc.getTitle(), bc.getCompiler().cdefTitle, bc.getBuildParams().cflags, bc.getBuildParams().prepDefines, "N/A" ) outputPath = lib_output bin_dir = os.path.join( outputPath, args.bindir ) header_dir = os.path.join( outputPath, args.headerdir ) objs = list() ## TODO: place this in CTXCompiler where it belongs when the spaghetti code is gone ## changing working directory to .ctx/obj/[BUILDCONFIGNAME] dest_wd = os.path.join(obj_dir, bc.getTitle()) try: os.makedirs(dest_wd) except: pass old_path = os.path.abspath('') os.chdir(dest_wd) # Process components if component_build: infoMessage("Building components...", 1) components = create_components( items, cview.getItemPaths('comp'), obj_dir, launch_path ) allmods = set() for comp in components: for library, modules in comp.libraries.items(): mods = expand_list_files( cview, modules ) depmgr.addCodeModules( mods, args.tests ) allmods |= set(modules) depMods = depmgr.getModuleDependencies(allmods) depmgr.emptyCodeModules() if len(depMods - set(allmods)) > 0: for module in depMods - set(allmods): warningMessage('The module \"'+module+'\" was not specified to be built in any specified .comp file, but at least one of its headers were included in another module, linker errors may arise') for comp in components: ctx_log.ctxlogBeginComponent( comp.name ) # Build component modules. for library, modules in comp.libraries.items(): modules = expand_list_files( cview, modules ) depmgr.addCodeModules( modules, args.tests ) args.library_name = library infoMessage('args: %s'%args, 6) objs += buildmodules( depmgr, session, modules, args, bin_dir, session.bc.getTitle(), args.library_name) if (args.all_headers): header_path = os.path.join(lib_output, args.headerdir ) export_public_module_headers( depmgr, modules, header_path ) depmgr.emptyCodeModules() export_headers( depmgr, comp.publicHeaders, header_dir, cview ) ctx_log.ctxlogEndComponent() #Process modules else: infoMessage("Building modules...", 1) depmgr.addCodeModules( items, args.tests ) if args.deps: print >>sys.stderr, "Dependencies for:", print >>sys.stderr, items print >>sys.stderr, depmgr.getCodeModulesWithDependencies() objs += buildmodules( depmgr, session, items, args, outputPath, bc.getTitle(), libraryName=args.library_name) export_public_module_headers( depmgr, items, header_dir ) if args.executable_name: session.linkExecutable(objs, bin_dir, args.executable_name) # Write log if requested if args.logfile != None: logfilepath = os.path.join( lib_output, args.logfile ) logpath = os.path.normpath(os.path.dirname( logfilepath )) if len(logpath) and not os.path.isdir(logpath): os.makedirs( logpath ) ctx_log.ctxlogWriteToFile( logfilepath, appendToExisting=False ) os.chdir(old_path) # Restore environment if args.env != None: switchEnvironment( oldEnv, False )
def cmd_buildcomp(args): launch_path = os.path.abspath('.') view_dir = get_view_dir(args.view) obj_dir = view_dir + os.sep + '.ctx/obj' if args.output[0] == '/' or args.output[0] == '\\' or args.output[1:3] == ':\\': lib_output = args.output else: # relative to view root lib_output = os.path.join(view_dir,args.output) from contexo import ctx_cmod from contexo import ctx_base from contexo import ctx_envswitch from contexo.ctx_depmgr import CTXDepMgr absIncDirs = map(os.path.abspath, args.incdirs) # Switch to specified environment oldEnv = None if args.env != None: envLayout = EnvironmentLayout( cfgFile, args.env ) oldEnv = switchEnvironment( envLayout, True ) if args.logfile != None: ctx_log.ctxlogStart() # Prepare all deprecated_nra_warning( args ) deprecated_repo_validation_warning(args) cview = ctx_view.CTXView( view_dir, validate=False ) components = expand_list_files( cview, args.components ) bc = getBuildConfiguration( cview, args ) bc.buildParams.incPaths.extend( absIncDirs ) #TODO: accessing 'private' data? deprecated_tolerate_missing_headers_warning(args) depmgr = CTXDepMgr ( codeModulePaths = cview.getItemPaths('modules'), failOnMissingHeaders = args.fail_on_missing_headers, archPath = bc.getArchPath(), legacyCompilingMod = args.legacy_compiling_mod, legacyDuplicateSources = args.legacy_duplicate_sources, globalOutputDir = obj_dir, bc = bc ) session = ctx_base.CTXBuildSession( bc ) session.setDependencyManager( depmgr ) # Register build configuration in log handler ctx_log.ctxlogSetBuildConfig( bc.getTitle(), bc.getCompiler().cdefTitle, bc.getBuildParams().cflags, bc.getBuildParams().prepDefines, "N/A" ) ## TODO: place this in CTXCompiler where it belongs when the spaghetti code is gone ## changing working directory to .ctx/obj/[BUILDCONFIGNAME] dest_wd = os.path.join(obj_dir, bc.getTitle()) try: os.makedirs(dest_wd) except: pass old_path = os.path.abspath('') os.chdir(dest_wd) deleteModuleSources = set() # Process components components = create_components( components, cview.getItemPaths('comp'), obj_dir, launch_path ) infoMessage("Building components...", 1) allmods = set() for comp in components: for library, modules in comp.libraries.items(): mods = expand_list_files( cview, modules ) depmgr.addCodeModules( mods, args.tests ) allmods |= set(modules) depMods = depmgr.getModuleDependencies(allmods) depmgr.emptyCodeModules() if len(depMods - set(allmods)) > 0: for module in depMods - set(allmods): warningMessage('The module \"'+module+'\" was not specified to be built in any specified .comp file, but at least one of its headers were included in another module, linker errors may arise') for comp in components: ctx_log.ctxlogBeginComponent( comp.name ) lib_dir = os.path.join( lib_output, args.libdir ) header_dir = os.path.join( lib_output, args.headerdir ) # Build component modules. for library, modules in comp.libraries.items(): modules = expand_list_files( cview, modules ) depmgr.addCodeModules( modules, args.tests ) args.lib = library infoMessage('args: %s'%args, 6) buildmodules( depmgr, session, modules, args, lib_dir, session.bc.getTitle(), libraryName = args.lib) if args.deletesources == True: for module in modules: modPath = depmgr.resolveCodeModulePath(module) deleteModuleSources.add(modPath) depmgr.emptyCodeModules() export_headers( depmgr, comp.publicHeaders, header_dir, cview ) ctx_log.ctxlogEndComponent() # Write log if requested if args.logfile != None: logfilepath = os.path.join( lib_output, args.logfile ) logpath = os.path.normpath(os.path.dirname( logfilepath )) if len(logpath) and not os.path.isdir(logpath): os.makedirs( logpath ) ctx_log.ctxlogWriteToFile( logfilepath, appendToExisting=False ) os.chdir(old_path) # Restore environment if args.env != None: switchEnvironment( oldEnv, False ) if args.deletesources == True: modPath = depmgr.resolveCodeModulePath(module) for modpath in deleteModuleSources: try: srcdir = os.path.join(modpath, 'src') shutil.rmtree(srcdir) infoMessage("Removing source directory: " + srcdir, 1) except: pass try: incdir = os.path.join(modpath, 'inc') shutil.rmtree(incdir) infoMessage("Removing private include directory: " + incdir, 1) except: pass try: testdir = os.path.join(modpath, 'test') shutil.rmtree(testdir) infoMessage("Removing test source directory: " + testdir, 1) except: pass