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

Can't apply patches with relative paths for local recipe #2623

Closed
5 tasks done
dbnicholson opened this issue Jun 23, 2022 · 2 comments · Fixed by #2640
Closed
5 tasks done

Can't apply patches with relative paths for local recipe #2623

dbnicholson opened this issue Jun 23, 2022 · 2 comments · Fixed by #2640

Comments

@dbnicholson
Copy link
Contributor

Checklist

  • the issue is indeed a bug and not a support request
  • issue doesn't already exist: https://github.com/kivy/python-for-android/issues
  • I have a short, runnable example that reproduces the issue
  • I reproduced the problem with the latest development version (p4a.branch = develop)
  • I used the grave accent (aka backticks) to format code or logs when appropriated

Versions

  • Python: 3.9.2
  • OS: Linux
  • Kivy: N/A
  • Cython: N/A
  • OpenJDK: N/A

Description

A patch with a relative path in a local recipe can't be applied because the patch can't be found:

  RAN: /usr/bin/patch -t -d /home/dan/.local/share/python-for-android/build/other_builds/zstandard/x86_64__ndk_target_21/zstandard -p1 -i p4a-recipes/zstandard/preprocessor.patch

  STDOUT:
/usr/bin/patch: **** Can't open patch file p4a-recipes/zstandard/preprocessor.patch : No such file or directory

The problem is that -d changes the directory before reading the patch passed with -i. With a normal recipe, the path to -i is absolute because it's derived from Context.root_dir, which is absolute. Unless the caller passes an absolute path to --local-recipes, the local recipe patch path will also be relative.

buildozer.spec

N/A

Logs

[INFO]:    Prebuilding zstandard for x86_64
[INFO]:    zstandard has no prebuild_x86_64, skipping
[INFO]:    Applying patches for zstandard[x86_64]
[INFO]:    Applying patch preprocessor.patch
[INFO]:    -> running patch -t -d /home/dan/.local/share/python-for-android/build/other_builds/zstandard/x86_64__ndk_targ...(and 63 more)
           working: /usr/bin/patch: **** Can't open patch file p4a-recipes/zstandard/preprocessor.patch : No such file or directory        Exception in thread background thread for pid 987188:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/lib/python3.9/site-packages/sh.py", line 1683, in wrap
    fn(*rgs, **kwargs)
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/lib/python3.9/site-packages/sh.py", line 2662, in background_thread
    handle_exit_code(exit_code)
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/lib/python3.9/site-packages/sh.py", line 2349, in fn
    return self.command.handle_command_exit_code(exit_code)
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/lib/python3.9/site-packages/sh.py", line 905, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_2: 

  RAN: /usr/bin/patch -t -d /home/dan/.local/share/python-for-android/build/other_builds/zstandard/x86_64__ndk_target_21/zstandard -p1 -i p4a-recipes/zstandard/preprocessor.patch

  STDOUT:
/usr/bin/patch: **** Can't open patch file p4a-recipes/zstandard/preprocessor.patch : No such file or directory


  STDERR:

[INFO]:    STDOUT:                                                                                                                         
	/usr/bin/patch: **** Can't open patch file p4a-recipes/zstandard/preprocessor.patch : No such file or directory
[INFO]:    STDERR:
	
Traceback (most recent call last):
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/bin/p4a", line 11, in <module>
    load_entry_point('python-for-android==2022.3.13', 'console_scripts', 'p4a')()
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/lib/python3.9/site-packages/pythonforandroid/entrypoints.py", line 18, in main
    ToolchainCL()
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/lib/python3.9/site-packages/pythonforandroid/toolchain.py", line 728, in __init__
    getattr(self, command)(args)
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/lib/python3.9/site-packages/pythonforandroid/toolchain.py", line 151, in wrapper_func
    build_dist_from_args(ctx, dist, args)
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/lib/python3.9/site-packages/pythonforandroid/toolchain.py", line 210, in build_dist_from_args
    build_recipes(build_order, python_modules, ctx,
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/lib/python3.9/site-packages/pythonforandroid/build.py", line 593, in build_recipes
    recipe.apply_patches(arch)
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/lib/python3.9/site-packages/pythonforandroid/recipe.py", line 560, in apply_patches
    self.apply_patch(
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/lib/python3.9/site-packages/pythonforandroid/recipe.py", line 263, in apply_patch
    shprint(sh.patch, "-t", "-d", build_dir, "-p1",
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/lib/python3.9/site-packages/pythonforandroid/logger.py", line 167, in shprint
    for line in output:
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/lib/python3.9/site-packages/sh.py", line 953, in next
    self.wait()
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/lib/python3.9/site-packages/sh.py", line 879, in wait
    self.handle_command_exit_code(exit_code)
  File "/home/dan/src/kolibri/kolibri-installer-android/venv/lib/python3.9/site-packages/sh.py", line 905, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_2: 

  RAN: /usr/bin/patch -t -d /home/dan/.local/share/python-for-android/build/other_builds/zstandard/x86_64__ndk_target_21/zstandard -p1 -i p4a-recipes/zstandard/preprocessor.patch

  STDOUT:
/usr/bin/patch: **** Can't open patch file p4a-recipes/zstandard/preprocessor.patch : No such file or directory


  STDERR:
@mzakharo
Copy link
Contributor

Try declaring your relative recipe directory path through buildozer.spec. Buildozer transforms it through os.path.realpath to make things work.

@dbnicholson
Copy link
Contributor Author

I'm not using buildozer, but it should be easy enough to have p4a DTRT:

diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py
index 9badb0d9..7d34891f 100644
--- a/pythonforandroid/toolchain.py
+++ b/pythonforandroid/toolchain.py
@@ -720,7 +720,7 @@ class ToolchainCL:
 
         self._archs = args.arch
 
-        self.ctx.local_recipes = args.local_recipes
+        self.ctx.local_recipes = realpath(args.local_recipes)
         self.ctx.copy_libs = args.copy_libs
 
         self.ctx.activity_class_name = args.activity_class_name

Just need to turn it into a proper PR.

dbnicholson added a commit to dbnicholson/python-for-android that referenced this issue Jul 22, 2022
This is necessary when using patches in a local recipe since
`Recipe.apply_patch` assumes the recipe directory is absolute and uses
`patch -d` to change directories. It could just be fixed there, but this
ensures that recipe directories are always absolute.

Closes: kivy#2623
dbnicholson added a commit to dbnicholson/python-for-android that referenced this issue Jul 22, 2022
This is necessary when using patches in a local recipe since
`Recipe.apply_patch` assumes the recipe directory is absolute and uses
`patch -d` to change directories. It could just be fixed there, but this
ensures that recipe directories are always absolute.

Closes: kivy#2623
dbnicholson added a commit to dbnicholson/python-for-android that referenced this issue Jul 22, 2022
This is necessary when using patches in a local recipe since
`Recipe.apply_patch` assumes the recipe directory is absolute and uses
`patch -d` to change directories. It could just be fixed there, but this
ensures that recipe directories are always absolute.

Closes: kivy#2623
misl6 pushed a commit that referenced this issue Jul 22, 2022
This is necessary when using patches in a local recipe since
`Recipe.apply_patch` assumes the recipe directory is absolute and uses
`patch -d` to change directories. It could just be fixed there, but this
ensures that recipe directories are always absolute.

Closes: #2623
misl6 added a commit that referenced this issue Sep 5, 2022
* Add option for copying arbitratry xml files to src/main/res/xml without touching manifest

* handle the case of getting list as res_xml

* Remove stray - in output file name

The final component in the package name is just the extension, so
prefixing it with a - means the output file ends in -.<ext>.

* Resolve absolute path to local recipes (#2640)

This is necessary when using patches in a local recipe since
`Recipe.apply_patch` assumes the recipe directory is absolute and uses
`patch -d` to change directories. It could just be fixed there, but this
ensures that recipe directories are always absolute.

Closes: #2623

* Fix webview Back button behaviour (#2636)

* Fixes TypeError: str.join() takes exactly one argument (2 given) in hostpython3/__init__.py", line 69 (#2642)

* Update __init__.py

.buildozer/android/platform/python-for-android/pythonforandroid/recipes/hostpython3/__init__.py", line 69, in get_recipe_env
    env["PKG_CONFIG_PATH"] = os.pathsep.join(
TypeError: str.join() takes exactly one argument (2 given)

* according of 

#2642 (review)

* RTSP support for ffmpeg

Added UDP and TCP protocols to "--enable-procol" to supporting RTSP streams over each.

Added RTSP to "--enable-demuxer" to supporting RTSP with ffmpeg.

* Fixes some E275 - assert is a keyword. (#2647)

* Add icon-bg and icon-fg to fix_args + adds a missing folder in webview dir template (#2633)

* Add icon-bg and icon-fg to fix_args

Fix the icon-bg and icon-fg arguments and also create the folder
mipmap-anydpi-v26 if it doesn't exists before trying to create a file
inside.

* Use existing ensure_dir function to create anydpi_dir

* Add mipmap-anydpi-v26 to bootstrap template

This makes available the directory in the final template so it's not
needed to check the directory exists.

* Updates matplotlib, fixes an issue related to shared libc++ (#2645)

* Updates matplotlib, fixes an issue related to shared libc++

* Cleanup

* Update supported Python versions (#2656)

* Remove six and enum34 dependency (#2657)

* Force --platform=linux/amd64 in Dockerfile (#2660)

* Use p4a_install instead of install, as a file named INSTALL is already present. (#2663)

* Update CHANGELOG.md & change version for release 2022.09.04

Co-authored-by: Eero af Heurlin <[email protected]>
Co-authored-by: Dan Nicholson <[email protected]>
Co-authored-by: Andre Miras <[email protected]>
Co-authored-by: Andy Trofimov <[email protected]>
Co-authored-by: Akshay Arora <[email protected]>
Co-authored-by: --=FurtiF™=-- <[email protected]>
Co-authored-by: alickc <[email protected]>
Co-authored-by: danigm <[email protected]>
shyamnathp pushed a commit to shyamnathp/python-for-android that referenced this issue Feb 17, 2023
This is necessary when using patches in a local recipe since
`Recipe.apply_patch` assumes the recipe directory is absolute and uses
`patch -d` to change directories. It could just be fixed there, but this
ensures that recipe directories are always absolute.

Closes: kivy#2623
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants