1
1
from os .path import (join , dirname , isdir , splitext , basename )
2
- from os import listdir
2
+ from os import listdir , walk , sep
3
3
import sh
4
4
import glob
5
5
import importlib
6
+ import os
7
+ import shutil
6
8
7
9
from pythonforandroid .logger import (warning , shprint , info , logger ,
8
10
debug )
11
13
from pythonforandroid .recipe import Recipe
12
14
13
15
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
+
14
36
class Bootstrap (object ):
15
37
'''An Android project template, containing recipe stuff for
16
38
compilation and templated fields for APK info.
@@ -77,6 +99,9 @@ def get_build_dir(self):
77
99
def get_dist_dir (self , name ):
78
100
return join (self .ctx .dist_dir , name )
79
101
102
+ def get_common_dir (self ):
103
+ return os .path .abspath (join (self .bootstrap_dir , ".." , 'common' ))
104
+
80
105
@property
81
106
def name (self ):
82
107
modname = self .__class__ .__module__
@@ -86,9 +111,10 @@ def prepare_build_dir(self):
86
111
'''Ensure that a build dir exists for the recipe. This same single
87
112
dir will be used for building all different archs.'''
88
113
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 )
92
118
if self .ctx .symlink_java_src :
93
119
info ('Symlinking java src instead of copying' )
94
120
shprint (sh .rm , '-r' , join (self .build_dir , 'src' ))
@@ -109,7 +135,7 @@ def run_distribute(self):
109
135
@classmethod
110
136
def list_bootstraps (cls ):
111
137
'''Find all the available bootstraps and return them.'''
112
- forbidden_dirs = ('__pycache__' , )
138
+ forbidden_dirs = ('__pycache__' , 'common' )
113
139
bootstraps_dir = join (dirname (__file__ ), 'bootstraps' )
114
140
for name in listdir (bootstraps_dir ):
115
141
if name in forbidden_dirs :
0 commit comments