1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_watch: 2*61c4878aSAndroid Build Coastguard Worker 3*61c4878aSAndroid Build Coastguard Worker.. rst-class:: with-subtitle 4*61c4878aSAndroid Build Coastguard Worker 5*61c4878aSAndroid Build Coastguard Worker======== 6*61c4878aSAndroid Build Coastguard Workerpw_watch 7*61c4878aSAndroid Build Coastguard Worker======== 8*61c4878aSAndroid Build Coastguard Worker.. pigweed-module:: 9*61c4878aSAndroid Build Coastguard Worker :name: pw_watch 10*61c4878aSAndroid Build Coastguard Worker 11*61c4878aSAndroid Build Coastguard Worker * **Automatically trigger build actions when source files change** 12*61c4878aSAndroid Build Coastguard Worker 13*61c4878aSAndroid Build Coastguard Worker---------- 14*61c4878aSAndroid Build Coastguard WorkerBackground 15*61c4878aSAndroid Build Coastguard Worker---------- 16*61c4878aSAndroid Build Coastguard WorkerIn the web development space, file system watchers like `nodemon 17*61c4878aSAndroid Build Coastguard Worker<https://www.npmjs.com/package/nodemon>`_ and `watchman 18*61c4878aSAndroid Build Coastguard Worker<https://facebook.github.io/watchman/>`_ are prevalent. These watchers trigger 19*61c4878aSAndroid Build Coastguard Workeractions when files change (such as reloading a web server), making development 20*61c4878aSAndroid Build Coastguard Workermuch faster. In the embedded space, file system watchers are less prevalent but 21*61c4878aSAndroid Build Coastguard Workerno less useful! 22*61c4878aSAndroid Build Coastguard Worker 23*61c4878aSAndroid Build Coastguard Worker.. _module-pw_watch-design: 24*61c4878aSAndroid Build Coastguard Worker 25*61c4878aSAndroid Build Coastguard Worker------------ 26*61c4878aSAndroid Build Coastguard WorkerOur solution 27*61c4878aSAndroid Build Coastguard Worker------------ 28*61c4878aSAndroid Build Coastguard Worker``pw_watch`` is similar to file system watchers found in web development 29*61c4878aSAndroid Build Coastguard Workertooling but is focused around embedded development use cases. After changing 30*61c4878aSAndroid Build Coastguard Workersource code, ``pw_watch`` can instantly compile, flash, and run tests. 31*61c4878aSAndroid Build Coastguard Worker 32*61c4878aSAndroid Build Coastguard Worker.. figure:: https://storage.googleapis.com/pigweed-media/pw_watch_test_demo2.gif 33*61c4878aSAndroid Build Coastguard Worker :width: 1420 34*61c4878aSAndroid Build Coastguard Worker :alt: ``pw watch`` running in fullscreen mode and displaying errors 35*61c4878aSAndroid Build Coastguard Worker 36*61c4878aSAndroid Build Coastguard Worker ``pw watch`` running in fullscreen mode and displaying errors. 37*61c4878aSAndroid Build Coastguard Worker 38*61c4878aSAndroid Build Coastguard WorkerCombined with the GN-based build which expresses the full dependency tree, 39*61c4878aSAndroid Build Coastguard Workeronly the exact tests affected by source changes are run. 40*61c4878aSAndroid Build Coastguard Worker 41*61c4878aSAndroid Build Coastguard WorkerThe demo below shows ``pw_watch`` building for a STMicroelectronics 42*61c4878aSAndroid Build Coastguard WorkerSTM32F429I-DISC1 development board, flashing the board with the affected test, 43*61c4878aSAndroid Build Coastguard Workerand verifying the test runs as expected. Once this is set up, you can attach 44*61c4878aSAndroid Build Coastguard Workermultiple devices to run tests in a distributed manner to reduce the time it 45*61c4878aSAndroid Build Coastguard Workertakes to run tests. 46*61c4878aSAndroid Build Coastguard Worker 47*61c4878aSAndroid Build Coastguard Worker.. figure:: https://storage.googleapis.com/pigweed-media/pw_watch_on_device_demo.gif 48*61c4878aSAndroid Build Coastguard Worker :width: 800 49*61c4878aSAndroid Build Coastguard Worker :alt: pw_watch running on-device tests 50*61c4878aSAndroid Build Coastguard Worker 51*61c4878aSAndroid Build Coastguard Worker.. _module-pw_watch-get-started: 52*61c4878aSAndroid Build Coastguard Worker 53*61c4878aSAndroid Build Coastguard Worker----------- 54*61c4878aSAndroid Build Coastguard WorkerGet started 55*61c4878aSAndroid Build Coastguard Worker----------- 56*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash 57*61c4878aSAndroid Build Coastguard Worker 58*61c4878aSAndroid Build Coastguard Worker cd ~/pigweed 59*61c4878aSAndroid Build Coastguard Worker source activate.sh 60*61c4878aSAndroid Build Coastguard Worker pw watch 61*61c4878aSAndroid Build Coastguard Worker 62*61c4878aSAndroid Build Coastguard WorkerThe simplest way to get started with ``pw_watch`` is to launch it from a shell 63*61c4878aSAndroid Build Coastguard Workerusing the Pigweed environment as ``pw watch``. By default, ``pw_watch`` watches 64*61c4878aSAndroid Build Coastguard Workerfor repository changes and triggers the default Ninja build target at ``//out``. 65*61c4878aSAndroid Build Coastguard WorkerTo override this behavior, provide the ``-C`` argument to ``pw watch``. 66*61c4878aSAndroid Build Coastguard Worker 67*61c4878aSAndroid Build Coastguard WorkerSee :ref:`module-pw_watch-guide` for more examples and 68*61c4878aSAndroid Build Coastguard Worker:ref:`module-pw_watch-cli` for detailed CLI usage information. 69*61c4878aSAndroid Build Coastguard Worker 70*61c4878aSAndroid Build Coastguard Worker.. toctree:: 71*61c4878aSAndroid Build Coastguard Worker :hidden: 72*61c4878aSAndroid Build Coastguard Worker :maxdepth: 1 73*61c4878aSAndroid Build Coastguard Worker 74*61c4878aSAndroid Build Coastguard Worker guide 75*61c4878aSAndroid Build Coastguard Worker cli 76