@@ -61,6 +61,16 @@ def get_directory(filename):
61
61
exit (1 )
62
62
63
63
64
+ import contextlib
65
+ @contextlib .contextmanager
66
+ def current_directory (new_dir ):
67
+ cur_dir = getcwd ()
68
+ print ('Switching current directory to' , new_dir )
69
+ chdir (new_dir )
70
+ yield
71
+ print ('Directory context ended, switching to' , cur_dir )
72
+ chdir (cur_dir )
73
+
64
74
65
75
66
76
# def cache_execution(f):
@@ -198,7 +208,7 @@ def get_env(self):
198
208
toolchain_prefix = 'arm-linux-androideabi'
199
209
toolchain_version = '4.4.3'
200
210
elif self .ctx .ndk_ver [:2 ] == 'r9' :
201
- toolchain_prefix == 'arm-linux-androideabi'
211
+ toolchain_prefix = 'arm-linux-androideabi'
202
212
toolchain_version = '4.9'
203
213
else :
204
214
print ('Error: NDK not supported by these tools?' )
@@ -207,7 +217,7 @@ def get_env(self):
207
217
env ['TOOLCHAIN_PREFIX' ] = toolchain_prefix
208
218
env ['TOOLCHAIN_VERSION' ] = toolchain_version
209
219
210
- env ['PATH' ] = "{sdk_dir}/toolchains/{toolchain_prefix}-{toolchain_version}/prebuilt/{py_platform}-x86/bin/:{ndk_dir}/toolchains/{toolchain_prefix}-{toolchain_version}/prebuilt/{py_platform}-x86_64/bin/:{ndk_dir}:{sdk_dir}/tools:{path}" .format (sdk_dir = sdk_dir , ndk_dir = ndk_dir , toolchain_prefix = toolchain_prefix , toolchain_version = toolchain_version , py_platform = py_platform , path = environ .get ('PATH' ))
220
+ env ['PATH' ] = "{sdk_dir}/toolchains/{toolchain_prefix}-{toolchain_version}/prebuilt/{py_platform}-x86/bin/:{ndk_dir}/toolchains/{toolchain_prefix}-{toolchain_version}/prebuilt/{py_platform}-x86_64/bin/:{ndk_dir}:{sdk_dir}/tools:{path}" .format (sdk_dir = self . ctx . sdk_dir , ndk_dir = self . ctx . ndk_dir , toolchain_prefix = toolchain_prefix , toolchain_version = toolchain_version , py_platform = py_platform , path = environ .get ('PATH' ))
211
221
212
222
env ['CC' ] = '{toolchain_prefix}-gcc {cflags}' .format (
213
223
toolchain_prefix = toolchain_prefix ,
@@ -885,30 +895,30 @@ def extract(self):
885
895
# self.extract_file(self.archive_fn, build_dir)
886
896
887
897
# @cache_execution
888
- def build (self , arch ):
889
- self .build_dir = self .get_build_dir (arch .arch )
890
- if self .has_marker ("building" ):
891
- print ("Warning: {} build for {} has been incomplete" .format (
892
- self .name , arch .arch ))
893
- print ("Warning: deleting the build and restarting." )
894
- shutil .rmtree (self .build_dir )
895
- self .extract_arch (arch .arch )
896
-
897
- if self .has_marker ("build_done" ):
898
- print ("Build python for {} already done." .format (arch .arch ))
899
- return
900
-
901
- self .set_marker ("building" )
902
-
903
- chdir (self .build_dir )
904
- print ("Prebuild {} for {}" .format (self .name , arch .arch ))
905
- self .prebuild_arch (arch )
906
- print ("Build {} for {}" .format (self .name , arch .arch ))
907
- self .build_arch (arch )
908
- print ("Postbuild {} for {}" .format (self .name , arch .arch ))
909
- self .postbuild_arch (arch )
910
- self .delete_marker ("building" )
911
- self .set_marker ("build_done" )
898
+ # def build(self, arch):
899
+ # self.build_dir = self.get_build_dir(arch.arch)
900
+ # if self.has_marker("building"):
901
+ # print("Warning: {} build for {} has been incomplete".format(
902
+ # self.name, arch.arch))
903
+ # print("Warning: deleting the build and restarting.")
904
+ # shutil.rmtree(self.build_dir)
905
+ # self.extract_arch(arch.arch)
906
+
907
+ # if self.has_marker("build_done"):
908
+ # print("Build python for {} already done.".format(arch.arch))
909
+ # return
910
+
911
+ # self.set_marker("building")
912
+
913
+ # chdir(self.build_dir)
914
+ # print("Prebuild {} for {}".format(self.name, arch.arch))
915
+ # self.prebuild_arch(arch)
916
+ # print("Build {} for {}".format(self.name, arch.arch))
917
+ # self.build_arch(arch)
918
+ # print("Postbuild {} for {}".format(self.name, arch.arch))
919
+ # self.postbuild_arch(arch)
920
+ # self.delete_marker("building")
921
+ # self.set_marker("build_done")
912
922
913
923
# @cache_execution
914
924
def build_all (self ):
@@ -949,6 +959,9 @@ def prebuild(self):
949
959
# this to support
950
960
# multiple archs
951
961
962
+ def build (self ):
963
+ self .build_arch (self .ctx .archs [0 ]) # Same here!
964
+
952
965
def prebuild_arch (self , arch ):
953
966
prebuild = "prebuild_{}" .format (arch .arch )
954
967
if hasattr (self , prebuild ):
@@ -1097,68 +1110,69 @@ def prepare_build_dir(self, ctx):
1097
1110
1098
1111
1099
1112
class PythonRecipe (Recipe ):
1113
+ pass
1100
1114
# @cache_execution
1101
- def install (self ):
1102
- self .install_python_package ()
1103
- self .reduce_python_package ()
1115
+ # def install(self):
1116
+ # self.install_python_package()
1117
+ # self.reduce_python_package()
1104
1118
1105
- def install_python_package (self , name = None , env = None , is_dir = True ):
1106
- """Automate the installation of a Python package into the target
1107
- site-packages.
1119
+ # def install_python_package(self, name=None, env=None, is_dir=True):
1120
+ # """Automate the installation of a Python package into the target
1121
+ # site-packages.
1108
1122
1109
- It will works with the first filtered_archs, and the name of the recipe.
1110
- """
1111
- arch = self .filtered_archs [0 ]
1112
- if name is None :
1113
- name = self .name
1114
- if env is None :
1115
- env = self .get_recipe_env (arch )
1116
-
1117
- print ("Install {} into the site-packages" .format (name ))
1118
- build_dir = self .get_build_dir (arch .arch )
1119
- chdir (build_dir )
1120
- hostpython = sh .Command (self .ctx .hostpython )
1121
- iosbuild = join (build_dir , "iosbuild" )
1122
- shprint (hostpython , "setup.py" , "install" , "-O2" ,
1123
- "--prefix" , iosbuild ,
1124
- _env = env )
1125
- dest_dir = join (self .ctx .site_packages_dir , name )
1126
- if is_dir :
1127
- if exists (dest_dir ):
1128
- shutil .rmtree (dest_dir )
1129
- func = shutil .copytree
1130
- else :
1131
- func = shutil .copy
1132
- func (
1133
- join (iosbuild , "lib" ,
1134
- self .ctx .python_ver_dir , "site-packages" , name ),
1135
- dest_dir )
1136
-
1137
- def reduce_python_package (self ):
1138
- """Feel free to remove things you don't want in the final
1139
- site-packages.
1140
- """
1141
- pass
1123
+ # It will works with the first filtered_archs, and the name of the recipe.
1124
+ # """
1125
+ # arch = self.filtered_archs[0]
1126
+ # if name is None:
1127
+ # name = self.name
1128
+ # if env is None:
1129
+ # env = self.get_recipe_env(arch)
1130
+
1131
+ # print("Install {} into the site-packages".format(name))
1132
+ # build_dir = self.get_build_dir(arch.arch)
1133
+ # chdir(build_dir)
1134
+ # hostpython = sh.Command(self.ctx.hostpython)
1135
+ # iosbuild = join(build_dir, "iosbuild")
1136
+ # shprint(hostpython, "setup.py", "install", "-O2",
1137
+ # "--prefix", iosbuild,
1138
+ # _env=env)
1139
+ # dest_dir = join(self.ctx.site_packages_dir, name)
1140
+ # if is_dir:
1141
+ # if exists(dest_dir):
1142
+ # shutil.rmtree(dest_dir)
1143
+ # func = shutil.copytree
1144
+ # else:
1145
+ # func = shutil.copy
1146
+ # func(
1147
+ # join(iosbuild, "lib",
1148
+ # self.ctx.python_ver_dir, "site-packages", name),
1149
+ # dest_dir)
1150
+
1151
+ # def reduce_python_package(self):
1152
+ # """Feel free to remove things you don't want in the final
1153
+ # site-packages.
1154
+ # """
1155
+ # pass
1142
1156
1143
1157
1144
1158
class CythonRecipe (PythonRecipe ):
1145
1159
pre_build_ext = False
1146
1160
cythonize = True
1147
1161
1148
- def cythonize_file (self , filename ):
1149
- if filename .startswith (self .build_dir ):
1150
- filename = filename [len (self .build_dir ) + 1 :]
1151
- print ("Cythonize {}" .format (filename ))
1152
- cmd = sh .Command (join (self .ctx .root_dir , "tools" , "cythonize.py" ))
1153
- shprint (cmd , filename )
1154
-
1155
- def cythonize_build (self ):
1156
- if not self .cythonize :
1157
- return
1158
- root_dir = self .build_dir
1159
- for root , dirnames , filenames in walk (root_dir ):
1160
- for filename in fnmatch .filter (filenames , "*.pyx" ):
1161
- self .cythonize_file (join (root , filename ))
1162
+ # def cythonize_file(self, filename):
1163
+ # if filename.startswith(self.build_dir):
1164
+ # filename = filename[len(self.build_dir) + 1:]
1165
+ # print("Cythonize {}".format(filename))
1166
+ # cmd = sh.Command(join(self.ctx.root_dir, "tools", "cythonize.py"))
1167
+ # shprint(cmd, filename)
1168
+
1169
+ # def cythonize_build(self):
1170
+ # if not self.cythonize:
1171
+ # return
1172
+ # root_dir = self.build_dir
1173
+ # for root, dirnames, filenames in walk(root_dir):
1174
+ # for filename in fnmatch.filter(filenames, "*.pyx"):
1175
+ # self.cythonize_file(join(root, filename))
1162
1176
1163
1177
def biglink (self ):
1164
1178
dirs = []
@@ -1168,28 +1182,28 @@ def biglink(self):
1168
1182
cmd = sh .Command (join (self .ctx .root_dir , "tools" , "biglink" ))
1169
1183
shprint (cmd , join (self .build_dir , "lib{}.a" .format (self .name )), * dirs )
1170
1184
1171
- def get_recipe_env (self , arch ):
1172
- env = super (CythonRecipe , self ).get_recipe_env (arch )
1173
- env ["KIVYIOSROOT" ] = self .ctx .root_dir
1174
- env ["IOSSDKROOT" ] = arch .sysroot
1175
- env ["LDSHARED" ] = join (self .ctx .root_dir , "tools" , "liblink" )
1176
- env ["ARM_LD" ] = env ["LD" ]
1177
- env ["ARCH" ] = arch .arch
1178
- return env
1179
-
1180
- def build_arch (self , arch ):
1181
- build_env = self .get_recipe_env (arch )
1182
- hostpython = sh .Command (self .ctx .hostpython )
1183
- if self .pre_build_ext :
1184
- try :
1185
- shprint (hostpython , "setup.py" , "build_ext" , "-g" ,
1186
- _env = build_env )
1187
- except :
1188
- pass
1189
- self .cythonize_build ()
1190
- shprint (hostpython , "setup.py" , "build_ext" , "-g" ,
1191
- _env = build_env )
1192
- self .biglink ()
1185
+ # def get_recipe_env(self, arch):
1186
+ # env = super(CythonRecipe, self).get_recipe_env(arch)
1187
+ # env["KIVYIOSROOT"] = self.ctx.root_dir
1188
+ # env["IOSSDKROOT"] = arch.sysroot
1189
+ # env["LDSHARED"] = join(self.ctx.root_dir, "tools", "liblink")
1190
+ # env["ARM_LD"] = env["LD"]
1191
+ # env["ARCH"] = arch.arch
1192
+ # return env
1193
+
1194
+ # def build_arch(self, arch):
1195
+ # build_env = self.get_recipe_env(arch)
1196
+ # hostpython = sh.Command(self.ctx.hostpython)
1197
+ # if self.pre_build_ext:
1198
+ # try:
1199
+ # shprint(hostpython, "setup.py", "build_ext", "-g",
1200
+ # _env=build_env)
1201
+ # except:
1202
+ # pass
1203
+ # self.cythonize_build()
1204
+ # shprint(hostpython, "setup.py", "build_ext", "-g",
1205
+ # _env=build_env)
1206
+ # self.biglink()
1193
1207
1194
1208
1195
1209
def build_recipes (names , ctx ):
@@ -1221,6 +1235,7 @@ def build_recipes(names, ctx):
1221
1235
recipe_loaded .append (name )
1222
1236
build_order = list (graph .find_order ())
1223
1237
print ("Build order is {}" .format (build_order ))
1238
+ ctx .recipe_build_order = build_order
1224
1239
1225
1240
recipes = [Recipe .get_recipe (name , ctx ) for name in build_order ]
1226
1241
@@ -1236,6 +1251,9 @@ def build_recipes(names, ctx):
1236
1251
recipe .prebuild ()
1237
1252
1238
1253
# 3) build packages
1254
+ for recipe in recipes :
1255
+ recipe .build ()
1256
+
1239
1257
1240
1258
return
1241
1259
for recipe in recipes :
0 commit comments