Skip to content

Commit 9bb593f

Browse files
authored
install penv before calling tl-install and use penv for tl-install (#298)
1 parent 84be9f6 commit 9bb593f

File tree

6 files changed

+318
-106
lines changed

6 files changed

+318
-106
lines changed

builder/frameworks/arduino.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
http://arduino.cc/en/Reference/HomePage
2323
"""
2424

25+
import hashlib
2526
import os
26-
import sys
2727
import shutil
28-
import hashlib
28+
import sys
2929
import threading
3030
from contextlib import suppress
3131
from os.path import join, exists, isabs, splitdrive, commonpath, relpath
@@ -886,7 +886,7 @@ def get_frameworks_in_current_env():
886886
if flag_custom_sdkconfig and not flag_any_custom_sdkconfig:
887887
call_compile_libs()
888888

889-
# Main logic for Arduino Framework
889+
# Arduino framework configuration and build logic
890890
pioframework = env.subst("$PIOFRAMEWORK")
891891
arduino_lib_compile_flag = env.subst("$ARDUINO_LIB_COMPILE_FLAG")
892892

builder/frameworks/component_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
import shutil
1313
import re
1414
import yaml
15-
from yaml import SafeLoader
1615
from pathlib import Path
1716
from typing import Set, Optional, Dict, Any, List, Tuple, Pattern
17+
from yaml import SafeLoader
1818

1919

2020
class ComponentManagerConfig:
@@ -252,7 +252,7 @@ def _get_or_create_component_yml(self) -> str:
252252
Returns:
253253
Absolute path to the component YAML file
254254
"""
255-
# Try Arduino framework first
255+
# Check Arduino framework directory first
256256
afd = self.config.arduino_framework_dir
257257
framework_yml = str(Path(afd) / "idf_component.yml") if afd else ""
258258
if framework_yml and os.path.exists(framework_yml):

builder/frameworks/espidf.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
import copy
2424
import importlib.util
2525
import json
26-
import subprocess
27-
import sys
28-
import shutil
2926
import os
30-
from os.path import join
27+
import platform as sys_platform
3128
import re
3229
import requests
33-
import platform as sys_platform
30+
import shutil
31+
import subprocess
32+
import sys
33+
from os.path import join
3434
from pathlib import Path
3535
from urllib.parse import urlsplit, unquote
3636

@@ -1668,6 +1668,7 @@ def get_python_exe():
16681668
if not os.path.isfile(python_exe_path):
16691669
sys.stderr.write("Error: Missing Python executable file `%s`\n" % python_exe_path)
16701670
env.Exit(1)
1671+
16711672
return python_exe_path
16721673

16731674

@@ -1677,8 +1678,8 @@ def get_python_exe():
16771678

16781679
ensure_python_venv_available()
16791680

1680-
# ESP-IDF package doesn't contain .git folder, instead package version is specified
1681-
# in a special file "version.h" in the root folder of the package
1681+
# ESP-IDF package version is determined from version.h file
1682+
# since the package distribution doesn't include .git metadata
16821683

16831684
create_version_file()
16841685

@@ -1717,7 +1718,7 @@ def get_python_exe():
17171718

17181719

17191720
#
1720-
# Current build script limitations
1721+
# Known build system limitations
17211722
#
17221723

17231724
if any(" " in p for p in (FRAMEWORK_DIR, BUILD_DIR)):
@@ -1756,12 +1757,12 @@ def get_python_exe():
17561757
LIBSOURCE_DIRS=[str(Path(ARDUINO_FRAMEWORK_DIR) / "libraries")]
17571758
)
17581759

1759-
# Set ESP-IDF version environment variables (needed for proper Kconfig processing)
1760+
# Configure ESP-IDF version environment variables for Kconfig processing
17601761
framework_version = get_framework_version()
17611762
major_version = framework_version.split('.')[0] + '.' + framework_version.split('.')[1]
17621763
os.environ["ESP_IDF_VERSION"] = major_version
17631764

1764-
# Configure CMake arguments with ESP-IDF version
1765+
# Setup CMake configuration arguments
17651766
extra_cmake_args = [
17661767
"-DIDF_TARGET=" + idf_variant,
17671768
"-DPYTHON_DEPS_CHECKED=1",
@@ -1855,7 +1856,7 @@ def get_python_exe():
18551856
env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", build_bootloader(sdk_config))
18561857

18571858
#
1858-
# Target: ESP-IDF menuconfig
1859+
# ESP-IDF menuconfig target implementation
18591860
#
18601861

18611862
env.AddPlatformTarget(
@@ -2000,8 +2001,8 @@ def _skip_prj_source_files(node):
20002001
):
20012002
project_env = env.Clone()
20022003
if project_target_name != "__idf_main":
2003-
# Manually add dependencies to CPPPATH since ESP-IDF build system doesn't generate
2004-
# this info if the folder with sources is not named 'main'
2004+
# Add dependencies to CPPPATH for non-main source directories
2005+
# ESP-IDF build system requires manual dependency handling for custom source folders
20052006
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#rename-main
20062007
project_env.AppendUnique(CPPPATH=app_includes["plain_includes"])
20072008

@@ -2049,7 +2050,7 @@ def _skip_prj_source_files(node):
20492050
#
20502051

20512052
extra_elf2bin_flags = "--elf-sha256-offset 0xb0"
2052-
# https://github.com/espressif/esp-idf/blob/master/components/esptool_py/project_include.cmake#L58
2053+
# Reference: ESP-IDF esptool_py component configuration
20532054
# For chips that support configurable MMU page size feature
20542055
# If page size is configured to values other than the default "64KB" in menuconfig,
20552056
mmu_page_size = "64KB"

builder/main.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import importlib.util
1516
import locale
1617
import os
1718
import re
@@ -20,7 +21,6 @@
2021
import sys
2122
from os.path import isfile, join
2223
from pathlib import Path
23-
import importlib.util
2424

2525
from SCons.Script import (
2626
ARGUMENTS,
@@ -34,9 +34,8 @@
3434
from platformio.project.helpers import get_project_dir
3535
from platformio.util import get_serial_ports
3636
from platformio.compat import IS_WINDOWS
37-
from penv_setup import setup_python_environment
3837

39-
# Initialize environment and configuration
38+
# Initialize SCons environment and project configuration
4039
env = DefaultEnvironment()
4140
platform = env.PioPlatform()
4241
projectconfig = env.GetProjectConfig()
@@ -46,10 +45,10 @@
4645
core_dir = projectconfig.get("platformio", "core_dir")
4746
build_dir = Path(projectconfig.get("platformio", "build_dir"))
4847

49-
# Setup Python virtual environment and get executable paths
50-
PYTHON_EXE, esptool_binary_path = setup_python_environment(env, platform, core_dir)
48+
# Configure Python environment through centralized platform management
49+
PYTHON_EXE, esptool_binary_path = platform.setup_python_env(env)
5150

52-
# Initialize board configuration and MCU settings
51+
# Load board configuration and determine MCU architecture
5352
board = env.BoardConfig()
5453
board_id = env.subst("$BOARD")
5554
mcu = board.get("build.mcu", "esp32")
@@ -451,7 +450,7 @@ def switch_off_ldf():
451450
if not is_xtensa:
452451
toolchain_arch = "riscv32-esp"
453452

454-
# Initialize integration extra data if not present
453+
# Ensure integration extra data structure exists
455454
if "INTEGRATION_EXTRA_DATA" not in env:
456455
env["INTEGRATION_EXTRA_DATA"] = {}
457456

@@ -461,7 +460,7 @@ def switch_off_ldf():
461460
if ' ' in esptool_binary_path
462461
else esptool_binary_path
463462
)
464-
# Configure build tools and environment variables
463+
# Configure SCons build tools and compiler settings
465464
env.Replace(
466465
__get_board_boot_mode=_get_board_boot_mode,
467466
__get_board_f_flash=_get_board_f_flash,
@@ -637,7 +636,7 @@ def firmware_metrics(target, source, env):
637636
if env.GetProjectOption("custom_esp_idf_size_verbose", False):
638637
print(f"Running command: {' '.join(cmd)}")
639638

640-
# Call esp-idf-size with modified environment
639+
# Execute esp-idf-size with current environment
641640
result = subprocess.run(cmd, check=False, capture_output=False, env=os.environ)
642641

643642
if result.returncode != 0:

0 commit comments

Comments
 (0)