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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
|
<?xml version="1.0" encoding="UTF-8"?>
<guide self="ebuild-writing/common-mistakes/">
<chapter>
<title>Common mistakes</title>
<body>
<p>
This section contains information on the common mistakes developers make when
writing ebuilds.
</p>
</body>
<section>
<title>Common ebuild writing mistakes</title>
<subsection>
<title>Unguarded external calls</title>
<body>
<p>
Calls to external tools should be guarded with <c>|| die</c> (or use
<c>assert</c>) in almost all cases to allow failure to be detected.
See <uri link="::ebuild-writing/error-handling/"/>.
</p>
</body>
</subsection>
<subsection>
<title>Invalid use of <c>static</c> USE flag</title>
<body>
<p>
The <c>static</c> use-flag should only be used to make a binary use static
linking instead of dynamic linking. It should not be used to make a library
install static libraries. Instead, the <c>static-libs</c> use-flag is used for
this.
</p>
</body>
</subsection>
<subsection>
<title>Invalid use of <c>ROOT</c></title>
<body>
<p>
The usage of <c>ROOT</c> is only designed to influence the way the package is
installed (ie. into <c>ROOT</c>) <d/> building and compiling should not depend
on <c>ROOT</c>. As a consequence of this, the usage of <c>ROOT</c> in
<c>src_*</c> functions is not allowed. <c>pkgcheck</c> can now detect some
such cases via its <c>MisplacedVariable</c> check.
See <uri link="https://bugs.gentoo.org/775191">bug 775191</uri> for more
information.
</p>
<p>
See also <uri link="::ebuild-writing/variables/#ROOT"/>.
</p>
</body>
</subsection>
<subsection>
<title>Referencing the full path to documentation files that could be
compressed</title>
<body>
<p>
When printing out to the users where to find files like INSTALL, do not specify
the full path since <c>PORTAGE_COMPRESS</c> comes into play. The file could be
compressed with gzip, bzip2, or some other random compression tool. So,
instead of doing this:
</p>
<codesample lang="ebuild">
elog "They are listed in /usr/share/doc/${PF}/INSTALL.gz"
</codesample>
<p>
Do something like:
</p>
<codesample lang="ebuild">
elog "They are listed in the INSTALL file in /usr/share/doc/${PF}"
</codesample>
</body>
</subsection>
<subsection>
<title>Build log not verbose</title>
<body>
<p>
When writing ebuilds, you should always check the build log, because the build
system might ignore CC/CXX/LD/CFLAGS/LDFLAGS and such or add undesired flags
by default. In order to analyze this and have complete information, in case
someone reports a bug for your package, the <b>build log must always be verbose.</b>
</p>
<p>
There are several ways to fix non-verbose build logs depending on the build system:
</p>
<ul>
<li>
For <c>cmake</c>-based build systems, it should be sufficient that the
ebuild calls cmake_src_compile which picks up the cmake.eclass variable
<c>CMAKE_VERBOSE=1</c> by default. If you call emake directly for whatever
reason, you can do <c>emake VERBOSE=1</c> (note that 'cmake_src_compile'
takes arguments as well which are passed to make).
</li>
<li>
For <c>autotools</c> based build systems, <c>econf</c> automatically
passes '--disable-silent-rules' to <c>./configure</c>. If necessary,
<c>emake V=1</c> should also work. Note that <c>V=1</c> is not a universal
parameter so may not always work.
</li>
<li>
For custom Makefiles, you often have to write a patch. Try to get
upstream to include an option like 'V=1' to enable full verbosity.
</li>
<li>
Note that when building Go manually outside of the eclass, you
will need GOFLAGS="-x".
</li>
</ul>
<note>In case you encounter an affected package which uses a build system not
controllable by Portage or eclasses, you should file a bug (preferably with
a patch) and make it block the tracker
<uri link="https://bugs.gentoo.org/429308">bug 429308</uri>. Solutions above
ebuild level are preferred.</note>
</body>
</subsection>
<subsection>
<title>-Werror compiler flag not removed</title>
<body>
<p>
"-Werror" is a flag which turns all warnings into errors and thus will abort
compiling if any warning is encountered.
See <uri link="https://bugs.gentoo.org/260867">bug 260867</uri> for more
information and real-life examples/fixes in the Gentoo tree.
</p>
<p><b>Rationale</b></p>
<p>
This flag is not recommended for releases and should always be disabled when
encountered in build logs, because there are numerous cases where this breaks
without purpose, e.g.:
</p>
<ul>
<li>
new warnings on version bumps of GCC/glibc of which the developer was not
aware at the point of coding
</li>
<li>
some autoconf checks will fail badly
</li>
<li>
libraries adding deprecated API warnings although that API is still
working/supported
</li>
<li>
on less known architectures we may get different/more warnings than on
common ones
</li>
<li>
random breakage depending on what distro/architecture/library
version/kernel/userland the developer was testing "-Werror" on
</li>
</ul>
<p>
By turning off "-Werror", we will still see the warnings, but there is no reason
that they cause compile failure. Note that Portage already emits QA
notices about GCC warnings that can cause runtime breakage.
</p>
<p><b>How to fix</b></p>
<p>
To fix the affected build system you should try the following methods:
</p>
<ul>
<li>
remove the compiler flag from the build system, <e>e.g. Makefile.am or
configure.ac</e> or even provide a switch (for autotools based build
systems that could be "--disable-werror", which is good for sending a patch
upstream)
</li>
<li>
use <e>append-flags -Wno-error</e> (needs flag-o-matic.eclass); for this
to work the environment flags have to be respected and placed after build
system flags; this method is not preferred as it will disable all
"-Werror=specific-warning" flags as well, see next section
</li>
</ul>
<p>
Always check that it's really gone in the build log.
</p>
<p><b>Specific -Werror=... flags</b></p>
<p>
The compiler (e.g. GCC) can turn any specific warning into an error. A
specific -Werror flag would be "-Werror=implicit-function-declaration" for
example and will only affect warnings about implicit function declarations. It's
mostly safe to leave these untouched, because they are pinned to this issue and
should not cause random build-time breakage. Also, we can expect that upstream
did this on purpose to avoid known runtime errors and not just for testing their
builds. However, you should check the specified warnings yourself or ask other
developers if unsure.
</p>
<p><b>Exceptions</b></p>
<p>
Removing "-Werror" from configure.ac can cause breakage in very rare
cases where the configure phase relies on the exit code. See
<uri link="https://sourceforge.net/p/open-vm-tools/tracker/81/">
app-emulation/open-vm-tools bug</uri>. But even then we remove it from
the resulting Makefile.
</p>
</body>
</subsection>
<subsection>
<title>Missing/invalid/broken header</title>
<body>
<p>
When you submit your ebuilds, the header must be <e>exactly</e> the same as
the one in
<uri link="https://gitweb.gentoo.org/repo/gentoo.git/tree/skel.ebuild">
skel.ebuild</uri>.
</p>
<p>
The first two lines <e>must</e> look like this:
</p>
<pre>
# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
</pre>
</body>
</subsection>
<subsection>
<title>Redefined P, PV, PN, PF variables</title>
<body>
<p>
You should never redefine those variables. Always use MY_P, MY_PN, MY_PV,
P0, etc. See other ebuilds that do it in Portage for more information. Most
ebuilds use bash "Parameter Expansion". Please read the man page for bash to
understand how "Parameter Expansion" works.
</p>
<p>
By the way, if you find a package that re-defines it, don't copy it. Submit a
bug about that ebuild.
</p>
</body>
</subsection>
<subsection>
<title>Including version numbers in SRC_URI and S</title>
<body>
<p>
You should try not to include version numbers in the SRC_URI and S. Always try
to use ${PV} or ${P}. It makes maintaining the ebuild much easier. If a version
number is not consistent with the tarball/source, then use MY_P. An example
dev-python/pyopenal fetches a tarball called PyOpenAL, so we redefine it like:
</p>
<pre>
MY_P=${P/pyopenal/PyOpenAL}
SRC_URI="http://download.gna.org/pyopenal/${MY_P}.tar.gz"
S=${WORKDIR}/${MY_P}
</pre>
</body>
</subsection>
<subsection>
<title>DEPEND has syntactical errors</title>
<body>
<p>
There are many things that go wrong with user submitted DEPEND and RDEPEND
fields. Here are some important points to follow when you write the dependency
part.
</p>
<ul>
<li>
<e>Always include the CATEGORY.</e>
For example, use <c>>=x11-libs/gtk+-2</c> and not <c>>=gtk+-2</c>.
</li>
<li>
<e>Do not put an asterisk (*) for >= dependencies.</e>
For example, it should be <c>>=x11-libs/gtk+-2</c> rather than
<c>>=x11-libs/gtk+-2*</c>.
</li>
<li><e>GTK specific. Always use =x11-libs/gtk+-1.2* for GTK+1 apps.</e></li>
<li>
<e>Never depend on a meta package.</e>
So don't depend on gnome-base/gnome, always depend on the specific
libraries like libgnome.
</li>
<li>
<e>One dependency per line.</e>
Don't put multiple dependency on the same line. It makes it ugly to read
and hard to follow.
</li>
</ul>
</body>
</subsection>
<subsection>
<title>DEPEND is incomplete</title>
<body>
<note>
The tips in this section apply to all dependency classes, not just
<c>DEPEND</c>.
</note>
<p>
This is another very common error. The ebuild submitter submits an ebuild
that "just works" without checking if the dependencies are correct. Here are
some tips on how to find the correct dependencies.
</p>
<ul>
<li>
<e>Look in configure.in or configure.ac.</e>
Look for checks for packages in here. Things to look out for are pkg-config
checks or AM_* functions that check for a specific version.
</li>
<li>
<e>Look at included .spec files.</e>
A good indication of dependencies is to look at the included .spec files
for relevant deps. However, do not trust them to be the definitive complete
list of dependencies.
</li>
<li>
<e>Look at the application/library website.</e>
Check the application website for possible dependencies that they suggest
are needed.
</li>
<li>
<e>Read the README and INSTALL for the package.</e>
They usually also contain useful information about building and installing
packages.
</li>
<li>
<e>Remember non-binary dependencies such as pkg-config, doc generation
programs, etc.</e>
Usually the build process requires some dependencies such as intltool,
libtool, pkg-config, doxygen, scrollkeeper, gtk-doc, etc. Make sure those
are clearly stated, usually in <c>BDEPEND</c>.
</li>
</ul>
</body>
</subsection>
<subsection>
<title>LICENSE invalid</title>
<body>
<p>
Another common mistake users make when submitting ebuilds is supplying an
invalid license. For example, <c>GPL</c> is not a valid license. You need to
specify <c>GPL-1</c> or <c>GPL-2</c>. Same with <c>LGPL</c>. Make sure the
license you use in the <c>LICENSE</c> field is something that exists in
the <c>licenses</c> directory. As a tip, check the <c>COPYING</c>
in a source tarball for the license. If a package does not specify it
uses <c>GPL-1</c> or <c>GPL-2</c>, it is very likely it uses <c>GPL-2</c>.
</p>
<p>
If the license for the package you submit is unique and not in
<c>licenses/</c>, then you must submit the new license in a
separate file.
</p>
</body>
</subsection>
<subsection>
<title>Untested ARCHs in KEYWORDS</title>
<body>
<p>
Please do not add other ARCHs into KEYWORDS unless the ebuild has been tested on
that ARCH. Also all new ebuilds should be ~x86 or whatever architecture it is.
Make sure when you bump a version, the stable KEYWORDS are all marked as
<c>~</c>.
</p>
</body>
</subsection>
<subsection>
<title>Unused flags and eclass inherits</title>
<body>
<p>
Sometimes obsolete USE flags remain in IUSE despite having no function, e.g.
a dependency may have become mandatory but the USE flag remains in IUSE and
*DEPEND. Similarly, eclasses often become redundant due to changes in the
ebuild, or new EAPIs, e.g. <c>eutils.eclass</c> should be obsolete in modern
EAPIs. Remember to prune these.
</p>
</body>
</subsection>
<subsection>
<title>SLOT missing</title>
<body>
<p>
Make sure you have the SLOT variable in the ebuild. If you don't plan to use it,
don't remove it. Put in:
</p>
<pre>
SLOT="0"
</pre>
</body>
</subsection>
<subsection>
<title>DESCRIPTION and HOMEPAGE wrong</title>
<body>
<p>
Make sure the <c>DESCRIPTION</c> is not overly long. Good descriptions will
describe the main function of the package in a sentence.
</p>
<p>
Please check if the <c>HOMEPAGE</c> variable is right and leads users to the
right page if they want to find out more about the package. If no homepage for
the package is available, set the <c>HOMEPAGE</c> variable to
<c>https://wiki.gentoo.org/wiki/No_homepage</c>. Please also strive to test
HTTPS support for the site used in <c>HOMEPAGE</c>.
</p>
</body>
</subsection>
<subsection>
<title>Wrongfully used spaces instead of TABS</title>
<body>
<p>
It is no fun reformatting lines of ebuilds because the submitter did not follow
the guidelines to use TABS rather than spaces. So <e>please</e> use tabs!
</p>
</body>
</subsection>
<subsection>
<title>Trailing whitespace</title>
<body>
<p>
Remember to run <c>pkgcheck</c> over your ebuilds so it can tell you if there
is trailing whitespace at the end of lines or on empty lines.
</p>
</body>
</subsection>
<subsection>
<title>Adding redundant S=${WORKDIR}/${P}</title>
<body>
<p>
If <c>S=${WORKDIR}/${P}</c>, then you should not add it to your ebuild. This is
implied already, you should only add it if it is something other than
<c>${WORKDIR}/${P}</c>.
</p>
</body>
</subsection>
<subsection>
<title>Documentation missing</title>
<body>
<p>
If your package has documentation, make sure you install it using <c>dodoc</c>
or in <c>/usr/share/doc/${PF}</c>. Remember to check for errors when
running <c>dodoc</c>/<c>doins</c>.
</p>
<p>
If the package documentation is large or requires additional
dependencies to build, you should make it optional with the <c>doc</c>
USE flag. If the documentation is small and does not require
additional dependencies (e.g. <c>README</c> files), install it
unconditionally.
</p>
</body>
</subsection>
<subsection>
<title>Masking unsupported/broken USE flags</title>
<body>
<p>
Exceptionally, a package may have an unsupported/broken USE flag
(this can happen with <e>vanilla</e> or <e>custom-cflags</e>).
Then the USE flag must be masked for that ebuild
(usually in <e>profiles/base/package.use.mask</e>),
at least when the ebuild hits the stable branch.
</p>
</body>
</subsection>
<subsection>
<title>Not using latest EAPI</title>
<body>
<p>
Often, user-submitted ebuilds do not use the latest EAPI and may even
be several versions behind. EAPIs bring new helper functions and improved
methods for completing common tasks. It's recommended that submitted ebuilds
use the latest EAPI possible (subject to eclass constraints) to improve
the ebuild's quality and ease review.
</p>
</body>
</subsection>
<subsection>
<title>Calling pkg-config directly</title>
<body>
<p>
You should not call <c>pkg-config</c> directly in ebuilds because this is
problematic for e.g. cross-compiling. The correct helper respects
<c>${PKG_CONFIG}</c>. Instead, use <c>tc-getPKG_CONFIG</c> from
<c>toolchain-funcs.eclass</c>, e.g.
</p>
<codesample lang="ebuild">
sed -i -e "s:-lncurses:$($(tc-getPKG_CONFIG) --libs ncurses):" || die
</codesample>
<p>
Don't then forget to add <c>virtual/pkgconfig</c> to BDEPEND!
</p>
</body>
</subsection>
</section>
<section>
<title>Common ebuild submission mistakes</title>
<subsection>
<title>Introduction</title>
<body>
<p>
Please submit ebuilds properly by following the
<uri link="::ebuild-maintenance/new-ebuild/"/> tutorial.
</p>
</body>
</subsection>
<subsection>
<title>Tarballing an ebuild</title>
<body>
<p>
Please do not attach ebuilds or patches as tarballs. It avoids extra
operations when reviewing.
</p>
</body>
</subsection>
<subsection>
<title>Inlining ebuilds</title>
<body>
<p>
Don't cut and paste an ebuild into bugzilla's comment field.
</p>
</body>
</subsection>
<subsection>
<title>No description on what the package is</title>
<body>
<p>
Please let us know what the package is, and fill in the URL with the home page
of the application, if any exists.
</p>
</body>
</subsection>
<subsection>
<title>Package updates without explaining what has changed</title>
<body>
<p>
If you submit a package update, then make sure you explain what changes you made
to the ebuild. For example if a package introduces a new features/option and you
use a USE flag, list it in your bug. Don't make us hunt for it.
</p>
<p>
It is wise to submit a diff for a package update rather than the whole ebuild.
The best way to generate it would be:
</p>
<pre>
$ diff -u some-package-0.1.0.ebuild some-package-0.2.0.ebuild > ~/some-package-0.2.0.patch
</pre>
</body>
</subsection>
<subsection>
<title>Submitting unchanged ebuilds for version bumps</title>
<body>
<p>
If you are submitting a new version for a package in Portage, make sure the
existing ebuild works and make sure changes are incorporated in the new ebuild
(such as added documentation.) If there are no required changes to the ebuild
from the previous version, then don't attach the ebuild. Just say so in the bug
report that you copied the ebuild over and verified that the package works and
installs properly.
</p>
</body>
</subsection>
</section>
</chapter>
</guide>
|