Commit Graph

847 Commits

Author SHA1 Message Date
Marti Bolivar 77e30dc313 commands: list: accept project arguments
Support a list of projects in the arguments. The listed projects will
be limited to those named, in the order they are given on the command
line. This is the same way that "fetch", "forall", and other commands
operate on all projects by default, or just specified projects.

Remove the special-case text printing the manifest path. We'll handle
that by treating west and the manifest as projects in a later patch.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-11-08 16:33:27 +01:00
Marti Bolivar f87d618a5c commands: list: don't append slashes to paths
This creates extra slashes when users naively concatenate two paths
with the system path separator. It also looks weird on Windows.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-11-08 16:33:27 +01:00
Rajavardhan Gundi ab260c5f0e intel_s1000: scripts: Fix the runner script
This reverts commit bc7b1c595ed4090be6d80859a01a0bb372ae030c in
the zephyr main tree to fix the runner script and also does the
below modifications.
1) explicitly terminate processes.
2) implicitly call debugserver when debug is called.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-11-07 14:44:54 -07:00
Maureen Helm f917b440bf runners: pyocd: Don't reset after load
The mimxrt1052 does not have any internal flash, therefore a reset after
load blows away the code when loaded into sram. Reverse the order of the
pyocd commands such that the load follows the reset.

The command order now matches jlink.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2018-11-03 23:53:15 -06:00
Ulf Magnusson 9ef7557ec1 commands: project: Fetch tags from remotes
'git fetch/pull' by default doesn't fetch tags from remotes specified as
URLs, which is what we use. Pass --tags to get them.

This will only fetch tags pointing to commits reachable from the
manifest revision being fetched.

Fixes: #92

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-11-02 12:53:01 -06:00
Marti Bolivar 662b1b33a8 West 0.3.0
Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-11-01 17:15:41 +01:00
Carles Cufi 0327080452 tests: project: Fix behavior of shlex.split() on Windows
On Windows shlex.split() will remove all backslash separators
unless specifically instructed.
Quote the path to the manifest before splitting so that
backslash path separators don't get removed on Windows.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-11-01 17:08:44 +01:00
Carles Cufi dddd612bbb tests: manifest: Fix paths in tests
Tests were failing on Windows due to not using normalized paths.
Use normalized paths everywhere to avoid wrong path comparisons.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-11-01 17:08:44 +01:00
Carles Cufi fe7512428c manifest: Use normpath when building abspath
When creating the absolute path to a project in the manifest, use
os.path.normpath() to get correct path formatting on all platforms.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-11-01 17:08:44 +01:00
Marti Bolivar 629c574cf2 West 0.3.0rc1.
Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-11-01 13:36:15 +01:00
Ulf Magnusson ddd3331d50 commands: project: Fetch directly from URLs instead of remotes
Instead of fetching from remotes, fetch from URLs. This bypasses the
entire remote system, which is nice in that we no longer rely on how
remotes are configured. Users could delete remotes or point them
somewhere else, and things will still work.

I had somehow managed to miss all along is that Git allows URLs wherever
names of remotes are allowed.

Also put URLs into the initial west/config configuration file. Keep the
name 'remote' for the configuration value, as putting the name of a
remote there will work as well.

IOW, both of the following will work:

    [west]
    remote = https://github.com/zephyrproject-rtos/west
    revision = master

    [west]
    remote = my-custom-remote
    revision = master

For projects, create a remote named after the remote in the manifest
(like before), just for the user's convenience. We never use it
ourselves.

Fixes: #83

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-11-01 13:28:08 +01:00
Ulf Magnusson c5add1dd91 Add Bash auto-completion script
Currently completes flags and subcommand names.

Fixes: #24

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-11-01 01:08:38 +01:00
Ulf Magnusson 3c576b532c bootstrap: Don't error out for 'git@' URLs
Add 'git@' to the list of accepted prefixes. Alternatively, any username
could be accepted, but keep it simple while we have the URL check.

IMO, the check should be removed instead. It artificially restricts us
to a subset of what Git really supports, for no good reason.

Also fix a typo: s/git-shh:/git-ssh:/

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-10-30 19:19:24 +01:00
Carles Cufi 1eba32295d bootstrap: Rename -u to -m for consistency
Using `-u` as the manifest URL is confusing because:

* We use `-w` for the west url
* We use `--wr` for the west revision
* We use `--mr` for the manifest revision

Instead, use `-m` which is consistent with the rest of the options.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-10-26 15:46:38 +01:00
Ulf Magnusson eee4b239de commands: project: Clarify that 'west checkout' deals with local branches
As long as that's the case, it should be documented.

I suspect it might be a feature. If you've created a branch do to some
work with 'west branch fix-stuff repo1 repo2 repo3', then it's probably
unexpected if 'west checkout fix-stuff' checks out a remote branch
'fix-stuff' that happens to exist in some other repository.

Fixes: #34

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-10-26 11:37:10 +01:00
Ulf Magnusson 63b00e88dc commands: project: Show remote URLs for projects in 'west list'
This came up in https://github.com/zephyrproject-rtos/west/issues/52.

I'm not sure what the appropriate field widths are ({:n}). We could
tweak it later if some fields turn out to be too short/long.

Fixes: #37

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-10-26 11:36:36 +01:00
Ulf Magnusson 4875ba36b3 commands: project: Only update west/manifest via fast-forward
If either the west or the manifest repository has local modifications,
skip automatically updating the modified repository, with a warning.
This avoids merge conflicts when working on them.

Maybe the manifest repository update could be skipped if the west
repository is out of date, and vice versa, but I suspect this version
might be good enough.

Fixes: #59
Fixes: #62

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-10-24 10:44:56 +01:00
Ulf Magnusson dd5d76f563 bootstrap: Print some information during initalization
Makes it a bit clearer what's going on, and helps people find the
configuration file.

Example output:

    Initializing in /home/ulf/westwest
    === Cloning west repository from https://github.com/zephyrproject-rtos/west, rev. master ===
    Cloning into '/home/ulf/westwest/west/west'...
    remote: Enumerating objects: 803, done.
    remote: Total 803 (delta 0), reused 0 (delta 0), pack-reused 803
    Receiving objects: 100% (803/803), 239.55 KiB | 371.00 KiB/s, done.
    Resolving deltas: 100% (428/428), done.
    === Cloning manifest repisitory from https://github.com/zephyrproject-rtos/manifest, rev. master ===
    Cloning into '/home/ulf/westwest/west/manifest'...
    remote: Enumerating objects: 6, done.
    remote: Counting objects: 100% (6/6), done.
    remote: Compressing objects: 100% (6/6), done.
    remote: Total 25 (delta 0), reused 2 (delta 0), pack-reused 19
    Unpacking objects: 100% (25/25), done.
    === Initial configuration written to /home/ulf/westwest/west/config ===
    === West initialized ===

Maybe some helpful hint could be added to the end too.

Signed-off-by: Ulf Magnusson <ulfalizer@gmail.com>
2018-10-18 20:43:23 -06:00
Ulf Magnusson f134e604d6 commands: project: Add a 'west clone' command
This is just a shorthand for 'west fetch' + 'west checkout -b <branch>'.

The name of the branch is based on the revision from the manifest. For
revisions that are qualified refs (refs/heads/foo), the last component
(foo) is used as the name.

For SHA revisions, it doesn't make much much sense to name the branch
after the SHA, so 'work' is used instead.

The name of the created branch(es) can be overriden by passing
'-s <branch name>' to 'west clone'.

Signed-off-by: Ulf Magnusson <ulfalizer@gmail.com>
2018-10-18 20:43:23 -06:00
Ulf Magnusson b6a72c131e commands: project: Refactor self-update a bit
Just have two _update_manifest() and _update_west() functions and get
rid of the flags. Bit easier to follow.

_update() was a bit overly generic as a name too.

Signed-off-by: Ulf Magnusson <ulfalizer@gmail.com>
2018-10-18 20:43:23 -06:00
Ulf Magnusson 14a6644f7a commands: project: Give context-specific errors for failed self-updates
Add a context manager ('with foo:' thingy) for setting a context for a
block of code. The context is just some text that gets added to the
error whenever a Git command fails.

Use the context manager to point out whenever a failing Git command is
related to self-updates. That could be a bit tricky to debug otherwise.

Example error:

  FATAL ERROR: Command 'git rebase 'FETCH_HEAD^{commit}'' failed for
  manifest (west/manifest/), while running automatic self-update. Please
  fix the state of the repository, or pass --no-update to 'west
  fetch/pull' to skip updating the manifest and West for the duration of
  the command.

Signed-off-by: Ulf Magnusson <ulfalizer@gmail.com>
2018-10-18 20:43:23 -06:00
Ulf Magnusson a69eb1ac75 commands: project: Check if projects are up-to-date when rebasing
_update() updates the special west/ and manifest/ repositories and has
code for checking if HEAD contains all the commits from a particular
revision (is up-to-date re. the revision). Move that code into a
separate _up_to_date_with() function, and also use it when rebasing
normal projects.

This gives a less spammy message when running 'pull' and 'rebase' on
already up-to-date projects:

  $ west rebase
  === zephyr (zephyr/) is up-to-date with manifest-rev

This commit also removes the special error message when self-updating
fails, returning to plain _git() with check=True. A separate context
hint mechanism will be added after this commit instead.

Signed-off-by: Ulf Magnusson <ulfalizer@gmail.com>
2018-10-18 20:43:23 -06:00
Ulf Magnusson f81e73f504 commands: project: Allow West/manifest remote to be changed
Store the name of the remote used for West and manifest updates in
west/config, like Git does it. That way the remote can be switched
(after adding a remote).

Another option would be to store a URL, but it's less flexible and would
add hairy remote management code to rewrite remote URLs. It'd also make
it impossible for users to manually manage remotes in Git, as their
settings would get overwritten.

We could probably get rid of the Remote.url field. That information is
already available in the Git repository (we could fetch it from there if
we want to show it), and we should respect the repository settings in
case they have been changed by the user.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-10-18 20:43:23 -06:00
Ulf Magnusson 9c027d703d Make configuration values always available
This is nice in case something tries to read a configuration value
before the configuration files have been read. This could happen for the
logging functions for example, and for tests.

The configuration is empty before the configuration files have been
read, so defaults must be provided. They must be anyway though, for the
code to be robust in case configuration files are missing.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-10-18 20:43:23 -06:00
Ulf Magnusson 1967d3d47a Add color.ui option for turning colors on/off
Based on the corresponding git option (see git-config(1)).

'true'/'false' are the only supported values at the moment, but they
work the same as in git (output is colorized if color.ui = true and the
output file is a terminal). If color.ui isn't specified, it defaults to
true.

color.ui is not written to west/config, since it makes more sense as a
global option than a per-repository option. It can still be disabled in
west/config though, though ~/.westconfig would make more sense.

I was thinking of toggling colors at a higher level with colorama
at first, but colorama.init() makes it a bit tricky to get right for
both Linux and Windows. Probably not too bad to make it explicit like
this.

Add a _reset_colors() helper to log.py as well to factor out a tricky
and easily typo'd print().

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-10-18 20:43:23 -06:00
Ulf Magnusson 7fec6f03c8 commands: project: Use remote name from manifest instead of 'origin'
To be consistent with repo (though I haven't actually checked the
behavior myself).

Fixes: #73

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-10-18 20:43:23 -06:00
Ulf Magnusson a11ed67f04 commands: project: Improve behavior for an aborted initial 'fetch'
The old _fetch() behavior was to check out a detached HEAD at
'manifest-rev' if the repository was initialized in the same call to
_fetch(). This meant that no detached HEAD was checked out if the
initial fetch was aborted and then resumed.

Instead, always check out a detached head at 'manifest-rev' if nothing
is checked out in the repository (which is almost guaranteed to mean
that we're still in the 'git init' state). That makes aborting and
resuming safe.

Nothing being checked out can be detected by looking at HEAD, which will
point to a non-existing ref.

Fixes: #78

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-10-18 20:43:23 -06:00
Ulf Magnusson 1d61d9391a commands: project: Support any kind of revision format
Switch to a simpler and more flexible approach for dealing with upstream
revisions, that works with any revision format (SHA, branch, qualified
ref (e.g. refs/heads/foo), or (annotated) tag):

 1. Fetch (just) the upstream revision, exactly as specified.

 2. Dereference it to a commit via FETCH_HEAD, and point 'manifest-rev'
    at it.

    Using FETCH_HEAD makes it possible to apply ^{commit} peeling (see
    git-rev-parse(1)), which makes things work for e.g. annotated tags
    too (git tag -a ...).

A regression (could be an improvement, depending on how you see it) is
that just the upstream revision is fetched now. It'd be simple to do a
full fetch if we'd want that later though.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-10-18 20:43:23 -06:00
Ulf Magnusson dfcbc4adc2 Get west and manifest revisions from a configuration file
Add configuration file support via the standard Python configparser
module, which uses a Git-like .ini format. Use it to save the west and
manifest revisions specified when running 'west init', and use the saved
revisions when updating the west and manifest repositories.

Configuration file paths are based on Git, for consistency with the
Git-like commands. See the FILES section in git-config(1). Mac OS and
Windows paths were checked by Carles Cufi with
'git config --list --show-origin'.

Add some new shorthands to _expand_shorthands() in project.py to factor
out some logic while removing the hardcoding of the west and manifest
upstream branches. The qual-* versions of shorthands give the full path
to refs (refs/heads/foo, remotes/origin/bar, etc.)

Fixes: #63
Fixes: #67

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-10-18 20:43:23 -06:00
Marti Bolivar a52159b043 west: main: don't swallow Exception
Allow stack traces for unexpected errors to propagate to the user.
Leave the CalledProcessError handling since subprocess failure is
basically a RuntimeError and can happen for many reasons that
aren't west's fault.

Fixes #79.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-10-18 08:09:39 -06:00
Ulf Magnusson ac1d631b4a Rename 'list-projects' to 'list'
I got tired of typing 'list-projects' all the time.

'list' might be a bit less obviously related to projects, but I don't
think it would be that bad.

Signed-off-by: Ulf Magnusson <ulfalizer@gmail.com>
2018-10-10 09:54:21 -06:00
Ulf Magnusson 96e2cd0b27 commands: projects: Put '--' before URL in 'git remote add'
The URL is taken literally from the manifest. It's unlikely that anyone
would put a URL starting with a '-', but having weirdly named stuff be
correctly interpreted by Git could help with diagnosing bugs.

Maybe some other Git commands could be tightened up too, but they looked
safe from a glance.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-10-05 10:17:34 -06:00
Marti Bolivar b678172f60 Set bootstrap version to post-release 0.2.99
This mirrors what gets done in Zephyr.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-10-05 16:00:23 +02:00
Marti Bolivar 21fda3ab1a West 0.2.0
Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-10-05 15:32:47 +02:00
Marti Bolivar d722bb0b6f runners: pyocd: prefer hex files to bin files if possible
This doesn't affect the default functionality of the runner, but it's
nicer to flash hex files if possible. For example, some tools find it
easier to post-process hex files than binary files for flashing on the
board.

Keep test cases up to date.

Signed-off-by: Marti Bolivar <marti@foundries.io>
Signed-off-by: Michael Scott <michael@foundries.io>
2018-10-02 11:35:58 -06:00
Marti Bolivar b001a1243d West 0.2.0rc3
Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-10-02 19:29:45 +02:00
Marti Bolivar df134cea13 main.py: set ZEPHYR_BASE whenever possible
Set ZEPHYR_BASE in the environment for the duration of the command if
possible.

In order of decreasing precedence, get ZEPHYR_BASE from:

1. The west command line
2. The manifest file project named 'zephyr'
3. The calling environment's ZEPHYR_BASE

If the calling environment's ZEPHYR_BASE differs from the value
actually used, emit a warning. The user has probably run a zephyr-env
script in another Zephyr directory and forgotten about that, and will
almost certainly not like what they get.

Hopefully over time we can deprecate the zephyr-env scripts entirely,
but that remains to be seen.

Fixes: #46

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-10-02 01:20:57 +02:00
Marti Bolivar d21374bd55 west.manifest: forbid duplicate project paths
While implementing a manifest-based scan for the zephyr project, I
noticed that we aren't ensuring that projects always have distinct
paths (it's generally OK for them to have non-overlapping names; they
just can't be cloned to the same directories on the file system).

Add a check for that in west.manifest, along with a regression test.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-10-02 01:20:57 +02:00
Marti Bolivar 7527b98442 Reimplement west.manifest with more complete abstract types
Currently, west.manifest mostly can just return a list of Project
types, each of which is a namedtuple for the project contents we care
about.

It would be better and more flexible to have a "real" data type for
the manifest, along with concrete representations for its contents
such as default values and remotes.

Reimplement the module to add just these things, adding Manifest,
Defaults, and Remote types, and re-working the Project namedtuple into
a class type. All of these (except Manifest) use __slots__ to restrict
their attributes.

Keep the current users and test cases up to date, extending the tests
a bit more as well. This moves a bit more code out of project.py into
west.manifest.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-10-02 01:20:57 +02:00
Marti Bolivar 57e18b3ab1 Add test cases for west.manifest.
Exercise both invalid manifest detection and correct parsing of valid
manifests. To make it easier to write tests for invalid manifests,
just glob for any invalid_*.yml files in the same directory as the
test file.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-10-02 01:20:57 +02:00
Marti Bolivar f4a1f5d685 west.manifest: fix some remote validation issues
Add checks for nonexistent default remotes, projects without well
defined remotes, and projects without remotes (this last one in the
absence of a default remote).

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-10-02 01:20:57 +02:00
Marti Bolivar 1b973297f6 west.manifest: don't crash if the manifest contains no data
pykwalify raises a CoreError if you pass it an empty manifest. This is
by definition malformed, but the current manifest code lets this
exception pass rather than catching it and reporting the issue.

Avoid the exception by explicitly checking for, and handling, empty
manifest data. This has the ancillary benefit of only loading the
manifest file once.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-10-02 01:20:57 +02:00
Marti Bolivar 1104f45e1e Extract manifest parsing to west.manifest
Add a new module for parsing the manifest, containing the Project
definition, as well as a routine for extracting projects from a
manifest. For now, this is a pretty straightforward copy/paste job,
but we do avoid calling log.die from the manifest parsing code by
adding a new MalformedManifest exception type.

Move the manifest schema to src/west/manifest-schema.yml as part of this.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-10-02 01:20:57 +02:00
Marti Bolivar 166ed2457e Import all west modules from west.
We are getting user feedback about missing dependencies (like
"commands" and "log") that are actually imports of internal west
modules by those names.

We've been playing games with the python path to omit typing "west",
but this always caused inconsistency (as the bootstrapper version is
imported as west._bootstrap.version) and now it's causing outright
user confusion.

Let's just be consistent and import everything as west.xxx.

Fixes #57.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-10-01 15:12:54 -06:00
Marti Bolivar 797dce2366 README.rst: fix instructions so users get 0.2.0rc2 from pypi
This is leading early testers astray.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-10-01 15:12:54 -06:00
Henrik Brix Andersen 76c162dbb1 runner: pyocd: add support for specifying SWDCLK frequency
Add support for specifying the SWDCLK frequency in Hz for pyOCD.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2018-09-25 12:59:58 -06:00
Marti Bolivar fff3c89926 West 0.2.0rc2
Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-25 18:05:53 +02:00
Marti Bolivar 682dda9907 west/main.py: don't try to guess the bootstrap version at all.
The comment added to print_version_info() explains the situation:

    The bootstrapper will print its own version, as well as that of
    the west repository itself, then exit. So if this file is being
    asked to print the version, it's because it's being run
    directly, and not via the bootstrapper.

    Rather than play tricks like invoking "pip show west" (which
    assumes the bootstrapper was installed via pip, the common but
    not universal case), refuse the temptation to make guesses and
    print an honest answer.

This will go away as we phase out the west doskey macro and shell
script in the Zephyr repository.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-25 17:51:17 +02:00
Marti Bolivar a3b124e809 commands: build: clean up help output for missing source dir
Treat the case of a missing source directory specially, to make the
error message clearer.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-25 17:51:17 +02:00
Marti Bolivar 65a6ec5b0d commands: build: fix source directory consistency check
The error message is confusing since what's output is not what was
tested. We also want to make sure to do absolute paths on both cached
and source directories just in case of issues (e.g. on Windows,
case-sensitivity is a potential source of problems).

(We can't use os.path.samefile because that's not cross-platform.)

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-09-25 17:51:17 +02:00