How to use the west.log.wrn 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 NordicPlayground / fw-nrfconnect-nrf / scripts / west_commands / ncs_commands.py View on Github external
banner = zp.format('{ncs_name} ({path}):', ncs_name=nn)

        if np.name == 'zephyr':
            nrev = self.manifest.get_projects(['zephyr'])[0].revision
            zrev = self.zephyr_sha
        else:
            nrev = np.revision
            zrev = zp.revision

        nsha = self.checked_sha(np, nrev)
        zsha = self.checked_sha(zp, zrev)

        if not np.is_cloned() or nsha is None or zsha is None:
            log.small_banner(banner)
            if not np.is_cloned():
                log.wrn('project is not cloned; please run "west update"')
            elif nsha is None:
                log.wrn("can't compare; please run \"west update {}\"".
                        format(nn),
                        '(need revision {})'.format(np.revision))
            elif zsha is None:
                log.wrn("can't compare; please fetch upstream URL", zp.url,
                        '(need revision {})'.format(zp.revision))
            return

        cp = np.git('rev-list --left-right --count {}...{}'.format(zsha, nsha),
                    capture_stdout=True)
        behind, ahead = [int(c) for c in cp.stdout.split()]

        if zsha == nsha:
            status = 'up to date'
        elif ahead and not behind:
github zephyrproject-rtos / west / src / west / app / project.py View on Github external
def warn_once_if_no_git():
    # Using an LRU cache means this gets called once. Afterwards, the
    # memoized return value (None) is simply returned from the cache,
    # so the warning is emitted only once per process invocation.
    if shutil.which('git') is None:
        log.wrn('git is not installed or cannot be found; this may fail')
github NordicPlayground / fw-nrfconnect-nrf / scripts / west_commands / ncs_west_helpers.py View on Github external
if rsha in downstream_out:
                    log.dbg('** commit {} ("{}") was reverted in {}'.
                            format(rsha, commit_shortlog(downstream_out[rsha]),
                                   sha), level=log.VERBOSE_VERY)
                    del downstream_out[rsha]
                    continue
                elif rsha is not None:
                    # Make sure the reverted commit is in downstream history.
                    # (It might not be in all_downstream_oot if e.g.
                    # downstream reverts an upstream patch as a hotfix, and we
                    # shouldn't warn about that.)
                    is_ancestor = self._dp.git(
                        'merge-base --is-ancestor {} {}'.format(rsha, dsha),
                        capture_stdout=True).returncode == 0
                    if not is_ancestor:
                        log.wrn(('commit {} ("{}") reverts {}, '
                                 "which isn't in downstream history").
                                format(sha, sl, rsha))

            # Emit a warning if we have a non-revert patch with an
            # incorrect sauce tag. (Again, downstream might carry reverts
            # of upstream patches as hotfixes, which we shouldn't
            # warn about.)
            if (not shortlog_has_sauce(sl, self._downstream_sauce) and
                    not is_revert):
                log.wrn('bad or missing sauce tag: {} ("{}")'.format(sha, sl))

            downstream_out[sha] = c
            log.dbg('** added oot patch: {} ("{}")'.format(sha, sl),
                    level=log.VERBOSE_VERY)

        return list(downstream_out.values())
github zephyrproject-rtos / zephyr / scripts / meta / west / commands / project.py View on Github external
def _wrn(project, msg):
    # Warn with 'msg'. Supports the same (foo) shorthands as the git commands.

    log.wrn(_expand_shorthands(project, msg))
github zephyrproject-rtos / zephyr / scripts / west_commands / run_common.py View on Github external
def _dump_context(command, args, runner_args, cached_runner_var):
    build_dir = _build_dir(args, die_if_none=False)

    # Try to figure out the CMake cache file based on the build
    # directory or an explicit argument.
    if build_dir is not None:
        cache_file = path.abspath(
            path.join(build_dir, args.cmake_cache or cmake.DEFAULT_CACHE))
    elif args.cmake_cache:
        cache_file = path.abspath(args.cmake_cache)
    else:
        cache_file = None

    # Load the cache itself, if possible.
    if cache_file is None:
        log.wrn('No build directory (--build-dir) or CMake cache '
                '(--cmake-cache) given or found; output will be limited')
        cache = None
    else:
        try:
            cache = cmake.CMakeCache(cache_file)
        except Exception:
            log.die('Cannot load cache {}.'.format(cache_file))

    # If we have a build directory, try to ensure build artifacts are
    # up to date. If that doesn't work, still try to print information
    # on a best-effort basis.
    if build_dir and not args.skip_rebuild:
        try:
            cmake.run_build(build_dir)
        except CalledProcessError:
            msg = 'Failed re-building application; cannot load context. '
github zephyrproject-rtos / west / src / west / app / main.py View on Github external
path_specs = extension_commands(manifest=self.manifest)
        extension_names = set()

        for path, specs in path_specs.items():
            # Filter out attempts to shadow built-in commands as well as
            # command names which are already used.

            filtered = []
            for spec in specs:
                if spec.name in self.builtins:
                    log.wrn(f'ignoring project {spec.project.name} '
                            f'extension command "{spec.name}"; '
                            'this is a built in command')
                    continue
                if spec.name in extension_names:
                    log.wrn(f'ignoring project {spec.project.name} '
                            f'extension command "{spec.name}"; '
                            f'command "{spec.name}" is '
                            'already defined as extension command')
                    continue

                filtered.append(spec)
                extension_names.add(spec.name)
                self.extensions[spec.name] = spec

            self.extension_groups[path] = filtered
github zephyrproject-rtos / zephyr / scripts / west_commands / build.py View on Github external
log.die("source directory specified twice:({} and {})".format(
                                            source_dir, self.args.source_dir))
            self.args.source_dir = source_dir
        log.dbg('source_dir: {} cmake_opts: {}'.format(self.args.source_dir,
                                                       self.args.cmake_opts),
                level=log.VERBOSE_EXTREME)
        self._sanity_precheck()
        self._setup_build_dir()

        if args.pristine is not None:
            pristine = args.pristine
        else:
            # Load the pristine={auto, always, never} configuration value
            pristine = config_get('pristine', 'never')
            if pristine not in ['auto', 'always', 'never']:
                log.wrn(
                    'treating unknown build.pristine value "{}" as "never"'.
                    format(pristine))
                pristine = 'never'
        self.auto_pristine = (pristine == 'auto')

        log.dbg('pristine: {} auto_pristine: {}'.format(pristine,
                                                        self.auto_pristine),
                level=log.VERBOSE_VERY)
        if is_zephyr_build(self.build_dir):
            if pristine == 'always':
                self._run_pristine()
                self.run_cmake = True
            else:
                self._update_cache()
                if (self.args.cmake or self.args.cmake_opts or
                        self.args.cmake_only):
github zephyrproject-rtos / west / src / west / app / project.py View on Github external
# Print helpful information to the user about a project that
    # might have just left a branch behind.

    if branch == 'HEAD':
        # If there was no branch checked out, there are no
        # additional diagnostics that need emitting.
        return

    rel = relpath(project.abspath)
    if is_ancestor:
        # If the branch we just left behind is a descendant of
        # the new HEAD (e.g. if this is a topic branch the
        # user is working on and the remote hasn't changed),
        # print a message that makes it easy to get back,
        # no matter where in the workspace os.getcwd() is.
        log.wrn(f'left behind {project.name} branch "{branch}"; '
                f'to switch back to it (fast forward), use: '
                f'git -C {rel} checkout {branch}')
        log.dbg('(To do this automatically in the future,',
                'use "west update --keep-descendants".)')
    else:
        # Tell the user how they could rebase by hand, and
        # point them at west update --rebase.
        log.wrn(f'left behind {project.name} branch "{branch}"; '
                f'to rebase onto the new HEAD: '
                f'git -C {rel} rebase {sha} {branch}')
        log.dbg('(To do this automatically in the future,',
                'use "west update --rebase".)')