Skip to content

Commit 4f30d2e

Browse files
authored
call esptool with full path
1 parent 20268d7 commit 4f30d2e

File tree

1 file changed

+50
-9
lines changed

1 file changed

+50
-9
lines changed

builder/main.py

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,21 +257,51 @@ def _get_installed_uv_packages():
257257
def install_esptool(env):
258258
"""
259259
Install esptool from package folder "tool-esptoolpy" using uv package manager.
260+
Also determines the path to the esptool executable binary.
260261
261262
Args:
262263
env: SCons environment object
263264
264265
Returns:
265-
bool: True if successful, False otherwise
266+
str: Path to esptool executable, or 'esptool' as fallback
266267
"""
268+
def _get_esptool_executable_path(python_exe):
269+
"""
270+
Get the path to the esptool executable binary.
271+
272+
Args:
273+
python_exe (str): Path to Python executable
274+
275+
Returns:
276+
str: Path to esptool executable
277+
"""
278+
if not python_exe or not os.path.isfile(python_exe):
279+
return 'esptool' # Fallback
280+
281+
python_dir = os.path.dirname(python_exe)
282+
283+
if sys.platform == "win32":
284+
scripts_dir = os.path.join(python_dir, "Scripts")
285+
esptool_exe = os.path.join(scripts_dir, "esptool.exe")
286+
else:
287+
scripts_dir = os.path.join(python_dir)
288+
esptool_exe = os.path.join(scripts_dir, "esptool")
289+
290+
if os.path.isfile(esptool_exe):
291+
return esptool_exe
292+
293+
return 'esptool'
294+
267295
try:
268296
subprocess.check_call(
269297
[env.subst("$PYTHONEXE"), "-c", "import esptool"],
270298
stdout=subprocess.DEVNULL,
271299
stderr=subprocess.DEVNULL,
272-
env=os.environ # Use modified environment with custom PYTHONPATH
300+
env=os.environ
273301
)
274-
return True
302+
python_exe = env.subst("$PYTHONEXE")
303+
esptool_binary_path = _get_esptool_executable_path(python_exe)
304+
return esptool_binary_path
275305
except (subprocess.CalledProcessError, FileNotFoundError):
276306
pass
277307

@@ -282,18 +312,22 @@ def install_esptool(env):
282312
"uv", "pip", "install", "--quiet",
283313
f"--python={env.subst('$PYTHONEXE')}",
284314
"-e", esptool_repo_path
285-
], env=os.environ) # Use modified environment with custom PYTHONPATH
286-
return True
315+
], env=os.environ)
316+
317+
python_exe = env.subst("$PYTHONEXE")
318+
esptool_binary_path = _get_esptool_executable_path(python_exe)
319+
return esptool_binary_path
320+
287321
except subprocess.CalledProcessError as e:
288322
print(f"Warning: Failed to install esptool: {e}")
289-
return False
323+
return 'esptool' # Fallback
290324

291-
return False
325+
return 'esptool' # Fallback
292326

293327

294328
# Install Python dependencies and esptool
295329
install_python_deps()
296-
install_esptool(env)
330+
esptool_binary_path = install_esptool(env)
297331

298332

299333
def BeforeUpload(target, source, env):
@@ -675,6 +709,13 @@ def switch_off_ldf():
675709
if "INTEGRATION_EXTRA_DATA" not in env:
676710
env["INTEGRATION_EXTRA_DATA"] = {}
677711

712+
# Take care of possible whitespaces in path
713+
objcopy_value = (
714+
f'"{esptool_binary_path}"'
715+
if ' ' in esptool_binary_path
716+
else esptool_binary_path
717+
)
718+
678719
# Configure build tools and environment variables
679720
env.Replace(
680721
__get_board_boot_mode=_get_board_boot_mode,
@@ -704,7 +745,7 @@ def switch_off_ldf():
704745
"bin",
705746
"%s-elf-gdb" % toolchain_arch,
706747
),
707-
OBJCOPY='esptool',
748+
OBJCOPY=objcopy_value,
708749
RANLIB="%s-elf-gcc-ranlib" % toolchain_arch,
709750
SIZETOOL="%s-elf-size" % toolchain_arch,
710751
ARFLAGS=["rc"],

0 commit comments

Comments
 (0)