Commit Graph

716 Commits

Author SHA1 Message Date
Marti Bolivar b415864493 Mark top level west directory with .west_topdir file
Add an empty file .west_topdir into the top-level west directory
during initialization time, and search for it when trying to locate
that directory in the bootstrap script and west itself.

This avoids ambiguities when other directories in the installation are
also named 'west' (such as zephyr/doc/west), and propagates a fix made
in src/west/util.py to the equivalent bootstrap routine in
src/west/bootstrap/main.py (west installed in the root directory is
now found there too).

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-15 10:33:05 +02:00
Marti Bolivar 5ce351b61c test_project.py: make zephyrproject/west/.west_topdir file in tmpdir
This doesn't affect the behavior of the current west, but will be
needed to test an upcoming patch which creates and uses that file.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-15 10:33:05 +02:00
Marti Bolivar 35816bbe0a tests: test project commands locally
Change the way the project test case fixtures are set up to create
local git repositories in the temporary directory, and a manifest that
refers to them.

This lets the test cases run without a network connection, which is
faster, and avoids false negatives that occur when the test
environment has a bad network connection.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-15 10:33:05 +02:00
Marti Bolivar e5457a91f0 test_project.py: delete unused import
Discovered while inspecting this file for needed changes in subsequent
patches.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-15 10:33:05 +02:00
Marti Bolivar e09987d5c9 setup.py: make classifiers a list
A tuple was originally used to indicate that the variable was
immutable, but this generates a warning on python 3.7; setuptools
really wants a list.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-15 10:33:05 +02:00
Marti Bolivar b2d9f99b41 README.rst: add link to zephyr docs
This is useful context.

Fixes #29.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-15 10:33:05 +02:00
Ulf Magnusson b7670c75ff Store the West source code and the manifest in west/
I was confused by the other design, because I intuitively expected West
metadata to go in .west/. To me the other design feels a little bit like
having an empty /home/foo/user/ directory that marks the /home/foo/
directory as containing the user's files.

Use west/ instead of .west/ to avoid "hiding" the implementation of the
building/flashing commands. I would've preferred to split them from the
repo-like functionality instead, but if they're going to be in the same
repository, then it's a decent comprise.

Remove the code that hides the west directory on Windows (via 'attrib')
as well, since it doesn't make much sense anymore.

This commit also fixes a small bug in west_topdir(): A west/ in the root
directory wasn't found.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-09-12 09:16:01 -07:00
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