1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_watch-guide: 2*61c4878aSAndroid Build Coastguard Worker 3*61c4878aSAndroid Build Coastguard Worker===================== 4*61c4878aSAndroid Build Coastguard Workerpw_watch how-to guide 5*61c4878aSAndroid Build Coastguard Worker===================== 6*61c4878aSAndroid Build Coastguard Worker.. pigweed-module-subpage:: 7*61c4878aSAndroid Build Coastguard Worker :name: pw_watch 8*61c4878aSAndroid Build Coastguard Worker 9*61c4878aSAndroid Build Coastguard WorkerThis guide shows you how to do common ``pw_watch`` tasks. 10*61c4878aSAndroid Build Coastguard Worker 11*61c4878aSAndroid Build Coastguard WorkerSee :ref:`docs-build-system` for an overview of Pigweed's approach to build 12*61c4878aSAndroid Build Coastguard Workersystems. 13*61c4878aSAndroid Build Coastguard Worker 14*61c4878aSAndroid Build Coastguard Worker------------------------------- 15*61c4878aSAndroid Build Coastguard WorkerSet up your Pigweed environment 16*61c4878aSAndroid Build Coastguard Worker------------------------------- 17*61c4878aSAndroid Build Coastguard WorkerSee :ref:`activate-pigweed-environment` if you see an error like this: 18*61c4878aSAndroid Build Coastguard Worker 19*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh 20*61c4878aSAndroid Build Coastguard Worker 21*61c4878aSAndroid Build Coastguard Worker pw watch 22*61c4878aSAndroid Build Coastguard Worker bash: pw: command not found 23*61c4878aSAndroid Build Coastguard Worker 24*61c4878aSAndroid Build Coastguard Worker----- 25*61c4878aSAndroid Build Coastguard WorkerNinja 26*61c4878aSAndroid Build Coastguard Worker----- 27*61c4878aSAndroid Build Coastguard WorkerThis section contains common use cases for :ref:`docs-build-system-gn` 28*61c4878aSAndroid Build Coastguard Workerusers. 29*61c4878aSAndroid Build Coastguard Worker 30*61c4878aSAndroid Build Coastguard Worker.. _module-pw_watch-guide-ninja-custom-dirs: 31*61c4878aSAndroid Build Coastguard Worker 32*61c4878aSAndroid Build Coastguard WorkerSet up a custom build directory 33*61c4878aSAndroid Build Coastguard Worker------------------------------- 34*61c4878aSAndroid Build Coastguard Worker 35*61c4878aSAndroid Build Coastguard WorkerBefore running any command that uses a custom build directory, you need to 36*61c4878aSAndroid Build Coastguard Workerrun ``gn gen <dir>``, where ``<dir>`` is a placeholder for the name of your 37*61c4878aSAndroid Build Coastguard Workercustom build directory. 38*61c4878aSAndroid Build Coastguard Worker 39*61c4878aSAndroid Build Coastguard WorkerFor example, before running this command: 40*61c4878aSAndroid Build Coastguard Worker 41*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh 42*61c4878aSAndroid Build Coastguard Worker 43*61c4878aSAndroid Build Coastguard Worker pw watch -C out2 44*61c4878aSAndroid Build Coastguard Worker 45*61c4878aSAndroid Build Coastguard WorkerYou need to run this command: 46*61c4878aSAndroid Build Coastguard Worker 47*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh 48*61c4878aSAndroid Build Coastguard Worker 49*61c4878aSAndroid Build Coastguard Worker gn gen out2 50*61c4878aSAndroid Build Coastguard Worker 51*61c4878aSAndroid Build Coastguard WorkerBuild the default target and use the default build directory 52*61c4878aSAndroid Build Coastguard Worker------------------------------------------------------------ 53*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh 54*61c4878aSAndroid Build Coastguard Worker 55*61c4878aSAndroid Build Coastguard Worker pw watch 56*61c4878aSAndroid Build Coastguard Worker 57*61c4878aSAndroid Build Coastguard WorkerThe default build directory is ``out``. 58*61c4878aSAndroid Build Coastguard Worker 59*61c4878aSAndroid Build Coastguard WorkerCustomize the build directory 60*61c4878aSAndroid Build Coastguard Worker----------------------------- 61*61c4878aSAndroid Build Coastguard WorkerThis section assumes you have completed 62*61c4878aSAndroid Build Coastguard Worker:ref:`module-pw_watch-guide-ninja-custom-dirs`. 63*61c4878aSAndroid Build Coastguard Worker 64*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh 65*61c4878aSAndroid Build Coastguard Worker 66*61c4878aSAndroid Build Coastguard Worker pw watch -C out2 67*61c4878aSAndroid Build Coastguard Worker 68*61c4878aSAndroid Build Coastguard WorkerThis builds the default target in ``out2``. 69*61c4878aSAndroid Build Coastguard Worker 70*61c4878aSAndroid Build Coastguard WorkerBuild two targets 71*61c4878aSAndroid Build Coastguard Worker----------------- 72*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh 73*61c4878aSAndroid Build Coastguard Worker 74*61c4878aSAndroid Build Coastguard Worker pw watch stm32f429i python.lint 75*61c4878aSAndroid Build Coastguard Worker 76*61c4878aSAndroid Build Coastguard WorkerThe ``stm32f429i`` and ``python.lint`` targets are both built in the default 77*61c4878aSAndroid Build Coastguard Workerbuild directory (``out``). 78*61c4878aSAndroid Build Coastguard Worker 79*61c4878aSAndroid Build Coastguard WorkerBuild the same target in different build directories 80*61c4878aSAndroid Build Coastguard Worker---------------------------------------------------- 81*61c4878aSAndroid Build Coastguard WorkerThis section assumes you have completed 82*61c4878aSAndroid Build Coastguard Worker:ref:`module-pw_watch-guide-ninja-custom-dirs`. 83*61c4878aSAndroid Build Coastguard Worker 84*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh 85*61c4878aSAndroid Build Coastguard Worker 86*61c4878aSAndroid Build Coastguard Worker pw watch -C out1 -C out2 87*61c4878aSAndroid Build Coastguard Worker 88*61c4878aSAndroid Build Coastguard WorkerThis example builds the default target in both ``out1`` and ``out2``. 89*61c4878aSAndroid Build Coastguard Worker 90*61c4878aSAndroid Build Coastguard WorkerBuild different targets in different build directories 91*61c4878aSAndroid Build Coastguard Worker------------------------------------------------------ 92*61c4878aSAndroid Build Coastguard WorkerThis section assumes you have completed 93*61c4878aSAndroid Build Coastguard Worker:ref:`module-pw_watch-guide-ninja-custom-dirs`. 94*61c4878aSAndroid Build Coastguard Worker 95*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh 96*61c4878aSAndroid Build Coastguard Worker 97*61c4878aSAndroid Build Coastguard Worker pw watch stm32f429i -C out2 python.lint 98*61c4878aSAndroid Build Coastguard Worker 99*61c4878aSAndroid Build Coastguard WorkerThe ``stm32f429i`` target is built in the default build directory (``out``). 100*61c4878aSAndroid Build Coastguard WorkerThe ``python.lint`` target is built in the custom build directory (``out2``). 101*61c4878aSAndroid Build Coastguard Worker 102*61c4878aSAndroid Build Coastguard WorkerUnit test integration 103*61c4878aSAndroid Build Coastguard Worker--------------------- 104*61c4878aSAndroid Build Coastguard WorkerThanks to GN's understanding of the full dependency tree, only the tests 105*61c4878aSAndroid Build Coastguard Workeraffected by a file change are run when ``pw_watch`` triggers a build. By 106*61c4878aSAndroid Build Coastguard Workerdefault, host builds using ``pw_watch`` will run unit tests. To run unit tests 107*61c4878aSAndroid Build Coastguard Workeron a device as part of ``pw_watch``, refer to your device's 108*61c4878aSAndroid Build Coastguard Worker:ref:`target documentation<docs-targets>`. 109*61c4878aSAndroid Build Coastguard Worker 110*61c4878aSAndroid Build Coastguard Worker---------------------------- 111*61c4878aSAndroid Build Coastguard WorkerBuild-system-agnostic guides 112*61c4878aSAndroid Build Coastguard Worker---------------------------- 113*61c4878aSAndroid Build Coastguard WorkerThis section discusses general use cases that all apply to all ``pw watch`` 114*61c4878aSAndroid Build Coastguard Workerusage. In other words, these use cases are not affected by whether you're 115*61c4878aSAndroid Build Coastguard Workerusing GN, Bazel, and so on. 116*61c4878aSAndroid Build Coastguard Worker 117*61c4878aSAndroid Build Coastguard WorkerIgnore files 118*61c4878aSAndroid Build Coastguard Worker------------ 119*61c4878aSAndroid Build Coastguard Worker``pw watch`` only rebuilds when a file that is not ignored by Git changes. 120*61c4878aSAndroid Build Coastguard WorkerAdding exclusions to a ``.gitignore`` causes ``pw watch`` to ignore them, even 121*61c4878aSAndroid Build Coastguard Workerif the files were forcibly added to a repo. By default, only files matching 122*61c4878aSAndroid Build Coastguard Workercertain extensions are applied, even if they're tracked by Git. The 123*61c4878aSAndroid Build Coastguard Worker``--patterns`` and ``--ignore-patterns`` arguments can be used to include or 124*61c4878aSAndroid Build Coastguard Workerexclude specific patterns. These patterns do not override Git's ignoring logic. 125*61c4878aSAndroid Build Coastguard Worker 126*61c4878aSAndroid Build Coastguard WorkerThe ``--exclude-list`` argument can be used to exclude directories from being 127*61c4878aSAndroid Build Coastguard Workerwatched. This decreases the number of files monitored with ``inotify`` in Linux. 128*61c4878aSAndroid Build Coastguard Worker 129*61c4878aSAndroid Build Coastguard WorkerAutomatically reload docs 130*61c4878aSAndroid Build Coastguard Worker------------------------- 131*61c4878aSAndroid Build Coastguard WorkerWhen using ``--serve-docs``, by default the docs will be rebuilt when changed, 132*61c4878aSAndroid Build Coastguard Workerjust like code files. However, you will need to manually reload the page in 133*61c4878aSAndroid Build Coastguard Workeryour browser to see changes. 134*61c4878aSAndroid Build Coastguard Worker 135*61c4878aSAndroid Build Coastguard WorkerDisable automatic rebuilds 136*61c4878aSAndroid Build Coastguard Worker-------------------------- 137*61c4878aSAndroid Build Coastguard Worker``pw watch`` automatically restarts an ongoing build when files change. This 138*61c4878aSAndroid Build Coastguard Workercan be disabled with the ``--no-restart`` option. While running ``pw watch``, 139*61c4878aSAndroid Build Coastguard Workeryou may also press :kbd:`Enter` to immediately restart a build. 140