@@ -82,15 +82,30 @@ def run(command, *, host=None, env=None, log=True, **kwargs):
82
82
if env is None :
83
83
env = os .environ .copy ()
84
84
if host :
85
- env .update (android_env (host ))
85
+ # The -I and -L arguments used when building Python should not be reused
86
+ # when building third-party extension modules, so pass them via the
87
+ # NODIST environment variables.
88
+ host_env = android_env (host )
89
+ for name in ["CFLAGS" ,"CXXFLAGS" ,"LDFLAGS" ]:
90
+ flags = []
91
+ nodist = []
92
+ for word in host_env [name ].split ():
93
+ (nodist if word .startswith (("-I" ,"-L" ))else flags ).append (word )
94
+ host_env [name ]= " " .join (flags )
95
+ host_env [f"{ name } _NODIST" ]= " " .join (nodist )
96
+
97
+ print_env (host_env )
98
+ env .update (host_env )
86
99
87
100
if log :
88
101
print (">" ," " .join (map (str ,command )))
89
102
return subprocess .run (command ,env = env ,** kwargs )
90
103
91
104
92
- def print_env (context ):
93
- android_env (getattr (context ,"host" ,None ))
105
+ # Format the environment so it can be pasted into a shell.
106
+ def print_env (env ):
107
+ for key ,value in sorted (env .items ()):
108
+ print (f"export{ key } ={ shlex .quote (value )} " )
94
109
95
110
96
111
def android_env (host ):
@@ -126,10 +141,6 @@ def android_env(host):
126
141
if not env :
127
142
raise ValueError (f"Found no variables in{ env_script .name } output:\n "
128
143
+ env_output )
129
-
130
- # Format the environment so it can be pasted into a shell.
131
- for key ,value in sorted (env .items ()):
132
- print (f"export{ key } ={ shlex .quote (value )} " )
133
144
return env
134
145
135
146
@@ -220,9 +231,12 @@ def make_host_python(context):
220
231
for pattern in ("include/python*" ,"lib/libpython*" ,"lib/python*" ):
221
232
delete_glob (f"{ prefix_dir } /{ pattern } " )
222
233
234
+ # The Android environment variables were already captured in the Makefile by
235
+ # `configure`, and passing them again when running `make` may cause some
236
+ # flags to be duplicated. So we don't use the `host` argument here.
223
237
os .chdir (host_dir )
224
- run (["make" ,"-j" ,str (os .cpu_count ())], host = context . host )
225
- run (["make" ,"install" ,f"prefix={ prefix_dir } " ], host = context . host )
238
+ run (["make" ,"-j" ,str (os .cpu_count ())])
239
+ run (["make" ,"install" ,f"prefix={ prefix_dir } " ])
226
240
227
241
228
242
def build_all (context ):
@@ -628,6 +642,10 @@ def package(context):
628
642
print (f"Wrote{ package_path } " )
629
643
630
644
645
+ def env (context ):
646
+ print_env (android_env (getattr (context ,"host" ,None )))
647
+
648
+
631
649
# Handle SIGTERM the same way as SIGINT. This ensures that if we're terminated
632
650
# by the buildbot worker, we'll make an attempt to clean up our subprocesses.
633
651
def install_signal_handler ():
@@ -717,7 +735,7 @@ def main():
717
735
"build-testbed" :build_testbed ,
718
736
"test" :run_testbed ,
719
737
"package" :package ,
720
- "env" :print_env ,
738
+ "env" :env ,
721
739
}
722
740
723
741
try :