def __enter__(self): print("Configuring...") self.config = Configure(self.zenv.environment) # This adds some pre-added tests self.config.AddTests({ "detectStdlib": detectStdlib, "detectFilesystem": detectFilesystem }); return self
def can_be_compiled(env, code): """Check if the code can be compiled""" conf = Configure(env) if not conf.TryCompile(code, '.cc'): if not os.path.isfile('.sconf_temp/conftest_0.cc'): env.PrintError( "TryCompile failed. Rerun the scons with '--config=force' parameter" ) res = False else: res = True env = conf.Finish() return res
def is64BitMachine(env, platform, machine): """Determine if machine has 64 or 32 bit architecture""" if platform == 'Linux' and machine == 'x86_64': return True else: ccflags = '' # Run the test conf = Configure(env, custom_tests={'CheckBits': CheckHas64Bits}) ret = conf.CheckBits(ccflags) env = conf.Finish() if ret < 1: print 'Cannot run test, assume 32 bit system' return False elif ret == 64: # Test shows 64 bit system' return True else: # Test shows 32 bit system' return False
def check_godot_headers_directory(environment, godot_cpp_directory): """Verifies that the godot_headers directory inside the Godot-CPP directory has been downloaded as a git submodule and is complete. @param godot_cpp_directory Directory into which Godot-CPP was checked out @returns True if the godot_headers subdirectory is complete, False otherwise""" configure_godot_headers = Configure(environment) godot_headers_directory = os.path.join(godot_cpp_directory, 'godot_headers') is_complete = True for file in godot_headers_files_subset: file_path = os.path.join(godot_headers_directory, file) if not os.path.isfile(file_path): is_complete = False #if not configure_godot_headers.CheckCXXHeader(file_path): # is_complete = False if is_complete: print( "\033[92mGodot-CPP appears to be complete, with godot_headers submodule\033[0m" ) else: print( "\033[95mERROR: The godot_headers directory seems to be incomplete.\033[0m" ) print( "\033[95m This is a git submodule of Godot-CPP and needs to be\033[0m" ) print( "\033[95m checked out together with Godot-CPP. Please repeat the\033[0m" ) print( "\033[95m clone of the template with --recurse-submodules\033[0m" ) #Exit(1) raise FileNotFoundError( errno.ENOENT, 'Missing godot_headers directory. Incomplete git checkout?', os.path.join(godot_cpp_directory, 'godot_headers'))
class ConfigContext: def __init__(self, zenv): self.zenv = zenv; def __enter__(self): print("Configuring...") self.config = Configure(self.zenv.environment) # This adds some pre-added tests self.config.AddTests({ "detectStdlib": detectStdlib, "detectFilesystem": detectFilesystem }); return self def addTest(self, name: str, function): self.config.AddTest(name, function) def addTests(self, testMap): self.config.AddTests(testMap) def test(self, name: str, *args, **kwargs): """ This function either executes an existing test, or adds a new one with a supplied callback. The callback has to be a named argument, or the call being: test("myNewTest", callback = someFunction) """ callback = None if "callback" in kwargs: callback = kwargs["callback"] del kwargs["callback"] # See if the callback can be set if callback is not None: self.config.AddTest(name, callback) # Finally, before running, make sure the test exists, # regardless of whether it was just added or not if not hasattr(self.config, name): raise RuntimeError("Test not registered: " + name) return getattr(self.config, name)(*args, **kwargs) def configureFilesystem(self): """ This method configures the filesystem based on my preferred standard. """ self.config.detectStdlib(self.zenv) (supportsFilesystem, needsLink) = self.config.detectFilesystem(self.zenv) if not supportsFilesystem: raise RuntimeError("This build doesn't support filesystem") if (needsLink): if self.zenv.stdlib == "libstdc++": self.zenv.withLibraries(["stdc++fs"]) else: # libc++ # MSVC doesn't require linking in any configurations, so it's # the only other alternative self.zenv.withLibraries(["c++fs"]) def __exit__(self, type, value, traceback): print("Configuration done") self.config.Finish() self.config = None
def base_setup(env, prereqs=None): """Setup the scons environment for the compiler Include all our preferred compile options for the chosen compiler and build type. """ if GetOption('help') or GetOption('clean'): return compiler = env['CC'] build_type = env['BUILD_TYPE'] print(f'Setting up compile environment for {compiler}') print(f"Build type is '{build_type}'") prev_compiler = env.get('BSETUP', False) if prev_compiler: if prev_compiler != compiler: print('Env is already setup for a different compiler') print('Env already setup') Exit(2) # Turn on -Wall first, then DESIRED_FLAGS may disable some of the options # that this brings in. env.Append(CCFLAGS=['-g', '-Wshadow', '-Wall', '-fpic']) env.AppendIfSupported(CCFLAGS=DESIRED_FLAGS) if build_type == 'debug': if compiler == 'gcc': env.AppendUnique(CCFLAGS=['-Og']) else: env.AppendUnique(CCFLAGS=['-O0']) else: if build_type == 'release': env.AppendUnique(CPPDEFINES='DAOS_BUILD_RELEASE') env.AppendUnique(CCFLAGS=['-O2']) env.AppendUnique(CPPDEFINES={'_FORTIFY_SOURCE': '2'}) if build_type != 'release': env.AppendUnique(CPPDEFINES={'FAULT_INJECTION': '1'}) env.AppendUnique(CPPDEFINES={'CMOCKA_FILTER_SUPPORTED': '0'}) env.AppendUnique(CPPDEFINES='_GNU_SOURCE') cenv = env.Clone() cenv.Append(CFLAGS='-Werror') config = Configure(cenv) if config.CheckHeader('stdatomic.h'): config.Finish() env.AppendUnique(CPPDEFINES={'HAVE_STDATOMIC': '1'}) elif prereqs: config.Finish() prereqs.require(env, 'openpa', headers_only=True) else: config.Finish() if compiler == 'icx' and not GetOption('no_rpath'): # Hack to add rpaths for path in env['ENV']['LD_LIBRARY_PATH'].split(':'): if 'oneapi' in path: env.AppendUnique(RPATH_FULL=[path]) if GetOption('preprocess'): # Could refine this but for now, just assume these warnings are ok env.AppendIfSupported(CCFLAGS=PP_ONLY_FLAGS) env['BSETUP'] = compiler
def SetupEnvironment(env): # install initial required methods _installEnvironmentMethods(env) # load required tools global __file__ toolpath = [os.path.join(os.path.dirname(__file__), 'scons_tools')] env.Tool('disttar', toolpath = toolpath) CreateConfigHBuilder(env) # setup environment env.Replace(SB_CREATED_LIBRARIES={}) env.Replace(ARGUMENTS=ARGUMENTS) env.Replace(SB_CONFIG_HS={}) env.Replace(SB_CURRENT_CONFIG_H=None) # if specified initialize config header configHeader = env.get('CONFIG_HEADER') if SCons.Util.is_String(configHeader): configHeader = ConfigHeader(filename=configHeader) elif isinstance(configHeader, ConfigHeader): pass elif configHeader: configHeader = ConfigHeader() else: configHeader = None env.Replace(CONFIG_HEADER = configHeader) # setup compiler compilerSetupFunc = GetCompiler(env.get('compiler')) if compilerSetupFunc: compilerSetupFunc(env) # setup user-defined compiler options: # libpath -> LIBPATH # cpppath -> CPPPATH # ccflags -> CCFLAGS # linkflags -> LINKFLAGS if env.get('libpath'): libpath = env['libpath'].split(os.pathsep) for p in libpath: env.Append(LIBPATH=[p]) if env.get('cpppath'): cpppath = env['cpppath'].split(os.pathsep) for p in cpppath: env.Append(CPPPATH=[p]) if env.get('ccflags'): ccflags = env['ccflags'].split() for f in ccflags: env.Append(CCFLAGS=[f]) if env.get('linkflags'): linkflags = env['linkflags'].split() for f in linkflags: env.Append(LINKFLAGS=[f]) # setup architecture archSetupFunc = GetArchitecture(env.get('arch')) if archSetupFunc: archSetupFunc(env) CustomizeEnvironment(env) # setup configuration conf = Configure(env, custom_tests=GetCustomTests(), conf_dir=os.path.join(env['BUILD_DIR'], '.sconf_temp'), log_file=os.path.join(env['BUILD_DIR'], 'config.log')) setattr(conf, 'sb_config_h', configHeader) CustomizeConfiguration(conf) env = conf.Finish() # setup modified versions of the Program and Library builders # save original builders env.scStaticLibrary = env.StaticLibrary env.scSharedLibrary = env.SharedLibrary env.scProgram = env.Program env.scLibrary = env.Library env.scLoadableModule = env.LoadableModule # install my builders env.StaticLibrary = env.SB_StaticLibrary env.Library = env.SB_StaticLibrary env.SharedLibrary = env.SB_SharedLibrary env.LoadableModule = env.SB_LoadableModule env.Program = env.SB_Program FinalizeEnvironment(env) return env