aboutsummaryrefslogtreecommitdiff
blob: a5432726fcbb5cc42a3f93a43200b7324d342c92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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
}
</codesample>
</body>
</section>
</chapter>
</guide>