Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_wrap('''
Runs 'git status' for each of the specified projects (default: all
cloned projects). Extra arguments are passed as-is to 'git status'.
'''),
accepts_unknown_args=True)
def do_add_parser(self, parser_adder):
return _add_parser(parser_adder, self, _project_list_arg)
def do_run(self, args, user_args):
for project in _cloned_projects(args):
_inf(project, 'status of {name_and_path}')
_git(project, 'status', extra_args=user_args)
class Update(WestCommand):
def __init__(self):
super().__init__(
'update',
_wrap('''
Updates the manifest repository and/or the West source code
repository. The remote to update from is taken from the
manifest.remote and manifest.remote configuration settings, and the
revision from manifest.revision and west.revision configuration
settings.
There is normally no need to run this command manually, because
'west fetch' and 'west pull' automatically update the West and
manifest repositories to the latest version before doing anything
else.
Pass --update-west or --update-manifest to update just that
Extra arguments are passed as-is to 'git diff'.
'''),
accepts_unknown_args=True)
def do_add_parser(self, parser_adder):
return _add_parser(parser_adder, self, _project_list_arg)
def do_run(self, args, user_args):
for project in _cloned_projects(args):
# Use paths that are relative to the base directory to make it
# easier to see where the changes are
_git(project, 'diff --src-prefix={path}/ --dst-prefix={path}/',
extra_args=user_args)
class Status(WestCommand):
def __init__(self):
super().__init__(
'status',
_wrap('''
Runs 'git status' for each of the specified projects (default: all
cloned projects). Extra arguments are passed as-is to 'git status'.
'''),
accepts_unknown_args=True)
def do_add_parser(self, parser_adder):
return _add_parser(parser_adder, self, _project_list_arg)
def do_run(self, args, user_args):
for project in _cloned_projects(args):
_inf(project, 'status of {name_and_path}')
_git(project, 'status', extra_args=user_args)
The source and build directories can be explicitly set with the
--source-dir and --build-dir options. The build directory defaults to
'build' if it is not auto-detected. The build directory is always
created if it does not exist.
This command runs CMake to generate a build system if one is not
present in the build directory, then builds the application.
Subsequent builds try to avoid re-running CMake; you can force it
to run by setting --cmake.
To pass additional options to CMake, give them as extra arguments
after a '--' For example, "west build -- -DOVERLAY_CONFIG=some.conf" sets
an overlay config file. (Doing this forces a CMake run.)'''
class Build(WestCommand):
def __init__(self):
super(Build, self).__init__(
'build',
BUILD_HELP,
accepts_unknown_args=False)
self.source_dir = None
'''Source directory for the build, or None on error.'''
self.build_dir = None
'''Final build directory used to run the build, or None on error.'''
self.created_build_dir = False
'''True if the build directory was created; False otherwise.'''
# Copyright (c) 2018 Open Source Foundries Limited.
# Copyright 2019 Foundries.io
#
# SPDX-License-Identifier: Apache-2.0
'''west "debug" and "debugserver" commands.'''
from textwrap import dedent
from west.commands import WestCommand
from run_common import desc_common, add_parser_common, do_run_common
class Debug(WestCommand):
def __init__(self):
super(Debug, self).__init__(
'debug',
# Keep this in sync with the string in west-commands.yml.
'flash and interactively debug a Zephyr application',
dedent('''
Connect to the board, program the flash, and start a
debugging session.\n\n''') +
desc_common('debug'),
accepts_unknown_args=True)
def do_add_parser(self, parser_adder):
return add_parser_common(parser_adder, self)
def do_run(self, my_args, runner_args):
The source and build directories can be explicitly set with the
--source-dir and --build-dir options. The build directory defaults to
'build' if it is not auto-detected. The build directory is always
created if it does not exist.
This command runs CMake to generate a build system if one is not
present in the build directory, then builds the application.
Subsequent builds try to avoid re-running CMake; you can force it
to run by setting --cmake.
To pass additional options to CMake, give them as extra arguments
after a '--' For example, "west build -- -DOVERLAY_CONFIG=some.conf" sets
an overlay config file. (Doing this forces a CMake run.)'''
class Build(WestCommand):
def __init__(self):
super(Build, self).__init__(
'build',
'compile a Zephyr application',
BUILD_DESCRIPTION,
accepts_unknown_args=False)
self.source_dir = None
'''Source directory for the build, or None on error.'''
self.build_dir = None
'''Final build directory used to run the build, or None on error.'''
self.created_build_dir = False
'''True if the build directory was created; False otherwise.'''
def do_add_parser(self, parser_adder):
return _add_parser(parser_adder, self, _no_update_arg,
_project_list_arg)
def do_run(self, args, user_args):
if args.update:
_update_manifest(args)
_update_west(args)
for project in _projects(args, listed_must_be_cloned=False):
_fetch(project)
_rebase(project)
class Rebase(WestCommand):
def __init__(self):
super().__init__(
'rebase',
_wrap('''
Rebase projects.
Rebases the checked-out branch (or detached HEAD) on top of '{}' in
each of the specified projects (default: all cloned projects),
effectively bringing the branch up to date.
'''.format(_MANIFEST_REV_BRANCH) + _MANIFEST_REV_HELP))
def do_add_parser(self, parser_adder):
return _add_parser(parser_adder, self, _project_list_arg)
def do_run(self, args, user_args):
#
# This sets the 'configfile' attribute depending on the option string,
# which must be --system, --global, or --local.
def __call__(self, parser, namespace, ignored, option_string=None):
values = {'--system': SYSTEM, '--global': GLOBAL, '--local': LOCAL}
rev = {v: k for k, v in values.items()}
if getattr(namespace, self.dest):
previous = rev[getattr(namespace, self.dest)]
parser.error(f"argument {option_string}: "
f"not allowed with argument {previous}")
setattr(namespace, self.dest, values[option_string])
class Config(WestCommand):
def __init__(self):
super().__init__(
'config',
'get or set configuration settings in west config files',
CONFIG_DESCRIPTION,
requires_workspace=False)
def do_add_parser(self, parser_adder):
parser = parser_adder.add_parser(
self.name,
help=self.help,
formatter_class=argparse.RawDescriptionHelpFormatter,
description=self.description,
epilog=CONFIG_EPILOG)
parser.add_argument('-l', '--list', action='store_true',
'''The "ncs-xyz" extension commands.'''
from pathlib import PurePath
import subprocess
from textwrap import dedent
import packaging.version
from west import log
from west.commands import WestCommand
from west.manifest import Manifest, MalformedManifest
from west.version import __version__ as west_ver
import yaml
import ncs_west_helpers as nwh
class NcsWestCommand(WestCommand):
# some common code that will be useful to multiple commands
def check_west_version(self):
min_ver = '0.6.99'
if (packaging.version.parse(west_ver) <
packaging.version.parse(min_ver)):
log.die('this command currently requires a pre-release west',
'(your west version is {}, but must be at least {}).'.
format(west_ver, min_ver))
@staticmethod
def checked_sha(project, revision):
# get revision's SHA and check that it exists in the project.
# returns the SHA on success, or None if we can't unwrap revision
# to a SHA which is present in the project.
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
import argparse
import os
from west import log
from west.commands import WestCommand
# Relative to the folder where this script lives
COMPLETION_REL_PATH = 'completion/west-completion'
class Completion(WestCommand):
def __init__(self):
super().__init__(
'completion',
# Keep this in sync with the string in west-commands.yml.
'display shell completion scripts',
'Display shell completion scripts.',
accepts_unknown_args=False)
def do_add_parser(self, parser_adder):
parser = parser_adder.add_parser(
self.name,
help=self.help,
formatter_class=argparse.RawDescriptionHelpFormatter,
description=self.description)
{}'''.format(_NO_UPDATE_HELP, _MANIFEST_REV_HELP)))
def do_add_parser(self, parser_adder):
return _add_parser(parser_adder, self, _no_update_arg,
_project_list_arg)
def do_run(self, args, user_args):
if args.update:
_update_manifest(args)
_update_west(args)
for project in _projects(args, listed_must_be_cloned=False):
_fetch(project)
class Pull(WestCommand):
def __init__(self):
super().__init__(
'pull',
_wrap('''
Clone/fetch and rebase projects.
Fetches upstream changes in each of the specified projects
(default: all projects) and rebases the checked-out branch (or
detached HEAD state) on top of '{}', effectively bringing the
branch up to date. Repositories that do not already exist are
cloned.
{}
{}'''.format(_MANIFEST_REV_BRANCH, _NO_UPDATE_HELP,
_MANIFEST_REV_HELP)))