Skip to content

Commit

Permalink
pw_env_setup: Run npm install on bootstrap
Browse files Browse the repository at this point in the history
Change-Id: Ia9c912c1ee7f03089efab6ce642a5793b0a8de98
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/184639
Reviewed-by: Rob Mohr <mohrr@google.com>
Commit-Queue: Asad Memon <asadmemon@google.com>
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
asadm authored and CQ Bot Account committed Dec 15, 2023
1 parent c1906b0 commit cecf666
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"pw_protobuf_compiler": "./dist/bin/pw_protobuf_compiler.js"
},
"scripts": {
"postinstall": "cd pw_web/log-viewer && npm install --quiet --no-progress --loglevel=error",
"prebuild": "rimraf dist && npm run build-protos",
"build-protos": "ts-node -P tsconfig.json ts/buildprotos.ts",
"build": "npm run rollup",
Expand Down
6 changes: 6 additions & 0 deletions pigweed.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
"root_variable": "PW_ROOT",
"relative_pigweed_root": ".",
"rosetta": "allow",
"project_actions": [
{
"import_path": "pw_env_setup",
"module_name": "npm_action"
}
],
"gni_file": "build_overrides/pigweed_environment.gni",
"cipd_package_files": [
"pw_env_setup/py/pw_env_setup/cipd_setup/upstream.json"
Expand Down
1 change: 1 addition & 0 deletions pw_env_setup/py/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pw_python_package("py") {
"pw_env_setup/environment.py",
"pw_env_setup/gni_visitor.py",
"pw_env_setup/json_visitor.py",
"pw_env_setup/npm_action.py",
"pw_env_setup/python_packages.py",
"pw_env_setup/shell_visitor.py",
"pw_env_setup/spinner.py",
Expand Down
43 changes: 43 additions & 0 deletions pw_env_setup/py/pw_env_setup/npm_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2023 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
"""NPM pw_env_setup action plugin.
This action triggers `npm install` after CIPD setup.
"""
import subprocess
import os
import shutil


def run_action(env=None):
"""Project action to run 'npm install'."""
if not env:
raise ValueError(f"Missing 'env', got %{env}")

with env():
npm = shutil.which('npm')
repo_root = os.environ.get('PW_PROJECT_ROOT') or os.environ.get(
'PW_ROOT'
)
subprocess.run(
[
npm,
"install",
"--quiet",
"--no-progress",
"--loglevel=error",
],
stdout=subprocess.PIPE,
cwd=repo_root,
)

0 comments on commit cecf666

Please sign in to comment.