11from os .path import (join , dirname , isdir , splitext , basename )
2- from os import listdir
2+ from os import listdir , walk , sep
33import sh
44import glob
55import importlib
6+ import os
7+ import shutil
68
79from pythonforandroid .logger import (warning , shprint , info , logger ,
810 debug )
1113from pythonforandroid .recipe import Recipe
1214
1315
16+ def copy_files (src_root , dest_root , override = True ):
17+ for root , dirnames , filenames in walk (src_root ):
18+ for filename in filenames :
19+ subdir = root .replace (src_root , "" )
20+ if subdir .startswith (sep ):
21+ subdir = subdir [1 :]
22+ dest_dir = join (dest_root , subdir )
23+ if not os .path .exists (dest_dir ):
24+ os .makedirs (dest_dir )
25+ src_file = join (root , filename )
26+ dest_file = join (dest_dir , filename )
27+ if os .path .isfile (src_file ):
28+ if override and os .path .exists (dest_file ):
29+ os .unlink (dest_file )
30+ if not os .path .exists (dest_file ):
31+ shutil .copy (src_file , dest_file )
32+ else :
33+ os .makedirs (dest_file )
34+
35+
1436class Bootstrap (object ):
1537 '''An Android project template, containing recipe stuff for
1638 compilation and templated fields for APK info.
@@ -77,6 +99,9 @@ def get_build_dir(self):
7799 def get_dist_dir (self , name ):
78100 return join (self .ctx .dist_dir , name )
79101
102+ def get_common_dir (self ):
103+ return os .path .abspath (join (self .bootstrap_dir , ".." , 'common' ))
104+
80105 @property
81106 def name (self ):
82107 modname = self .__class__ .__module__
@@ -86,9 +111,10 @@ def prepare_build_dir(self):
86111 '''Ensure that a build dir exists for the recipe. This same single
87112 dir will be used for building all different archs.'''
88113 self .build_dir = self .get_build_dir ()
89- shprint (sh .cp , '-r' ,
90- join (self .bootstrap_dir , 'build' ),
91- self .build_dir )
114+ self .common_dir = self .get_common_dir ()
115+ copy_files (join (self .bootstrap_dir , 'build' ), self .build_dir )
116+ copy_files (join (self .common_dir , 'build' ), self .build_dir ,
117+ override = False )
92118 if self .ctx .symlink_java_src :
93119 info ('Symlinking java src instead of copying' )
94120 shprint (sh .rm , '-r' , join (self .build_dir , 'src' ))
@@ -109,7 +135,7 @@ def run_distribute(self):
109135 @classmethod
110136 def list_bootstraps (cls ):
111137 '''Find all the available bootstraps and return them.'''
112- forbidden_dirs = ('__pycache__' , )
138+ forbidden_dirs = ('__pycache__' , 'common' )
113139 bootstraps_dir = join (dirname (__file__ ), 'bootstraps' )
114140 for name in listdir (bootstraps_dir ):
115141 if name in forbidden_dirs :
0 commit comments