33import subprocess
44import sys
55import sysconfig
6- import typing
6+ import typing as T
77
88import toposort
99
1010from . import config
1111from .subproject import Subproject
12- from .util import run_pip
12+ from .util import run_cmd
1313
1414
1515class Context :
@@ -27,13 +27,13 @@ def __init__(self, verbose: bool) -> None:
2727 self .wheel_path = self .root_path / "dist"
2828 self .other_wheel_path = self .root_path / "dist-other"
2929
30- subprojects : typing .List [Subproject ] = []
30+ subprojects : T .List [Subproject ] = []
3131 for project , cfg in self .cfg .subprojects .items ():
3232 # Skip projects that aren't compatible with the robot
3333 if self .is_robot and not cfg .robot :
3434 continue
3535
36- subprojects .append (Subproject (cfg , self .subprojects_path / project ))
36+ subprojects .append (Subproject (self , cfg , self .subprojects_path / project ))
3737
3838 # Create a sorted dictionary of subprojects ordered by build order
3939 si = {p .pyproject_name : i for i , p in enumerate (subprojects )}
@@ -47,6 +47,29 @@ def __init__(self, verbose: bool) -> None:
4747 for i in toposort .toposort_flatten (ti , sort = False )
4848 }
4949
50+ # build_python is for build dependencies, python is for the target environment
51+ # - if crossenv is specified, then we use that instead
52+ self ._build_python = None
53+ self .python = sys .executable
54+
55+ @property
56+ def build_python (self ):
57+ if self ._build_python is None :
58+ self ._build_python = self .python
59+
60+ # try to detect if we're running in crossenv's cross python and
61+ # use the build python instead
62+ if getattr (sys , "cross_compiling" , False ) == True :
63+ pth = pathlib .Path (self ._build_python ).resolve ()
64+ if pth .parts [- 3 :- 1 ] == ("cross" , "bin" ):
65+ self ._build_python = str (
66+ pathlib .Path (
67+ * (pth .parts [:- 3 ] + ("build" , "bin" , pth .parts [- 1 ]))
68+ )
69+ )
70+
71+ return self ._build_python
72+
5073 def git_commit (self , msg : str , * relpath : str ):
5174 subprocess .run (
5275 ["git" , "commit" , "-F" , "-" , "--" ] + list (relpath ),
@@ -102,13 +125,14 @@ def install_build_deps(
102125 external .append (req )
103126
104127 if external :
105- run_pip (
128+ self . run_pip (
106129 "install" ,
107130 * [str (req ) for req in external ],
131+ installing_build_deps = True ,
108132 )
109133
110134 if internal :
111- run_pip (
135+ self . run_pip (
112136 "install" ,
113137 "--no-index" ,
114138 "--find-links" ,
@@ -117,3 +141,11 @@ def install_build_deps(
117141 str (self .other_wheel_path ),
118142 * [str (req ) for req in internal ],
119143 )
144+
145+ def run_pip (self , * args : str , cwd = None , installing_build_deps : bool = False ):
146+ if installing_build_deps :
147+ python = self .build_python
148+ else :
149+ python = self .python
150+
151+ run_cmd (python , "-m" , "pip" , "--disable-pip-version-check" , * args , cwd = cwd )
0 commit comments