Skip to content

Commit 4e733a6

Browse files
committed
Made SDL2 patching do a dry run to check it will work
1 parent 70fe338 commit 4e733a6

File tree

1 file changed

+18
-13
lines changed
  • pythonforandroid/bootstraps/common/build

1 file changed

+18
-13
lines changed

pythonforandroid/bootstraps/common/build/build.py

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

546551

547552
def parse_args_and_make_package(args=None):

0 commit comments

Comments
 (0)