1+ Import ("env" )
2+
3+ import shutil
4+ import os
5+
6+ def after_build (source , target , env ):
7+ print (" > Start of build project extra script" )
8+
9+ # Obtenir le chemin du fichier .bin compilé
10+ firmware_path = str (target [0 ])
11+ if not os .path .exists (firmware_path ):
12+ print (f"Error: Firmware not found at { firmware_path } " )
13+ return
14+
15+ # Créer le dossier de sortie s'il n'existe pas
16+ current_dir = os .getcwd ()
17+ output_dir = os .path .join (current_dir , "bin" )
18+ if not os .path .exists (output_dir ):
19+ os .makedirs (output_dir )
20+ print (f"Created output directory: { output_dir } " )
21+
22+ # Nettoyer et copier le firmware.bin
23+ bin_input = firmware_path
24+ bin_output = os .path .join (output_dir , "firmware.bin" )
25+ if os .path .exists (bin_output ):
26+ try :
27+ os .remove (bin_output )
28+ print ("Cleaned up existing firmware.bin" )
29+ except Exception as e :
30+ print (f"Warning: Could not remove existing firmware.bin: { e } " )
31+
32+ # Nettoyer et copier le firmware.elf
33+ elf_input = os .path .splitext (firmware_path )[0 ] + ".elf"
34+ elf_output = os .path .join (output_dir , "firmware.elf" )
35+ if os .path .exists (elf_output ):
36+ try :
37+ os .remove (elf_output )
38+ print ("Cleaned up existing firmware.elf" )
39+ except Exception as e :
40+ print (f"Warning: Could not remove existing firmware.elf: { e } " )
41+
42+ # Copier les nouveaux fichiers firmware
43+ try :
44+ shutil .copy2 (bin_input , bin_output )
45+ print (f"Successfully copied new firmware.bin to: { bin_output } " )
46+
47+ shutil .copy2 (elf_input , elf_output )
48+ print (f"Successfully copied new firmware.elf to: { elf_output } " )
49+ except Exception as e :
50+ print (f"Error copying firmware files: { e } " )
51+
52+ print (" > End of build project extra script" )
53+
54+ # Ajouter le script après la création du binaire
55+ env .AddPostAction ("$BUILD_DIR/${PROGNAME}.bin" , after_build )
56+ print ("Extra script loaded" )
0 commit comments