From 8a02feb671ada339acd6945e8cf3147d92642cac Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Mon, 18 Nov 2019 10:12:05 +0100 Subject: [PATCH] tools: Don't use git work-tree in idf_tools.py Closes https://github.com/espressif/esp-idf/issues/4355 --- tools/idf_tools.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tools/idf_tools.py b/tools/idf_tools.py index e9978ec609..d99cd4e017 100755 --- a/tools/idf_tools.py +++ b/tools/idf_tools.py @@ -837,9 +837,32 @@ def get_python_env_path(): with open(version_file_path, "r") as version_file: idf_version_str = version_file.read() else: - idf_version_str = subprocess.check_output(['git', '--work-tree=' + global_idf_path, 'describe', '--tags'], cwd=global_idf_path, env=os.environ).decode() + try: + idf_version_str = subprocess.check_output(['git', 'describe', '--tags'], + cwd=global_idf_path, env=os.environ).decode() + except subprocess.CalledProcessError as e: + warn('Git describe was unsuccessul: {}'.format(e)) + idf_version_str = '' match = re.match(r'^v([0-9]+\.[0-9]+).*', idf_version_str) - idf_version = match.group(1) + if match: + idf_version = match.group(1) + else: + idf_version = None + # fallback when IDF is a shallow clone + try: + with open(os.path.join(global_idf_path, 'components', 'esp_common', 'include', 'esp_idf_version.h')) as f: + m = re.search(r'^#define\s+ESP_IDF_VERSION_MAJOR\s+(\d+).+?^#define\s+ESP_IDF_VERSION_MINOR\s+(\d+)', + f.read(), re.DOTALL | re.MULTILINE) + if m: + idf_version = '.'.join((m.group(1), m.group(2))) + else: + warn('Reading IDF version from C header file failed!') + except Exception as e: + warn('Is it not possible to determine the IDF version: {}'.format(e)) + + if idf_version is None: + fatal('IDF version cannot be determined') + raise SystemExit(1) idf_python_env_path = os.path.join(global_idf_tools_path, 'python_env', 'idf{}_py{}_env'.format(idf_version, python_ver_major_minor))