west build is invalid choice

Hi,

I have installed the nRF Connect SDK v2.0.0 with Visual Studio and can now successfully, build, flash and run the nrf9160 at_client sample application. But when I try to build it from the command line west says that 'build' is an invalid choice. When building from the command line, I select "Open Terminal" from the nRF Connect SDK line in the toolchain manager. Then when I try to build, I get this:

at_client [master●] % west build -b nrf9160dk_nrf9160_ns
usage: west [-h] [-z ZEPHYR_BASE] [-v] [-V] <command> ...
west: error: argument <command>: invalid choice: 'build' (choose from 'init', 'update', 'list', 'manifest', 'diff', 'status', 'forall', 'help', 'config', 'topdir', 'selfupdate')
Any ideas why this is happening?
Thanks
Greg
  • Hello Greg,

    My name is Ted, and I just recently got this error myself.  I've been building ncs 1.6.1 based sample apps and a custom app for a while now, so `west` generally works as expected.  The error you give here is exactly what I saw when I mistakenly issued my `west build . . .` command outside the directory in which my custom, Zephyr based app lives.

    I don't know how your project directory structure looks, but mine is structured like this:

                                           |
                                          ncs
                                           |
         +-------------+-------------+-----+-----+--------+---------+----------+
         |             |             |           |        |         |          |
    custom_app     bootloader     modules       nrf    nrfxlib    zephyr     .west

    The `west` utility only knows about its "build" option when I invoke west in the directory named custom_app.  I believe this has to do with the way `west` looks for additional python modules when it first starts up.  Because the parent 'ncs' directory is the location I chose to initialize as a 'west workspace', there's a hidden .west directory created there, along side my custom app.  There's a tiny one-line or few-lines config file there which I believe points `west` to some further, Zephyr specific options such as 'build'.

    The reason I can run `west` in any path is that I've added its full path to my environment variable $PATH.

    When you open your terminal from nRF Connect SDK is it clear to you, or can you check which is your current working directory?  That might be the issue causing your error.

    - Ted

  • Thanks Ted. What I have done is copy one of Nordic's sample apps (at_client) to a new directory and I ran west from that directory when it failed. Your post made me try one more thing. I went back to the original sample app and ran 'west build' from that directory and it works. So now I just have to figure out what west is missing when I copied the sample app to a new location.

    To sum up, if I build the sample app from it's original location, which on my computer is:

    /opt/nordic/ncs/v2.0.0/nrf/samples/nrf9160/at_client

    Then west is happy and it builds. If I try to build my copy of at_client at:

    ~/git/nordic/at_client

    Then west says build is an invalid choice. I can however build it from VS Code.

    I guess I need to go learn more about west and Zephyr...

  • Solved it. If I run:

        export ZEPHYR_BASE=/opt/nordic/ncs/v2.0.0/zephyr

    and then run west build it works. Interesting, if I try to specify the ZEPHYR_BASE on the west command line with -z it does not work. Anyway, I would think that the ZEPHYR_BASE would have been set up by the Open Terminal command.

  • Hi Greg,

    That's more clear to me now when you describe "I copied one of Nordic's sample apps to a new directory and I ran west from [there]...".  I think what is missing is that Nordic Semi's Zephyr based sample apps are part of a larger 'west workspace'.  To copy a single app to another location without performing a `west init` on that new location will leave the `west` utility with only its core commands, not the extra ones which are provided by either Zephyr or Nordic.

    You can do what you want to do, but from what I gather you are trying to make a stand alone application out of an existing sample app from one of Nordic's ncs releases.  Is your goal to work with a given sample app, and be able to copy or clone that to new locations on demand?

    A few months ago I found myself needing to do this.  There are a couple steps involved, but the work is not too harrowing.  When I wanted to extend and experiment with Nordic Semi's aws_iot sample app, and be able to check that into a git repo of my choosing, I needed to complete four key steps:

    (1)  copy the sample app to a new dedicated location

    (2)  create a west manifest file along side the sample app's src directory

    (3)  invoke `west init -l custom_app` in the parent directory of my project dir named custom_app

    (4)  cd into 'custom_app' and invoke `west update`

    To create the west manifest file, a file which is by convention named 'west.yml' took me the longest time to figure out of any of these steps.  It is possible I have forgotten some details, but these steps are in the ballpark of what's needed to move from building within Nordic Semi's super big west based project, to building our own apps based on Nordic and Zephyr source trees.

    The critical benefit I needed from this effort is the ability to version control my coding work.  In the sample apps which came with my initial `git clone` of Nordic ncs, I can update all I want, but I cannot git control any of my changes.  Git is already pointed to Nordic's repositories on github.  That is the way I want it, but I need to be able to leverage their open source code in my own work, and track my changes in git repositories where I have read and write access.

    As an aside, here is what my west.yml west manifest file looks like:

    manifest:
      remotes:
        - name: nrfconnect
          url-base: https://github.com/nrfconnect
      projects:
        - name: nrf 
          repo-path: sdk-nrf
          remote: nrfconnect
          revision: v1.6.1
          import: true 
    ## 2021-10-28 - contributor Ted removing Kionix out-of-Zephyr-tree driver dependency:
    ##    # Drivers repository
    ##    - name: zephyr-driver-work-v2
    ##      path: kionix-drivers
    ##      revision: sensor-configuration-routines-work-001
    ##      url: [email protected]:tedhavelka/zephyr-driver-work-v2
      self:
        # This repository should be cloned to 
        path: aws-iot-stand-alone
    

    Lines which begin with # are commented out.

    Basically this is the simplest of west manifest files.  All it says to `west` when I invoke `west update` is for this utility to go and either download or update Nordic's nrf repository, at its 1.6.1 release.  You can find other more complex examples of west manifest files in ncs 1.6.1 itself -- it has a lot of third party code projects comprising it -- and also in Zephyr RTOS source tree.

    I think you're pretty close to copying and building your desired sample app in a path of your choosing.  But you will need to `west` initialize that path location, and then `west update` to download the needed third party repos.

    Hope this helps, Greg.  Stay safe,

    - Ted

  • Ah ok,

    I think your exporting of $ZEPHYR_BASE probably informs `west` of the path needed to get to /opt/nordic/ncs/v2.0.0/zephyr/scripts/zephyr_module.py. I'm guessing such a script exists on your system.

    I'm not proficient in Python, but it looks like this script may be the entry point for `west` to obtain its build related extending commands, the one that was not available when you tried earlier from the nRF Connect terminal window.

    If you are good compiling and working in the arbitrary location then you're home!  If you need to version control your work, you may be faced with making the sample copy a fully stand alone Zephyr application.

    Glad to hear you have gotten things running as quickly!

    - Ted

Related