def run( *args, **kwargs ): from cuppa.log import initialise_logging from cuppa.log import mask_secrets import SCons.Errors import cuppa.output caller = getframeinfo(stack()[1][0]) sconstruct_path = caller.filename initialise_logging() try: import cuppa.construct cuppa.construct.run( sconstruct_path, *args, **kwargs ) except SCons.Errors.BuildError as error: log_exception( error ) if len(error.args) >= 1: error.args = (mask_secrets(str(error.args[0])),) + error.args[1:] raise except SCons.Errors.StopError as error: log_exception( error ) if len(error.args) >= 1: error.args = (mask_secrets(str(error.args[0])),) + error.args[1:] raise except SCons.Errors.UserError as error: log_exception( error ) if len(error.args) >= 1: error.args = (mask_secrets(str(error.args[0])),) + error.args[1:] raise except Exception as error: log_exception( error ) if len(error.args) >= 1: error.args = (mask_secrets(str(error.args[0])),) + error.args[1:] raise SCons.Errors.StopError( error )
def run( *args, **kwargs ): from cuppa.log import initialise_logging from cuppa.log import mask_secrets import SCons.Errors caller = getframeinfo(stack()[1][0]) sconstruct_path = caller.filename initialise_logging() try: import cuppa.construct cuppa.construct.run( sconstruct_path, *args, **kwargs ) except SCons.Errors.BuildError as error: log_exception( error ) if len(error.args) >= 1: error.args = (mask_secrets(str(error.args[0])),) + error.args[1:] raise except SCons.Errors.StopError as error: log_exception( error ) if len(error.args) >= 1: error.args = (mask_secrets(str(error.args[0])),) + error.args[1:] raise except SCons.Errors.UserError as error: log_exception( error ) if len(error.args) >= 1: error.args = (mask_secrets(str(error.args[0])),) + error.args[1:] raise except Exception as error: log_exception( error ) if len(error.args) >= 1: error.args = (mask_secrets(str(error.args[0])),) + error.args[1:] raise SCons.Errors.StopError( error )
def run(*args, **kwargs): from inspect import getframeinfo, stack caller = getframeinfo(stack()[1][0]) sconsctruct_path = caller.filename import traceback from cuppa.log import logger, initialise_logging from cuppa.colourise import as_info import logging initialise_logging() try: import cuppa.core cuppa.core.run(sconsctruct_path, *args, **kwargs) except Exception as error: logger.error("Cuppa terminated by exception [{}: {}]".format( as_info(error.__class__.__name__), as_info(str(error)))) if not logger.isEnabledFor(logging.EXCEPTION): logger.error("Use {} (or above) to see the stack".format( as_info("--verbosity=exception"))) logger.exception(traceback.format_exc())
def __init__( self, base_path = os.path.abspath( '.' ), branch_root = None, default_options = {}, default_projects = [], default_variants = [], default_dependencies = [], default_profiles = [], default_runner = None, configure_callback = None, dependencies = {}, tools = [] ): cuppa.version.check_current_version() set_base_options() initialise_logging() cuppa_env = CuppaEnvironment() cuppa_env.add_tools( tools ) self.initialise_options( cuppa_env, default_options, dependencies ) cuppa_env['configured_options'] = {} self._configure = cuppa.configure.Configure( cuppa_env, callback=configure_callback ) verbosity = cuppa_env.get_option( 'verbosity' ) if verbosity: set_logging_level( verbosity ) cuppa_env['sconstruct_file'] = cuppa_env.get_option( 'file' ) if not cuppa_env['sconstruct_file']: for path in [ 'SConstruct', 'Sconstruct', 'sconstruct' ]: if os.path.exists( path ): cuppa_env['sconstruct_file'] = path cuppa_env['raw_output'] = cuppa_env.get_option( 'raw_output' ) and True or False cuppa_env['standard_output'] = cuppa_env.get_option( 'standard_output' ) and True or False if not cuppa_env['raw_output'] and not cuppa_env['standard_output']: cuppa_env.colouriser().enable() reset_logging_format() logger.info( "using sconstruct file [{}]".format( as_notice( cuppa_env['sconstruct_file'] ) ) ) help = cuppa_env.get_option( 'help' ) and True or False self._configure.load() cuppa_env['minimal_output'] = cuppa_env.get_option( 'minimal_output' ) cuppa_env['ignore_duplicates'] = cuppa_env.get_option( 'ignore_duplicates' ) cuppa_env['working_dir'] = os.getcwd() cuppa_env['launch_dir'] = os.path.relpath( SCons.Script.GetLaunchDir(), cuppa_env['working_dir'] ) cuppa_env['run_from_launch_dir'] = cuppa_env['launch_dir'] == "." cuppa_env['launch_offset_dir'] = "." if not cuppa_env['run_from_launch_dir']: levels = len( cuppa_env['launch_dir'].split( os.path.sep ) ) cuppa_env['launch_offset_dir'] = os.path.sep.join( ['..' for i in range(levels)] ) cuppa_env['base_path'] = os.path.normpath( os.path.expanduser( base_path ) ) cuppa_env['branch_root'] = branch_root and os.path.normpath( os.path.expanduser( branch_root ) ) or base_path cuppa_env['branch_dir'] = cuppa_env['branch_root'] and os.path.relpath( cuppa_env['base_path'], cuppa_env['branch_root'] ) or None thirdparty = cuppa_env.get_option( 'thirdparty' ) if thirdparty: thirdparty = os.path.normpath( os.path.expanduser( thirdparty ) ) cuppa_env['thirdparty'] = thirdparty build_root = cuppa_env.get_option( 'build_root', default='_build' ) cuppa_env['build_root'] = os.path.normpath( os.path.expanduser( build_root ) ) download_root = cuppa_env.get_option( 'download_root', default='_cuppa' ) cuppa_env['download_root'] = os.path.normpath( os.path.expanduser( download_root ) ) cache_root = cuppa_env.get_option( 'cache_root', default='~/_cuppa/_cache' ) cuppa_env['cache_root'] = os.path.normpath( os.path.expanduser( cache_root ) ) if not os.path.exists( cuppa_env['cache_root'] ): os.makedirs( cuppa_env['cache_root'] ) cuppa_env['default_projects'] = default_projects cuppa_env['default_variants'] = default_variants and set( default_variants ) or set() cuppa_env['default_dependencies'] = default_dependencies and default_dependencies or [] cuppa_env['BUILD_WITH'] = cuppa_env['default_dependencies'] cuppa_env['dependencies'] = {} cuppa_env['default_profiles'] = default_profiles and default_profiles or [] cuppa_env['BUILD_PROFILE'] = cuppa_env['default_profiles'] cuppa_env['profiles'] = {} test_runner = cuppa_env.get_option( 'runner', default=default_runner and default_runner or 'process' ) cuppa_env['default_runner'] = test_runner cuppa_env['show_test_output'] = cuppa_env.get_option( 'show-test-output' ) and True or False self.add_variants ( cuppa_env ) self.add_toolchains ( cuppa_env ) self.add_platforms ( cuppa_env ) cuppa_env['platform'] = cuppa.build_platform.Platform.current() toolchains = cuppa_env.get_option( 'toolchains' ) cuppa_env[ 'target_architectures' ] = None if not help and not self._configure.handle_conf_only(): default_toolchain = cuppa_env['platform'].default_toolchain() if not toolchains: toolchains = [ cuppa_env[self.toolchains_key][default_toolchain] ] else: toolchains = [ cuppa_env[self.toolchains_key][t] for t in toolchains ] cuppa_env['active_toolchains'] = toolchains def add_dependency( name, dependency ): cuppa_env['dependencies'][name] = dependency cuppa.modules.registration.get_options( "methods", cuppa_env ) if not help and not self._configure.handle_conf_only(): cuppa_env[self.project_generators_key] = {} cuppa.modules.registration.add_to_env( "dependencies", cuppa_env, add_dependency ) cuppa.modules.registration.add_to_env( "profiles", cuppa_env ) cuppa.modules.registration.add_to_env( "methods", cuppa_env ) cuppa.modules.registration.add_to_env( "project_generators", cuppa_env ) for method_plugin in pkg_resources.iter_entry_points( group='cuppa.method.plugins', name=None ): method_plugin.load().add_to_env( cuppa_env ) if dependencies: for name, dependency in dependencies.iteritems(): dependency.add_to_env( cuppa_env, add_dependency ) # TODO - default_profile if cuppa_env.get_option( 'dump' ): cuppa_env.dump() SCons.Script.Exit() job_count = cuppa_env.get_option( 'num_jobs' ) parallel = cuppa_env.get_option( 'parallel' ) parallel_mode = "manually" if job_count==1 and parallel: job_count = multiprocessing.cpu_count() if job_count > 1: SCons.Script.SetOption( 'num_jobs', job_count ) parallel_mode = "automatically" cuppa_env['job_count'] = job_count cuppa_env['parallel'] = parallel if job_count>1: logger.debug( "Running in {} with option [{}] set {} as [{}]".format( as_emphasised("parallel mode"), as_info( "jobs" ), as_emphasised(parallel_mode), as_info( str( SCons.Script.GetOption( 'num_jobs') ) ) ) ) if not help and self._configure.handle_conf_only(): self._configure.save() if not help and not self._configure.handle_conf_only(): self.build( cuppa_env ) if self._configure.handle_conf_only(): print "cuppa: Handling onfiguration only, so no builds will be attempted." print "cuppa: With the current configuration executing 'scons -D' would be equivalent to:" print "" print "scons -D {}".format( self._command_line_from_settings( cuppa_env['configured_options'] ) ) print "" print "cuppa: Nothing to be done. Exiting." SCons.Script.Exit()