|
7 | 7 | import sys |
8 | 8 | import subprocess |
9 | 9 | import json |
| 10 | +import shutil |
10 | 11 |
|
11 | 12 | # color output on windows |
12 | 13 | if sys.platform == 'win32': |
@@ -467,12 +468,52 @@ def install_compilation_env(target): |
467 | 468 |
|
468 | 469 | print('\r\nAll done! You can now run:\r\n\r\n {}build.py build\r\n'.format('python ' if sys.platform == 'win32' else './')) |
469 | 470 |
|
| 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 | + |
470 | 506 | def install_prerequisites(): |
471 | 507 | # install ESP-IDF prerequisites |
472 | 508 | ESP_LOGI('Ready to install ESP-IDF prerequisites..') |
473 | 509 | cmd = '' |
474 | 510 | 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)) |
476 | 517 | elif sys.platform == 'darwin': |
477 | 518 | cmd = 'brew install cmake ninja dfu-util ccache python3' |
478 | 519 | elif sys.platform == 'win32': |
|
0 commit comments