Skip to content

Commit

Permalink
pw_env_setup: Add PW_PACKAGE_ROOT variable
Browse files Browse the repository at this point in the history
Add a PW_PACKAGE_ROOT environment variable but don't use it yet. Will
need to wait a bit to ensure people have rerun bootstrap after this CL
lands before using this variable.

Bug: b/240707084
Change-Id: I154e1533b0094dff1e2d8d8884383da348c4fc14
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/103882
Reviewed-by: Armando Montanez <amontanez@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com>
  • Loading branch information
mohrr authored and CQ Bot Account committed Jul 29, 2022
1 parent 9ac358b commit cc9adfe
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions pw_cli/py/pw_cli/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def pigweed_environment_parser() -> envparse.EnvironmentParser:
type=envparse.strict_bool,
default=False)
parser.add_var('PW_ENVIRONMENT_ROOT')
parser.add_var('PW_PACKAGE_ROOT')
parser.add_var('PW_PROJECT_ROOT')
parser.add_var('PW_ROOT')
parser.add_var('PW_SKIP_BOOTSTRAP')
Expand Down
4 changes: 4 additions & 0 deletions pw_env_setup/docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ The following environment variables are set by env setup.
all-caps version of the basename of the package file, without the extension.
(E.g., "path/foo.json" becomes ``PW_FOO_CIPD_INSTALL_DIR``.)

``PW_PACKAGE_ROOT``
Location that packages installed by ``pw package`` will be installed to.

``VIRTUAL_ENV``
Path to Pigweed's virtualenv.

Expand Down Expand Up @@ -522,6 +525,7 @@ the GNI file specified in the environment config file.
dir_cipd_pigweed = "<pigweed-root>/.environment/cipd/packages/pigweed"
dir_cipd_luci = "<pigweed-root>/.environment/cipd/packages/luci"
dir_virtual_env = "<pigweed-root>/.environment/pigweed-venv"
dir_pw_package_root = "<pigweed-root>/.environment/packages"
}
It's straightforward to use these variables.
Expand Down
12 changes: 7 additions & 5 deletions pw_env_setup/py/pw_env_setup/env_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,18 +625,20 @@ def pw_package(self, unused_spin):

result = result_func()

pkg_dir = os.path.join(self._install_dir, 'packages')
self._env.set('PW_PACKAGE_ROOT', pkg_dir)

if not os.path.isdir(pkg_dir):
os.makedirs(pkg_dir)

if not self._pw_packages:
return result(_Result.Status.SKIPPED)

logdir = os.path.join(self._install_dir, 'packages')
if not os.path.isdir(logdir):
os.makedirs(logdir)

for pkg in self._pw_packages:
print('installing {}'.format(pkg))
cmd = ['pw', 'package', 'install', pkg]

log = os.path.join(logdir, '{}.log'.format(pkg))
log = os.path.join(pkg_dir, '{}.log'.format(pkg))
try:
with open(log, 'w') as outs, self._env():
print(*cmd, file=outs)
Expand Down
4 changes: 4 additions & 0 deletions pw_env_setup/py/pw_env_setup/gni_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def visit_set(self, set): # pylint: disable=redefined-builtin
self._lines.append(' dir_virtual_env = "{}"'.format(
self._abspath_to_gn_path(set.value)))

if set.name == 'PW_PACKAGE_ROOT':
self._lines.append(' dir_pw_package_root = "{}"'.format(
self._abspath_to_gn_path(set.value)))

def visit_clear(self, clear):
pass

Expand Down
1 change: 1 addition & 0 deletions pw_package/py/pw_package/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def parse_args(argv: List[str] = None) -> argparse.Namespace:
'-e',
dest='pkg_root',
type=pathlib.Path,
# TODO(b/240707084) Replace with PW_PACKAGE_ROOT.
default=(pathlib.Path(os.environ['_PW_ACTUAL_ENVIRONMENT_ROOT']) /
'packages'),
)
Expand Down

0 comments on commit cc9adfe

Please sign in to comment.