@@ -231,3 +231,125 @@ def test_install_libraries(self, mock_install_libs, mock_get_libraries):
231
231
mock_install_libs .assert_called_once_with (
232
232
arch , * mock_get_libraries .return_value
233
233
)
234
+
235
+
236
+ class TesSTLRecipe (BaseClassSetupBootstrap , unittest .TestCase ):
237
+ def setUp (self ):
238
+ """
239
+ Initialize a Context with a Bootstrap and a Distribution to properly
240
+ test a recipe which depends on android's STL library, to do so we reuse
241
+ `BaseClassSetupBootstrap`
242
+ """
243
+ super (TesSTLRecipe , self ).setUp ()
244
+ self .ctx .bootstrap = Bootstrap ().get_bootstrap ('sdl2' , self .ctx )
245
+ self .setUp_distribution_with_bootstrap (self .ctx .bootstrap )
246
+ self .ctx .python_recipe = Recipe .get_recipe ('python3' , self .ctx )
247
+
248
+ def test_get_stl_lib_dir (self ):
249
+ """
250
+ Test that :meth:`~pythonforandroid.recipe.STLRecipe.get_stl_lib_dir`
251
+ returns the expected path for the stl library
252
+ """
253
+ arch = ArchAarch_64 (self .ctx )
254
+ recipe = Recipe .get_recipe ('icu' , self .ctx )
255
+ self .assertTrue (recipe .need_stl_shared )
256
+ self .assertEqual (
257
+ recipe .get_stl_lib_dir (arch ),
258
+ os .path .join (
259
+ self .ctx .ndk_dir ,
260
+ 'sources/cxx-stl/llvm-libc++/libs/{arch}' .format (
261
+ arch = arch .arch
262
+ ),
263
+ ),
264
+ )
265
+
266
+ @mock .patch ("pythonforandroid.archs.glob" )
267
+ @mock .patch ('pythonforandroid.archs.find_executable' )
268
+ @mock .patch ('pythonforandroid.build.ensure_dir' )
269
+ def test_get_recipe_env_with (
270
+ self , mock_ensure_dir , mock_find_executable , mock_glob
271
+ ):
272
+ """
273
+ Test that :meth:`~pythonforandroid.recipe.STLRecipe.get_recipe_env`
274
+ returns some expected keys and values.
275
+
276
+ .. note:: We don't check all the env variables, only those one specific
277
+ of :class:`~pythonforandroid.recipe.STLRecipe`, the others
278
+ should be tested in the proper test.
279
+ """
280
+ expected_compiler = (
281
+ "/opt/android/android-ndk/toolchains/"
282
+ "llvm/prebuilt/linux-x86_64/bin/clang"
283
+ )
284
+ mock_find_executable .return_value = expected_compiler
285
+ mock_ensure_dir .return_value = True
286
+ mock_glob .return_value = ["llvm" ]
287
+
288
+ arch = ArchAarch_64 (self .ctx )
289
+ recipe = Recipe .get_recipe ('icu' , self .ctx )
290
+ assert recipe .need_stl_shared , True
291
+ env = recipe .get_recipe_env (arch )
292
+ # check `find_executable` calls
293
+ mock_find_executable .assert_called_once_with (
294
+ expected_compiler , path = os .environ ['PATH' ]
295
+ )
296
+ self .assertIsInstance (env , dict )
297
+
298
+ # check `CPPFLAGS`
299
+ expected_cppflags = {
300
+ '-I{stl_include}' .format (stl_include = recipe .stl_include_dir )
301
+ }
302
+ self .assertIn ('CPPFLAGS' , env )
303
+ for flags in expected_cppflags :
304
+ self .assertIn (flags , env ['CPPFLAGS' ])
305
+
306
+ # check `LIBS`
307
+ self .assertIn ('LDFLAGS' , env )
308
+ self .assertIn ('-L' + recipe .get_stl_lib_dir (arch ), env ['LDFLAGS' ])
309
+ self .assertIn ('LIBS' , env )
310
+ self .assertIn ('-lc++_shared' , env ['LIBS' ])
311
+
312
+ # check `CXXFLAGS` and `CXX`
313
+ for flag in {'CXXFLAGS' , 'CXX' }:
314
+ self .assertIn (flag , env )
315
+ self .assertIn ('-frtti -fexceptions' , env [flag ])
316
+
317
+ @mock .patch ('pythonforandroid.recipe.Recipe.install_libs' )
318
+ @mock .patch ('pythonforandroid.recipe.isfile' )
319
+ @mock .patch ('pythonforandroid.build.ensure_dir' )
320
+ def test_install_stl_lib (
321
+ self , mock_ensure_dir , mock_isfile , mock_install_lib
322
+ ):
323
+ """
324
+ Test that :meth:`~pythonforandroid.recipe.STLRecipe.install_stl_lib`,
325
+ calls the method :meth:`~pythonforandroid.recipe.Recipe.install_libs`
326
+ with the proper arguments: a subclass of
327
+ :class:`~pythonforandroid.archs.Arch` and our stl lib
328
+ (:attr:`~pythonforandroid.recipe.STLRecipe.stl_lib_name`)
329
+ """
330
+ mock_ensure_dir .return_value = True
331
+ mock_isfile .return_value = False
332
+ mock_install_lib .return_value = True
333
+
334
+ arch = ArchAarch_64 (self .ctx )
335
+ recipe = Recipe .get_recipe ('icu' , self .ctx )
336
+ recipe .ctx = self .ctx
337
+ assert recipe .need_stl_shared , True
338
+ recipe .install_stl_lib (arch )
339
+ mock_install_lib .assert_called_once_with (
340
+ arch ,
341
+ '{ndk_dir}/sources/cxx-stl/llvm-libc++/'
342
+ 'libs/{arch}/lib{stl_lib}.so' .format (
343
+ ndk_dir = self .ctx .ndk_dir ,
344
+ arch = arch .arch ,
345
+ stl_lib = recipe .stl_lib_name ,
346
+ ),
347
+ )
348
+
349
+ @mock .patch ('pythonforandroid.recipe.Recipe.install_stl_lib' )
350
+ def test_postarch_build (self , mock_install_stl_lib ):
351
+ arch = ArchAarch_64 (self .ctx )
352
+ recipe = Recipe .get_recipe ('icu' , self .ctx )
353
+ assert recipe .need_stl_shared , True
354
+ recipe .postbuild_arch (arch )
355
+ mock_install_stl_lib .assert_called_once_with (arch )
0 commit comments