Skip to content

Commit 8251488

Browse files
committed
Avoid some DRY issues + minor fixes + version bump
1 parent 2abaa31 commit 8251488

Some content is hidden

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

56 files changed

+77
-713
lines changed

pythonforandroid/bootstrap.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
rmdir, move)
1515
from pythonforandroid.recipe import Recipe
1616

17+
SDL_BOOTSTRAPS = ("sdl2", "sdl3")
18+
1719

1820
def copy_files(src_root, dest_root, override=True, symlink=False):
1921
for root, dirnames, filenames in walk(src_root):
@@ -150,7 +152,7 @@ def get_bootstrap_dirs(self):
150152
return bootstrap_dirs
151153

152154
def _copy_in_final_files(self):
153-
if self.name in ["sdl2", "sdl3"]:
155+
if self.name in SDL_BOOTSTRAPS:
154156
# Get the paths for copying SDL's java source code:
155157
sdl_recipe = Recipe.get_recipe(self.name, self.ctx)
156158
sdl_build_dir = sdl_recipe.get_jni_dir()
@@ -193,7 +195,7 @@ def assemble_distribution(self):
193195
@classmethod
194196
def all_bootstraps(cls):
195197
'''Find all the available bootstraps and return them.'''
196-
forbidden_dirs = ('__pycache__', 'common')
198+
forbidden_dirs = ('__pycache__', 'common', '_sdl_common')
197199
bootstraps_dir = join(dirname(__file__), 'bootstraps')
198200
result = set()
199201
for name in listdir(bootstraps_dir):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from os.path import join
2+
3+
import sh
4+
5+
from pythonforandroid.toolchain import (
6+
Bootstrap, shprint, current_directory, info, info_main)
7+
from pythonforandroid.util import ensure_dir, rmdir
8+
9+
10+
class SDLGradleBootstrap(Bootstrap):
11+
name = "_sdl_common"
12+
13+
recipe_depends = []
14+
15+
def assemble_distribution(self):
16+
info_main("# Creating Android project ({})".format(self.name))
17+
18+
rmdir(self.dist_dir)
19+
info("Copying SDL/gradle build")
20+
shprint(sh.cp, "-r", self.build_dir, self.dist_dir)
21+
22+
# either the build use environment variable (ANDROID_HOME)
23+
# or the local.properties if exists
24+
with current_directory(self.dist_dir):
25+
with open('local.properties', 'w') as fileh:
26+
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
27+
28+
with current_directory(self.dist_dir):
29+
info("Copying Python distribution")
30+
31+
self.distribute_javaclasses(self.ctx.javaclass_dir,
32+
dest_dir=join("src", "main", "java"))
33+
34+
for arch in self.ctx.archs:
35+
python_bundle_dir = join(f'_python_bundle__{arch.arch}', '_python_bundle')
36+
ensure_dir(python_bundle_dir)
37+
38+
self.distribute_libs(arch, [self.ctx.get_libs_dir(arch.arch)])
39+
site_packages_dir = self.ctx.python_recipe.create_python_bundle(
40+
join(self.dist_dir, python_bundle_dir), arch)
41+
if not self.ctx.with_debug_symbols:
42+
self.strip_libraries(arch)
43+
self.fry_eggs(site_packages_dir)
44+
45+
if 'sqlite3' not in self.ctx.recipe_build_order:
46+
with open('blacklist.txt', 'a') as fileh:
47+
fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')
48+
49+
super().assemble_distribution()

pythonforandroid/bootstraps/common/build/build.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from fnmatch import fnmatch
2121
import jinja2
2222

23+
from pythonforandroid.bootstrap import SDL_BOOTSTRAPS
2324
from pythonforandroid.util import rmdir, ensure_dir, max_build_tool_version
2425

2526

@@ -220,6 +221,10 @@ def compile_py_file(python_file, optimize_python=True):
220221
return ".".join([os.path.splitext(python_file)[0], "pyc"])
221222

222223

224+
def is_sdl_bootstrap():
225+
return get_bootstrap_name() in SDL_BOOTSTRAPS
226+
227+
223228
def make_package(args):
224229
# If no launcher is specified, require a main.py/main.pyc:
225230
if (get_bootstrap_name() != "sdl" or args.launcher is None) and \
@@ -541,7 +546,7 @@ def make_package(args):
541546
"debug": "debug" in args.build_mode,
542547
"native_services": args.native_services
543548
}
544-
if get_bootstrap_name() in ["sdl2", "sdl3"]:
549+
if is_sdl_bootstrap():
545550
render_args["url_scheme"] = url_scheme
546551

547552
render(
@@ -596,7 +601,7 @@ def make_package(args):
596601
"args": args,
597602
"private_version": hashlib.sha1(private_version.encode()).hexdigest()
598603
}
599-
if get_bootstrap_name() in ["sdl2", "sdl3"]:
604+
if is_sdl_bootstrap():
600605
render_args["url_scheme"] = url_scheme
601606
render(
602607
'strings.tmpl.xml',
@@ -769,7 +774,7 @@ def create_argument_parser():
769774
ap.add_argument('--private', dest='private',
770775
help='the directory with the app source code files' +
771776
' (containing your main.py entrypoint)',
772-
required=(get_bootstrap_name() not in ["sdl2", "sdl3"]))
777+
required=(not is_sdl_bootstrap()))
773778
ap.add_argument('--package', dest='package',
774779
help=('The name of the java package the project will be'
775780
' packaged under.'),
@@ -787,7 +792,7 @@ def create_argument_parser():
787792
'same number of groups of numbers as previous '
788793
'versions.'),
789794
required=True)
790-
if get_bootstrap_name() in ["sdl2", "sdl3"]:
795+
if is_sdl_bootstrap():
791796
ap.add_argument('--launcher', dest='launcher', action='store_true',
792797
help=('Provide this argument to build a multi-app '
793798
'launcher, rather than a single app.'))
@@ -1044,7 +1049,7 @@ def _read_configuration():
10441049
args.orientation, args.manifest_orientation
10451050
)
10461051

1047-
if get_bootstrap_name() in ["sdl2", "sdl3"]:
1052+
if is_sdl_bootstrap():
10481053
args.sdl_orientation_hint = get_sdl_orientation_hint(args.orientation)
10491054

10501055
if args.res_xmls and isinstance(args.res_xmls[0], list):
@@ -1073,8 +1078,7 @@ def _read_configuration():
10731078
if x.strip() and not x.strip().startswith('#')]
10741079
WHITELIST_PATTERNS += patterns
10751080

1076-
if args.private is None and \
1077-
get_bootstrap_name() in ['sdl2', 'sdl3'] and args.launcher is None:
1081+
if args.private is None and is_sdl_bootstrap() and args.launcher is None:
10781082
print('Need --private directory or ' +
10791083
'--launcher (SDL2/SDL3 bootstrap only)' +
10801084
'to have something to launch inside the .apk!')
+4-46
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,12 @@
1-
from os.path import join
1+
from pythonforandroid.bootstraps._sdl_common import SDLGradleBootstrap
22

3-
import sh
43

5-
from pythonforandroid.toolchain import (
6-
Bootstrap, shprint, current_directory, info, info_main)
7-
from pythonforandroid.util import ensure_dir, rmdir
8-
9-
10-
class SDL2GradleBootstrap(Bootstrap):
11-
name = 'sdl2'
4+
class SDL2GradleBootstrap(SDLGradleBootstrap):
5+
name = "sdl2"
126

137
recipe_depends = list(
14-
set(Bootstrap.recipe_depends).union({'sdl2'})
8+
set(SDLGradleBootstrap.recipe_depends).union({"sdl2"})
159
)
1610

17-
def assemble_distribution(self):
18-
info_main("# Creating Android project ({})".format(self.name))
19-
20-
rmdir(self.dist_dir)
21-
info("Copying SDL2/gradle build")
22-
shprint(sh.cp, "-r", self.build_dir, self.dist_dir)
23-
24-
# either the build use environment variable (ANDROID_HOME)
25-
# or the local.properties if exists
26-
with current_directory(self.dist_dir):
27-
with open('local.properties', 'w') as fileh:
28-
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
29-
30-
with current_directory(self.dist_dir):
31-
info("Copying Python distribution")
32-
33-
self.distribute_javaclasses(self.ctx.javaclass_dir,
34-
dest_dir=join("src", "main", "java"))
35-
36-
for arch in self.ctx.archs:
37-
python_bundle_dir = join(f'_python_bundle__{arch.arch}', '_python_bundle')
38-
ensure_dir(python_bundle_dir)
39-
40-
self.distribute_libs(arch, [self.ctx.get_libs_dir(arch.arch)])
41-
site_packages_dir = self.ctx.python_recipe.create_python_bundle(
42-
join(self.dist_dir, python_bundle_dir), arch)
43-
if not self.ctx.with_debug_symbols:
44-
self.strip_libraries(arch)
45-
self.fry_eggs(site_packages_dir)
46-
47-
if 'sqlite3' not in self.ctx.recipe_build_order:
48-
with open('blacklist.txt', 'a') as fileh:
49-
fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')
50-
51-
super().assemble_distribution()
52-
5311

5412
bootstrap = SDL2GradleBootstrap()
+4-48
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,12 @@
1-
from os.path import join
1+
from pythonforandroid.bootstraps._sdl_common import SDLGradleBootstrap
22

3-
import sh
43

5-
from pythonforandroid.toolchain import (
6-
Bootstrap, shprint, current_directory, info, info_main)
7-
from pythonforandroid.util import ensure_dir, rmdir
8-
9-
10-
class SDL3GradleBootstrap(Bootstrap):
11-
name = 'sdl3'
12-
13-
conflicts = ['sdl2']
4+
class SDL3GradleBootstrap(SDLGradleBootstrap):
5+
name = "sdl3"
146

157
recipe_depends = list(
16-
set(Bootstrap.recipe_depends).union({'sdl3'})
8+
set(SDLGradleBootstrap.recipe_depends).union({"sdl3"})
179
)
1810

19-
def assemble_distribution(self):
20-
info_main("# Creating Android project ({})".format(self.name))
21-
22-
rmdir(self.dist_dir)
23-
info("Copying SDL3/gradle build")
24-
shprint(sh.cp, "-r", self.build_dir, self.dist_dir)
25-
26-
# either the build use environment variable (ANDROID_HOME)
27-
# or the local.properties if exists
28-
with current_directory(self.dist_dir):
29-
with open('local.properties', 'w') as fileh:
30-
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
31-
32-
with current_directory(self.dist_dir):
33-
info("Copying Python distribution")
34-
35-
self.distribute_javaclasses(self.ctx.javaclass_dir,
36-
dest_dir=join("src", "main", "java"))
37-
38-
for arch in self.ctx.archs:
39-
python_bundle_dir = join(f'_python_bundle__{arch.arch}', '_python_bundle')
40-
ensure_dir(python_bundle_dir)
41-
42-
self.distribute_libs(arch, [self.ctx.get_libs_dir(arch.arch)])
43-
site_packages_dir = self.ctx.python_recipe.create_python_bundle(
44-
join(self.dist_dir, python_bundle_dir), arch)
45-
if not self.ctx.with_debug_symbols:
46-
self.strip_libraries(arch)
47-
self.fry_eggs(site_packages_dir)
48-
49-
if 'sqlite3' not in self.ctx.recipe_build_order:
50-
with open('blacklist.txt', 'a') as fileh:
51-
fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')
52-
53-
super().assemble_distribution()
54-
5511

5612
bootstrap = SDL3GradleBootstrap()

pythonforandroid/bootstraps/sdl3/build/.gitignore

-14
This file was deleted.

pythonforandroid/bootstraps/sdl3/build/blacklist.txt

-84
This file was deleted.

pythonforandroid/bootstraps/sdl3/build/jni/Application.mk

-8
This file was deleted.

pythonforandroid/bootstraps/sdl3/build/src/main/java/.gitkeep

Whitespace-only changes.

pythonforandroid/bootstraps/sdl3/build/src/main/java/org/kivy/android/GenericBroadcastReceiver.java

-19
This file was deleted.

0 commit comments

Comments
 (0)