25
25
ZIP_FILE_EXTENSION = ".zip"
26
26
EXCLUDE_FILE_EXTENSION = ['socket' ]
27
27
28
+ DUMP_DIR_PATH = "dumped_tasks"
29
+
28
30
29
31
def is_exclude_file (file_abs_path ):
30
32
excluded = False
@@ -39,16 +41,119 @@ def is_exclude_file(file_abs_path):
39
41
return excluded
40
42
41
43
42
- def zip_module (orig_path , desc_name ):
44
+ def join_source_path (build_output_path , bom_src_path ):
45
+ if bom_src_path == '' :
46
+ return ''
47
+ leaf_folder = os .path .basename (os .path .normpath (build_output_path ))
48
+ split_path = bom_src_path .split (leaf_folder )
49
+ if len (split_path ) == 1 :
50
+ return bom_src_path
51
+ join_path = os .path .join (build_output_path , split_path [1 ][1 :])
52
+ # join_path = join_path.replace('\\', '/')
53
+ return join_path
54
+
55
+
56
+ def check_valid_file_type (file_path , timestamp ):
57
+ validation = True
58
+ if not os .path .isfile (file_path ) or \
59
+ os .path .islink (file_path ) or \
60
+ os .path .getsize (file_path ) > 1024 * 1024 or \
61
+ file_path .endswith ('.cmd' ) or \
62
+ file_path .endswith ('.o' ):
63
+ validation = False
64
+
65
+ if validation :
66
+ creation_time = os .path .getmtime (file_path )
67
+ if creation_time > timestamp :
68
+ validation = False
69
+
70
+ return validation
71
+
72
+
73
+ def get_dump_files (oss_key , dump_dir ):
74
+ dump_file_list = os .listdir (dump_dir )
75
+ found_list = []
76
+
77
+ logger .debug (f'Check dump oss : { oss_key } ' )
78
+
79
+ if oss_key == "" :
80
+ return found_list
81
+
82
+ if dump_file_list is None :
83
+ print ("no dump info" )
84
+ return found_list
85
+
86
+ for dump in dump_file_list :
87
+ if dump .startswith (oss_key ):
88
+ print ("found dump file" )
89
+ print (dump )
90
+ found_list .append (dump )
91
+
92
+ return found_list
93
+
94
+
95
+ def zip_module (orig_path , desc_name , build_output_dir , timestamp , full_src_uri , pf ):
43
96
FAILED_MSG_PREFIX = "Failed: " + desc_name + " " + orig_path
44
97
success = True
45
98
failed_msg = [FAILED_MSG_PREFIX ]
46
99
desc_name = desc_name .strip ()
47
100
zip_name = desc_name + ZIP_FILE_EXTENSION
101
+ uri_path_list = []
102
+ dumptasks_dir = os .path .join (build_output_dir , DUMP_DIR_PATH )
103
+ oss_dump_list = get_dump_files (pf , dumptasks_dir )
104
+
105
+ uris = full_src_uri .split ()
106
+
107
+ for uri in uris :
108
+ if uri .startswith ("file://" ):
109
+ src_uri_file = uri .split ("file://" )[1 ]
110
+ uri_path = os .path .join (orig_path , src_uri_file )
111
+ uri_path = join_source_path (build_output_dir , uri_path )
112
+ logger .debug (f'uri full path : { uri_path } ' )
113
+ uri_path_list .append (uri_path )
114
+
115
+ if len (uri_path_list ) > 0 :
116
+ uri_path = uri_path_list [0 ]
117
+ else :
118
+ uri_path = None
119
+
120
+ orig_path = join_source_path (build_output_dir , orig_path )
121
+
122
+ if os .path .islink (orig_path ):
123
+ orig_path = os .path .realpath (orig_path )
124
+ orig_path = join_source_path (build_output_dir , orig_path )
48
125
49
126
if desc_name == "" :
50
127
logger .debug ("Recipe name is missing" )
128
+ elif uri_path is not None and os .path .exists (uri_path ) and os .path .isfile (uri_path ):
129
+
130
+ zip_object = zipfile .ZipFile (zip_name , "w" , zipfile .ZIP_DEFLATED )
131
+ for uri_path in uri_path_list :
132
+
133
+ try :
134
+ abs_src = os .path .abspath (orig_path )
135
+ abs_name = os .path .abspath (uri_path )
136
+ des_path = os .path .join (source_desc_folder , zip_name )
137
+
138
+ relpath = os .path .relpath (abs_name , abs_src )
139
+ zip_object .write (abs_name , relpath )
140
+ except Exception as ex :
141
+ success = False
142
+ failed_msg .append (f'|--- { ex } ' )
143
+
144
+ try :
145
+ for dump in oss_dump_list :
146
+ dump_orig_path = os .path .join (dumptasks_dir , dump )
147
+ zip_object .write (dump_orig_path , os .path .basename (dump_orig_path ))
148
+
149
+ zip_object .close ()
150
+ shutil .move (zip_name , des_path )
151
+ except Exception as ex :
152
+ success = False
153
+ failed_msg .append (f'|--- { ex } ' )
154
+
51
155
elif orig_path != "" and os .path .exists (orig_path ):
156
+
52
157
abs_src = os .path .abspath (orig_path )
53
158
des_path = os .path .join (source_desc_folder , zip_name )
54
159
compress_file = []
@@ -59,6 +164,8 @@ def zip_module(orig_path, desc_name):
59
164
abs_name = os .path .abspath (os .path .join (dir_name , filename ))
60
165
if is_exclude_file (abs_name ):
61
166
continue
167
+ if not check_valid_file_type (abs_name , timestamp ):
168
+ continue
62
169
if os .path .islink (abs_name ):
63
170
abs_name = os .readlink (abs_name )
64
171
if not os .path .isfile (abs_name ):
@@ -71,11 +178,16 @@ def zip_module(orig_path, desc_name):
71
178
success = False
72
179
failed_msg .append (f'|--- { ex } ' )
73
180
try :
181
+ for dump in oss_dump_list :
182
+ dump_orig_path = os .path .join (dumptasks_dir , dump )
183
+ zip_object .write (dump_orig_path , os .path .basename (dump_orig_path ))
184
+
74
185
zip_object .close ()
75
186
shutil .move (zip_name , des_path )
76
187
except Exception as ex :
77
188
success = False
78
189
failed_msg .append (f'|--- { ex } ' )
190
+
79
191
else :
80
192
success = False
81
193
failed_msg .append (f"|--- Can't find source path: { orig_path } " )
@@ -114,7 +226,7 @@ def zip_compressed_source(output_dir="", total_list=[]):
114
226
logger .info (f"\n * Final compressed file: { final_zip_file } " )
115
227
116
228
117
- def collect_source (pkg_list : List [PackageItem ], output_dir : str ):
229
+ def collect_source (pkg_list : List [PackageItem ], output_dir : str , build_output_dir : str ):
118
230
global source_desc_folder
119
231
if output_dir == "" :
120
232
output_dir = os .getcwd ()
@@ -141,9 +253,14 @@ def collect_source(pkg_list: List[PackageItem], output_dir: str):
141
253
src_uri = recipe_item .download_location
142
254
base_path = recipe_item .file_path
143
255
256
+ full_uri = recipe_item .full_src_uri
257
+ pf = recipe_item .pf
144
258
# zip downloaded source codes and located to package_zip folders
145
259
total_list .append (recipe_name + ZIP_FILE_EXTENSION )
146
- success , failed_msg = zip_module (recipe_item .src_path , recipe_name )
260
+ source_timestamp = recipe_item .source_done
261
+ zip_file_name = recipe_name + "_" + recipe_item .version
262
+
263
+ success , failed_msg = zip_module (recipe_item .src_path , zip_file_name , build_output_dir , source_timestamp , full_uri , pf )
147
264
if success :
148
265
success_list .append (recipe_name )
149
266
else :
@@ -168,4 +285,4 @@ def collect_source(pkg_list: List[PackageItem], output_dir: str):
168
285
write_txt_file (output_failed_txt , "\n " .join (failed_list ))
169
286
170
287
# zip package source codes
171
- zip_compressed_source (output_dir , total_list )
288
+ # zip_compressed_source(output_dir, total_list)
0 commit comments