Commit Graph

59 Commits

Author SHA1 Message Date
Marti Bolivar 9e25be5e35 setup.py: move version back to 0.1.0
As discussed internally, we're ready to push this to the 'real'
PyPI (not Test PyPI) now. The version has been incremented several
times previously during testing uploads on Test PyPI. This is no
longer necessary, so set it to the real semantic version we desire for
this stage, which is 0.1.0.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-11 18:55:54 +02:00
Marti Bolivar c5dd4f4c20 bootstrap: add python2 error check
Fail hard when run under Python 2. This catches delegated commands as
well, since those are run by this file.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-11 18:55:54 +02:00
Marti Bolivar f8c2929dee bootstrap: add -b/--base-url init option
This option allows setting a base URL for both the west and manifest
repositories. That makes for shorter initialization in cases where you
want to "west init -b https://example.com/some-other-zephyr/" instead
of:

west init -u https://example.com/some-other-zephyr/manifest -w https://example.com/some-other-zephyr/west

Suggested-by: Carles Cufi <carles.cufi@nordicsemi.no>
Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-11 18:55:54 +02:00
Marti Bolivar 34dc0c2246 README: updates for initial PyPI upload
Fixes and updates to the README before the first upload to PyPI.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-11 18:55:54 +02:00
Ulf Magnusson 2aad71a7d4 cmd: project: Colorize messages
Use the colorama library to print informational messages from West
project commands in bright green, and all warnings and errors in bright
red. This makes it easier to distinguish them from other output (e.g.
command output from Git).

Colorized output is disabled if stdout is not a terminal. This is
handled by colorama, which wraps sys.stdout and sys.stderr.

colorama also translates ANSI escapes for us on Windows, where they
might not be natively supported.

Fixes: #25

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-09-07 12:42:33 +02:00
Ulf Magnusson 809b46c975 cmd: project: Add a _cloned_projects() helper function
This pattern was cropping up in a bunch of places:

  for project in _projects(args):
      if _cloned(project):
          ...

The new helper replaces it with

  for project in _cloned_projects(args):
      ...

Suggested by Marti Bolivar.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-09-07 12:42:33 +02:00
Ulf Magnusson c49dd1b192 cmd: project: Use 'git init' + 'git fetch' instead of 'git clone'
Use this command sequence instead of 'git clone':

  git init <path>
  In <path>:
    git remote add origin <url>
    git [--depth n] fetch origin [<branch-or-SHA>, if clone-depth is used]
    git update-ref refs/heads/manifest-rev <branch-or-SHA>
    git checkout --detach refs/heads/manifest-rev

This has two advantages:

  - No local branches are created automatically, giving us better
    control over the initial state of the repository

  - The final three commands can be reused for fetching changes from an
    existing repository, giving a single code path for all fetches

Let the initial state of a repository be a detached HEAD at
'manifest-rev'. We could also have the initial state have nothing at all
checked out, but it causes commands like 'git rebase' to fail, and might
look confusing.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-09-07 12:42:33 +02:00
Marti Bolivar 2673e8ca87 cmd: project: fix edge case when revision is a SHA
If the revision is a SHA, we cannot assume the clone command will
fetch anything valid, as the remote HEAD may not have been properly
initialized.

For safety in that case, run a checkout step to ensure the work tree
is properly set up.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-30 10:33:40 -05:00
Marti Bolivar 07d83e1dbe cmd: project: fix up project existence checks
_cloned() says it prints a warning if there's an issue with the
project, but it actually calls _die(), which as it turns out is never
what we want it to do at the moment.

Let's fix that by making it a simple predicate that absorbs
_verify_repo()'s conclusions without its sting.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-30 10:33:40 -05:00
Marti Bolivar 3d36be7d91 cmd: project: clean up project URL calculation
Set a project's URL correctly from the time the manifest is parsed,
rather than fixing it up later. The current scheme is a bit deceptive
with regards to the naming of the Project namedtuple field.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-30 10:33:40 -05:00
Marti Bolivar 4a21d521ac cmd: project: only look for project-related defaults
Just a bit of future-proofing; won't affect functionality. Rather than
assuming all defaults pertain to projects, keep a list of defaults
that do and filter the defaults map to just those.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-30 10:33:40 -05:00
Marti Bolivar 65e447ede0 cmd: project: add debug logging for git commands
Besides development debugging, these make it easier to get traces from
users.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-30 10:33:40 -05:00
Marti Bolivar 6b53400e6e cmd: project: cosmetics to make flake8 happy
Whitespace changes to appease the linter. Use an implicit continuation
line with parentheses instead of \-continuation while handling
over-indentation complaints.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-30 10:33:40 -05:00
Maureen Helm c80013329e runner: Implement attach command in pyocd runner
Adds support for starting a pyocd debugging session without programming
the flash.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2018-08-29 17:38:53 -05:00
Maureen Helm 19b86f3aea runner: Implement attach command in jlink runner
Adds support for starting a jlink debugging session without programming
the flash

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2018-08-29 17:38:53 -05:00
Maureen Helm 044776b115 runner: Introduce attach command
Introduces a new west command to start a debugging session without
programming the flash. This can be used when you want to debug a Zephyr
application that is already running.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2018-08-29 17:38:53 -05:00
Ulf Magnusson 063761bd67 Make 'west branch' by itself list all local branches
Analogous to running 'git branch', except for all projects. Also lists
the project(s) each branch appears in.

Example output:

  $ python3 -m west branch
  FIX-FOO            zephyr, Kconfiglib
  manifest-rev       zephyr, net-tools, Kconfiglib
  master             zephyr, net-tools
  zephyr             Kconfiglib

I'm planning to change 'git clone' into 'git init' + 'git remote add' +
'git fetch' later, which avoids creating the last two local branches.
Maybe manifest-rev should be hidden as well.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-29 16:43:20 -05:00
Ulf Magnusson 360897915d Add 'forall' command
Passes its command as-is to the shell, within the repositories of each
of the specified projects (or all cloned projects by default).

I was thinking of making the shell quoting for long commands optional,
by joining all the words with a space or the like, but it might get
tricky with argparse. Could look into it more later.

Piggyback some cleanup: Make the absolute path of a project available in
project.abspath, to avoid having to do a bunch of join()s with
util.west_topdir().

Fix some copy-paste comment mess-ups in the tests too.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-29 16:30:48 -05:00
Marti Bolivar 6d18b668ef bootstrap: fix path after test reorg
The bootstrap script no longer works properly since the src/ directory
was added to support test cases. Fix that.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-25 20:59:18 -05:00
Marti Bolivar 856793a3a6 cmd: build: rename force_cmake to run_cmake
Suggested by Ulf Magnusson.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-25 19:06:35 -05:00
Marti Bolivar bf8823d26f cmd: build: fix force_cmake calculation
Checking for a forced CMake due to the presence of CMake-related
arguments should only matter if the build directory already exists and
seems to contain a zephyr build system.

Otherwise, we always need to run CMake.

Once set for any reason, the bit should be sticky, and should be a
bool.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-25 19:06:35 -05:00
Ulf Magnusson 4587ee1763 Add project commands for dealing with multiple repositories
Add simple Google repo-like functionality, for dealing with multiple Git
repositories.

The command set is mirrored after Git. All commands except
'list-projects' accept an optional list of projects, and default to all
(cloned) projects.

  - west list-projects

    Lists projects and their repositories

  - west fetch

    Clone/fetch projects. Supports 'clone-depth', for making shallow
    clones.

  - west rebase

    Rebase local branches to the revision specified in the manifest

  - west pull

    'west fetch' + 'west rebase' (similar to 'sync' in Google repo)

  - west branch

    Create a new branch in one or more repositories (for working on some
    issue)

  - west checkout

    Check out a branch in each repository that has it. Supports a -b
    flag for creating the branch first.

  - west diff

    Run 'git diff' in each repository

  - west status

    Run 'git status' in reach repository

There's no way to submit a multi-repository change for review yet.

Currently, a convenience branch 'manifest-rev' is created in each
project, which points to the revision specified for the project in the
manifest. 'manifest-rev' is updated by 'west fetch' and 'west pull'.

Local branches created with 'west branch' are set to track
'manifest-rev'. This makes e.g. a plain 'git status' or 'git pull' work
sensibly even when the manifest revision is an SHA.

We'll see if 'manifest-rev' is too magic later. It's explained in the
help texts of all the relevant commands at least.

It might be nicer to create 'manifest-rev' in e.g. refs/remotes instead
of refs/heads. Git doesn't seem to like trying to create a branch that
tracks a branch in refs/remotes unless it's a "proper" upstream branch
though.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-24 14:16:18 -05:00
Marti Bolivar ed9f4fe735 Add build command.
This is an optional convenience wrapper around cmake + ninja (or any
other generator supported by Zephyr). It will never be mandatory to
use this wrapper. Raw CMake and Ninja/Make/etc. will always be
supported.

This command attempts to do what you mean when run from a Zephyr
application source or a pre-existing build directory:

- When "west build" is run from a Zephyr build directory, the source
  directory is obtained from the CMake cache, and that build directory
  is re-compiled.

- Otherwise, the source directory defaults to the current working
  directory, so running "west build" from a Zephyr application's
  source directory compiles it.

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.)

A separate helper library is placed in west.build to make adapting
flash/debug/debugserver workflows play nicer with build in future
patches.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-21 16:09:13 -05:00
Marti Bolivar 53d5bf0e37 cmake: add extensions necessary for build command
Extend the CMake helper with some extra knowledge needed to support
'west build':

- add run_cmake() for general-purpose invocations of CMake
- teach the CMake cache some more Python protocol methods

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-21 16:09:13 -05:00
Marti Bolivar 3a24890a24 testing: add shippable integration
This ought to run the tests across a good enough spread of supported
Python versions to get started, and collect coverage statistics.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-21 14:54:29 -05:00
Marti Bolivar ce3f4fd565 tests_requirements.txt: add pytest-cov
This enables gathering of code coverage data during testing.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-21 14:54:29 -05:00
Marti Bolivar 04accde952 tests: add nrfjprog runner tests
Add an exhaustive test suite.

Check expected results for all combinations of runner constructor
parameters, both when instantiating the runner directly via its
constructor and when using command line arguments via its create()
method. Ensure consistent results.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-20 09:17:57 -07:00
Marti Bolivar f86da451f9 tests: add pyocd tests
Add test coverage for flash, debug, and debugserver commands, using
runners created directly with their constructors, as well as via
command line arguments, with methods that would run syscalls mocked
out.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-20 09:17:57 -07:00
Marti Bolivar 9b7d58343f Add py.test-based test infrastructure
Follow along with what the cool kids are doing and add py.test
integration.

This patch doesn't add any test cases, but sets up packages to
test the runner classes as additional work.

To run the test suite, use:

$ python3 setup.py test

Since there are no tests, these pass.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-20 09:17:57 -07:00
Marti Bolivar 304776695b Move install_requires contents to requirements.txt
This makes it easier to do editable installs or work on West in a
virtualenv.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-20 09:17:57 -07:00
Marti Bolivar 1e809d5757 Move sources into a src/ directory
As prep work for adding test cases, follow pytest best practices by
having a src/ directory:

https://docs.pytest.org/en/latest/goodpractices.html#tests-outside-application-code

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-20 09:17:57 -07:00
Gautier Seidel 1f35506a5e Apply Zephyr commit 1952c56e7
NOTE: This applies Zephyr commit 1952c56e7 ("esp32: add abitily to
      flash bootloader"), which was merged without going through this
      tree first.

'make flash' also flashes the bootloader

Signed-off-by: Gautier Seidel <gautier.seidel@tado.com>
Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-20 09:17:57 -07:00
Wayne Ren d0f184412a Apply Zephyr commit 4a8393dd6
NOTE: This applies the West-specific portions of Zephyr commit
      4a8393dd6 ("esp32: add abitily to flash bootloader"), which was
      merged without going through this tree first.

add nsim runner in west

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-20 09:17:57 -07:00
Jamie McCrae 112b87759e Apply Zephyr commit 60e97de58
NOTE: This applies Zephyr commit 60e97de58 ("scripts: runner:
      nrfjprog: Allow specifying serial number of nrfjprog"), which
      was merged without going through this tree first.

This allows for scripts using nrfjrog to specify the serial number of
the attached device to use instead of showing a list of available
devices by adding an optional parameter.

Signed-off-by: Jamie McCrae <jamie.mccrae@lairdtech.com>
Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-08-20 09:17:57 -07:00
Marti Bolivar 8e22ca68c3 Add bootstrap script.
Add a separate package for bootstrapping West and a Zephyr manifest
repository, and have the setuptools integration install that instead
of the "real" West.

Signed-off-by: Marti Bolivar <marti.f.bolivar@gmail.com>
2018-06-11 21:43:50 -04:00
Marti Bolivar 4d75a749d0 .gitignore: add __pycache__/
Clean up the status output.

Signed-off-by: Marti Bolivar <marti.f.bolivar@gmail.com>
2018-06-11 21:43:50 -04:00
Marti Bolivar 321ab2e179 runner: core: fix docstrings for ReST integration
A couple of docstrings are causing issues when imported into Sphinx;
fix these up.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-06-08 11:52:03 -04:00
Marti Bolivar 2e9e6b255d Add setuptools integration.
Follow along with the tutorial:

https://packaging.python.org/tutorials/packaging-projects/

The version number is because of repeated uploads to TestPyPI.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-06-06 12:21:14 -04:00
Marti Bolivar d8542f297c main: tweaks to enable setuptools integration
The setuptools entry_points kwarg can generate platform-specific
scripts to run. These call the entry points with no arguments,
however, so tweak our main() to use sys.argv and its caller to stop
passing it.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-06-06 12:21:14 -04:00
Marti Bolivar 2570866cf2 Move everything into a west/ directory
This is necessary to properly configure this as a Python package with
setuptools integration.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-06-06 12:21:14 -04:00
Marti Bolivar d656eb4a32 runner: add --erase flag to nrfjprog.py
By default, use a sector erase to flash boards with nrfjprog.py.

To allow getting the old behavior, add an --erase flag that works the
exact same way as the corresponding jlink.py argument: if present, a
full flash erase is done before programming. If absent, only a sector
erase is done.

Fixes zephyrproject-rtos/zephyr#6147

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-06-04 08:42:55 -04:00
Marti Bolivar 894aedbc0e runner: nios2.py: fix create() and constructor
The constructor call is missing a mandatory argument. The constructor
itself has a typo.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-06-04 08:41:34 -04:00
Marti Bolivar 323b96a917 cmake.py: ensure empty strings are empty lists
Ensure that CmakeCache.get_list() returns an empty list when the cache
entry is the empty string.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-06-04 08:41:34 -04:00
Marti Bolivar a65b8b87f2 main: downgrade missing ZEPHYR_BASE to a warning
This is not strictly necessary for flashing and debugging, and is
causing issues in Linux environments where users run "make flash" as
root instead of installing udev rules.

Fixes: #7676

(Though we will need to revisit this when adding commands that run
CMake).

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-05-23 10:27:36 -04:00
Marti Bolivar 53fc351eb1 cmd: add context-sensitive runner help
Though commands like "west flash -h" now have help for generic runner
configuration options, runner-specific context is not printed.

In order to print this information, we would ideally want to know the
currently available runners from a build directory. Otherwise, we
can't print the current cached configuration, and the user will likely
be overwhelmed by a giant list of options etc. available for all the
runners in the package.

However, we can't print that information out without re-doing the
build, which is not safe to do when the user just gives '--help'.

To provide more complete help without causing side effects in the
default help output, add a new -H/--context option, which explicitly
re-runs the build (unless --skip-rebuild was given), parses the cache,
and prints context-sensitive help. This can be combined with the -r
option to restrict help to a particular runner.

Examples:

- Print context for all available flash runners:

      west flash -H --build-dir build-frdm_k64f/

- Print context for just one runner:

      west flash -H --build-dir build-frdm_k64f/ -r jlink

- Print context for all available debug runners, if current
  working directory is a build directory:

      west debug -H

If no context is available because there is no CMake cache file, this
command can still be used to obtain generic information about
runners. It emits a warning in this case.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-05-23 10:27:36 -04:00
Marti Bolivar 05358c9789 runner: add build directory to runner configuration
Add the build directory to the central runner configuration.
This is commonly useful information.

The first place we can use it is to eliminate guessing the current
working directory when building objects to parse .config.

It's not necessary to modify the build system for this, so leave the
relevant command line flag among the general options.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-05-23 10:27:36 -04:00
Marti Bolivar dfd1bf48bc runner: introduce common runner configuration
Continue better integration of the runner subpackage into west by
moving the common runner configuration options into the command
core. This allows commands like "west flash -h" to display help for
common overrides like --kernel-hex.

Adjustments needed to make this happen are:

- Change the build system to separate common configuration values from
  runner-specific options and arguments

- Prepare the runner core by defining a new RunnerConfig class that
  represents the common configuration, and accepting that from a new
  create() method, which replaces create_from_args().

- Convert all concrete runner classes to use the new style of
  argument parsing and initialization.

- Group the command options appropriately for help output readability

There's still a bit of tool-specific stuff in the common
configuration (gdb and openocd configuration in particular); a more
generic way to deal with that will be necessary to better support
things like non-GDB debuggers, but that's out of scope of this patch.

All the runner-specific options are still in the runner packge, which
currently prevents them from being included in "west flash -h" etc.
Fixing that is also out of scope of this patch.

This has the ancillary benefit of getting rid of the legacy 'debug'
argument to ZephyrBinaryRunner, which is no longer appropriate since
verbose debug logging is handled by log.py in west.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-05-23 10:27:36 -04:00
Marti Bolivar 54e48e8bf5 runner: convert runner to use log module
Replace all informational messages with calls to log functions.

Cases which must interact via the terminal and standard output are not
modified.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-05-23 10:27:35 -04:00
Marti Bolivar 98dc26cfd2 runner: fix some intel_s1000 runner issues
There are a few issues with the intel_s1000 runner:

- it doesn't attach to the client when running debug (this is
  a part of the command's contract specified in core.py)

- it uses hard-coded sleeps when running subprocesses instead of
  waiting for them to terminate

- it re-implements pre-existing popen_ignore_int() functionality (in a
  way that is not portable to Windows) rather than using it directly

Fix these issues.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-05-23 10:27:35 -04:00
Marti Bolivar 3bbcb7ab4d runner: clean up intel_s1000 runner
Make the flake8 linter happy, spell the board name with the correct
case in the module docstring, and keep the usual camel case naming
convention used for classes.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-05-23 10:27:35 -04:00