1.. _west-built-in-cmds: 2 3Built-in commands 4################# 5 6This page describes west's built-in commands, some of which were introduced in 7:ref:`west-basics`, in more detail. 8 9Some commands are related to Git commands with the same name, but operate 10on the entire workspace. For example, ``west diff`` shows local changes in 11multiple Git repositories in the workspace. 12 13Some commands take projects as arguments. These arguments can be project 14names as specified in the manifest file, or (as a fallback) paths to them 15on the local file system. Omitting project arguments to commands which 16accept them (such as ``west list``, ``west forall``, etc.) usually defaults 17to using all projects in the manifest file plus the manifest repository 18itself. 19 20For additional help, run ``west <command> -h`` (e.g. ``west init -h``). 21 22.. _west-init: 23 24west init 25********* 26 27This command creates a west workspace. It can be used in two ways: 28 291. Cloning a new manifest repository from a remote URL 302. Creating a workspace around an existing local manifest repository 31 32**Option 1**: to clone a new manifest repository from a remote URL, use: 33 34.. code-block:: none 35 36 west init [-m URL] [--mr REVISION] [--mf FILE] [directory] 37 38The new workspace is created in the given :file:`directory`, creating a new 39:file:`.west` inside this directory. You can give the manifest URL using 40the ``-m`` switch, the initial revision to check out using ``--mr``, and 41the location of the manifest file within the repository using ``--mf``. 42 43For example, running: 44 45.. code-block:: shell 46 47 west init -m https://github.com/zephyrproject-rtos/zephyr --mr v1.14.0 zp 48 49would clone the upstream official zephyr repository into :file:`zp/zephyr`, 50and check out the ``v1.14.0`` release. This command creates 51:file:`zp/.west`, and set the ``manifest.path`` :ref:`configuration option 52<west-config>` to ``zephyr`` to record the location of the manifest 53repository in the workspace. The default manifest file location is used. 54 55The ``-m`` option defaults to ``https://github.com/zephyrproject-rtos/zephyr``. 56The ``--mf`` option defaults to ``west.yml``. Since west v0.10.1, west will use 57the default branch in the manifest repository unless the ``--mr`` option 58is used to override it. (In prior versions, ``--mr`` defaulted to ``master``.) 59 60If no ``directory`` is given, the current working directory is used. 61 62**Option 2**: to create a workspace around an existing local manifest 63repository, use: 64 65.. code-block:: none 66 67 west init -l [--mf FILE] directory 68 69This creates :file:`.west` **next to** :file:`directory` in the file 70system, and sets ``manifest.path`` to ``directory``. 71 72As above, ``--mf`` defaults to ``west.yml``. 73 74**Reconfiguring the workspace**: 75 76If you change your mind later, you are free to change ``manifest.path`` and 77``manifest.file`` using :ref:`west-config-cmd` after running ``west init``. 78Just be sure to run ``west update`` afterwards to update your workspace to 79match the new manifest file. 80 81.. _west-update: 82 83west update 84*********** 85 86.. code-block:: none 87 88 west update [-f {always,smart}] [-k] [-r] 89 [--group-filter FILTER] [--stats] [PROJECT ...] 90 91**Which projects are updated:** 92 93By default, this command parses the manifest file, usually 94:file:`west.yml`, and updates each project specified there. 95If your manifest uses :ref:`project groups <west-manifest-groups>`, then 96only the active projects are updated. 97 98To operate on a subset of projects only, give ``PROJECT`` argument(s). Each 99``PROJECT`` is either a project name as given in the manifest file, or a 100path that points to the project within the workspace. If you specify 101projects explicitly, they are updated regardless of whether they are active. 102 103**Project update procedure:** 104 105For each project that is updated, this command: 106 107#. Initializes a local Git repository for the project in the workspace, if 108 it does not already exist 109#. Inspects the project's ``revision`` field in the manifest, and fetches 110 it from the remote if it is not already available locally 111#. Sets the project's :ref:`manifest-rev <west-manifest-rev>` branch to the 112 commit specified by the revision in the previous step 113#. Checks out ``manifest-rev`` in the local working copy as a `detached 114 HEAD <https://git-scm.com/docs/git-checkout#_detached_head>`_ 115#. If the manifest file specifies a :ref:`submodules 116 <west-manifest-submodules>` key for the project, recursively updates 117 the project's submodules as described below. 118 119To avoid unnecessary fetches, ``west update`` will not fetch project 120``revision`` values which are Git SHAs or tags that are already available 121locally. This is the behavior when the ``-f`` (``--fetch``) option has its 122default value, ``smart``. To force this command to fetch from project remotes 123even if the revisions appear to be available locally, either use ``-f always`` 124or set the ``update.fetch`` :ref:`configuration option <west-config>` to 125``always``. SHAs may be given as unique prefixes as long as they are acceptable 126to Git [#fetchall]_. 127 128If the project ``revision`` is a Git ref that is neither a tag nor a SHA (i.e. 129if the project is tracking a branch), ``west update`` always fetches, 130regardless of ``-f`` and ``update.fetch``. 131 132Some branch names might look like short SHAs, like ``deadbeef``. West treats 133these like SHAs. You can disambiguate by prefixing the ``revision`` value with 134``refs/heads/``, e.g. ``revision: refs/heads/deadbeef``. 135 136For safety, ``west update`` uses ``git checkout --detach`` to check out a 137detached ``HEAD`` at the manifest revision for each updated project, 138leaving behind any branches which were already checked out. This is 139typically a safe operation that will not modify any of your local branches. 140 141However, if you had added some local commits onto a previously detached 142``HEAD`` checked out by west, then git will warn you that you've left 143behind some commits which are no longer referred to by any branch. These 144may be garbage-collected and lost at some point in the future. To avoid 145this if you have local commits in the project, make sure you have a local 146branch checked out before running ``west update``. 147 148If you would rather rebase any locally checked out branches instead, use 149the ``-r`` (``--rebase``) option. 150 151If you would like ``west update`` to keep local branches checked out as 152long as they point to commits that are descendants of the new 153``manifest-rev``, use the ``-k`` (``--keep-descendants``) option. 154 155.. note:: 156 157 ``west update --rebase`` will fail in projects that have git conflicts 158 between your branch and new commits brought in by the manifest. You 159 should immediately resolve these conflicts as you usually do with 160 ``git``, or you can use ``git -C <project_path> rebase --abort`` to 161 ignore incoming changes for the moment. 162 163 With a clean working tree, a plain ``west update`` never fails 164 because it does not try to hold on to your commits and simply 165 leaves them aside. 166 167 ``west update --keep-descendants`` offers an intermediate option that 168 never fails either but does not treat all projects the same: 169 170 - in projects where your branch diverged from the incoming commits, it 171 does not even try to rebase and leaves your branches behind just like a 172 plain ``west update`` does; 173 - in all other projects where no rebase or merge is needed it keeps 174 your branches in place. 175 176**One-time project group manipulation:** 177 178The ``--group-filter`` option can be used to change which project groups 179are enabled or disabled for the duration of a single ``west update`` command. 180See :ref:`west-manifest-groups` for details on the project group feature. 181 182The ``west update`` command behaves as if the ``--group-filter`` option's 183value were appended to the ``manifest.group-filter`` 184:ref:`configuration option <west-config-index>`. 185 186For example, running ``west update --group-filter=+foo,-bar`` would behave 187the same way as if you had temporarily appended the string ``"+foo,-bar"`` 188to the value of ``manifest.group-filter``, run ``west update``, then restored 189``manifest.group-filter`` to its original value. 190 191Note that using the syntax ``--group-filter=VALUE`` instead of 192``--group-filter VALUE`` avoids issues parsing command line options 193if you just want to disable a single group, e.g. ``--group-filter=-bar``. 194 195**Submodule update procedure:** 196 197If a project in the manifest has a ``submodules`` key, the submodules are 198updated as follows, depending on the value of the ``submodules`` key. 199 200If the project has ``submodules: true``, west first synchronizes the project's 201submodules with: 202 203.. code-block:: 204 205 git submodule sync --recursive 206 207West then runs one of the following in the project repository, depending on 208whether you run ``west update`` with the ``--rebase`` option or without it: 209 210.. code-block:: 211 212 # without --rebase, e.g. "west update": 213 git submodule update --init --checkout --recursive 214 215 # with --rebase, e.g. "west update --rebase": 216 git submodule update --init --rebase --recursive 217 218Otherwise, the project has ``submodules: <list-of-submodules>``. In this 219case, west synchronizes the project's submodules with: 220 221.. code-block:: 222 223 git submodule sync --recursive -- <submodule-path> 224 225Then it updates each submodule in the list as follows, depending on whether you 226run ``west update`` with the ``--rebase`` option or without it: 227 228.. code-block:: 229 230 # without --rebase, e.g. "west update": 231 git submodule update --init --checkout --recursive <submodule-path> 232 233 # with --rebase, e.g. "west update --rebase": 234 git submodule update --init --rebase --recursive <submodule-path> 235 236The ``git submodule sync`` commands are skipped if the 237``update.sync-submodules`` :ref:`west-config` option is false. 238 239.. _west-built-in-misc: 240 241Other project commands 242********************** 243 244West has a few more commands for managing the projects in the 245workspace, which are summarized here. Run ``west <command> -h`` for 246detailed help. 247 248- ``west list``: print a line of information about each project in the 249 manifest, according to a format string 250- ``west manifest``: manage the manifest file. See :ref:`west-manifest-cmd`. 251- ``west diff``: run ``git diff`` in local project repositories 252- ``west status``: run ``git status`` in local project repositories 253- ``west forall``: run an arbitrary command in local project repositories 254- ``west compare``: compare the state of the workspace against the manifest 255 256Other built-in commands 257*********************** 258 259Finally, here is a summary of other built-in commands. 260 261- ``west config``: get or set :ref:`configuration options <west-config>` 262- ``west topdir``: print the top level directory of the west workspace 263- ``west help``: get help about a command, or print information about all 264 commands in the workspace, including :ref:`west-extensions` 265 266.. rubric:: Footnotes 267 268.. [#fetchall] 269 270 West may fetch all refs from the Git server when given a SHA as a revision. 271 This is because some Git servers have historically not allowed fetching 272 SHAs directly. 273