How to use the west.configuration.config.get function in west

To help you get started, we’ve selected a few west examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zephyrproject-rtos / west / src / west / app / main.py View on Github external
# The command line --zephyr-base takes precedence over
        # everything else.
        zb = os.path.abspath(args.zephyr_base)
        zb_origin = 'command line'
    else:
        # If the user doesn't specify it concretely, then use ZEPHYR_BASE
        # from the environment or zephyr.base from west.configuration.
        #
        # (We will configure zephyr.base to the project that has path
        # 'zephyr' as a last resort here.)
        #
        # At some point, we need a more flexible way to set environment
        # variables based on manifest contents, but this is good enough
        # to get started with and to ask for wider testing.
        zb_env = os.environ.get('ZEPHYR_BASE')
        zb_prefer = config.config.get('zephyr', 'base-prefer',
                                      fallback=None)
        rel_zb_config = config.config.get('zephyr', 'base', fallback=None)
        if rel_zb_config is None:
            projects = None
            try:
                projects = manifest.get_projects(['zephyr'])
            except ValueError:
                pass
            if projects:
                zephyr = projects[0]
                config.update_config('zephyr', 'base', zephyr.path)
                rel_zb_config = zephyr.path
        if rel_zb_config is not None:
            zb_config = Path(topdir) / rel_zb_config
        else:
            zb_config = None
github zephyrproject-rtos / zephyr / scripts / west_commands / build.py View on Github external
def config_get(option, fallback):
    return config.get('build', option, fallback=fallback)
github zephyrproject-rtos / zephyr / scripts / west_commands / run_common.py View on Github external
def _build_dir(args, die_if_none=True):
    # Get the build directory for the given argument list and environment.
    if args.build_dir:
        return args.build_dir

    guess = config.get('build', 'guess-dir', fallback='never')
    guess = guess == 'runners'
    dir = find_build_dir(None, guess)

    if dir and is_zephyr_build(dir):
        return dir
    elif die_if_none:
        msg = '--build-dir was not given, '
        if dir:
            msg = msg + 'and neither {} nor {} are zephyr build directories.'
        else:
            msg = msg + ('{} is not a build directory and the default build '
                         'directory cannot be determined. Check your '
                         'build.dir-fmt configuration option')
        log.die(msg.format(getcwd(), dir))
    else:
        return None
github zephyrproject-rtos / west / src / west / app / main.py View on Github external
zb = os.path.abspath(args.zephyr_base)
        zb_origin = 'command line'
    else:
        # If the user doesn't specify it concretely, then use ZEPHYR_BASE
        # from the environment or zephyr.base from west.configuration.
        #
        # (We will configure zephyr.base to the project that has path
        # 'zephyr' as a last resort here.)
        #
        # At some point, we need a more flexible way to set environment
        # variables based on manifest contents, but this is good enough
        # to get started with and to ask for wider testing.
        zb_env = os.environ.get('ZEPHYR_BASE')
        zb_prefer = config.config.get('zephyr', 'base-prefer',
                                      fallback=None)
        rel_zb_config = config.config.get('zephyr', 'base', fallback=None)
        if rel_zb_config is None:
            projects = None
            try:
                projects = manifest.get_projects(['zephyr'])
            except ValueError:
                pass
            if projects:
                zephyr = projects[0]
                config.update_config('zephyr', 'base', zephyr.path)
                rel_zb_config = zephyr.path
        if rel_zb_config is not None:
            zb_config = Path(topdir) / rel_zb_config
        else:
            zb_config = None

        if zb_prefer == 'env' and zb_env is not None:
github zephyrproject-rtos / west / src / west / app / project.py View on Github external
def fetch_strategy(self, args):
        cfg = config.get('update', 'fetch', fallback=None)
        if cfg is not None and cfg not in ('always', 'smart'):
            log.wrn(f'ignoring invalid config update.fetch={cfg}; '
                    'choices: always, smart')
            cfg = None
        if args.fetch_strategy:
            return args.fetch_strategy
        elif cfg:
            return cfg
        else:
            return 'smart'
github zephyrproject-rtos / zephyr / scripts / west_commands / build_helpers.py View on Github external
The default build directory is computed by reading the build.dir-fmt
    configuration option, defaulting to DEFAULT_BUILD_DIR if not set. It might
    be None if the build.dir-fmt configuration option is set but cannot be
    resolved.
    If the given argument is truthy, it is returned. Otherwise, if
    the default build folder is a build directory, it is returned.
    Next, if the current working directory is a build directory, it is
    returned. Finally, the default build directory is returned (may be None).
    '''

    if dir:
        build_dir = dir
    else:
        cwd = os.getcwd()
        default = config.get('build', 'dir-fmt', fallback=DEFAULT_BUILD_DIR)
        default = _resolve_build_dir(default, guess, cwd, **kwargs)
        log.dbg('config dir-fmt: {}'.format(default), level=log.VERBOSE_EXTREME)
        if default and is_zephyr_build(default):
            build_dir = default
        elif is_zephyr_build(cwd):
            build_dir = cwd
        else:
            build_dir = default
    log.dbg('build dir: {}'.format(build_dir), level=log.VERBOSE_EXTREME)
    if build_dir:
        return os.path.abspath(build_dir)
    else:
        return None