Skip to content

Commit 987ced8

Browse files
committed
Merge branch 'tools/fix_compilation_failure_on_non_debian_os' into 'master'
fix(tools): Fixed compilation failure issue on non-debian os See merge request application/esp-at!2087
2 parents f643f31 + 65ce7cd commit 987ced8

1 file changed

Lines changed: 42 additions & 1 deletion

File tree

‎build.py‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import sys
88
import subprocess
99
import json
10+
import shutil
1011

1112
# color output on windows
1213
if sys.platform == 'win32':
@@ -467,12 +468,52 @@ def install_compilation_env(target):
467468

468469
print('\r\nAll done! You can now run:\r\n\r\n {}build.py build\r\n'.format('python ' if sys.platform == 'win32' else './'))
469470

471+
LINUX_PREREQ_CMDS = {
472+
'apt-get': 'sudo apt-get install git wget flex bison gperf python3 python3-pip python3-venv python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0',
473+
'dnf': 'sudo dnf install git wget flex bison gperf python3 python3-pip python3-setuptools cmake ninja-build ccache dfu-util libusbx',
474+
'yum': 'sudo yum install git wget flex bison gperf python3 python3-pip python3-setuptools cmake ninja-build ccache dfu-util libusbx',
475+
'pacman': 'sudo pacman -S --needed gcc git make flex bison gperf python python-pip python-setuptools cmake ninja ccache dfu-util libusb',
476+
}
477+
478+
def detect_linux_package_manager():
479+
os_id = ''
480+
id_like = ''
481+
try:
482+
with open('/etc/os-release') as f:
483+
for line in f:
484+
if line.startswith('ID='):
485+
os_id = line.split('=', 1)[1].strip().strip('"').lower()
486+
elif line.startswith('ID_LIKE='):
487+
id_like = line.split('=', 1)[1].strip().strip('"').lower()
488+
except OSError:
489+
pass
490+
491+
hint = ' '.join((os_id, id_like))
492+
if any(name in hint for name in ('debian', 'ubuntu')):
493+
candidates = ('apt-get',)
494+
elif any(name in hint for name in ('fedora', 'rhel', 'centos', 'rocky', 'alma')):
495+
candidates = ('dnf', 'yum')
496+
elif 'arch' in hint:
497+
candidates = ('pacman',)
498+
else:
499+
candidates = ('apt-get', 'dnf', 'yum', 'pacman')
500+
501+
for pkg_mgr in candidates:
502+
if shutil.which(pkg_mgr):
503+
return pkg_mgr
504+
return None
505+
470506
def install_prerequisites():
471507
# install ESP-IDF prerequisites
472508
ESP_LOGI('Ready to install ESP-IDF prerequisites..')
473509
cmd = ''
474510
if sys.platform == 'linux':
475-
cmd = 'sudo apt-get install git wget flex bison gperf python3 python3-pip python3-venv python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0'
511+
pkg_mgr = detect_linux_package_manager()
512+
cmd = LINUX_PREREQ_CMDS.get(pkg_mgr)
513+
if not cmd:
514+
manual_cmds = '\n'.join(' - {}'.format(v) for v in LINUX_PREREQ_CMDS.values())
515+
raise Exception('unsupported Linux package manager. Please install ESP-IDF prerequisites manually by running one of the following commands:\n{}'.format(manual_cmds))
516+
ESP_LOGI('Using package manager: {}'.format(pkg_mgr))
476517
elif sys.platform == 'darwin':
477518
cmd = 'brew install cmake ninja dfu-util ccache python3'
478519
elif sys.platform == 'win32':

0 commit comments

Comments
 (0)