8000 Common bootstrap to be shared across bootstraps · kivy/python-for-android@4e55085 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4e55085

Browse files
kollivierAndreMiras
authored andcommitted
Common bootstrap to be shared across bootstraps
This is the first step to fix DRY across bootstraps, refs #988
1 parent 99475fc commit 4e55085

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+40
-10
lines changed

pythonforandroid/bootstrap.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from os.path import (join, dirname, isdir, splitext, basename)
2-
from os import listdir
2+
from os import listdir, walk, sep
33
import sh
44
import glob
55
import json
66
import importlib
7+
import os
8+
import shutil
79

810
from pythonforandroid.logger import (warning, shprint, info, logger,
911
debug)
@@ -12,6 +14,25 @@
1214
from pythonforandroid.recipe import Recipe
1315

1416

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+
1536
class Bootstrap(object):
1637
'''An Android project template, containing recipe stuff for
1738
compilation and templated fields for APK info.
@@ -78,6 +99,9 @@ def get_build_dir(self):
7899
def get_dist_dir(self, name):
79100
return join(self.ctx.dist_dir, name)
80101

102+
def get_common_dir(self):
103+
return os.path.abspath(join(self.bootstrap_dir, "..", 'common'))
104+
81105
@property
82106
def name(self):
83107
modname = self.__class__.__module__
@@ -87,9 +111,9 @@ def prepare_build_dir(self):
87111
'''Ensure that a build dir exists for the recipe. This same single
88112
dir will be used for building all different archs.'''
89113
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)
93117
if self.ctx.symlink_java_src:
94118
info('Symlinking java src instead of copying')
95119
shprint(sh.rm, '-r', join(self.build_dir, 'src'))
@@ -121,7 +145,7 @@ def run_distribute(self):
121145
@classmethod
122146
def list_bootstraps(cls):
123147
'''Find all the available bootstraps and return them.'''
124-
forbidden_dirs = ('__pycache__', )
148+
forbidden_dirs = ('__pycache__', 'common')
125149
bootstraps_dir = join(dirname(__file__), 'bootstraps')
126150
for name in listdir(bootstraps_dir):
127151
if name in forbidden_dirs:

0 commit comments

Comments
 (0)
0