1414from pythonforandroid .recipe import Recipe
1515
1616
17- def copy_files (src_root , dest_root , override = True ):
17+ def copy_files (src_root , dest_root , override = True , symlink = False ):
1818 for root , dirnames , filenames in walk (src_root ):
1919 for filename in filenames :
2020 subdir = normpath (root .replace (src_root , "" ))
@@ -29,7 +29,10 @@ def copy_files(src_root, dest_root, override=True):
2929 if override and os .path .exists (dest_file ):
3030 os .unlink (dest_file )
3131 if not os .path .exists (dest_file ):
32- shutil .copy (src_file , dest_file )
32+ if symlink :
33+ os .symlink (src_file , dest_file )
34+ else :
35+ shutil .copy (src_file , dest_file )
3336 else :
3437 os .makedirs (dest_file )
3538
@@ -109,7 +112,7 @@ def check_recipe_choices(self):
109112 and optional dependencies are being used,
110113 and returns a list of these.'''
111114 recipes = []
112- built_recipes = self .ctx .recipe_build_order
115+ built_recipes = self .ctx .recipe_build_order or []
113116 for recipe in self .recipe_depends :
114117 if isinstance (recipe , (tuple , list )):
115118 for alternative in recipe :
@@ -137,21 +140,27 @@ def name(self):
137140 modname = self .__class__ .__module__
138141 return modname .split ("." , 2 )[- 1 ]
139142
143+ def get_bootstrap_dirs (self ):
144+ """get all bootstrap directories, following the MRO path"""
145+
146+ # get all bootstrap names along the __mro__, cutting off Bootstrap and object
147+ classes = self .__class__ .__mro__ [:- 2 ]
148+ bootstrap_names = [cls .name for cls in classes ] + ['common' ]
149+ bootstrap_dirs = [
150+ join (self .ctx .root_dir , 'bootstraps' , bootstrap_name )
151+ for bootstrap_name in reversed (bootstrap_names )
152+ ]
153+ return bootstrap_dirs
154+
140155 def prepare_build_dir (self ):
141- '''Ensure that a build dir exists for the recipe. This same single
142- dir will be used for building all different archs.'''
156+ """Ensure that a build dir exists for the recipe. This same single
157+ dir will be used for building all different archs."""
158+ bootstrap_dirs = self .get_bootstrap_dirs ()
159+ # now do a cumulative copy of all bootstrap dirs
143160 self .build_dir = self .get_build_dir ()
144- self .common_dir = self .get_common_dir ()
145- copy_files (join (self .bootstrap_dir , 'build' ), self .build_dir )
146- copy_files (join (self .common_dir , 'build' ), self .build_dir ,
147- override = False )
148- if self .ctx .symlink_java_src :
149- info ('Symlinking java src instead of copying' )
150- shprint (sh .rm , '-r' , join (self .build_dir , 'src' ))
151- shprint (sh .mkdir , join (self .build_dir , 'src' ))
152- for dirn in listdir (join (self .bootstrap_dir , 'build' , 'src' )):
153- shprint (sh .ln , '-s' , join (self .bootstrap_dir , 'build' , 'src' , dirn ),
154- join (self .build_dir , 'src' ))
161+ for bootstrap_dir in bootstrap_dirs :
162+ copy_files (join (bootstrap_dir , 'build' ), self .build_dir , symlink = self .ctx .symlink_bootstrap_files )
163+
155164 with current_directory (self .build_dir ):
156165 with open ('project.properties' , 'w' ) as fileh :
157166 fileh .write ('target=android-{}' .format (self .ctx .android_api ))
0 commit comments