pw_env_setup: Log environment in Python setup
Log the current environment when installing Python packages into a
virtualenv.
Change-Id: I43d9d5e43c79fa6516fd870934b7a312696e2a1d
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/27120
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Armando Montanez <amontanez@google.com>
Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com>
diff --git a/pw_env_setup/py/pw_env_setup/virtualenv_setup/install.py b/pw_env_setup/py/pw_env_setup/virtualenv_setup/install.py
index 433b08f..fd6b97f 100644
--- a/pw_env_setup/py/pw_env_setup/virtualenv_setup/install.py
+++ b/pw_env_setup/py/pw_env_setup/virtualenv_setup/install.py
@@ -189,6 +189,19 @@
def install_packages(gn_target):
build = os.path.join(venv_path, gn_target.name)
+ env_log = 'env-{}.log'.format(gn_target.name)
+ env_log_path = os.path.join(venv_path, env_log)
+ with open(env_log_path, 'w') as outs:
+ for key, value in sorted(os.environ.items()):
+ if key.upper().endswith('PATH'):
+ print(key, '=', file=outs)
+ # pylint: disable=invalid-name
+ for v in value.split(os.pathsep):
+ print(' ', v, file=outs)
+ # pylint: enable=invalid-name
+ else:
+ print(key, '=', value, file=outs)
+
gn_log = 'gn-gen-{}.log'.format(gn_target.name)
gn_log_path = os.path.join(venv_path, gn_log)
try: