blob: 306bec2b9ad888949bdfad7bf6e89079d1b35ff8 [file] [log] [blame]
Wyatt Heplerf9fb90f2020-09-30 18:59:33 -07001.. _module-pw_watch:
Armando Montanezbcc194b2020-03-10 10:23:18 -07002
3--------
4pw_watch
5--------
Armando Montanez0054a9b2020-03-13 13:06:24 -07006``pw_watch`` is similar to file system watchers found in the web development
7space. These watchers trigger a web server reload on source change, increasing
Armando Montanezbcc194b2020-03-10 10:23:18 -07008iteration. In the embedded space, file system watchers are less prevalent but no
9less useful! The Pigweed watcher module makes it easy to instantly compile,
10flash, and run tests upon save.
11
12.. image:: doc_resources/pw_watch_on_device_demo.gif
13
14.. note::
15
Wyatt Heplerc9e51d22020-10-29 09:12:37 -070016 ``pw_watch`` currently only works with Pigweed's GN and CMake builds.
Armando Montanezbcc194b2020-03-10 10:23:18 -070017
18Module Usage
19============
Armando Montanez0054a9b2020-03-13 13:06:24 -070020The simplest way to get started with ``pw_watch`` is to launch it from a shell
Wyatt Hepler00efe182020-11-23 08:25:14 -080021using the Pigweed environment as ``pw watch``. By default, ``pw_watch`` watches
Wyatt Heplerd4a847e2021-09-10 18:16:33 -070022for repository changes and triggers the default Ninja build target at out/. To
23override this behavior, provide the ``-C`` argument to ``pw watch``.
Armando Montanezbcc194b2020-03-10 10:23:18 -070024
25.. code:: sh
26
Wyatt Heplerd4a847e2021-09-10 18:16:33 -070027 # Use ./out/ as the build directory and build the default target
Wyatt Hepler00efe182020-11-23 08:25:14 -080028 pw watch
Armando Montanezbcc194b2020-03-10 10:23:18 -070029
Wyatt Heplerd4a847e2021-09-10 18:16:33 -070030 # Use ./out/ as the build directory and build the stm32f429i target
Wyatt Hepler00efe182020-11-23 08:25:14 -080031 pw watch python.lint stm32f429i
Armando Montanezbcc194b2020-03-10 10:23:18 -070032
Wyatt Hepler00efe182020-11-23 08:25:14 -080033 # Build pw_run_tests.modules in the out/cmake directory
34 pw watch -C out/cmake pw_run_tests.modules
Armando Montanezbcc194b2020-03-10 10:23:18 -070035
Wyatt Hepler00efe182020-11-23 08:25:14 -080036 # Build the default target in out/ and pw_apps in out/cmake
37 pw watch -C out -C out/cmake pw_apps
Armando Montanez7366d5a2020-06-17 15:04:43 -070038
Wyatt Heplerd4a847e2021-09-10 18:16:33 -070039 # Build python.tests in out/ and build pw_apps in out/cmake
Wyatt Hepler00efe182020-11-23 08:25:14 -080040 pw watch python.tests -C out/cmake pw_apps
Armando Montanezbcc194b2020-03-10 10:23:18 -070041
Wyatt Hepler6a0a6492021-06-24 09:46:05 -070042 # Build the default target, but only run up to 8 jobs in parallel.
43 pw watch -j8
44
Adam MacBeth9b3abb22021-07-15 17:58:55 +000045 # Build the default target and start a docs server on http://127.0.0.1:8000
46 pw watch --serve-docs
47
48 # Build the default target and start a docs server on http://127.0.0.1:5555
49 pw watch --serve-docs --serve-docs-port=5555
50
Anthony DiGirolamo67e1d802022-01-29 13:46:31 -080051 # Build with a full screen terminal user interface similar to pw_console.
52 pw watch --fullscreen
Elaine Hwange2dc38c2021-11-28 17:56:12 +080053
Wyatt Heplerea500562021-04-15 07:49:51 -070054``pw watch`` only rebuilds when a file that is not ignored by Git changes.
55Adding exclusions to a ``.gitignore`` causes watch to ignore them, even if the
56files were forcibly added to a repo. By default, only files matching certain
57extensions are applied, even if they're tracked by Git. The ``--patterns`` and
58``--ignore_patterns`` arguments can be used to include or exclude specific
59patterns. These patterns do not override Git's ignoring logic.
Armando Montanezbcc194b2020-03-10 10:23:18 -070060
Wyatt Heplerea500562021-04-15 07:49:51 -070061The ``--exclude_list`` argument can be used to exclude directories from being
62watched. This decreases the number of files monitored with inotify in Linux.
Chenghanc4c46b62020-05-08 17:43:23 -040063
Wyatt Hepler9e080152021-04-15 08:20:05 -070064By default, ``pw watch`` automatically restarts an ongoing build when files
65change. This can be disabled with the ``--no-restart`` option. While running
66``pw watch``, you may also press enter to immediately restart a build.
Wyatt Heplerf7051512021-03-30 09:08:47 -070067
Wyatt Hepler6a0a6492021-06-24 09:46:05 -070068See ``pw watch -h`` for the full list of command line arguments.
69
Armando Montanezbcc194b2020-03-10 10:23:18 -070070Unit Test Integration
71=====================
Armando Montanezbcc194b2020-03-10 10:23:18 -070072Thanks to GN's understanding of the full dependency tree, only the tests
Armando Montanez0054a9b2020-03-13 13:06:24 -070073affected by a file change are run when ``pw_watch`` triggers a build. By
74default, host builds using ``pw_watch`` will run unit tests. To run unit tests
75on a device as part of ``pw_watch``, refer to your device's
Wyatt Heplerf9fb90f2020-09-30 18:59:33 -070076:ref:`target documentation<docs-targets>`.