-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rework common bootstrap area based on kollivier's work #1496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
from os.path import (join, dirname, isdir, splitext, basename) | ||
from os import listdir | ||
from os import listdir, walk, sep | ||
import sh | ||
import glob | ||
import importlib | ||
import os | ||
import shutil | ||
|
||
from pythonforandroid.logger import (warning, shprint, info, logger, | ||
debug) | ||
|
@@ -11,6 +13,26 @@ | |
from pythonforandroid.recipe import Recipe | ||
|
||
|
||
def copy_files(src_root, dest_root, override=True): | ||
for root, dirnames, filenames in walk(src_root): | ||
for filename in filenames: | ||
subdir = root.replace(src_root, "") | ||
if subdir.startswith(sep): | ||
subdir = subdir[1:] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor suggestion/question:
Which also covers he case were subdir = os.path.normpath(root.replace(src_root, "")) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. normpath won't remove a leading(!) slash, only a trailing one. It could still be used in addition, but I'm pretty certain the point of this code is to make sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yes I misread as |
||
dest_dir = join(dest_root, subdir) | ||
if not os.path.exists(dest_dir): | ||
os.makedirs(dest_dir) | ||
src_file = join(root, filename) | ||
dest_file = join(dest_dir, filename) | ||
if os.path.isfile(src_file): | ||
if override and os.path.exists(dest_file): | ||
os.unlink(dest_file) | ||
if not os.path.exists(dest_file): | ||
shutil.copy(src_file, dest_file) | ||
else: | ||
os.makedirs(dest_file) | ||
|
||
|
||
class Bootstrap(object): | ||
'''An Android project template, containing recipe stuff for | ||
compilation and templated fields for APK info. | ||
|
@@ -77,6 +99,9 @@ def get_build_dir(self): | |
def get_dist_dir(self, name): | ||
return join(self.ctx.dist_dir, name) | ||
|
||
def get_common_dir(self): | ||
return os.path.abspath(join(self.bootstrap_dir, "..", 'common')) | ||
|
||
@property | ||
def name(self): | ||
modname = self.__class__.__module__ | ||
|
@@ -86,9 +111,10 @@ def prepare_build_dir(self): | |
'''Ensure that a build dir exists for the recipe. This same single | ||
dir will be used for building all different archs.''' | ||
self.build_dir = self.get_build_dir() | ||
shprint(sh.cp, '-r', | ||
join(self.bootstrap_dir, 'build'), | ||
self.build_dir) | ||
self.common_dir = self.get_common_dir() | ||
copy_files(join(self.bootstrap_dir, 'build'), self.build_dir) | ||
copy_files(join(self.common_dir, 'build'), self.build_dir, | ||
override=False) | ||
if self.ctx.symlink_java_src: | ||
info('Symlinking java src instead of copying') | ||
shprint(sh.rm, '-r', join(self.build_dir, 'src')) | ||
|
@@ -109,7 +135,7 @@ def run_distribute(self): | |
@classmethod | ||
def list_bootstraps(cls): | ||
'''Find all the available bootstraps and return them.''' | ||
forbidden_dirs = ('__pycache__', ) | ||
forbidden_dirs = ('__pycache__', 'common') | ||
bootstraps_dir = join(dirname(__file__), 'bootstraps') | ||
for name in listdir(bootstraps_dir): | ||
if name in forbidden_dirs: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(call all-subdir-makefiles) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,9 @@ def wrapper_func(self, args): | |
user_ndk_ver=self.ndk_version, | ||
user_ndk_api=self.ndk_api) | ||
dist = self._dist | ||
bs = Bootstrap.get_bootstrap(args.bootstrap, ctx) | ||
# recipes rarely change, but during dev, bootstraps can change from | ||
# build to build, so run prepare_bootstrap even if needs_build is false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment says we run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting! Might be an oversight by @kollivier and maybe it was supposed to have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code wasn't used in the original PR, either, so whatever I was intending to do, I never actually made it happen. I think it can just be removed. From the comment, I suspect that during some tests I found a case where switching the bootstrap didn't trigger a rebuild. Even if that was still true, it's likely not a common case (I was triggering it no doubt because I was testing with different bootstraps!) and can be fixed with a clean rebuild. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, thanks for cleaning this up and getting it running against the latest code! :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kollivier you're welcome, and this would have been infinitely more work without your foundation, so thanks again for starting this! |
||
if dist.needs_build: | ||
if dist.folder_exists(): # possible if the dist is being replaced | ||
dist.delete() | ||
|
@@ -183,7 +186,8 @@ def build_dist_from_args(ctx, dist, args): | |
|
||
ctx.dist_name = bs.distribution.name | ||
ctx.prepare_bootstrap(bs) | ||
ctx.prepare_dist(ctx.dist_name) | ||
if dist.needs_build: | ||
ctx.prepare_dist(ctx.dist_name) | ||
|
||
build_recipes(build_order, python_modules, ctx) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason not to use
shutil.copytree
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shutil.copytree
can't override I think, or at least I am not aware of it. Also, according to Stack Overflow, it can't skip existing files either which is really needed here, and which is what the function does withoverride=False
. So I don't want to rule out that this could be done withshutil
functions somehow, but this seemed to be a good way to do it. I didn't write this code by the way, this is99%
@kollivier 's part - but I would have done something similarThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right, it should work in python3 with a copy_function that ignore existing files, but that option is not present in python2, there is the
ignore
argument, probably with set intersection to ignore, but not sure how much simpler that would be. Nothing wrong with having a specific function anyway.