More explanations about "patch-add","patch-set-add" , and enviroment variables in general
Closed this issue · 4 comments
Describe your question below
I was trying to build nautilus-admin-gtk4
from the AUR
but it fails, maybe a dependency issue, and I was trying to fix through patch-add
but it didn't work, trying to make a patch from PKGBUILD
then append it patch-set-add
also didn't work to fix the issue but add another issue :
ERROR: depends contains invalid characters: ' '
So what I'm asking here is how patch packages, and also how to add enviroment variables to makepkg
i.e. export CC=clang
and other envs.
okay, so there are two ways to deal with it:
- Original implementation in which full source diff (via
git diff
) is created. It is still useful sometimes (e.g. if you need to attach a big external patch to the build), but I wouldn't recommend it, because it might cause issues with support - basically any upstream PKGBUILD change might break your patch. This is supported bypatch-set-add
command. - Per variable implementation. In this scenario, the variable will be appended (the order is not guaranteed) at the end of the PKGBUILD. This is the recommended way, though it has some simple magic under the hood.
Let me describe the magic it has:
-
In case if variable name ends with
()
the parser will treat the content inside the body as a function, basically something like- variable name
pkgver()
- variable value
{ date --utc --iso-8601=seconds; }
will lead to the following PKGBUILD extension:
pkgver() { date --utc --iso-8601=seconds; }
and, finally, during the build process pkgver will be assigned to the current utc timestamp (in iso8061 format).
- variable name
-
Otherwise (i.e. variable name does not end with
()
) if variable value starts and ends with round brackets, the content inside will be parsed as array. This is the scenario of thedepends
variable should be. Please, note, that it doesn't support addition, instead it just overrides value as is. An example:- variable name
depends
- variable value
("python" python-pytest)
will lead to:
depends=(python python-pytest)
(it will also remove quotes which are not required). However, while I was writing this message I realized, that this type of input is not actually supported by
patch-add
command and was fixed in 2b33510 (availabe with 2.13.7 release). - variable name
-
Otherwise - if variable name does not end with
()
and variable value is not inside round brackets, then the content will be parsed as normal string. The last example:- variable name
pkgname
- variable value
ahriman-fix
will lead to
pkgname=ahriman-fix
- variable name
In order to explicitly use the last case, the value should be put inside quotes. Some notes:
- As I mentioned above, the variables will be appended to the end of PKGBUILD randomly (actually in the order of the patch creation, however, it is not guaranteed). So, in case if any of default PKGBUILD variables relies on your variable, it will not work (unless you specify the override too). Say for example, if you override
pkgver
and it is used insource
array, the source array will still contain the original pkgver value unless you specify override for it also. - Environment and makepkg variables should work in the same way - at least as a small test I used
PKGEXT
override without any issues. However, the restriction above still applies.
See also https://ahriman.readthedocs.io/en/stable/faq.html#how-to-change-pkgbuilds-before-build, I might have copy this comment there though
Thank you very much for the thorough explanation, I managed to fix all broken packages with patch-set-add
and I'll try the patch-add
for future rebuilds/updates to test, since as you said before git diff
is not recommended anyway, which gave me bunch of errors until -somehow- I managed to fix them, but still works (amazing indeed).
Since I'm migrating my local repo to an AHRIMAN
one's, I also have a couple of packages that needs to build outside a clean chroot
since one - a kernel- uses gcc GCOV
and needs a rebuild, and the other - a rust package- need to store/download into root
folder (something like /.root/cargo). so my question is can I build those without the makechrootpkg
, is there an option for that?
can I build those without the makechrootpkg, is there an option for that?
no. However, there is an option to bind directories inside chroot, you can use something like
[build]
makechrootpkg_flags = -d /path/to/external/cargo/directory:/root/.cargo
Thank you again that was very help, managed to fix all broken PKGBUILD
s,the AUR
is a dangerous place sometimes 😄