pw_env_setup: Always generate actions.json

Change-Id: If6daa829641c83a6f1411fa48d5de1529da37b6c
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/45020
Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Armando Montanez <amontanez@google.com>
Reviewed-by: Anthony DiGirolamo <tonymd@google.com>
diff --git a/bootstrap.sh b/bootstrap.sh
index 589b3a2..99dcad0 100644
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -89,7 +89,7 @@
 if [ "$(basename "$_PW_BOOTSTRAP_PATH")" = "bootstrap.sh" ] || \
   [ ! -f "$SETUP_SH" ] || \
   [ ! -s "$SETUP_SH" ]; then
-  pw_bootstrap --shell-file "$SETUP_SH" --install-dir "$_PW_ACTUAL_ENVIRONMENT_ROOT" --json-file "$_PW_ACTUAL_ENVIRONMENT_ROOT/actions.json" --config-file "$PW_ROOT/pw_env_setup/config.json"
+  pw_bootstrap --shell-file "$SETUP_SH" --install-dir "$_PW_ACTUAL_ENVIRONMENT_ROOT" --config-file "$PW_ROOT/pw_env_setup/config.json"
   pw_finalize bootstrap "$SETUP_SH"
 else
   pw_activate
diff --git a/pw_env_setup/docs.rst b/pw_env_setup/docs.rst
index 7832a9f..e6d9fb7 100644
--- a/pw_env_setup/docs.rst
+++ b/pw_env_setup/docs.rst
@@ -236,6 +236,48 @@
 ``PW_ENVSETUP_QUIET``
   Disables all non-error output.
 
+Non-Shell Environments
+**********************
+If using this outside of bash—for example directly from an IDE or CI
+system—users can process the ``actions.json`` file that's generated in the
+environment directory. It lists variables to set, clear, and modify. An
+example ``actions.json`` is shown below. The "append" and "prepend" actions
+are listed in the order they should be applied, so the
+``<pigweed-root>/out/host/host_tools`` entry should be at the beginning of
+``PATH`` and not in the middle somewhere.
+
+.. code-block:: json
+
+  {
+      "modify": {
+          "PATH": {
+              "append": [],
+              "prepend": [
+                  "<pigweed-root>/.environment/cipd",
+                  "<pigweed-root>/.environment/cipd/pigweed",
+                  "<pigweed-root>/.environment/cipd/pigweed/bin",
+                  "<pigweed-root>/.environment/cipd/luci",
+                  "<pigweed-root>/.environment/cipd/luci/bin",
+                  "<pigweed-root>/.environment/pigweed-venv/bin",
+                  "<pigweed-root>/out/host/host_tools"
+              ],
+              "remove": []
+          }
+      },
+      "set": {
+          "PW_PROJECT_ROOT": "<pigweed-root>",
+          "PW_ROOT": "<pigweed-root>",
+          "_PW_ACTUAL_ENVIRONMENT_ROOT": "<pigweed-root>/.environment",
+          "PW_CIPD_INSTALL_DIR": "<pigweed-root>/.environment/cipd",
+          "CIPD_CACHE_DIR": "/usr/local/google/home/mohrr/.cipd-cache-dir",
+          "PW_PIGWEED_CIPD_INSTALL_DIR": "<pigweed-root>/.environment/cipd/pigweed",
+          "PW_LUCI_CIPD_INSTALL_DIR": "<pigweed-root>/.environment/cipd/luci",
+          "VIRTUAL_ENV": "<pigweed-root>/.environment/pigweed-venv",
+          "PYTHONHOME": null,
+          "__PYVENV_LAUNCHER__": null
+      }
+  }
+
 Implementation
 **************
 
diff --git a/pw_env_setup/py/pw_env_setup/env_setup.py b/pw_env_setup/py/pw_env_setup/env_setup.py
index 9c397a0..a771cd3 100755
--- a/pw_env_setup/py/pw_env_setup/env_setup.py
+++ b/pw_env_setup/py/pw_env_setup/env_setup.py
@@ -207,6 +207,8 @@
             self._parse_config_file(config_file)
 
         self._json_file = json_file
+        if not self._json_file:
+            self._json_file = os.path.join(self._install_dir, 'actions.json')
 
         self._use_existing_cipd = use_existing_cipd
 
@@ -582,7 +584,8 @@
 
     parser.add_argument(
         '--json-file',
-        help='Dump environment variable operations to a JSON file.',
+        help=('Dump environment variable operations to a JSON file. Default: '
+              '<install_dir>/actions.json'),
         default=None,
     )