develop/west/built-in.html · develop/west/built-in.rst 공식 원문 ↗

Zephyr 3.7.0 · Develop · West · Built-in commands

West 내장 명령

West workspace를 만들고 manifest revision에 맞춰 여러 project를 안전하게 갱신하는 내장 명령의 실제 동작을 설명합니다.

Official pathdevelop/west/built-in.html
Source filedevelop/west/built-in.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

west init의 원격·로컬 방식, west update의 fetch·detached HEAD·rebase·keep-descendants·group filter·submodule 정책과 나머지 project 명령을 정리합니다.

Initialize

remote · local manifest

Update

fetch · checkout · branch

Projects

group · submodule · commands

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 21393706A20A8E06A7FA756D1BE7C0464F85621BDC34B7AE1761402910D7616E
.. _west-built-in-cmds:

Built-in commands
#################

This page describes west's built-in commands, some of which were introduced in
:ref:`west-basics`, in more detail.

Some commands are related to Git commands with the same name, but operate
on the entire workspace. For example, ``west diff`` shows local changes in
multiple Git repositories in the workspace.

Some commands take projects as arguments. These arguments can be project
names as specified in the manifest file, or (as a fallback) paths to them
on the local file system. Omitting project arguments to commands which
accept them (such as ``west list``, ``west forall``, etc.) usually defaults
to using all projects in the manifest file plus the manifest repository
itself.

For additional help, run ``west <command> -h`` (e.g. ``west init -h``).

.. _west-init:

west init
*********

This command creates a west workspace. It can be used in two ways:

1. Cloning a new manifest repository from a remote URL
2. Creating a workspace around an existing local manifest repository

**Option 1**: to clone a new manifest repository from a remote URL, use:

.. code-block:: none

   west init [-m URL] [--mr REVISION] [--mf FILE] [directory]

The new workspace is created in the given :file:`directory`, creating a new
:file:`.west` inside this directory. You can give the manifest URL using
the ``-m`` switch, the initial revision to check out using ``--mr``, and
the location of the manifest file within the repository using ``--mf``.

For example, running:

.. code-block:: shell

   west init -m https://github.com/zephyrproject-rtos/zephyr --mr v1.14.0 zp

would clone the upstream official zephyr repository into :file:`zp/zephyr`,
and check out the ``v1.14.0`` release. This command creates
:file:`zp/.west`, and set the ``manifest.path`` :ref:`configuration option
<west-config>` to ``zephyr`` to record the location of the manifest
repository in the workspace. The default manifest file location is used.

The ``-m`` option defaults to ``https://github.com/zephyrproject-rtos/zephyr``.
The ``--mf`` option defaults to ``west.yml``. Since west v0.10.1, west will use
the default branch in the manifest repository unless the ``--mr`` option
is used to override it. (In prior versions, ``--mr`` defaulted to ``master``.)

If no ``directory`` is given, the current working directory is used.

**Option 2**: to create a workspace around an existing local manifest
repository, use:

.. code-block:: none

   west init -l [--mf FILE] directory

This creates :file:`.west` **next to** :file:`directory` in the file
system, and sets ``manifest.path`` to ``directory``.

As above, ``--mf`` defaults to ``west.yml``.

**Reconfiguring the workspace**:

If you change your mind later, you are free to change ``manifest.path`` and
``manifest.file`` using :ref:`west-config-cmd` after running ``west init``.
Just be sure to run ``west update`` afterwards to update your workspace to
match the new manifest file.

.. _west-update:

west update
***********

.. code-block:: none

   west update [-f {always,smart}] [-k] [-r]
               [--group-filter FILTER] [--stats] [PROJECT ...]

**Which projects are updated:**

By default, this command parses the manifest file, usually
:file:`west.yml`, and updates each project specified there.
If your manifest uses :ref:`project groups <west-manifest-groups>`, then
only the active projects are updated.

To operate on a subset of projects only, give ``PROJECT`` argument(s). Each
``PROJECT`` is either a project name as given in the manifest file, or a
path that points to the project within the workspace. If you specify
projects explicitly, they are updated regardless of whether they are active.

**Project update procedure:**

For each project that is updated, this command:

#. Initializes a local Git repository for the project in the workspace, if
   it does not already exist
#. Inspects the project's ``revision`` field in the manifest, and fetches
   it from the remote if it is not already available locally
#. Sets the project's :ref:`manifest-rev <west-manifest-rev>` branch to the
   commit specified by the revision in the previous step
#. Checks out ``manifest-rev`` in the local working copy as a `detached
   HEAD <https://git-scm.com/docs/git-checkout#_detached_head>`_
#. If the manifest file specifies a :ref:`submodules
   <west-manifest-submodules>` key for the project, recursively updates
   the project's submodules as described below.

To avoid unnecessary fetches, ``west update`` will not fetch project
``revision`` values which are Git SHAs or tags that are already available
locally. This is the behavior when the ``-f`` (``--fetch``) option has its
default value, ``smart``. To force this command to fetch from project remotes
even if the revisions appear to be available locally, either use ``-f always``
or set the ``update.fetch`` :ref:`configuration option <west-config>` to
``always``. SHAs may be given as unique prefixes as long as they are acceptable
to Git [#fetchall]_.

If the project ``revision`` is a Git ref that is neither a tag nor a SHA (i.e.
if the project is tracking a branch), ``west update`` always fetches,
regardless of ``-f`` and ``update.fetch``.

Some branch names might look like short SHAs, like ``deadbeef``. West treats
these like SHAs. You can disambiguate by prefixing the ``revision`` value with
``refs/heads/``, e.g. ``revision: refs/heads/deadbeef``.

For safety, ``west update`` uses ``git checkout --detach`` to check out a
detached ``HEAD`` at the manifest revision for each updated project,
leaving behind any branches which were already checked out. This is
typically a safe operation that will not modify any of your local branches.

However, if you had added some local commits onto a previously detached
``HEAD`` checked out by west, then git will warn you that you've left
behind some commits which are no longer referred to by any branch. These
may be garbage-collected and lost at some point in the future. To avoid
this if you have local commits in the project, make sure you have a local
branch checked out before running ``west update``.

If you would rather rebase any locally checked out branches instead, use
the ``-r`` (``--rebase``) option.

If you would like ``west update`` to keep local branches checked out as
long as they point to commits that are descendants of the new
``manifest-rev``, use the ``-k`` (``--keep-descendants``) option.

.. note::

   ``west update --rebase`` will fail in projects that have git conflicts
   between your branch and new commits brought in by the manifest. You
   should immediately resolve these conflicts as you usually do with
   ``git``, or you can use ``git -C <project_path> rebase --abort`` to
   ignore incoming changes for the moment.

   With a clean working tree, a plain ``west update`` never fails
   because it does not try to hold on to your commits and simply
   leaves them aside.

   ``west update --keep-descendants`` offers an intermediate option that
   never fails either but does not treat all projects the same:

   - in projects where your branch diverged from the incoming commits, it
     does not even try to rebase and leaves your branches behind just like a
     plain ``west update`` does;
   - in all other projects where no rebase or merge is needed it keeps
     your branches in place.

**One-time project group manipulation:**

The ``--group-filter`` option can be used to change which project groups
are enabled or disabled for the duration of a single ``west update`` command.
See :ref:`west-manifest-groups` for details on the project group feature.

The ``west update`` command behaves as if the ``--group-filter`` option's
value were appended to the ``manifest.group-filter``
:ref:`configuration option <west-config-index>`.

For example, running ``west update --group-filter=+foo,-bar`` would behave
the same way as if you had temporarily appended the string ``"+foo,-bar"``
to the value of ``manifest.group-filter``, run ``west update``, then restored
``manifest.group-filter`` to its original value.

Note that using the syntax ``--group-filter=VALUE`` instead of
``--group-filter VALUE`` avoids issues parsing command line options
if you just want to disable a single group, e.g. ``--group-filter=-bar``.

**Submodule update procedure:**

If a project in the manifest has a ``submodules`` key, the submodules are
updated as follows, depending on the value of the ``submodules`` key.

If the project has ``submodules: true``, west first synchronizes the project's
submodules with:

.. code-block::

   git submodule sync --recursive

West then runs one of the following in the project repository, depending on
whether you run ``west update`` with the ``--rebase`` option or without it:

.. code-block::

   # without --rebase, e.g. "west update":
   git submodule update --init --checkout --recursive

   # with --rebase, e.g. "west update --rebase":
   git submodule update --init --rebase --recursive

Otherwise, the project has ``submodules: <list-of-submodules>``. In this
case, west synchronizes the project's submodules with:

.. code-block::

   git submodule sync --recursive -- <submodule-path>

Then it updates each submodule in the list as follows, depending on whether you
run ``west update`` with the ``--rebase`` option or without it:

.. code-block::

   # without --rebase, e.g. "west update":
   git submodule update --init --checkout --recursive <submodule-path>

   # with --rebase, e.g. "west update --rebase":
   git submodule update --init --rebase --recursive <submodule-path>

The ``git submodule sync`` commands are skipped if the
``update.sync-submodules`` :ref:`west-config` option is false.

.. _west-built-in-misc:

Other project commands
**********************

West has a few more commands for managing the projects in the
workspace, which are summarized here. Run ``west <command> -h`` for
detailed help.

- ``west compare``: compare the state of the workspace against the manifest
- ``west diff``: run ``git diff`` in local project repositories
- ``west forall``: run an arbitrary command in local project repositories
- ``west grep``: search for patterns in local project repositories
- ``west list``: print a line of information about each project in the
  manifest, according to a format string
- ``west manifest``: manage the manifest file. See :ref:`west-manifest-cmd`.
- ``west status``: run ``git status`` in local project repositories

Other built-in commands
***********************

Finally, here is a summary of other built-in commands.

- ``west config``: get or set :ref:`configuration options <west-config>`
- ``west topdir``: print the top level directory of the west workspace
- ``west help``: get help about a command, or print information about all
  commands in the workspace, including :ref:`west-extensions`

.. rubric:: Footnotes

.. [#fetchall]

   West may fetch all refs from the Git server when given a SHA as a revision.
   This is because some Git servers have historically not allowed fetching
   SHAs directly.

Part 3

한국어 전문 번역

내장 명령

이 페이지는 West 기본 개념에서 소개한 명령을 포함해 west의 내장 명령을 더 자세히 설명합니다.

일부 명령은 같은 이름의 Git 명령과 관련되지만 한 저장소가 아니라 workspace 전체에 적용됩니다. 예를 들어 west diff는 workspace의 여러 Git 저장소에 있는 로컬 변경 사항을 보여 줍니다.

일부 명령은 project를 argument로 받습니다. Argument에는 manifest file에 적힌 project 이름을 쓰며, 일치하는 이름이 없으면 로컬 파일 시스템의 project path로 해석합니다.

west list나 west forall처럼 project를 받을 수 있는 명령에서 project argument를 생략하면 일반적으로 manifest의 모든 project와 manifest repository 자체를 대상으로 합니다.

추가 도움말은 west <command> -h로 확인합니다. 예를 들어 west init -h를 실행합니다.

west init

west init은 west workspace를 만들며 다음 두 방식으로 사용할 수 있습니다.

  1. 원격 URL에서 새 manifest repository를 복제합니다.
  2. 이미 존재하는 로컬 manifest repository를 중심으로 workspace를 만듭니다.

방식 1: 원격 manifest repository 복제

west init [-m URL] [--mr REVISION] [--mf FILE] [directory]

지정한 directory에 새 workspace를 만들고 그 안에 .west를 생성합니다. -m으로 manifest URL, --mr로 처음 checkout할 revision, --mf로 repository 내부 manifest file 위치를 지정합니다.

예를 들어 다음 명령을 실행합니다.

west init -m https://github.com/zephyrproject-rtos/zephyr --mr v1.14.0 zp

이 명령은 upstream 공식 Zephyr repository를 zp/zephyr로 복제하고 v1.14.0 release를 checkout합니다. 또한 zp/.west를 만들고 manifest repository 위치를 기록하기 위해 manifest.path 설정 option을 zephyr로 지정합니다. Manifest file은 기본 위치를 사용합니다.

-m의 기본값은 https://github.com/zephyrproject-rtos/zephyr이고 --mf의 기본값은 west.yml입니다.

West v0.10.1부터 --mr로 덮어쓰지 않으면 manifest repository의 default branch를 사용합니다. 이전 version에서는 --mr 기본값이 master였습니다.

directory를 생략하면 현재 작업 디렉터리를 사용합니다.

방식 2: 기존 로컬 manifest repository 사용

west init -l [--mf FILE] directory

이 명령은 파일 시스템에서 directory 안이 아니라 그 바로 옆에 .west를 만들고 manifest.path를 directory로 설정합니다. 이 방식에서도 --mf 기본값은 west.yml입니다.

Workspace 재설정

west init을 실행한 뒤에도 west config로 manifest.path와 manifest.file을 바꿀 수 있습니다. 변경한 다음에는 반드시 west update를 실행해 workspace를 새 manifest file과 일치시켜야 합니다.

west update

west update [-f {always,smart}] [-k] [-r]
            [--group-filter FILTER] [--stats] [PROJECT ...]

갱신 대상 project

기본적으로 이 명령은 대개 west.yml인 manifest file을 분석하고 그 안에 지정된 각 project를 갱신합니다. Manifest가 project group을 사용한다면 활성 project만 갱신합니다.

일부 project만 처리하려면 하나 이상의 PROJECT argument를 지정합니다. 각 값은 manifest의 project 이름 또는 workspace 안의 project를 가리키는 path입니다. Project를 명시적으로 지정하면 활성 여부와 관계없이 갱신합니다.

Project 갱신 절차

갱신 대상인 각 project에 대해 다음 순서로 작업합니다.

  1. Workspace에 로컬 Git repository가 없으면 초기화합니다.
  2. Manifest의 revision field를 확인하고 해당 revision이 로컬에 없으면 remote에서 fetch합니다.
  3. Project의 manifest-rev branch가 앞 단계의 revision이 지정한 commit을 가리키게 합니다.
  4. detached HEAD 상태로 로컬 working copy에서 manifest-rev를 checkout합니다.
  5. Manifest에 project의 submodules key가 있으면 아래 절차에 따라 submodule을 재귀적으로 갱신합니다.

Fetch 정책

불필요한 fetch를 피하기 위해 west update는 manifest의 revision 값이 Git SHA 또는 tag이고 이미 로컬에 있으면 remote에서 가져오지 않습니다. -f 또는 --fetch의 기본값 smart가 이 동작을 선택합니다.

Revision이 이미 있어 보여도 remote에서 강제로 fetch하려면 -f always를 사용하거나 update.fetch 설정을 always로 지정합니다. Git이 받아들이는 고유 prefix라면 SHA를 짧게 적을 수도 있습니다.

Project revision이 tag나 SHA가 아닌 Git ref, 즉 branch를 추적한다면 -f와 update.fetch 값에 관계없이 항상 fetch합니다.

deadbeef처럼 짧은 SHA처럼 보이는 branch 이름은 west가 SHA로 취급합니다. revision: refs/heads/deadbeef처럼 refs/heads/ prefix를 붙여 branch임을 명확히 할 수 있습니다.

Detached HEAD와 로컬 branch 보호

안전을 위해 west update는 git checkout --detach로 각 project의 manifest revision을 detached HEAD에 checkout합니다. 기존에 checkout돼 있던 branch는 그대로 남으므로 보통 로컬 branch를 수정하지 않습니다.

하지만 west가 이전에 checkout한 detached HEAD 위에 로컬 commit을 추가했다면, 새 revision으로 이동할 때 어느 branch도 참조하지 않는 commit을 남긴다는 Git 경고가 나타납니다. 이 commit은 나중에 garbage collection으로 사라질 수 있습니다. Project에 로컬 commit이 있다면 west update 전에 로컬 branch를 checkout해야 합니다.

현재 checkout한 로컬 branch를 새 revision 위로 rebase하려면 -r 또는 --rebase를 사용합니다.

로컬 branch가 새 manifest-rev commit의 descendant일 때 그 branch를 계속 checkout한 상태로 두려면 -k 또는 --keep-descendants를 사용합니다.

한 번만 적용하는 project group 변경

--group-filter는 한 번의 west update가 실행되는 동안 활성화하거나 비활성화할 project group을 바꿉니다. Project group 기능 자체는 West manifest group 문서를 참고합니다.

west update는 --group-filter 값이 manifest.group-filter 설정 option 뒤에 임시로 추가된 것처럼 동작합니다.

west update --group-filter=+foo,-bar는 manifest.group-filter에 +foo,-bar를 잠시 추가하고 update한 뒤 원래 값으로 되돌린 것과 같습니다. 이 예는 foo group을 활성화하고 bar group을 비활성화합니다.

한 group만 비활성화할 때 command-line option 분석 문제를 피하려면 --group-filter -bar 대신 --group-filter=-bar 형식을 사용합니다.

Submodule 갱신 절차

Manifest의 project에 submodules key가 있으면 그 값에 따라 다음과 같이 갱신합니다.

submodules: true이면 먼저 project의 모든 submodule을 동기화합니다.

git submodule sync --recursive

그 뒤 west update에 --rebase를 썼는지에 따라 project repository에서 다음 명령 중 하나를 실행합니다.

# without --rebase, e.g. "west update":
git submodule update --init --checkout --recursive

# with --rebase, e.g. "west update --rebase":
git submodule update --init --rebase --recursive

그 밖의 경우에는 submodules: <list-of-submodules> 형식입니다. 이때 목록에 든 각 submodule path를 다음과 같이 동기화합니다.

git submodule sync --recursive -- <submodule-path>

그런 다음 --rebase 사용 여부에 따라 목록의 각 submodule을 다음과 같이 갱신합니다.

# without --rebase, e.g. "west update":
git submodule update --init --checkout --recursive <submodule-path>

# with --rebase, e.g. "west update --rebase":
git submodule update --init --rebase --recursive <submodule-path>

update.sync-submodules 설정 option이 false이면 git submodule sync 명령은 건너뜁니다.

그 밖의 project 명령

West는 workspace의 project를 관리하는 다음 명령도 제공합니다. 자세한 도움말은 west <command> -h로 확인합니다.

  • west compare: workspace 상태와 manifest를 비교합니다.
  • west diff: 로컬 project repository에서 git diff를 실행합니다.
  • west forall: 로컬 project repository에서 임의 명령을 실행합니다.
  • west grep: 로컬 project repository에서 pattern을 검색합니다.
  • west list: format string에 따라 manifest의 각 project 정보를 한 줄씩 출력합니다.
  • west manifest: manifest file을 관리합니다.
  • west status: 로컬 project repository에서 git status를 실행합니다.

그 밖의 내장 명령

  • west config: 설정 option을 읽거나 씁니다.
  • west topdir: west workspace의 최상위 디렉터리를 출력합니다.
  • west help: 특정 명령의 도움말 또는 extension을 포함한 workspace 전체 명령 정보를 출력합니다.

각주: SHA fetch

Revision으로 SHA를 주면 west가 Git server의 모든 ref를 fetch할 수 있습니다. 일부 Git server가 역사적으로 SHA를 직접 fetch하는 것을 허용하지 않았기 때문입니다.

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.