@@ -257,21 +257,51 @@ def _get_installed_uv_packages():
257
257
def install_esptool (env ):
258
258
"""
259
259
Install esptool from package folder "tool-esptoolpy" using uv package manager.
260
+ Also determines the path to the esptool executable binary.
260
261
261
262
Args:
262
263
env: SCons environment object
263
264
264
265
Returns:
265
- bool: True if successful, False otherwise
266
+ str: Path to esptool executable, or 'esptool' as fallback
266
267
"""
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
+
267
295
try :
268
296
subprocess .check_call (
269
297
[env .subst ("$PYTHONEXE" ), "-c" , "import esptool" ],
270
298
stdout = subprocess .DEVNULL ,
271
299
stderr = subprocess .DEVNULL ,
272
- env = os .environ # Use modified environment with custom PYTHONPATH
300
+ env = os .environ
273
301
)
274
- return True
302
+ python_exe = env .subst ("$PYTHONEXE" )
303
+ esptool_binary_path = _get_esptool_executable_path (python_exe )
304
+ return esptool_binary_path
275
305
except (subprocess .CalledProcessError , FileNotFoundError ):
276
306
pass
277
307
@@ -282,18 +312,22 @@ def install_esptool(env):
282
312
"uv" , "pip" , "install" , "--quiet" ,
283
313
f"--python={ env .subst ('$PYTHONEXE' )} " ,
284
314
"-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
+
287
321
except subprocess .CalledProcessError as e :
288
322
print (f"Warning: Failed to install esptool: { e } " )
289
- return False
323
+ return 'esptool' # Fallback
290
324
291
- return False
325
+ return 'esptool' # Fallback
292
326
293
327
294
328
# Install Python dependencies and esptool
295
329
install_python_deps ()
296
- install_esptool (env )
330
+ esptool_binary_path = install_esptool (env )
297
331
298
332
299
333
def BeforeUpload (target , source , env ):
@@ -675,6 +709,13 @@ def switch_off_ldf():
675
709
if "INTEGRATION_EXTRA_DATA" not in env :
676
710
env ["INTEGRATION_EXTRA_DATA" ] = {}
677
711
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
+
678
719
# Configure build tools and environment variables
679
720
env .Replace (
680
721
__get_board_boot_mode = _get_board_boot_mode ,
@@ -704,7 +745,7 @@ def switch_off_ldf():
704
745
"bin" ,
705
746
"%s-elf-gdb" % toolchain_arch ,
706
747
),
707
- OBJCOPY = 'esptool' ,
748
+ OBJCOPY = objcopy_value ,
708
749
RANLIB = "%s-elf-gcc-ranlib" % toolchain_arch ,
709
750
SIZETOOL = "%s-elf-size" % toolchain_arch ,
710
751
ARFLAGS = ["rc" ],
0 commit comments