@@ -41,12 +41,13 @@ def set_program_override(pkg_bin: ExternalProgram, for_machine: MachineChoice) -
41
41
PkgConfigInterface .pkg_bin_per_machine [for_machine ] = pkg_bin
42
42
43
43
@staticmethod
44
- def instance (env : Environment , for_machine : MachineChoice , silent : bool ) -> T .Optional [PkgConfigInterface ]:
44
+ def instance (env : Environment , for_machine : MachineChoice , silent : bool ,
45
+ extra_paths : T .Optional [T .List [str ]] = None ) -> T .Optional [PkgConfigInterface ]:
45
46
'''Return a pkg-config implementation singleton'''
46
47
for_machine = for_machine if env .is_cross_build () else MachineChoice .HOST
47
48
impl = PkgConfigInterface .class_impl [for_machine ]
48
49
if impl is False :
49
- impl = PkgConfigCLI (env , for_machine , silent , PkgConfigInterface .pkg_bin_per_machine [for_machine ])
50
+ impl = PkgConfigCLI (env , for_machine , silent , PkgConfigInterface .pkg_bin_per_machine [for_machine ], extra_paths )
50
51
if not impl .found ():
51
52
impl = None
52
53
if not impl and not silent :
@@ -55,7 +56,9 @@ def instance(env: Environment, for_machine: MachineChoice, silent: bool) -> T.Op
55
56
return impl
56
57
57
58
@staticmethod
58
- def _cli (env : Environment , for_machine : MachineChoice , silent : bool = False ) -> T .Optional [PkgConfigCLI ]:
59
+ def _cli (env : Environment , for_machine : MachineChoice ,
60
+ extra_paths : T .Optional [T .List [str ]] = None ,
61
+ silent : bool = False ) -> T .Optional [PkgConfigCLI ]:
59
62
'''Return the CLI pkg-config implementation singleton
60
63
Even when we use another implementation internally, external tools might
61
64
still need the CLI implementation.
@@ -66,15 +69,16 @@ def _cli(env: Environment, for_machine: MachineChoice, silent: bool = False) ->
66
69
if impl and not isinstance (impl , PkgConfigCLI ):
67
70
impl = PkgConfigInterface .class_cli_impl [for_machine ]
68
71
if impl is False :
69
- impl = PkgConfigCLI (env , for_machine , silent , PkgConfigInterface .pkg_bin_per_machine [for_machine ])
72
+ impl = PkgConfigCLI (env , for_machine , silent , PkgConfigInterface .pkg_bin_per_machine [for_machine ], extra_paths )
70
73
if not impl .found ():
71
74
impl = None
72
75
PkgConfigInterface .class_cli_impl [for_machine ] = impl
73
76
return T .cast ('T.Optional[PkgConfigCLI]' , impl ) # Trust me, mypy
74
77
75
78
@staticmethod
76
- def get_env (env : Environment , for_machine : MachineChoice , uninstalled : bool = False ) -> EnvironmentVariables :
77
- cli = PkgConfigInterface ._cli (env , for_machine )
79
+ def get_env (env : Environment , for_machine : MachineChoice , uninstalled : bool = False ,
80
+ extra_paths : T .Optional [T .List [str ]] = None ) -> EnvironmentVariables :
81
+ cli = PkgConfigInterface ._cli (env , for_machine , extra_paths )
78
82
return cli ._get_env (uninstalled ) if cli else EnvironmentVariables ()
79
83
80
84
@staticmethod
@@ -123,11 +127,13 @@ class PkgConfigCLI(PkgConfigInterface):
123
127
'''pkg-config CLI implementation'''
124
128
125
129
def __init__ (self , env : Environment , for_machine : MachineChoice , silent : bool ,
126
- pkgbin : T .Optional [ExternalProgram ] = None ) -> None :
130
+ pkgbin : T .Optional [ExternalProgram ] = None ,
131
+ extra_paths : T .Optional [T .List [str ]] = None ) -> None :
127
132
super ().__init__ (env , for_machine )
128
133
self ._detect_pkgbin (pkgbin )
129
134
if self .pkgbin and not silent :
130
135
mlog .log ('Found pkg-config:' , mlog .green ('YES' ), mlog .bold (f'({ self .pkgbin .get_path ()} )' ), mlog .blue (self .pkgbin_version ))
136
+ self .extra_paths = extra_paths or []
131
137
132
138
def found (self ) -> bool :
133
139
return bool (self .pkgbin )
@@ -258,7 +264,7 @@ def _get_env(self, uninstalled: bool = False) -> EnvironmentVariables:
258
264
key = OptionKey ('pkg_config_path' , machine = self .for_machine )
259
265
pathlist = self .env .coredata .optstore .get_value_for (key )
260
266
assert isinstance (pathlist , list )
261
- extra_paths : T .List [str ] = pathlist [:]
267
+ extra_paths : T .List [str ] = pathlist + self . extra_paths
262
268
if uninstalled :
263
269
bpath = self .env .get_build_dir ()
264
270
if bpath is not None :
@@ -297,11 +303,13 @@ def _call_pkgbin(self, args: T.List[str], env: T.Optional[EnvironOrDict] = None)
297
303
class PkgConfigDependency (ExternalDependency ):
298
304
299
305
def __init__ (self , name : str , environment : Environment , kwargs : T .Dict [str , T .Any ],
300
- language : T .Optional [str ] = None ) -> None :
306
+ language : T .Optional [str ] = None ,
307
+ extra_paths : T .Optional [T .List [str ]] = None ) -> None :
301
308
super ().__init__ (DependencyTypeName ('pkgconfig' ), environment , kwargs , language = language )
302
309
self .name = name
303
310
self .is_libtool = False
304
- pkgconfig = PkgConfigInterface .instance (self .env , self .for_machine , self .silent )
311
+ self .extra_paths = extra_paths or []
312
+ pkgconfig = PkgConfigInterface .instance (self .env , self .for_machine , self .silent , self .extra_paths )
305
313
if not pkgconfig :
306
314
msg = f'Pkg-config for machine { self .for_machine } not found. Giving up.'
307
315
if self .required :
0 commit comments