mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
tools: move cmake executable check into function uses it
Before this change idf.py could exit with reason cmake does not exist in PATH even cmake will not be executed by idf.py (e.g., 'idf.py gdb').
This commit is contained in:
parent
0fd4b09a46
commit
c17a7f446c
35
tools/idf.py
35
tools/idf.py
@ -27,7 +27,7 @@ from collections import Counter, OrderedDict, _OrderedDictKeysView
|
|||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from pkgutil import iter_modules
|
from pkgutil import iter_modules
|
||||||
from types import FrameType
|
from types import FrameType
|
||||||
from typing import Any, Callable, Dict, List, Optional, TextIO, Union
|
from typing import Any, Callable, Dict, List, Optional, Union
|
||||||
|
|
||||||
# pyc files remain in the filesystem when switching between branches which might raise errors for incompatible
|
# pyc files remain in the filesystem when switching between branches which might raise errors for incompatible
|
||||||
# idf.py extensions. Therefore, pyc file generation is turned off:
|
# idf.py extensions. Therefore, pyc file generation is turned off:
|
||||||
@ -37,8 +37,8 @@ import python_version_checker # noqa: E402
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from idf_py_actions.errors import FatalError # noqa: E402
|
from idf_py_actions.errors import FatalError # noqa: E402
|
||||||
from idf_py_actions.tools import (PropertyDict, executable_exists, get_target, idf_version, # noqa: E402
|
from idf_py_actions.tools import (PROG, SHELL_COMPLETE_RUN, SHELL_COMPLETE_VAR, PropertyDict, # noqa: E402
|
||||||
merge_action_lists, realpath)
|
debug_print_idf_version, get_target, merge_action_lists, print_warning, realpath)
|
||||||
if os.getenv('IDF_COMPONENT_MANAGER') != '0':
|
if os.getenv('IDF_COMPONENT_MANAGER') != '0':
|
||||||
from idf_component_manager import idf_extensions
|
from idf_component_manager import idf_extensions
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -53,23 +53,6 @@ PYTHON = sys.executable
|
|||||||
# you have to pass env=os.environ explicitly anywhere that we create a process
|
# you have to pass env=os.environ explicitly anywhere that we create a process
|
||||||
os.environ['PYTHON'] = sys.executable
|
os.environ['PYTHON'] = sys.executable
|
||||||
|
|
||||||
# Name of the program, normally 'idf.py'.
|
|
||||||
# Can be overridden from idf.bat using IDF_PY_PROGRAM_NAME
|
|
||||||
PROG = os.getenv('IDF_PY_PROGRAM_NAME', 'idf.py')
|
|
||||||
|
|
||||||
# environment variable used during click shell completion run
|
|
||||||
SHELL_COMPLETE_VAR = '_IDF.PY_COMPLETE'
|
|
||||||
|
|
||||||
# was shell completion invoked?
|
|
||||||
SHELL_COMPLETE_RUN = SHELL_COMPLETE_VAR in os.environ
|
|
||||||
|
|
||||||
|
|
||||||
# function prints warning when autocompletion is not being performed
|
|
||||||
# set argument stream to sys.stderr for errors and exceptions
|
|
||||||
def print_warning(message: str, stream: TextIO=None) -> None:
|
|
||||||
if not SHELL_COMPLETE_RUN:
|
|
||||||
print(message, file=stream or sys.stderr)
|
|
||||||
|
|
||||||
|
|
||||||
def check_environment() -> List:
|
def check_environment() -> List:
|
||||||
"""
|
"""
|
||||||
@ -79,10 +62,6 @@ def check_environment() -> List:
|
|||||||
"""
|
"""
|
||||||
checks_output = []
|
checks_output = []
|
||||||
|
|
||||||
if not executable_exists(['cmake', '--version']):
|
|
||||||
debug_print_idf_version()
|
|
||||||
raise FatalError("'cmake' must be available on the PATH to use %s" % PROG)
|
|
||||||
|
|
||||||
# verify that IDF_PATH env variable is set
|
# verify that IDF_PATH env variable is set
|
||||||
# find the directory idf.py is in, then the parent directory of this, and assume this is IDF_PATH
|
# find the directory idf.py is in, then the parent directory of this, and assume this is IDF_PATH
|
||||||
detected_idf_path = realpath(os.path.join(os.path.dirname(__file__), '..'))
|
detected_idf_path = realpath(os.path.join(os.path.dirname(__file__), '..'))
|
||||||
@ -137,14 +116,6 @@ def _safe_relpath(path: str, start: Optional[str]=None) -> str:
|
|||||||
return os.path.abspath(path)
|
return os.path.abspath(path)
|
||||||
|
|
||||||
|
|
||||||
def debug_print_idf_version() -> None:
|
|
||||||
version = idf_version()
|
|
||||||
if version:
|
|
||||||
print_warning('ESP-IDF %s' % version)
|
|
||||||
else:
|
|
||||||
print_warning('ESP-IDF version unknown')
|
|
||||||
|
|
||||||
|
|
||||||
def init_cli(verbose_output: List=None) -> Any:
|
def init_cli(verbose_output: List=None) -> Any:
|
||||||
# Click is imported here to run it after check_environment()
|
# Click is imported here to run it after check_environment()
|
||||||
import click
|
import click
|
||||||
|
@ -16,6 +16,16 @@ import yaml
|
|||||||
from .constants import GENERATORS
|
from .constants import GENERATORS
|
||||||
from .errors import FatalError
|
from .errors import FatalError
|
||||||
|
|
||||||
|
# Name of the program, normally 'idf.py'.
|
||||||
|
# Can be overridden from idf.bat using IDF_PY_PROGRAM_NAME
|
||||||
|
PROG = os.getenv('IDF_PY_PROGRAM_NAME', 'idf.py')
|
||||||
|
|
||||||
|
# environment variable used during click shell completion run
|
||||||
|
SHELL_COMPLETE_VAR = '_IDF.PY_COMPLETE'
|
||||||
|
|
||||||
|
# was shell completion invoked?
|
||||||
|
SHELL_COMPLETE_RUN = SHELL_COMPLETE_VAR in os.environ
|
||||||
|
|
||||||
|
|
||||||
def executable_exists(args: List) -> bool:
|
def executable_exists(args: List) -> bool:
|
||||||
try:
|
try:
|
||||||
@ -78,6 +88,13 @@ def idf_version() -> Optional[str]:
|
|||||||
return version
|
return version
|
||||||
|
|
||||||
|
|
||||||
|
# function prints warning when autocompletion is not being performed
|
||||||
|
# set argument stream to sys.stderr for errors and exceptions
|
||||||
|
def print_warning(message: str, stream: TextIO=None) -> None:
|
||||||
|
if not SHELL_COMPLETE_RUN:
|
||||||
|
print(message, file=stream or sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
def color_print(message: str, color: str, newline: Optional[str]='\n') -> None:
|
def color_print(message: str, color: str, newline: Optional[str]='\n') -> None:
|
||||||
""" Print a message to stderr with colored highlighting """
|
""" Print a message to stderr with colored highlighting """
|
||||||
ansi_normal = '\033[0m'
|
ansi_normal = '\033[0m'
|
||||||
@ -95,6 +112,10 @@ def red_print(message: str, newline: Optional[str]='\n') -> None:
|
|||||||
color_print(message, ansi_red, newline)
|
color_print(message, ansi_red, newline)
|
||||||
|
|
||||||
|
|
||||||
|
def debug_print_idf_version() -> None:
|
||||||
|
print_warning(f'ESP-IDF {idf_version() or "version unknown"}')
|
||||||
|
|
||||||
|
|
||||||
def generate_hints(*filenames: str) -> Generator:
|
def generate_hints(*filenames: str) -> Generator:
|
||||||
"""Getting output files and printing hints on how to resolve errors based on the output."""
|
"""Getting output files and printing hints on how to resolve errors based on the output."""
|
||||||
with open(os.path.join(os.path.dirname(__file__), 'hints.yml'), 'r') as file:
|
with open(os.path.join(os.path.dirname(__file__), 'hints.yml'), 'r') as file:
|
||||||
@ -383,6 +404,11 @@ def ensure_build_directory(args: 'PropertyDict', prog_name: str, always_run_cmak
|
|||||||
the build directory, an error is raised. If the parameter is None, this function will set it to
|
the build directory, an error is raised. If the parameter is None, this function will set it to
|
||||||
an auto-detected default generator or to the value already configured in the build directory.
|
an auto-detected default generator or to the value already configured in the build directory.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if not executable_exists(['cmake', '--version']):
|
||||||
|
debug_print_idf_version()
|
||||||
|
raise FatalError(f'"cmake" must be available on the PATH to use {PROG}')
|
||||||
|
|
||||||
project_dir = args.project_dir
|
project_dir = args.project_dir
|
||||||
# Verify the project directory
|
# Verify the project directory
|
||||||
if not os.path.isdir(project_dir):
|
if not os.path.isdir(project_dir):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user