aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Norvell <chadnorvell@google.com>2022-10-13 06:13:47 +0000
committerCQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-13 06:13:47 +0000
commite9ab2f89ccf2e379ab05cbaf5502e50101350717 (patch)
treeac1de8d95d544d30b8842202881e8cb8ea0a344f
parent4809a1162ff614e0d9f7b9dc49e37a8da47da8e5 (diff)
downloadpigweed-e9ab2f89ccf2e379ab05cbaf5502e50101350717.tar.gz
pw_ide: Remove init, info subcommands
`init` is being replaced by the more useful `setup`. `info` will come back in a different form. Change-Id: I85b77cb9acb57fef5601bd1d65e51a1b465c93f8 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/112518 Reviewed-by: Anthony DiGirolamo <tonymd@google.com> Commit-Queue: Chad Norvell <chadnorvell@google.com>
-rw-r--r--.pw_ide.yaml1
-rw-r--r--pw_ide/py/commands_test.py16
-rw-r--r--pw_ide/py/pw_ide/__main__.py44
-rw-r--r--pw_ide/py/pw_ide/commands.py110
4 files changed, 20 insertions, 151 deletions
diff --git a/.pw_ide.yaml b/.pw_ide.yaml
index 131358f4d..94b81136b 100644
--- a/.pw_ide.yaml
+++ b/.pw_ide.yaml
@@ -1,6 +1,5 @@
config_title: pw_ide
setup:
- - pw ide init
- gn gen out --export-compile-commands
- pw ide cpp --process out/compile_commands.json --set pw_strict_host_clang_debug --no-override
diff --git a/pw_ide/py/commands_test.py b/pw_ide/py/commands_test.py
index 553d905c9..708dc848d 100644
--- a/pw_ide/py/commands_test.py
+++ b/pw_ide/py/commands_test.py
@@ -16,25 +16,25 @@
import os
import unittest
-from pw_ide.commands import cmd_init
+from pw_ide.commands import _make_working_dir
from pw_ide.settings import PW_IDE_DIR_NAME
from test_cases import PwIdeTestCase
-class TestCmdInit(PwIdeTestCase):
- """Tests cmd_init"""
- def test_make_dir_does_not_exist_creates_dir(self):
+class TestMakeWorkingDir(PwIdeTestCase):
+ """Tests _make_working_dir"""
+ def test_does_not_exist_creates_dir(self):
settings = self.make_ide_settings(working_dir=PW_IDE_DIR_NAME)
self.assertFalse(settings.working_dir.exists())
- cmd_init(silent=True, settings=settings)
+ _make_working_dir(settings=settings)
self.assertTrue(settings.working_dir.exists())
- def test_make_dir_does_exist_is_idempotent(self):
+ def test_does_exist_is_idempotent(self):
settings = self.make_ide_settings(working_dir=PW_IDE_DIR_NAME)
- cmd_init(silent=True, settings=settings)
+ _make_working_dir(settings=settings)
modified_when_1 = os.path.getmtime(settings.working_dir)
- cmd_init(silent=True, settings=settings)
+ _make_working_dir(settings=settings)
modified_when_2 = os.path.getmtime(settings.working_dir)
self.assertEqual(modified_when_1, modified_when_2)
diff --git a/pw_ide/py/pw_ide/__main__.py b/pw_ide/py/pw_ide/__main__.py
index 76463f256..ebd250e6c 100644
--- a/pw_ide/py/pw_ide/__main__.py
+++ b/pw_ide/py/pw_ide/__main__.py
@@ -18,8 +18,8 @@ from pathlib import Path
import sys
from typing import (Any, Callable, cast, Dict, Generic, NoReturn, Optional,
TypeVar, Union)
-from pw_ide.commands import (cmd_info, cmd_init, cmd_cpp, cmd_python,
- cmd_setup)
+
+from pw_ide.commands import cmd_cpp, cmd_python, cmd_setup
# TODO(chadnorvell): Move this docstring-as-argparse-docs functionality
# to pw_cli.
@@ -129,46 +129,6 @@ def _parse_args() -> argparse.Namespace:
subcommand_parser = parser_root.add_subparsers(help='Subcommands')
- parser_info = subcommand_parser.add_parser(
- 'info',
- description=_docstring_summary(cmd_info.__doc__),
- help=_reflow_docstring(cmd_info.__doc__))
- parser_info.add_argument('--working-dir',
- dest='working_dir',
- action='store_true',
- help='Report Pigweed IDE working directory.')
- parser_info.add_argument('--available-compdbs',
- dest='available_compdbs',
- action='store_true',
- help='Report the compilation databases currently '
- 'in the working directory.')
- parser_info.add_argument('--available-targets',
- dest='available_targets',
- action='store_true',
- help='Report all available targets, which are '
- 'targets that are defined in .pw_ide.yaml '
- 'and have compilation databases in the '
- 'working directory. This is equivalent to: '
- 'pw ide cpp --list')
- parser_info.add_argument('--defined-targets',
- dest='defined_targets',
- action='store_true',
- help='Report all defined targets, which are '
- 'targets that are defined in .pw_ide.yaml.')
- parser_info.add_argument('--compdb-targets',
- dest='compdb_file_for_targets',
- type=Path,
- metavar='COMPILATION_DATABASE',
- help='Report all of the targets found in the '
- 'provided compilation database.')
- parser_info.set_defaults(func=cmd_info)
-
- parser_init = subcommand_parser.add_parser(
- 'init',
- description=_docstring_summary(cmd_init.__doc__),
- help=_reflow_docstring(cmd_init.__doc__))
- parser_init.set_defaults(func=cmd_init)
-
parser_cpp = subcommand_parser.add_parser(
'cpp',
description=_docstring_summary(cmd_cpp.__doc__),
diff --git a/pw_ide/py/pw_ide/commands.py b/pw_ide/py/pw_ide/commands.py
index d252a6cfb..4136c9f40 100644
--- a/pw_ide/py/pw_ide/commands.py
+++ b/pw_ide/py/pw_ide/commands.py
@@ -14,14 +14,12 @@
"""pw_ide CLI command implementations."""
from pathlib import Path
-import platform
import shlex
import subprocess
import sys
-from typing import Callable, Optional
+from typing import Optional
-from pw_ide.cpp import (aggregate_compilation_database_targets,
- CppCompilationDatabase, CppIdeFeaturesState)
+from pw_ide.cpp import CppCompilationDatabase, CppIdeFeaturesState
from pw_ide.exceptions import (BadCompDbException, InvalidTargetException,
MissingCompDbException)
@@ -32,33 +30,11 @@ from pw_ide.settings import IdeSettings
# TODO(b/246850113): Replace prints with pw_cli.logs
-def _print_working_dir(settings: IdeSettings) -> None:
- print(f'Pigweed IDE working directory: {str(settings.working_dir)}\n')
-
-
def _print_current_target(settings: IdeSettings) -> None:
print('Current C/C++ language server analysis target: '
f'{CppIdeFeaturesState(settings).current_target}\n')
-def _print_defined_targets(settings: IdeSettings) -> None:
- print('C/C++ targets defined in .pw_ide.yaml:')
-
- for target in settings.targets:
- print(f'\t{target}')
-
- print('')
-
-
-def _print_available_targets(settings: IdeSettings) -> None:
- print('C/C++ targets available for language server analysis:')
-
- for toolchain in sorted(CppIdeFeaturesState(settings).available_targets):
- print(f'\t{toolchain}')
-
- print('')
-
-
def _print_enabled_available_targets(settings: IdeSettings) -> None:
print('C/C++ targets available for language server analysis:')
@@ -69,85 +45,19 @@ def _print_enabled_available_targets(settings: IdeSettings) -> None:
print('')
-def _print_available_compdbs(settings: IdeSettings) -> None:
- print('C/C++ compilation databases in the working directory:')
-
- for target in CppIdeFeaturesState(settings):
- output = target.compdb_file_path.name
-
- if target.compdb_cache_path is not None:
- output += f'\n\t\tcache: {str(target.compdb_cache_path.name)}'
-
- print(f'\t{output}')
-
- print('')
-
-
-def _print_compdb_targets(compdb_file: Path) -> None:
- print(f'Unique targets in {str(compdb_file)}:')
-
- for target in sorted(aggregate_compilation_database_targets(compdb_file)):
- print(f'\t{target}')
-
- print('')
-
-
def _print_python_venv_path() -> None:
print('Python virtual environment path: ' f'{PythonPaths().interpreter}\n')
-def _print_unsupported_platform_error(msg: str = 'run') -> None:
- system = platform.system()
- system = 'None' if system == '' else system
- print(f'Failed to {msg} on this unsupported platform: {system}\n')
-
-
-def cmd_info(available_compdbs: bool,
- available_targets: bool,
- defined_targets: bool,
- working_dir: bool,
- compdb_file_for_targets: Path = None,
- settings: IdeSettings = IdeSettings()):
- """Report diagnostic info about Pigweed IDE features."""
- if working_dir:
- _print_working_dir(settings)
-
- if defined_targets:
- _print_defined_targets(settings)
-
- if available_compdbs:
- _print_available_compdbs(settings)
-
- if available_targets:
- _print_available_targets(settings)
-
- if compdb_file_for_targets is not None:
- _print_compdb_targets(compdb_file_for_targets)
-
-
-def cmd_init(silent: bool = False,
- settings: IdeSettings = IdeSettings()) -> None:
- """Create IDE features working directory and supporting files.
-
- When called without arguments, this creates the Pigweed IDE features working
- directory defined in the settings file and ensures that further `pw_ide`
- commands work as expected by creating all the other IDE infrastructure.
-
- This command is idempotent, so it's safe to run it prophylactically or as a
- precursor to other commands to ensure that the Pigweed IDE features are in a
- working state.
- """
-
- maybe_print: Callable[[str], None] = print
-
- if silent:
- maybe_print = lambda _: None
-
+def _make_working_dir(settings: IdeSettings, quiet: bool = False) -> None:
if not settings.working_dir.exists():
settings.working_dir.mkdir()
- maybe_print('Initialized the Pigweed IDE working directory.')
+ print('Initialized the Pigweed IDE working directory at '
+ f'{settings.working_dir}')
else:
- maybe_print('Pigweed IDE working directory already present.')
+ if not quiet:
+ print('Pigweed IDE working directory already present at '
+ f'{settings.working_dir}')
def cmd_cpp(
@@ -161,7 +71,7 @@ def cmd_cpp(
Provides tools for processing C/C++ compilation databases and setting the
particular target/toochain to use for code analysis."""
- cmd_init(silent=True, settings=settings)
+ _make_working_dir(settings)
default = True
if should_list_targets:
@@ -225,7 +135,7 @@ def cmd_cpp(
def cmd_python(
should_get_venv_path: bool, settings: IdeSettings = IdeSettings()) -> None:
"""Configure Python IDE support for Pigweed projects."""
- cmd_init(silent=True, settings=settings)
+ _make_working_dir(settings)
if should_get_venv_path:
_print_python_venv_path()