Skip to content

Commit

Permalink
pw_ide: Add command to build VSC extension
Browse files Browse the repository at this point in the history
Change-Id: If91f7363b93074afab6ee5c16a5fcdd7547382cc
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/184992
Commit-Queue: Chad Norvell <[email protected]>
Reviewed-by: Anthony DiGirolamo <[email protected]>
  • Loading branch information
chadnorvell authored and CQ Bot Account committed Dec 14, 2023
1 parent 8ffa93f commit 82c82d9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pw_ide/py/pw_ide/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ def _build_argument_parser() -> argparse.ArgumentParser:
metavar='SETTINGS_TYPE',
help='do not update these settings types',
)
parser_vscode.add_argument(
'--build-extension',
action='store_true',
help='build the extension from source',
)

return parser_root

Expand Down
12 changes: 12 additions & 0 deletions pw_ide/py/pw_ide/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

from pw_ide import vscode
from pw_ide.vscode import (
build_extension as build_vscode_extension,
VscSettingsManager,
VscSettingsType,
)
Expand Down Expand Up @@ -142,6 +143,7 @@ def cmd_setup(
def cmd_vscode(
include: Optional[List[VscSettingsType]] = None,
exclude: Optional[List[VscSettingsType]] = None,
build_extension: bool = False,
reporter: StatusReporter = StatusReporter(),
pw_ide_settings: PigweedIdeSettings = PigweedIdeSettings(),
) -> None:
Expand Down Expand Up @@ -200,6 +202,16 @@ def cmd_vscode(
Likewise, it can be enabled by setting that value to true. It is enabled by
default.
"""
if build_extension:
reporter.info('Building the Visual Studio Code extension')

try:
build_vscode_extension(Path(env.PW_ROOT))
except subprocess.CalledProcessError:
reporter.err("Failed! See output for more info.")
else:
reporter.ok('Built successfully!')

if not pw_ide_settings.editor_enabled('vscode'):
reporter.wrn(
'Visual Studio Code support is disabled in settings! If this is '
Expand Down
24 changes: 24 additions & 0 deletions pw_ide/py/pw_ide/vscode.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
import os
from pathlib import Path
import platform
import shutil
import subprocess
from typing import Any, Dict, List, Optional, OrderedDict

from pw_cli.env import pigweed_environment
Expand Down Expand Up @@ -424,3 +426,25 @@ class VscSettingsManager(EditorSettingsManager[VscSettingsType]):
VscSettingsType.EXTENSIONS: _default_extensions,
VscSettingsType.LAUNCH: _default_launch,
}


def build_extension(pw_root: Path):
"""Build the VS Code extension."""

license_path = pw_root / 'LICENSE'
icon_path = pw_root.parent / 'icon.png'

vsc_ext_path = pw_root / 'pw_ide' / 'ts' / 'pigweed-vscode'
temp_license_path = vsc_ext_path / 'LICENSE'
temp_icon_path = vsc_ext_path / 'icon.png'

shutil.copy(license_path, temp_license_path)
shutil.copy(icon_path, temp_icon_path)

try:
subprocess.run(['vsce', 'package'], check=True, cwd=vsc_ext_path)
except subprocess.CalledProcessError as e:
raise e
finally:
temp_license_path.unlink()
temp_icon_path.unlink()

0 comments on commit 82c82d9

Please sign in to comment.