Skip to content

Commit

Permalink
Merge branch 'refactor/avoid_using_git_v5.2' into 'release/v5.2'
Browse files Browse the repository at this point in the history
fix(tools): Avoiding crashing when Git is not present in system when acquiring IDF version (v5.2)

See merge request espressif/esp-idf!31433
  • Loading branch information
dobairoland committed Jun 12, 2024
2 parents ab80ad8 + 1d5621b commit e5ffb3c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tools/idf_py_actions/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def executable_exists(args: List) -> bool:


def _idf_version_from_cmake() -> Optional[str]:
"""Acquires version of ESP-IDF from version.cmake"""
version_path = os.path.join(os.environ['IDF_PATH'], 'tools/cmake/version.cmake')
regex = re.compile(r'^\s*set\s*\(\s*IDF_VERSION_([A-Z]{5})\s+(\d+)')
ver = {}
Expand Down Expand Up @@ -113,7 +114,7 @@ def idf_version() -> Optional[str]:
'--work-tree=%s' % os.environ['IDF_PATH'],
'describe', '--tags', '--dirty', '--match', 'v*.*',
]).decode('utf-8', 'ignore').strip()
except (subprocess.CalledProcessError, UnicodeError):
except Exception:
# if failed, then try to parse cmake.version file
sys.stderr.write('WARNING: Git version unavailable, reading from source\n')
version = _idf_version_from_cmake()
Expand Down Expand Up @@ -148,7 +149,7 @@ def get_default_serial_port() -> Any:

# 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:
def print_warning(message: str, stream: Optional[TextIO]=None) -> None:
if not SHELL_COMPLETE_RUN:
print(message, file=stream or sys.stderr)

Expand Down Expand Up @@ -277,8 +278,9 @@ def fit_text_in_terminal(out: str) -> str:


class RunTool:
def __init__(self, tool_name: str, args: List, cwd: str, env: Dict=None, custom_error_handler: FunctionType=None, build_dir: str=None,
hints: bool=True, force_progression: bool=False, interactive: bool=False, convert_output: bool=False) -> None:
def __init__(self, tool_name: str, args: List, cwd: str, env: Optional[Dict]=None, custom_error_handler: Optional[FunctionType]=None,
build_dir: Optional[str]=None, hints: bool=True, force_progression: bool=False, interactive: bool=False, convert_output: bool=False
) -> None:
self.tool_name = tool_name
self.args = args
self.cwd = cwd
Expand Down Expand Up @@ -471,7 +473,7 @@ def run_tool(*args: Any, **kwargs: Any) -> None:


def run_target(target_name: str, args: 'PropertyDict', env: Optional[Dict]=None,
custom_error_handler: FunctionType=None, force_progression: bool=False, interactive: bool=False) -> None:
custom_error_handler: Optional[FunctionType]=None, force_progression: bool=False, interactive: bool=False) -> None:
"""Run target in build directory."""
if env is None:
env = {}
Expand Down Expand Up @@ -554,7 +556,7 @@ def _detect_cmake_generator(prog_name: str) -> Any:


def ensure_build_directory(args: 'PropertyDict', prog_name: str, always_run_cmake: bool=False,
env: Dict=None) -> None:
env: Optional[Dict]=None) -> None:
"""Check the build directory exists and that cmake has been run there.
If this isn't the case, create the build directory (if necessary) and
Expand Down Expand Up @@ -671,7 +673,7 @@ def merge_action_lists(*action_lists: Dict) -> Dict:
return merged_actions


def get_sdkconfig_filename(args: 'PropertyDict', cache_cmdl: Dict=None) -> str:
def get_sdkconfig_filename(args: 'PropertyDict', cache_cmdl: Optional[Dict]=None) -> str:
"""
Get project's sdkconfig file name.
"""
Expand Down Expand Up @@ -720,7 +722,7 @@ def is_target_supported(project_path: str, supported_targets: List) -> bool:


def _check_idf_target(args: 'PropertyDict', prog_name: str, cache: Dict,
cache_cmdl: Dict, env: Dict=None) -> None:
cache_cmdl: Dict, env: Optional[Dict]=None) -> None:
"""
Cross-check the three settings (sdkconfig, CMakeCache, environment) and if there is
mismatch, fail with instructions on how to fix this.
Expand Down

0 comments on commit e5ffb3c

Please sign in to comment.