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 json
6
6
import importlib
7
+ import os
8
+ import shutil
7
9
8
10
from pythonforandroid .logger import (warning , shprint , info , logger ,
9
11
debug )
12
14
from pythonforandroid .recipe import Recipe
13
15
14
16
17
+ def copy_files (src_root , dest_root ):
18
+ for root , dirnames , filenames in walk (src_root ):
19
+ for filename in filenames :
20
+ subdir = root .replace (src_root , "" )
21
+ if subdir .startswith (sep ):
22
+ subdir = subdir [1 :]
23
+ dest_dir = join (dest_root , subdir )
24
+ if not os .path .exists (dest_dir ):
25
+ os .makedirs (dest_dir )
26
+ src_file = join (root , filename )
27
+ dest_file = join (dest_dir , filename )
28
+ if os .path .isfile (src_file ):
29
+ if os .path .exists (dest_file ):
30
+ os .unlink (dest_file )
31
+ shutil .copy (src_file , dest_file )
32
+ else :
33
+ os .makedirs (dest_file )
34
+
35
+
15
36
class Bootstrap (object ):
16
37
'''An Android project template, containing recipe stuff for
17
38
compilation and templated fields for APK info.
@@ -78,6 +99,9 @@ def get_build_dir(self):
78
99
def get_dist_dir (self , name ):
79
100
return join (self .ctx .dist_dir , name )
80
101
102
+ def get_common_dir (self ):
103
+ return os .path .abspath (join (self .bootstrap_dir , ".." , 'common' ))
104
+
81
105
@property
82
106
def name (self ):
83
107
modname = self .__class__ .__module__
@@ -87,9 +111,9 @@ def prepare_build_dir(self):
87
111
'''Ensure that a build dir exists for the recipe. This same single
88
112
dir will be used for building all different archs.'''
89
113
self .build_dir = self .get_build_dir ()
90
- shprint ( sh . cp , '-r' ,
91
- join (self .bootstrap_dir , 'build' ),
92
- 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 )
93
117
if self .ctx .symlink_java_src :
94
118
info ('Symlinking java src instead of copying' )
95
119
shprint (sh .rm , '-r' , join (self .build_dir , 'src' ))
@@ -121,7 +145,7 @@ def run_distribute(self):
121
145
@classmethod
122
146
def list_bootstraps (cls ):
123
147
'''Find all the available bootstraps and return them.'''
124
- forbidden_dirs = ('__pycache__' , )
148
+ forbidden_dirs = ('__pycache__' , 'common' )
125
149
bootstraps_dir = join (dirname (__file__ ), 'bootstraps' )
126
150
for name in listdir (bootstraps_dir ):
127
151
if name in forbidden_dirs :
0 commit comments