Skip to content
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

Bump to SDL2 2.0.10 & extract .java from SDL2 tarball: merge conflicts fixed #2113

Merged
merged 5 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Comment on lines +168 to +169
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could save one line by simulating the --parents flag:

Suggested change
if not os.path.exists(target_dir):
os.makedirs(target_dir)
os.makedirs(target_dir, exist_ok=True)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I wrote it like this to maintain Python 2 compatibility. So yes, for 3.x-only shortening it like this makes sense 👍

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
31 changes: 18 additions & 13 deletions pythonforandroid/bootstraps/common/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,24 +524,29 @@ 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):
inclement marked this conversation as resolved.
Show resolved Hide resolved
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