Skip to content

Commit 1b887be

Browse files
authored
Bump to SDL2 2.0.10 & extract .java from SDL2 tarball: merge conflicts fixed (kivy#2113)
* Bump to SDL2 2.0.10 & make sure to extract .java from SDL2 tarball * Made SDL2 patching do a dry run to check it will work * Update pythonforandroid/bootstraps/common/build/build.py Co-authored-by: Pol Canelles <canellestudi@gmail.com> * Made bootstrap tests clear the Recipe cache in setup * Made test_should_build not check non-existing storage_dir Authored-by: Jonas Thiem <jonas@thiem.email>
1 parent 66f6a34 commit 1b887be

21 files changed

+127
-5209
lines changed

pythonforandroid/bootstrap.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,23 @@ def get_bootstrap_dirs(self):
152152
]
153153
return bootstrap_dirs
154154

155+
def _copy_in_final_files(self):
156+
if self.name == "sdl2":
157+
# Get the paths for copying SDL2's java source code:
158+
sdl2_recipe = Recipe.get_recipe("sdl2", self.ctx)
159+
sdl2_build_dir = sdl2_recipe.get_jni_dir()
160+
src_dir = join(sdl2_build_dir, "SDL", "android-project",
161+
"app", "src", "main", "java",
162+
"org", "libsdl", "app")
163+
target_dir = join(self.dist_dir, 'src', 'main', 'java', 'org',
164+
'libsdl', 'app')
165+
166+
# Do actual copying:
167+
info('Copying in SDL2 .java files from: ' + str(src_dir))
168+
if not os.path.exists(target_dir):
169+
os.makedirs(target_dir)
170+
copy_files(src_dir, target_dir, override=True)
171+
155172
def prepare_build_dir(self):
156173
"""Ensure that a build dir exists for the recipe. This same single
157174
dir will be used for building all different archs."""
@@ -168,7 +185,12 @@ def prepare_build_dir(self):
168185
def prepare_dist_dir(self):
169186
ensure_dir(self.dist_dir)
170187

171-
def run_distribute(self):
188+
def assemble_distribution(self):
189+
''' Copies all the files into the distribution (this function is
190+
overridden by the specific bootstrap classes to do this)
191+
and add in the distribution info.
192+
'''
193+
self._copy_in_final_files()
172194
self.distribution.save_info(self.dist_dir)
173195

174196
@classmethod

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -530,24 +530,28 @@ def make_package(args):
530530
for patch_name in os.listdir(join('src', 'patches')):
531531
patch_path = join('src', 'patches', patch_name)
532532
print("Applying patch: " + str(patch_path))
533+
534+
# -N: insist this is FORWARD patch, don't reverse apply
535+
# -p1: strip first path component
536+
# -t: batch mode, don't ask questions
537+
patch_command = ["patch", "-N", "-p1", "-t", "-i", patch_path]
538+
533539
try:
534-
subprocess.check_output([
535-
# -N: insist this is FORWARd patch, don't reverse apply
536-
# -p1: strip first path component
537-
# -t: batch mode, don't ask questions
538-
"patch", "-N", "-p1", "-t", "-i", patch_path
539-
])
540+
# Use a dry run to establish whether the patch is already applied.
541+
# If we don't check this, the patch may be partially applied (which is bad!)
542+
subprocess.check_output(patch_command + ["--dry-run"])
540543
except subprocess.CalledProcessError as e:
541544
if e.returncode == 1:
542-
# Return code 1 means it didn't apply, this will
543-
# usually mean it is already applied.
544-
print("Warning: failed to apply patch (" +
545-
"exit code 1), " +
546-
"assuming it is already applied: " +
547-
str(patch_path)
548-
)
545+
# Return code 1 means not all hunks could be applied, this usually
546+
# means the patch is already applied.
547+
print("Warning: failed to apply patch (exit code 1), "
548+
"assuming it is already applied: ",
549+
str(patch_path))
549550
else:
550551
raise e
552+
else:
553+
# The dry run worked, so do the real thing
554+
subprocess.check_output(patch_command)
551555

552556

553557
def parse_args_and_make_package(args=None):

pythonforandroid/bootstraps/empty/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class EmptyBootstrap(Bootstrap):
88

99
can_be_chosen_automatically = False
1010

11-
def run_distribute(self):
11+
def assemble_distribution(self):
1212
print('empty bootstrap has no distribute')
1313
exit(1)
1414

pythonforandroid/bootstraps/sdl2/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SDL2GradleBootstrap(Bootstrap):
1212
set(Bootstrap.recipe_depends).union({'sdl2'})
1313
)
1414

15-
def run_distribute(self):
15+
def assemble_distribution(self):
1616
info_main("# Creating Android project ({})".format(self.name))
1717

1818
arch = self.ctx.archs[0]
@@ -50,7 +50,7 @@ def run_distribute(self):
5050
if not self.ctx.build_as_debuggable:
5151
self.strip_libraries(arch)
5252
self.fry_eggs(site_packages_dir)
53-
super().run_distribute()
53+
super().assemble_distribution()
5454

5555

5656
bootstrap = SDL2GradleBootstrap()

pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonActivity.java

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ protected void onPostExecute(String result) {
193193
mActivity.getPackageName(), PackageManager.GET_META_DATA).metaData;
194194

195195
PowerManager pm = (PowerManager) mActivity.getSystemService(Context.POWER_SERVICE);
196-
if ( mActivity.mMetaData.getInt("wakelock") == 1 ) {
196+
if (mActivity.mMetaData.getInt("wakelock") == 1) {
197197
mActivity.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "Screen On");
198198
mActivity.mWakeLock.acquire();
199199
}
@@ -450,35 +450,32 @@ public void appConfirmedActive() {
450450
public void considerLoadingScreenRemoval() {
451451
if (loadingScreenRemovalTimer != null)
452452
return;
453-
runOnUiThread(new Runnable() {
454-
public void run() {
455-
if (((PythonActivity)PythonActivity.mSingleton).mAppConfirmedActive &&
456-
loadingScreenRemovalTimer == null) {
457-
// Remove loading screen but with a delay.
458-
// (app can use p4a's android.loadingscreen module to
459-
// do it quicker if it wants to)
460-
// get a handler (call from main thread)
461-
// this will run when timer elapses
462-
TimerTask removalTask = new TimerTask() {
453+
if (PythonActivity.mSingleton != null &&
454+
mAppConfirmedActive &&
455+
loadingScreenRemovalTimer == null) {
456+
Log.v(TAG, "loading screen timer Runnable() launched.");
457+
// Remove loading screen but with a delay.
458+
// (app can use p4a's android.loadingscreen module to
459+
// do it quicker if it wants to)
460+
TimerTask removalTask = new TimerTask() {
461+
@Override
462+
public void run() {
463+
// post a runnable to the handler
464+
runOnUiThread(new Runnable() {
463465
@Override
464466
public void run() {
465-
// post a runnable to the handler
466-
runOnUiThread(new Runnable() {
467-
@Override
468-
public void run() {
469-
PythonActivity activity =
470-
((PythonActivity)PythonActivity.mSingleton);
471-
if (activity != null)
472-
activity.removeLoadingScreen();
473-
}
474-
});
467+
Log.v(TAG, "loading screen timer Runnable() finished.");
468+
PythonActivity activity =
469+
((PythonActivity)PythonActivity.mSingleton);
470+
if (activity != null)
471+
activity.removeLoadingScreen();
475472
}
476-
};
477-
loadingScreenRemovalTimer = new Timer();
478-
loadingScreenRemovalTimer.schedule(removalTask, 5000);
473+
});
479474
}
480-
}
481-
});
475+
};
476+
loadingScreenRemovalTimer = new Timer();
477+
loadingScreenRemovalTimer.schedule(removalTask, 5000);
478+
}
482479
}
483480

484481
public void removeLoadingScreen() {
@@ -589,14 +586,30 @@ protected void onResume() {
589586
if (this.mWakeLock != null) {
590587
this.mWakeLock.acquire();
591588
}
592-
Log.v(TAG, "onResume()");
589+
Log.v(TAG, "onResume(), mSDLThread exists yet: " + (mSDLThread != null));
593590
try {
594591
super.onResume();
592+
if (mSDLThread == null && !mIsResumedCalled) {
593+
// Ok so SDL2's onStart() usually launches the native code.
594+
// However, this may fail if native libs aren't loaded yet at that point
595+
// (due ot our loading screen) so we may need to manually trigger this,
596+
// otherwise code would only launch by leaving & re-entering the app:
597+
Log.v(TAG, "Loading screen workaround: triggering native resume");
598+
if (mSDLThread == null && mCurrentNativeState == NativeState.RESUMED) {
599+
// Force a state change so SDL2 doesn't just ignore the resume:
600+
mCurrentNativeState = NativeState.PAUSED;
601+
}
602+
resumeNativeThread(); // native resume to call native code
603+
}
595604
} catch (UnsatisfiedLinkError e) {
596605
// Catch resume while still in loading screen failing to
597606
// call native function (since it's not yet loaded)
607+
Log.v(TAG, "failed to call native onResume() because libs " +
608+
"aren't loaded yet. this is expected to happen");
598609
}
599610
considerLoadingScreenRemoval();
611+
Log.v(TAG, "onResume() done in PythonActivity, " +
612+
"mSDLThread exists yet: " + (mSDLThread != null));
600613
}
601614

602615
@Override
@@ -606,6 +619,7 @@ public void onWindowFocusChanged(boolean hasFocus) {
606619
} catch (UnsatisfiedLinkError e) {
607620
// Catch window focus while still in loading screen failing to
608621
// call native function (since it's not yet loaded)
622+
return; // no point in barging further
609623
}
610624
considerLoadingScreenRemoval();
611625
}

pythonforandroid/bootstraps/sdl2/build/src/main/java/org/libsdl/app/HIDDevice.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)