33import argparse
44import logging
55import os
6+ from pathlib import Path
67import shutil
78import subprocess
9+ from typing import Dict , List
810
9- from module .cross_toolchain import build_cross_toolchain
10- from module .host_lib import build_host_lib
1111from module .path import ProjectPaths
1212from module .prepare_source import download_and_patch
1313from module .profile import get_full_profile
14+ from module .util import ensure , overlayfs_ro
15+
16+ from module .host_lib import build_host_lib
17+ from module .cross_toolchain import build_cross_toolchain
1418from module .target_lib import build_target_lib
1519
1620def parse_args () -> argparse .Namespace :
@@ -53,25 +57,55 @@ def parse_args() -> argparse.Namespace:
5357 return result
5458
5559def clean (config : argparse .Namespace , paths : ProjectPaths ):
56- if paths .build .exists ():
57- shutil .rmtree (paths .build )
58- if paths .h_prefix .exists ():
59- shutil .rmtree (paths .h_prefix )
60+ if paths .build_dir .exists ():
61+ shutil .rmtree (paths .build_dir )
62+ if paths .layer_dir .exists ():
63+ shutil .rmtree (paths .layer_dir )
6064
6165def prepare_dirs (paths : ProjectPaths ):
62- paths .assets .mkdir (parents = True , exist_ok = True )
63- paths .build .mkdir (parents = True , exist_ok = True )
64- paths .dist .mkdir (parents = True , exist_ok = True )
66+ ensure (paths .assets_dir )
67+ ensure (paths .build_dir )
68+ ensure (paths .dist_dir )
69+
70+ def check_file_collision (layers : list [Path ]):
71+ file_to_package_map : Dict [str , List [str ]] = {}
72+ for layer in layers :
73+ for file in layer .glob ('**/*' ):
74+ if not file .is_dir ():
75+ file_path = str (file .relative_to (layer ))
76+ if file_path in file_to_package_map :
77+ file_to_package_map [file_path ].append (str (layer ))
78+ else :
79+ file_to_package_map [file_path ] = [str (layer )]
80+
81+ ok = True
82+ for file , packages in file_to_package_map .items ():
83+ if len (packages ) > 1 :
84+ ok = False
85+ print (f'file collision: { file } in { packages } ' )
86+
87+ if not ok :
88+ raise Exception ('file collision' )
6589
6690def package (paths : ProjectPaths ):
67- ret = subprocess .run ([
68- 'tar' ,
69- '-cf' ,
70- paths .container / 'qt.tar' ,
71- paths .h_prefix ,
72- ])
73- if ret .returncode != 0 :
74- raise Exception ('Failed to package' )
91+ layers = []
92+ for layer_group in (paths .layer_host , paths .layer_x , paths .layer_target ):
93+ for k , v in layer_group ._asdict ().items ():
94+ if k in ('prefix' , 'freetype_decycle' ):
95+ continue
96+ layers .append (v )
97+
98+ check_file_collision (layers )
99+
100+ with overlayfs_ro ('/usr/local' , [
101+ * map (lambda layer : layer / 'usr/local' , layers ),
102+ ]):
103+ subprocess .run ([
104+ 'tar' ,
105+ '-C' , '/usr/local' ,
106+ '-c' , '.' ,
107+ '-f' , paths .container_dir / 'qt.tar' ,
108+ ], check = True )
75109
76110def main ():
77111 config = parse_args ()
@@ -93,17 +127,11 @@ def main():
93127
94128 download_and_patch (profile .ver , paths , profile .info )
95129
96- os .environ ['PATH' ] = f'{ paths .h_prefix } /bin:{ os .environ ['PATH' ]} '
97-
98- os .environ ['PKG_CONFIG_LIBDIR' ] = f'{ paths .h_prefix } /lib/pkgconfig:{ paths .h_prefix } /share/pkgconfig'
99130 build_host_lib (profile .ver , paths , profile .info , config )
100- del os .environ ['PKG_CONFIG_LIBDIR' ]
101131
102132 build_cross_toolchain (profile .ver , paths , profile .info , config )
103133
104- os .environ ['PKG_CONFIG_LIBDIR' ] = f'{ paths .prefix } /lib/pkgconfig:{ paths .prefix } /share/pkgconfig'
105134 build_target_lib (profile .ver , paths , profile .info , config )
106- del os .environ ['PKG_CONFIG_LIBDIR' ]
107135
108136 package (paths )
109137
0 commit comments