8000 Fix build.py for webview and service_only bootstraps (now gradle comp… · pygame/python-for-android@c5138f6 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit c5138f6

Browse files
committed
Fix build.py for webview and service_only bootstraps (now gradle compatible)
1 parent f17f91a commit c5138f6

File tree

1 file changed

+48
-71
lines changed
  • pythonforandroid/bootstraps/common/build

1 file changed

+48
-71
lines changed

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 48 additions & 71 deletions
555
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def get_bootstrap_name():
6969
BLACKLIST_PATTERNS.append('*.py')
7070

7171
WHITELIST_PATTERNS = []
72-
if get_bootstrap_name() == "sdl2":
73-
WHITELIST_PATTERNS.append("pyconfig.h")
72+
if get_bootstrap_name() in ('sdl2', 'webview', 'service_only'):
73+
WHITELIST_PATTERNS.append('pyconfig.h')
7474

7575
python_files = []
7676

@@ -265,8 +265,6 @@ def make_package(args):
265265
sys.exit(1)
266266

267267
assets_dir = "src/main/assets"
268-
if get_bootstrap_name() != "sdl2":
269-
assets_dir = "assets"
270268

271269
# Delete the old assets.
272270
try_unlink(join(assets_dir, 'public.mp3'))
@@ -293,15 +291,13 @@ def make_package(args):
293291

294292
# Prepare some variables for templating process
295293
res_dir = "src/main/res"
296-
if get_bootstrap_name() == "webview":
297-
res_dir = "res"
298294
default_icon = 'templates/kivy-icon.png'
299295
default_presplash = 'templates/kivy-presplash.jpg'
296+
shutil.copy(
297+
args.icon or default_icon,
298+
join(res_dir, 'drawable/icon.png')
299+
)
300300
if get_bootstrap_name() != "service_only":
301-
shutil.copy(
302-
args.icon or default_icon,
303-
join(res_dir, 'drawable/icon.png')
304-
)
305301
shutil.copy(
306302
args.presplash or default_presplash,
307303
join(res_dir, 'drawable/presplash.jpg')
@@ -342,9 +338,9 @@ def make_package(args):
342338
with open(args.intent_filters) as fd:
343339
args.intent_filters = fd.read()
344340

345-
if get_bootstrap_name() == "sdl2":
346-
args.add_activity = args.add_activity or []
347-
args.activity_launch_mode = args.activity_launch_mode or ''
341+
# if get_bootstrap_name() == "sdl2":
342+
args.add_activity = args.add_activity or []
343+
args.activity_launch_mode = args.activity_launch_mode or ''
348344

349345
if args.extra_source_dirs:
350346
esd = []
@@ -376,17 +372,11 @@ def make_package(args):
376372
sticky = 'sticky' in options
377373

378374
service_names.append(name)
379-
service_target_path = ""
380-
if get_bootstrap_name() != "sdl2":
381-
service_target_path =\
382-
'src/{}/Service{}.java'.format(args.package.replace(".", "/"),
383-
name.capitalize())
384-
else:
385-
service_target_path =\
386-
'src/main/java/{}/Service{}.java'.format(
387-
args.package.replace(".", "/"),
388-
name.capitalize()
389-
)
375+
service_target_path =\
376+
'src/main/java/{}/Service{}.java'.format(
377+
args.package.replace(".", "/"),
378+
name.capitalize()
379+
)
390380
render(
391381
'Service.tmpl.java',
392382
service_target_path,
@@ -426,8 +416,6 @@ def make_package(args):
426416

427417
# Render out android manifest:
428418
manifest_path = "src/main/AndroidManifest.xml"
429-
if get_bootstrap_name() != "sdl2":
430-
manifest_path = "AndroidManifest.xml"
431419
render_args = {
432420
"args": args,
433421
"service": service,
@@ -443,45 +431,39 @@ def make_package(args):
443431

444432
# Copy the AndroidManifest.xml to the dist root dir so that ant
445433
# can also use it
446-
if get_bootstrap_name() == "sdl2":
447-
if exists( 57AE 9;AndroidManifest.xml'):
448-
remove('AndroidManifest.xml')
449-
shutil.copy(manifest_path, 'AndroidManifest.xml')
434+
if exists('AndroidManifest.xml'):
435+
remove('AndroidManifest.xml')
436+
shutil.copy(manifest_path, 'AndroidManifest.xml')
450437

451438
# gradle build templates
452-
if get_bootstrap_name() != "webview":
453-
# HISTORICALLY NOT SUPPORTED FOR WEBVIEW. Needs review? -JonasT
454-
render(
455-
'build.tmpl.gradle',
456-
'build.gradle',
457-
args=args,
458-
aars=aars,
459-
jars=jars,
460-
android_api=android_api,
461-
build_tools_version=build_tools_version)
439+
render(
440+
'build.tmpl.gradle',
441+
'build.gradle',
442+
args=args,
443+
aars=aars,
444+
jars=jars,
445+
android_api=android_api,
446+
build_tools_version=build_tools_version
447+
)
462448

463449
# ant build templates
464-
if get_bootstrap_name() != "service_only":
465-
# Historically, service_only doesn't support ant anymore.
466-
# Maybe we should also drop this for the others? -JonasT
467-
render(
468-
'build.tmpl.xml',
469-
'build.xml',
470-
args=args,
471-
versioned_name=versioned_name)
450+
render(
451+
'build.tmpl.xml',
452+
'build.xml',
453+
args=args,
454+
versioned_name=versioned_name)
472455

473456
# String resources:
474-
if get_bootstrap_name() != "service_only":
475-
render_args = {
476-
"args": args,
477-
"private_version": str(time.time())
478-
}
479-
if get_bootstrap_name() == "sdl2":
480-
render_args["url_scheme"] = url_scheme
481-
render(
482-
'strings.tmpl.xml',
483-
join(res_dir, 'values/strings.xml'),
484-
**render_args)
457+
render_args = {
458+
"args": args,
459+
"private_version": str(time.time())
460+
}
461+
if get_bootstrap_name() == "sdl2":
462+
render_args["url_scheme"] = url_scheme
463+
render(
464+
'strings.tmpl.xml',
465+
join(res_dir, 'values/strings.xml'),
466+
**render_args)
485467

486468
if exists("custom_rules.tmpl.xml"):
487469
render(
@@ -491,7 +473,7 @@ def make_package(args):
491473

492474
if get_bootstrap_name() == "webview":
493475
render('WebViewLoader.tmpl.java',
494-
'src/org/kivy/android/WebViewLoader.java',
476+
'src/main/java/org/kivy/android/WebViewLoader.java',
495477
args=args)
496478

497479
if args.sign:
@@ -553,6 +535,9 @@ def parse_args(args=None):
553535
help='The permissions to give this app.', nargs='+')
554536
ap.add_argument('--meta-data', dest='meta_data', action='append',
555537
help='Custom key=value to add in application metadata')
538+
ap.add_argument('--icon', dest='icon',
539+
help=('A png file to use as the icon for '
540+
'the application.'))
556541
if get_bootstrap_name() != "service_only":
557542
ap.add_argument('--presplash', dest='presplash',
558543
help=('A jpeg file to use as a screen while the '
@@ -568,9 +553,6 @@ def parse_args(args=None):
568553
ap.add_argument('--window', dest='window', action='store_true',
569554
default=False,
570
help='Indicate if the application will be windowed')
571-
ap.add_argument('--icon', dest='icon',
572-
help=('A png file to use as the icon for '
573-
'the application.'))
574556
ap.add_argument('--orientation', dest='orientation',
575557
default='portrait',
576558
help=('The orientation that the game will '
@@ -628,9 +610,6 @@ def parse_args(args=None):
628610
'directory'))
629611
ap.add_argument('--with-billing', dest='billing_pubkey',
630612
help='If set, the billing service will be added (not implemented)')
631-
ap.add_argument('--service', dest='services', action='append',
632-
help='Declare a new service entrypoint: '
633-
'NAME:PATH_TO_PY[:foreground]')
634613
ap.add_argument('--add-source', dest='extra_source_dirs', action='append',
635614
help='Include additional source dirs in Java build')
636615
if get_bootstrap_name() == "webview":
@@ -710,7 +689,7 @@ def _read_configuration():
710689
if args.meta_data is None:
711690
args.meta_data = []
712691

713-
if args.services is None:
692+
if (not hasattr(args, 'services')) or args.services is None:
714693
args.services = []
715694

716695
if args.try_system_python_compile:
@@ -741,10 +720,8 @@ def _read_configuration():
741720
if x.strip() and not x.strip().startswith('#')]
742721
WHITELIST_PATTERNS += patterns
743722

744-
if args.private is None and (
745-
get_bootstrap_name() != "sdl2" or
746-
args.launcher is None
747-
):
723+
if args.private is None and \
724+
get_bootstrap_name() == 'sdl2' and args.launcher is None:
748725
print('Need --private directory or ' +
749726
'--launcher (SDL2 bootstrap only)' +
750727
'to have something to launch inside the .apk!')

0 commit comments

Comments
 (0)
0