@@ -328,6 +328,10 @@ def configure_text(text: str, context: dict[str, str]) -> str:
328
328
return text
329
329
330
330
331
+ def configure_text_list (text_list : list [str ], context : dict [str , str ]) -> list [str ]:
332
+ return [configure_text (text = e , context = context ) for e in text_list ]
333
+
334
+
331
335
class ArchiveFileTree :
332
336
def __init__ (self ):
333
337
self ._tree : dict [str , NodeInArchive ] = {}
@@ -343,7 +347,7 @@ def add_to_archiver(self, archive_base: str, archiver: Archiver):
343
347
added_files = dict ()
344
348
345
349
def calculate_symlink_target (s : NodeInArchive ) -> str :
346
- dest_dir = os .path .dirname (s .path )
350
+ dest_dir = os .path .dirname (s .arcpath )
347
351
if dest_dir :
348
352
dest_dir += "/"
349
353
target = dest_dir + s .symtarget
@@ -357,19 +361,24 @@ def calculate_symlink_target(s: NodeInArchive) -> str:
357
361
358
362
# Add files in first pass
359
363
for arcpath , node in self ._tree .items ():
364
+ assert node is not None , f"{ arcpath } -> node"
360
365
if node .data is not None :
361
366
archiver .add_file_data (arcpath = arc_join (archive_base , arcpath ), data = node .data , time = node .time , mode = node .mode )
362
- added_files [node .path ] = node
367
+ assert node .arcpath is not None , f"{ node = } "
368
+ added_files [node .arcpath ] = node
363
369
elif node .path is not None :
364
370
archiver .add_file_path (arcpath = arc_join (archive_base , arcpath ), path = node .path )
365
- added_files [node .path ] = node
371
+ assert node .arcpath is not None , f"{ node = } "
372
+ added_files [node .arcpath ] = node
366
373
elif node .symtarget is not None :
367
374
remaining_symlinks .add (node )
368
375
elif node .directory :
369
376
pass
370
377
else :
371
378
raise ValueError (f"Invalid Archive Node: { repr (node )} " )
372
379
380
+ assert None not in added_files
381
+
373
382
# Resolve symlinks in second pass: zipfile does not support symlinks, so add files to zip archive
374
383
while True :
375
384
if not remaining_symlinks :
@@ -380,18 +389,18 @@ def calculate_symlink_target(s: NodeInArchive) -> str:
380
389
symlink_files_for_zip = {}
381
390
symlink_target_path = calculate_symlink_target (symlink )
382
391
if symlink_target_path in added_files :
383
- symlink_files_for_zip [symlink .path ] = added_files [symlink_target_path ]
392
+ symlink_files_for_zip [symlink .arcpath ] = added_files [symlink_target_path ]
384
393
else :
385
394
symlink_target_path_slash = symlink_target_path + "/"
386
395
for added_file in added_files :
387
396
if added_file .startswith (symlink_target_path_slash ):
388
- path_in_symlink = symlink .path + "/" + added_file .removeprefix (symlink_target_path_slash )
397
+ path_in_symlink = symlink .arcpath + "/" + added_file .removeprefix (symlink_target_path_slash )
389
398
symlink_files_for_zip [path_in_symlink ] = added_files [added_file ]
390
399
if symlink_files_for_zip :
391
400
symlinks_this_time .add (symlink )
392
401
extra_added_files .update (symlink_files_for_zip )
393
402
files_for_zip = [{"arcpath" : f"{ archive_base } /{ sym_path } " , "data" : sym_info .data , "mode" : sym_info .mode } for sym_path , sym_info in symlink_files_for_zip .items ()]
394
- archiver .add_symlink (arcpath = f"{ archive_base } /{ symlink .path } " , target = symlink .symtarget , time = symlink .time , files_for_zip = files_for_zip )
403
+ archiver .add_symlink (arcpath = f"{ archive_base } /{ symlink .arcpath } " , target = symlink .symtarget , time = symlink .time , files_for_zip = files_for_zip )
395
404
# if not symlinks_this_time:
396
405
# logger.info("files added: %r", set(path for path in added_files.keys()))
397
406
assert symlinks_this_time , f"No targets found for symlinks: { remaining_symlinks } "
@@ -545,6 +554,7 @@ def get_context(self, extra_context: typing.Optional[dict[str, str]]=None) -> di
545
554
"PROJECT_VERSION" : self .version ,
546
555
"PROJECT_COMMIT" : self .commit ,
547
556
"PROJECT_REVISION" : self .revision ,
557
+ "PROJECT_ROOT" : str (self .root ),
548
558
}
549
559
if extra_context :
550
560
ctx .update (extra_context )
@@ -741,23 +751,34 @@ def extract_filter(member: tarfile.TarInfo, path: str, /):
741
751
install_path = build_parent_dir / f"install-{ triplet } "
742
752
shutil .rmtree (install_path , ignore_errors = True )
743
753
build_path .mkdir (parents = True , exist_ok = True )
754
+ context = self .get_context ({
755
+ "ARCH" : arch ,
756
+ "DEP_PREFIX" : str (mingw_deps_path / triplet ),
757
+ })
758
+ extra_args = configure_text_list (text_list = self .release_info ["mingw" ]["autotools" ]["args" ], context = context )
759
+
744
760
with self .section_printer .group (f"Configuring MinGW { triplet } (autotools)" ):
745
- extra_args = [arg .replace ("@DEP_PREFIX@" , str (mingw_deps_path / triplet )) for arg in self .release_info ["mingw" ]["autotools" ]["args" ]]
746
761
assert "@" not in " " .join (extra_args ), f"@ should not be present in extra arguments ({ extra_args } )"
747
762
self .executer .run ([
748
763
self .root / "configure" ,
749
764
f"--prefix={ install_path } " ,
750
- f"--includedir={ install_path } /include" ,
751
- f"--libdir={ install_path } /lib" ,
752
- f"--bindir={ install_path } /bin" ,
765
+ f"--includedir=${{prefix} }/include" ,
766
+ f"--libdir=${{prefix} }/lib" ,
767
+ f"--bindir=${{prefix} }/bin" ,
753
768
f"--host={ triplet } " ,
754
769
f"--build=x86_64-none-linux-gnu" ,
755
770
] + extra_args , cwd = build_path , env = new_env )
756
771
with self .section_printer .group (f"Build MinGW { triplet } (autotools)" ):
757
772
self .executer .run (["make" , f"-j{ self .cpu_count } " ], cwd = build_path , env = new_env )
758
773
with self .section_printer .group (f"Install MinGW { triplet } (autotools)" ):
759
774
self .executer .run (["make" , "install" ], cwd = build_path , env = new_env )
760
- archive_file_tree .add_directory_tree (arc_dir = arc_join (arc_root , triplet ), path = install_path )
775
+ archive_file_tree .add_directory_tree (arc_dir = arc_join (arc_root , triplet ), path = install_path , time = self .arc_time )
776
+
777
+ print ("Recording arch-dependent extra files for MinGW development archive ..." )
778
+ extra_context = {
779
+ "TRIPLET" : ARCH_TO_TRIPLET [arch ],
780
+ }
781
+ archive_file_tree .add_file_mapping (arc_dir = arc_root , file_mapping = self .release_info ["mingw" ]["autotools" ].get ("files" , {}), file_mapping_root = self .root , context = self .get_context (extra_context = extra_context ), time = self .arc_time )
761
782
762
783
if "cmake" in self .release_info ["mingw" ]:
763
784
assert self .release_info ["mingw" ]["cmake" ]["shared-static" ] in ("args" , "both" )
@@ -770,6 +791,12 @@ def extract_filter(member: tarfile.TarInfo, path: str, /):
770
791
assert arch not in mingw_archs
771
792
mingw_archs .add (arch )
772
793
794
+ context = self .get_context ({
795
+ "ARCH" : arch ,
796
+ "DEP_PREFIX" : str (mingw_deps_path / triplet ),
797
+ })
798
+ extra_args = configure_text_list (text_list = self .release_info ["mingw" ]["cmake" ]["args" ], context = context )
799
+
773
800
build_path = build_parent_dir / f"build-{ triplet } "
774
801
install_path = build_parent_dir / f"install-{ triplet } "
775
802
shutil .rmtree (install_path , ignore_errors = True )
@@ -780,7 +807,6 @@ def extract_filter(member: tarfile.TarInfo, path: str, /):
780
807
args_for_shared_static = (["-DBUILD_SHARED_LIBS=ON" ], ["-DBUILD_SHARED_LIBS=OFF" ])
781
808
for arg_for_shared_static in args_for_shared_static :
782
809
with self .section_printer .group (f"Configuring MinGW { triplet } (CMake)" ):
783
- extra_args = [arg .replace ("@DEP_PREFIX@" , str (mingw_deps_path / triplet )) for arg in self .release_info ["mingw" ]["cmake" ]["args" ]]
784
810
assert "@" not in " " .join (extra_args ), f"@ should not be present in extra arguments ({ extra_args } )"
785
811
self .executer .run ([
786
812
f"cmake" ,
@@ -803,6 +829,13 @@ def extract_filter(member: tarfile.TarInfo, path: str, /):
803
829
self .executer .run (["cmake" , "--install" , str (build_path )], cwd = build_path , env = new_env )
804
830
archive_file_tree .add_directory_tree (arc_dir = arc_join (arc_root , triplet ), path = install_path , time = self .arc_time )
805
831
832
+ print ("Recording arch-dependent extra files for MinGW development archive ..." )
833
+ extra_context = {
834
+ "TRIPLET" : ARCH_TO_TRIPLET [arch ],
835
+ }
836
+ archive_file_tree .add_file_mapping (arc_dir = arc_root , file_mapping = self .release_info ["mingw" ]["cmake" ].get ("files" , {}), file_mapping_root = self .root , context = self .get_context (extra_context = extra_context ), time = self .arc_time )
837
+ print ("... done" )
838
+
806
839
print ("Recording extra files for MinGW development archive ..." )
807
840
archive_file_tree .add_file_mapping (arc_dir = arc_root , file_mapping = self .release_info ["mingw" ].get ("files" , {}), file_mapping_root = self .root , context = self .get_context (), time = self .arc_time )
808
841
print ("... done" )
@@ -1231,19 +1264,24 @@ def _build_msvc_devel(self) -> None:
1231
1264
zip_path = self .dist_path / f"{ self .project } -devel-{ self .version } -VC.zip"
1232
1265
arc_root = f"{ self .project } -{ self .version } "
1233
1266
1267
+ def copy_files_devel (ctx ):
1268
+ archive_file_tree .add_file_mapping (arc_dir = arc_root , file_mapping = self .release_info ["msvc" ]["files-devel" ], file_mapping_root = self .root , context = ctx , time = self .arc_time )
1269
+
1270
+
1234
1271
logger .info ("Collecting files..." )
1235
1272
archive_file_tree = ArchiveFileTree ()
1236
1273
if "msbuild" in self .release_info ["msvc" ]:
1237
1274
for arch in self .release_info ["msvc" ]["msbuild" ]["archs" ]:
1238
1275
arch_platform = self ._arch_to_vs_platform (arch = arch )
1239
1276
platform_context = self .get_context (arch_platform .extra_context ())
1240
1277
archive_file_tree .add_file_mapping (arc_dir = arc_root , file_mapping = self .release_info ["msvc" ]["msbuild" ]["files-devel" ], file_mapping_root = self .root , context = platform_context , time = self .arc_time )
1278
+ copy_files_devel (ctx = platform_context )
1241
1279
if "cmake" in self .release_info ["msvc" ]:
1242
1280
for arch in self .release_info ["msvc" ]["cmake" ]["archs" ]:
1243
1281
arch_platform = self ._arch_to_vs_platform (arch = arch )
1244
1282
platform_context = self .get_context (arch_platform .extra_context ())
1245
1283
archive_file_tree .add_file_mapping (arc_dir = arc_root , file_mapping = self .release_info ["msvc" ]["cmake" ]["files-devel" ], file_mapping_root = self ._arch_platform_to_install_path (arch_platform ), context = platform_context , time = self .arc_time )
1246
- archive_file_tree . add_file_mapping ( arc_dir = arc_root , file_mapping = self . release_info [ "msvc" ][ "files-devel" ], file_mapping_root = self . root , context = self . get_context (), time = self . arc_time )
1284
+ copy_files_devel ( ctx = platform_context )
1247
1285
1248
1286
with Archiver (zip_path = zip_path ) as archiver :
1249
1287
archive_file_tree .add_to_archiver (archive_base = "" , archiver = archiver )
0 commit comments