pw_env_setup: Set project root variable
Set the project root variable in pw_env_setup. It was previously only
setup in bootstrap.sh, so it wasn't logged in actions.json.
Change-Id: I1d5aac242a78e7bd3e517590c4c937f0cebdfafd
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/50760
Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com>
Reviewed-by: Anthony DiGirolamo <tonymd@google.com>
Commit-Queue: Rob Mohr <mohrr@google.com>
diff --git a/pw_env_setup/bazel_only.json b/pw_env_setup/bazel_only.json
index bb6900a..3e5fa96 100644
--- a/pw_env_setup/bazel_only.json
+++ b/pw_env_setup/bazel_only.json
@@ -1,4 +1,5 @@
{
+ "root_variable": "PW_ROOT",
"cipd_package_files": [
"pw_env_setup/py/pw_env_setup/cipd_setup/bazel.json",
"pw_env_setup/py/pw_env_setup/cipd_setup/python.json",
diff --git a/pw_env_setup/compatibility.json b/pw_env_setup/compatibility.json
index d580972..1a02c07 100644
--- a/pw_env_setup/compatibility.json
+++ b/pw_env_setup/compatibility.json
@@ -1,4 +1,5 @@
{
+ "root_variable": "PW_ROOT",
"cipd_package_files": [
"pw_env_setup/py/pw_env_setup/cipd_setup/pigweed.json",
"pw_env_setup/py/pw_env_setup/cipd_setup/bazel.json",
diff --git a/pw_env_setup/config.json b/pw_env_setup/config.json
index 4101841..6702b31 100644
--- a/pw_env_setup/config.json
+++ b/pw_env_setup/config.json
@@ -1,4 +1,5 @@
{
+ "root_variable": "PW_ROOT",
"cipd_package_files": [
"pw_env_setup/py/pw_env_setup/cipd_setup/pigweed.json",
"pw_env_setup/py/pw_env_setup/cipd_setup/python.json",
diff --git a/pw_env_setup/docs.rst b/pw_env_setup/docs.rst
index e999b6c..eed3bc5 100644
--- a/pw_env_setup/docs.rst
+++ b/pw_env_setup/docs.rst
@@ -198,6 +198,11 @@
.. _sample project: https://pigweed.googlesource.com/pigweed/sample_project/+/HEAD
+``root_variable``
+ Variable used to point to the root of the source tree. Optional, can always
+ use ``PW_PROJECT_ROOT`` instead. (That variable will be set regardless of
+ whether this is provided.)
+
``cipd_package_files``
CIPD package file. JSON file consisting of a list of dictionaries with "path",
"platforms", and "tags" keys. An example is below.
@@ -240,6 +245,7 @@
.. code-block:: json
{
+ "root_variable": "EXAMPLE_ROOT",
"cipd_package_files": [
"pigweed/pw_env_setup/py/pw_env_setup/cipd_setup/pigweed.json",
"pigweed/pw_env_setup/py/pw_env_setup/cipd_setup/luci.json"
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 02e3ffa..adf9cde 100755
--- a/pw_env_setup/py/pw_env_setup/env_setup.py
+++ b/pw_env_setup/py/pw_env_setup/env_setup.py
@@ -199,6 +199,7 @@
self._virtualenv_gn_targets = []
self._optional_submodules = []
self._virtualenv_system_packages = False
+ self._root_variable = None
self._config_file_name = getattr(config_file, 'name', 'config file')
if config_file:
@@ -213,6 +214,8 @@
self._use_existing_cipd = use_existing_cipd
self._virtualenv_gn_out_dir = virtualenv_gn_out_dir
+ if self._root_variable:
+ self._env.set(self._root_variable, project_root)
self._env.set('PW_PROJECT_ROOT', project_root)
self._env.set('PW_ROOT', pw_root)
self._env.set('_PW_ACTUAL_ENVIRONMENT_ROOT', install_dir)
@@ -248,6 +251,8 @@
def _parse_config_file(self, config_file):
config = json.load(config_file)
+ self._root_variable = config.pop('root_variable', None)
+
self._optional_submodules.extend(config.pop('optional_submodules', ()))
self._cipd_package_file.extend(