11#!/usr/bin/env python
22#
3- # SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
3+ # SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
44# SPDX-License-Identifier: Apache-2.0
55
66import os
77import sys
88import subprocess
99import shutil
10- import filecmp
1110import configparser
1211
1312def ESP_LOGI (x ):
@@ -106,17 +105,15 @@ def main():
106105 if not os .path .exists (src_patch_path ) or not os .path .exists (dst_patch_path ):
107106 raise Exception (f'{ src_patch_path } or { dst_patch_path } does not exist' )
108107
109- # avoid applying the same patch multiple times
110- dst_patch_file = os .path .join (repo_dir , path_option , patch_name )
111- if os .path .exists (dst_patch_file ):
112- ESP_LOGI (f'{ patch_name } already exists, skipping.' )
113- continue
114- else :
115- shutil .copy (src_patch_path , dst_patch_path )
116-
117108 # *.patch
118- cur_dir = os .getcwd ()
119109 if patch_name .endswith ('.patch' ):
110+ # avoid applying the same patch multiple times
111+ dst_patch_file = os .path .join (repo_dir , path_option , patch_name )
112+ if os .path .exists (dst_patch_file ):
113+ ESP_LOGI (f'{ patch_name } already exists, skipping.' )
114+ continue
115+ shutil .copy (src_patch_path , dst_patch_path )
116+ cur_dir = os .getcwd ()
120117 cmd = f'cd { dst_patch_path } && git apply --check { src_patch_path } && cd { cur_dir } '
121118 ret = subprocess .run (cmd , capture_output = True , shell = True )
122119 if ret .returncode :
@@ -127,17 +124,16 @@ def main():
127124 if ret :
128125 raise Exception (f'{ patch_name } apply failed.' )
129126 ESP_LOGI (f'{ patch_name } has been applied.' )
130- # *.a
127+ # *.a: always sync to overwrite the destination
131128 elif patch_name .endswith ('.a' ):
132- if filecmp .cmp (dst_patch_path , src_patch_path ):
133- ESP_LOGI (f'{ src_patch_path } does not need to be applied.' )
134- else :
135- shutil .copy (src_patch_path , dst_patch_path )
136- ESP_LOGI (f'{ src_patch_path } has been applied.' )
137- # directory
129+ shutil .copy (src_patch_path , dst_patch_path )
130+ ESP_LOGI (f'{ patch_name } has been synchronized to { dst_patch_path } .' )
131+ # directory: always sync to overwrite the destination
138132 elif os .path .isdir (src_patch_path ):
139133 shutil .copytree (src_patch_path , dst_patch_path , dirs_exist_ok = True )
140134 ESP_LOGI (f'Directory { src_patch_path } has been synchronized to { dst_patch_path } .' )
135+ else :
136+ raise Exception (f'Unsupported patch type: { patch_name } ' )
141137
142138if __name__ == '__main__' :
143139 try :
0 commit comments