1111from glob import glob
1212from .wrap import (open_wrapdburl , read_and_decompress , WrapException , get_releases ,
1313 get_releases_data , parse_patch_url )
14- from pathlib import Path
15-
1614from .. import mesonlib , msubprojects
1715
1816if T .TYPE_CHECKING :
@@ -91,11 +89,12 @@ def get_latest_version(name: str, allow_insecure: bool) -> T.Tuple[str, str]:
9189
9290def install (options : 'argparse.Namespace' ) -> None :
9391 name = options .name
94- if not os .path .isdir ('subprojects' ):
92+ subproject_dir_name = mesonlib .get_subproject_dir ()
93+ if subproject_dir_name is None or not os .path .isdir (subproject_dir_name ):
9594 raise SystemExit ('Subprojects dir not found. Run this script in your source root directory.' )
96- if os .path .isdir (os .path .join ('subprojects' , name )):
95+ if os .path .isdir (os .path .join (subproject_dir_name , name )):
9796 raise SystemExit ('Subproject directory for this project already exists.' )
98- wrapfile = os .path .join ('subprojects' , name + '.wrap' )
97+ wrapfile = os .path .join (subproject_dir_name , name + '.wrap' )
9998 if os .path .exists (wrapfile ):
10099 raise SystemExit ('Wrap file already exists.' )
101100 (version , revision ) = get_latest_version (name , options .allow_insecure )
@@ -143,11 +142,20 @@ def do_promotion(from_path: str, spdir_name: str) -> None:
143142 outputdir = os .path .join (spdir_name , sproj_name )
144143 if os .path .exists (outputdir ):
145144 raise SystemExit (f'Output dir { outputdir } already exists. Will not overwrite.' )
146- shutil .copytree (from_path , outputdir , ignore = shutil .ignore_patterns ('subprojects' ))
145+
146+ subpdir = mesonlib .get_subproject_dir ()
147+ if subpdir is not None :
148+ ignore = shutil .ignore_patterns (subpdir )
149+ else :
150+ ignore = None
151+
152+ shutil .copytree (from_path , outputdir , ignore = ignore )
147153
148154def promote (options : 'argparse.Namespace' ) -> None :
149155 argument = options .project_path
150- spdir_name = 'subprojects'
156+ spdir_name = mesonlib .get_subproject_dir ()
157+ if spdir_name is None :
158+ raise SystemExit ('Subproject dir not found. Run this script in your source root directory.' )
151159 sprojs = mesonlib .detect_subprojects (spdir_name )
152160
153161 # check if the argument is a full path to a subproject directory or wrap file
@@ -170,7 +178,9 @@ def promote(options: 'argparse.Namespace') -> None:
170178
171179def status (options : 'argparse.Namespace' ) -> None :
172180 print ('Subproject status' )
173- for w in glob ('subprojects/*.wrap' ):
181+ subdir = mesonlib .get_subproject_dir ()
182+ assert subdir is not None , "This should only happen in a non-native subproject"
183+ for w in glob (f'{ subdir } /*.wrap' ):
174184 name = os .path .basename (w )[:- 5 ]
175185 try :
176186 (latest_branch , latest_revision ) = get_latest_version (name , options .allow_insecure )
@@ -189,8 +199,12 @@ def status(options: 'argparse.Namespace') -> None:
189199
190200def update_db (options : 'argparse.Namespace' ) -> None :
191201 data = get_releases_data (options .allow_insecure )
192- Path ('subprojects' ).mkdir (exist_ok = True )
193- with Path ('subprojects/wrapdb.json' ).open ('wb' ) as f :
202+ subproject_dir_name = mesonlib .get_subproject_dir ()
203+ if subproject_dir_name is None :
204+ raise SystemExit ('Subproject dir not found. Run this script in your source root directory.' )
205+
206+ os .makedirs (subproject_dir_name , exist_ok = True )
207+ with open (os .path .join (subproject_dir_name , 'wrapdb.json' ), 'wb' ) as f :
194208 f .write (data )
195209
196210def run (options : 'argparse.Namespace' ) -> int :
0 commit comments