Skip to content

Commit

Permalink
Bump to SDL2 2.0.10 & extract .java from SDL2 tarball: merge conflict…
Browse files Browse the repository at this point in the history
…s fixed (#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 <[email protected]>

* Made bootstrap tests clear the Recipe cache in setup

* Made test_should_build not check non-existing storage_dir

Authored-by: Jonas Thiem <[email protected]>
  • Loading branch information
inclement authored May 1, 2020
1 parent 66f6a34 commit 1b887be
Show file tree
Hide file tree
Showing 21 changed files with 127 additions and 5,209 deletions.
24 changes: 23 additions & 1 deletion pythonforandroid/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,23 @@ def get_bootstrap_dirs(self):
]
return bootstrap_dirs

def _copy_in_final_files(self):
if self.name == "sdl2":
# Get the paths for copying SDL2's java source code:
sdl2_recipe = Recipe.get_recipe("sdl2", self.ctx)
sdl2_build_dir = sdl2_recipe.get_jni_dir()
src_dir = join(sdl2_build_dir, "SDL", "android-project",
"app", "src", "main", "java",
"org", "libsdl", "app")
target_dir = join(self.dist_dir, 'src', 'main', 'java', 'org',
'libsdl', 'app')

# Do actual copying:
info('Copying in SDL2 .java files from: ' + str(src_dir))
if not os.path.exists(target_dir):
os.makedirs(target_dir)
copy_files(src_dir, target_dir, override=True)

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."""
Expand All @@ -168,7 +185,12 @@ def prepare_build_dir(self):
def prepare_dist_dir(self):
ensure_dir(self.dist_dir)

def run_distribute(self):
def assemble_distribution(self):
''' Copies all the files into the distribution (this function is
overridden by the specific bootstrap classes to do this)
and add in the distribution info.
'''
self._copy_in_final_files()
self.distribution.save_info(self.dist_dir)

@classmethod
Expand Down
30 changes: 17 additions & 13 deletions pythonforandroid/bootstraps/common/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,24 +530,28 @@ def make_package(args):
for patch_name in os.listdir(join('src', 'patches')):
patch_path = join('src', 'patches', patch_name)
print("Applying patch: " + str(patch_path))

# -N: insist this is FORWARD patch, don't reverse apply
# -p1: strip first path component
# -t: batch mode, don't ask questions
patch_command = ["patch", "-N", "-p1", "-t", "-i", patch_path]

try:
subprocess.check_output([
# -N: insist this is FORWARd patch, don't reverse apply
# -p1: strip first path component
# -t: batch mode, don't ask questions
"patch", "-N", "-p1", "-t", "-i", patch_path
])
# Use a dry run to establish whether the patch is already applied.
# If we don't check this, the patch may be partially applied (which is bad!)
subprocess.check_output(patch_command + ["--dry-run"])
except subprocess.CalledProcessError as e:
if e.returncode == 1:
# Return code 1 means it didn't apply, this will
# usually mean it is already applied.
print("Warning: failed to apply patch (" +
"exit code 1), " +
"assuming it is already applied: " +
str(patch_path)
)
# Return code 1 means not all hunks could be applied, this usually
# means the patch is already applied.
print("Warning: failed to apply patch (exit code 1), "
"assuming it is already applied: ",
str(patch_path))
else:
raise e
else:
# The dry run worked, so do the real thing
subprocess.check_output(patch_command)


def parse_args_and_make_package(args=None):
Expand Down
2 changes: 1 addition & 1 deletion pythonforandroid/bootstraps/empty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class EmptyBootstrap(Bootstrap):

can_be_chosen_automatically = False

def run_distribute(self):
def assemble_distribution(self):
print('empty bootstrap has no distribute')
exit(1)

Expand Down
4 changes: 2 additions & 2 deletions pythonforandroid/bootstraps/sdl2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SDL2GradleBootstrap(Bootstrap):
set(Bootstrap.recipe_depends).union({'sdl2'})
)

def run_distribute(self):
def assemble_distribution(self):
info_main("# Creating Android project ({})".format(self.name))

arch = self.ctx.archs[0]
Expand Down Expand Up @@ -50,7 +50,7 @@ def run_distribute(self):
if not self.ctx.build_as_debuggable:
self.strip_libraries(arch)
self.fry_eggs(site_packages_dir)
super().run_distribute()
super().assemble_distribution()


bootstrap = SDL2GradleBootstrap()
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ protected void onPostExecute(String result) {
mActivity.getPackageName(), PackageManager.GET_META_DATA).metaData;

PowerManager pm = (PowerManager) mActivity.getSystemService(Context.POWER_SERVICE);
if ( mActivity.mMetaData.getInt("wakelock") == 1 ) {
if (mActivity.mMetaData.getInt("wakelock") == 1) {
mActivity.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "Screen On");
mActivity.mWakeLock.acquire();
}
Expand Down Expand Up @@ -450,35 +450,32 @@ public void appConfirmedActive() {
public void considerLoadingScreenRemoval() {
if (loadingScreenRemovalTimer != null)
return;
runOnUiThread(new Runnable() {
public void run() {
if (((PythonActivity)PythonActivity.mSingleton).mAppConfirmedActive &&
loadingScreenRemovalTimer == null) {
// Remove loading screen but with a delay.
// (app can use p4a's android.loadingscreen module to
// do it quicker if it wants to)
// get a handler (call from main thread)
// this will run when timer elapses
TimerTask removalTask = new TimerTask() {
if (PythonActivity.mSingleton != null &&
mAppConfirmedActive &&
loadingScreenRemovalTimer == null) {
Log.v(TAG, "loading screen timer Runnable() launched.");
// Remove loading screen but with a delay.
// (app can use p4a's android.loadingscreen module to
// do it quicker if it wants to)
TimerTask removalTask = new TimerTask() {
@Override
public void run() {
// post a runnable to the handler
runOnUiThread(new Runnable() {
@Override
public void run() {
// post a runnable to the handler
runOnUiThread(new Runnable() {
@Override
public void run() {
PythonActivity activity =
((PythonActivity)PythonActivity.mSingleton);
if (activity != null)
activity.removeLoadingScreen();
}
});
Log.v(TAG, "loading screen timer Runnable() finished.");
PythonActivity activity =
((PythonActivity)PythonActivity.mSingleton);
if (activity != null)
activity.removeLoadingScreen();
}
};
loadingScreenRemovalTimer = new Timer();
loadingScreenRemovalTimer.schedule(removalTask, 5000);
});
}
}
});
};
loadingScreenRemovalTimer = new Timer();
loadingScreenRemovalTimer.schedule(removalTask, 5000);
}
}

public void removeLoadingScreen() {
Expand Down Expand Up @@ -589,14 +586,30 @@ protected void onResume() {
if (this.mWakeLock != null) {
this.mWakeLock.acquire();
}
Log.v(TAG, "onResume()");
Log.v(TAG, "onResume(), mSDLThread exists yet: " + (mSDLThread != null));
try {
super.onResume();
if (mSDLThread == null && !mIsResumedCalled) {
// Ok so SDL2's onStart() usually launches the native code.
// However, this may fail if native libs aren't loaded yet at that point
// (due ot our loading screen) so we may need to manually trigger this,
// otherwise code would only launch by leaving & re-entering the app:
Log.v(TAG, "Loading screen workaround: triggering native resume");
if (mSDLThread == null && mCurrentNativeState == NativeState.RESUMED) {
// Force a state change so SDL2 doesn't just ignore the resume:
mCurrentNativeState = NativeState.PAUSED;
}
resumeNativeThread(); // native resume to call native code
}
} catch (UnsatisfiedLinkError e) {
// Catch resume while still in loading screen failing to
// call native function (since it's not yet loaded)
Log.v(TAG, "failed to call native onResume() because libs " +
"aren't loaded yet. this is expected to happen");
}
considerLoadingScreenRemoval();
Log.v(TAG, "onResume() done in PythonActivity, " +
"mSDLThread exists yet: " + (mSDLThread != null));
}

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

This file was deleted.

Loading

0 comments on commit 1b887be

Please sign in to comment.