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

Drop epatch command and rework eapply explanation #331

Merged
merged 4 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
.depend
documents.js
eclass-reference/

# Emacs backup files and locks
*~
.#*
2 changes: 1 addition & 1 deletion appendices/contributors/text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Misc
<author name="Brian Evans" email="grknight@gentoo.org">
<uri link="::ebuild-writing/eapi/"/>,
<uri link="::ebuild-writing/variables/"/>,
<uri link="::ebuild-writing/functions/src_prepare/epatch/"/>
<uri link="::ebuild-writing/functions/src_prepare/eapply/"/>
</author>
<author name="Lucas Ramage" email="ramage.lucas@protonmail.com">
Search functionality
Expand Down
136 changes: 136 additions & 0 deletions ebuild-writing/functions/src_prepare/eapply/text.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?xml version="1.0" encoding="UTF-8"?>
<guide self="ebuild-writing/functions/src_prepare/eapply/">
<chapter>
<title>Patching with eapply</title>
<body>

<p>
The canonical way of applying patches in ebuilds is to use the package
manager's <c>eapply</c> command, either by calling it explicitly, or by
assigning the <c>PATCHES</c> variable supported by the default
<c>src_prepare</c> implementation.
</p>

<important>
Applying patches to the sources from the upstream tarball is <e>strongly</e>
preferred to distributing your own modified tarball.
</important>

<p>
The <c>eapply</c> command takes one or more regular file or directory paths as
its arguments. Optionally, these can be preceded by GNU <c>patch</c> options.
</p>

<note>
The <c>--</c> delimiter indicates the end of options. This is useful if a
filename begins with a hyphen.
</note>

<ul>
<li>
If an argument is a regular file, it will be applied it in the working
directory by calling GNU <c>patch</c> with patch level <c>-p1</c>.
Specifying an explicit <c>-p<e>N</e></c> option will override the default
patch level.
</li>
<li>
For a directory, <c>patch -p1</c> applies all patch files with names ending
in <c>.diff</c> or <c>.patch</c> in that directory, in POSIXbetical order
of their names. Any other files in the directory are ignored.
Again, <c>-p<e>N</e></c> can be used to override the default patch level.
Note that <c>eapply</c> will not recurse into subdirectories.
</li>
</ul>

<p>
<c>eapply</c> was added in EAPI 6. It differs from the previously available
<c>epatch</c> in several ways:
</p>

<ul>
<li>
<c>eapply</c> will not unpack patches for you.
</li>
<li>
The patch level is no longer detected automatically. Patch levels other
than <c>-p1</c> must be specified manually.
</li>
<li>
When specifying a directory, at least one file with a name ending in
<c>.diff</c> or <c>.patch</c> must exist or the command fails.
</li>
</ul>
</body>

<section>
<title>Basic <c>eapply</c></title>
<body>

<p>
In its simplest form, <c>eapply</c> takes a single filename and applies that
patch. It will automatically <c>die</c> if the apply fails. The following is
taken from <c>sys-libs/gpm</c>:
</p>

<codesample lang="ebuild">
eapply "${FILESDIR}"/${P}-musl.patch
</codesample>

<p>
In the following simplified example taken from <c>www-client/firefox</c>,
a patchset is added to <c>SRC_URI</c> in order to fetch and unpack it.
<c>eapply</c> is then called with a directory argument. It applies all patches
found in that directory:
</p>

<codesample lang="ebuild">
SRC_URI+="https://dev.gentoo.org/~larry/patchsets/${P}-patches-01.tar.xz"

src_prepare() {
eapply "${WORKDIR}/firefox-patches"
eapply_user
}
</codesample>

<p>
The <uri link="::ebuild-writing/misc-files/patches/"/> chapter gives some
guidelines about where patches should be hosted and about their formatting.
</p>

<p>
The default <c><uri link="::ebuild-writing/functions/src_prepare"/></c>
function will look for a global PATCHES array to apply a list of patches
for you.
</p>

<codesample lang="ebuild">
PATCHES=(
# Fix install location
"${FILESDIR}/${P}-destdir.patch"
# Respect MAKEOPTS #876543
"${FILESDIR}/${P}-parallel_build.patch"
)
</codesample>
</body>
</section>

<section>
<title>Advanced <c>eapply</c></title>
<body>

<p>
This example shows how different patch levels can be applied:
</p>

<codesample lang="ebuild">
src_prepare() {
eapply -p2 "${WORKDIR}/${P}-suse-update.patch"
eapply -p0 "${FILESDIR}/${PV}-no-TIOCGDEV.patch"
eapply "${FILESDIR}/${PV}-gcc-6.patch"
eapply_user
ulm marked this conversation as resolved.
Show resolved Hide resolved
}
</codesample>
</body>
</section>
</chapter>
</guide>
187 changes: 0 additions & 187 deletions ebuild-writing/functions/src_prepare/epatch/text.xml

This file was deleted.

2 changes: 1 addition & 1 deletion ebuild-writing/functions/src_prepare/text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ when writing <c>src_prepare</c> functions.
</section>

</chapter>
<include href="epatch/"/>
<include href="eapply/"/>
<include href="autopackage/"/>
</guide>
2 changes: 1 addition & 1 deletion quickstart/text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ Note the <c>${FILESDIR}/${P}-destdir.patch</c> <d/> this refers to
subdirectory in the Gentoo repository. Larger patch files must go on your
developer's space at <c>dev.gentoo.org</c> rather than in <c>files/</c> or
mirrors <d/> see <uri link="::general-concepts/mirrors/#Gentoo Mirrors"/> and
<uri link="::ebuild-writing/functions/src_prepare/epatch/"/>.
<uri link="::ebuild-writing/functions/src_prepare/eapply/"/>.
</p>

<p>
Expand Down
2 changes: 1 addition & 1 deletion tools-reference/diff-and-patch/text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ To apply a patch, use <c>patch -pX &lt; whatever.patch</c>,
where <c>X</c> is a number representing the number of path components
which must be removed (typically this is <c>0</c> or <c>1</c>). Within
ebuilds, use the <c>eapply</c> function instead <d/> see
<uri link="::ebuild-writing/functions/src_prepare/epatch/"/>.
<uri link="::ebuild-writing/functions/src_prepare/eapply/"/>.
</p>

<p>
Expand Down
2 changes: 0 additions & 2 deletions xsl/lang.highlight.ebuild.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
cmake_src_prepare cmake_src_test cmake_use_find_package
<!-- desktop -->
doicon domenu make_desktop_entry make_session_desktop newicon newmenu
<!-- epatch -->
epatch
<!-- flag-o-matic -->
all-flag-vars append-atomic-flags append-cflags append-cppflags append-cxxflags append-fflags append-flags
append-ldflags append-lfs-flags append-libs filter-flags filter-ldflags filter-lfs-flags filter-lto filter-mfpmath
Expand Down
Loading