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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
|
<?xml version="1.0" encoding="UTF-8"?>
<devbook self="ebuild-writing/eapi/">
<chapter>
<title>EAPI usage and description</title>
<body>
<p>
The <uri link="https://wiki.gentoo.org/wiki/Project:Package_Manager_Specification">
Package Manager Specification</uri> is a standardization effort to ensure that
the ebuild file format, the ebuild repository format (of which the Gentoo
repository is Gentoo's main incarnation) as well as behaviour of the package
managers interacting with these ebuilds is properly written down and agreed
upon.
</p>
<p>
EAPI is a version defined in ebuilds and other package manager related files
which informs the package manager about the file syntax and content. It is,
in effect, the version of the Package Manager Specification that the file
adheres to.
</p>
<p>
This section provides usage and descriptions of the different EAPIs.
</p>
</body>
<section>
<title>Usage of EAPIs</title>
<body>
<important>
An overview about the important features of each EAPI is provided in the
appendix of the Package Manager Specification. The two-page leaflet
can be printed out, consulted for reference and is available
as <c>app-doc/pms</c> in the main tree.
</important>
<p>
You must set the EAPI variable by specifying it at the top of the ebuild:
</p>
<codesample lang="ebuild">
# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
</codesample>
<note>
Most developers prefer to set the EAPI version without quotes. However,
enclosing it in single or double quotes is also allowed.
</note>
<important>
EAPI must only be defined in ebuild files, not eclasses. (eclasses may have
EAPI-conditional code)
</important>
<p>
When writing new ebuilds developers can choose whatever EAPI they think
is the best. Using the features of the latest EAPI is encouraged.
</p>
</body>
<subsection>
<title>Upgrade path</title>
<body>
<p>
Gentoo policy is to support upgrades for installations at least a year old
with no/little intervention and up to two years old with minor intervention.
To achieve this, developers must avoid using the latest EAPI in ebuilds within
the <c>@system</c> set
(see <uri link="::general-concepts/dependencies/#Implicit system dependency"/>)
or its dependencies.
</p>
<p>
The Base System project has
<uri link="https://wiki.gentoo.org/wiki/Project:Base#Rules_and_limitations">rules</uri>
governing their use of newer EAPIs, as does the
<uri link="https://projects.gentoo.org/python/guide/package-maintenance.html#porting-packages-to-a-new-eapi">Python project</uri>.
</p>
<p>
It is also convention that blockers within ebuilds are retained for at least
2 years after the last ebuild matching the block is removed from the tree to
avoid file collisions for users upgrading older systems. <c>pkgcheck</c> has
a warning for this called <c>OutdatedBlocker</c> (or even
<c>NonexistentBlocker</c> for when the match is from pre-git times if using
a non-grafted repository).
</p>
</body>
</subsection>
</section>
<section>
<title>EAPIs 0 to 4</title>
<body>
<p>
EAPIs 0 to 4 are obsolete and must no longer be used. Refer to the Package
Manager Specification for details about them.
</p>
</body>
</section>
<section>
<title>EAPI 5</title>
<body>
<todo>
EAPI 5 is deprecated and should no longer appear here. The information needs to
be split up and moved to other sections.
</todo>
</body>
<subsection>
<title>EAPI 5 metadata</title>
<body>
<dl>
<dt>REQUIRED_USE supports new at-most-one-of operator</dt>
<dd>
The new <b>at-most-one-of</b> operator consists of the string <c>??</c>,
and is satisfied if zero or one (but no more) of its child elements is
matched.
</dd>
<dt>SLOT supports optional "sub-slot" part</dt>
<dd>
The <c>SLOT</c> variable may contain an optional <b>sub-slot</b> part that
follows the regular slot and is delimited by a <c>/</c> character.
The sub-slot must be a valid slot name. The sub-slot is used to represent
cases in which an upgrade to a new version of a package with a different
sub-slot may require dependent packages to be rebuilt. When the sub-slot
part is omitted from the SLOT definition, the package is considered to have
an implicit sub-slot which is equal to the regular slot.
</dd>
<dt>Slot operators and sub-slots in dependencies</dt>
<dd>
<p>
A slot dependency may contain an optional sub-slot part that follows the
regular slot and is delimited by a <c>/</c> character. This can be useful
for packages installing pre-built binaries that require a library with a
specific soname version which corresponds to the sub-slot. For example:
</p>
<codesample lang="ebuild">
RDEPEND="dev-libs/foo:0/3"
</codesample>
<p>
Package dependency specifications can use <b>slot operators</b> to clarify
what should happen if the slot and/or sub-slot of a runtime dependency
changes:
</p>
<ul>
<li>
<c>:*</c> Indicates that any slot value is acceptable. In addition,
for runtime dependencies, indicates that the package specifying the
dependency will not break if the package matching the dependency is
replaced by a different matching package with a different slot and/or
sub-slot.
</li>
<li>
<c>:=</c> Indicates that any slot value is acceptable. In addition,
for runtime dependencies, indicates that the package specifying the
dependency will break unless there is available a package matching
the dependency and whose slot and sub-slot are equal to the slot and
sub-slot of the best installed version that had matched this dependency
at the time when the package specifying this dependency had been
installed.
</li>
<li>
<p>
<c>:slot=</c> Indicates that only a specific slot value is acceptable,
and otherwise behaves identically to the <c>:=</c> operator.
</p>
<note>
use <c>:slot/subslot</c> without a <c>=</c> to depend on a specific
slot and sub-slot pair; it's a syntax error to use <c>:slot/subslot=</c>
in an ebuild.
</note>
</li>
</ul>
<p>
The <c>:slot</c> dependency syntax continues to behave like in EAPI=4 or
earlier, i.e. it indicates that only the specific slot value is acceptable,
but the package will not break when the version matching the runtime
dependency is replaced by a version with a different sub-slot.
</p>
<p>
For example:
</p>
<codesample lang="ebuild">
RDEPEND="dev-libs/foo:2=
>=dev-libs/bar-0.9:=
media-gfx/baz:*
x11-misc/wombat:0"
</codesample>
<p>
means that the package should be rebuilt when <c>foo:2</c> or
<c>>=bar-0.9</c> are upgraded to versions with different subslots,
but that changes in subslots of <c>baz</c> or <c>wombat:0</c> should be
ignored.
</p>
</dd>
</dl>
</body>
</subsection>
<subsection>
<title>EAPI 5 profiles</title>
<body>
<dl>
<dt>Profile stable USE forcing and masking</dt>
<dd>
In profile directories with an EAPI supporting stable masking, new USE
configuration files are supported: <c>use.stable.mask</c>,
<c>use.stable.force</c>, <c>package.use.stable.mask</c> and
<c>package.use.stable.force</c>. These files behave similarly to previously
supported USE configuration files, except that they only influence packages
that are merged due to a stable keyword.
</dd>
</dl>
</body>
</subsection>
<subsection>
<title>EAPI 5 helpers</title>
<body>
<dl>
<dt>econf adds --disable-silent-rules</dt>
<dd>
This option will automatically be passed if <c>--disable-silent-rules</c>
occurs in the output of <c>configure --help</c>.
</dd>
<dt>new* commands can read from standard input</dt>
<dd>
Standard input is read when the first parameter is <c>-</c> (a hyphen).
</dd>
<dt>New option --host-root for {has,best}_version</dt>
<dd>
This option <c>--host-root</c> will cause the query to apply to the host
root instead of ROOT.
</dd>
<dt>New doheader helper function</dt>
<dd>
Installs the given header files into <c>/usr/include/</c>. If option
<c>-r</c> is specified, descends recursively into any directories given.
</dd>
<dt>New usex helper function</dt>
<dd>
<!-- We probably need an example here -->
<pre>
USAGE: usex <USE flag> [true output] [false output] [true suffix] [false suffix]
DESCRIPTION:
If USE flag is set, echo [true output][true suffix] (defaults to "yes"),
otherwise echo [false output][false suffix] (defaults to "no").
</pre>
</dd>
</dl>
</body>
</subsection>
<subsection>
<title>EAPI 5 phases</title>
<body>
<dl>
<dt>src_test supports parallel tests</dt>
<dd>
Unlike older EAPIs, the default <c>src_test</c> implementation will not
pass the -j1 option to emake.
</dd>
</dl>
</body>
</subsection>
<subsection>
<title>EAPI 5 variables</title>
<body>
<dl>
<dt>EBUILD_PHASE_FUNC</dt>
<dd>
During execution of an ebuild phase function (such as <c>pkg_setup</c> or
<c>src_unpack</c>), the <c>EBUILD_PHASE_FUNC</c> variable will contain the
name of the phase function that is currently executing.
</dd>
</dl>
</body>
</subsection>
</section>
<section>
<title>EAPI 6</title>
<body>
<todo>
EAPI 6 is deprecated and should no longer appear here. The information needs to
be split up and moved to other sections.
</todo>
</body>
<subsection>
<title>EAPI 6 Bash version</title>
<body>
<dl>
<dt>Bash version</dt>
<dd>
Ebuilds can use features of Bash version 4.2 (was 3.2 before).
</dd>
</dl>
</body>
</subsection>
<subsection>
<title>EAPI 6 ebuild environment</title>
<body>
<dl>
<dt>Locale settings</dt>
<dd>
Behaviour of case modification and collation order (<c>LC_CTYPE</c> and
<c>LC_COLLATE</c>) are guaranteed to be the same as in the C locale, as far
as characters in the ASCII range are concerned.
</dd>
<dt><c>failglob</c> enabled</dt>
<dd>
For <c>EAPI=6</c>, the <c>failglob</c> option of bash is set in the global
scope of ebuilds. If set, failed pattern matches during filename expansion
result in an error when the ebuild is being sourced.
</dd>
</dl>
</body>
</subsection>
<subsection>
<title>EAPI 6 phases</title>
<body>
<dl>
<dt>Update default implementation of <c>src_prepare</c></dt>
<dd>
<p>
This phase is no longer a no-op, it supports applying patches via the
<c>PATCHES</c> variable and applying user patches via <c>eapply_user</c>.
The default <c>src_prepare</c> looks like this:
</p>
<codesample lang="ebuild">
src_prepare() {
if [[ $(declare -p PATCHES 2>/dev/null) == "declare -a"* ]]; then
[[ -n ${PATCHES[@]} ]] && eapply "${PATCHES[@]}"
else
[[ -n ${PATCHES} ]] && eapply ${PATCHES}
fi
eapply_user
}
</codesample>
</dd>
<dt>New <c>src_install</c> Phase Function</dt>
<dd>
<p>
This phase uses the new <c>einstalldocs</c> function for installation of
documentation. The default <c>src_install</c> looks like this:
</p>
<codesample lang="ebuild">
src_install() {
if [[ -f Makefile ]] || [[ -f GNUmakefile ]] || [[ -f makefile ]]; then
emake DESTDIR="${D}" install
fi
einstalldocs
}
</codesample>
</dd>
</dl>
</body>
</subsection>
<subsection>
<title>EAPI 6 helpers</title>
<body>
<dl>
<dt><c>einstall</c> banned</dt>
<dd>
The <c>einstall</c> helper has been banned with <c>EAPI=6</c>.
</dd>
<dt><c>dohtml</c> deprecated</dt>
<dd>
The <c>dohtml</c> helper has been deprecated with <c>EAPI=6</c>.
</dd>
<dt><c>nonfatal die</c></dt>
<dd>
When <c>die</c> or <c>assert</c> are called under the <c>nonfatal</c>
command and with the <c>-n</c> option, they will not abort the build
process but return with an error.
</dd>
<dt><c>eapply</c> support</dt>
<dd>
The <c>eapply</c> command is a simplified substitute for <c>epatch</c>
(from <c>eutils.eclass</c>), implemented in the package manager.
The patches from its file or directory arguments are applied using patch
<c>-p1</c>, but it accepts <c>patch(1)</c> options from GNU patch to
override default behavior.
</dd>
<dt><c>eapply_user</c> support</dt>
<dd>
<p>
The <c>eapply_user</c> command permits the package manager to apply
user-provided patches. It must be called from every <c>src_prepare</c>
function.
</p>
<note>
<c>eapply_user</c> doesn't need to be called explicitly when default
<c>src_prepare</c> is called.
</note>
</dd>
<dt><c>econf</c> adds <c>--docdir</c> and <c>--htmldir</c></dt>
<dd>
Options <c>--docdir</c> and <c>--htmldir</c> are passed to
<c>configure</c>, in addition to the existing options.
</dd>
<dt><c>in_iuse</c> support</dt>
<dd>
The <c>in_iuse</c> function returns <c>true</c> if the given parameter is
available in the ebuilds <c>USE</c>.
</dd>
<dt><c>unpack</c> changes</dt>
<dd>
<ul>
<li>
<c>unpack</c> supports relative paths without leading <c>./</c>
(<c>unpack foo/bar.tar.gz</c> is valid as relative path).
</li>
<li><c>unpack</c> supports <c>.txz</c> (xz compressed tarball).</li>
<li><c>unpack</c> matches filename extensions case-insensitively.</li>
</ul>
</dd>
<dt><c>einstalldocs</c> support</dt>
<dd>
The <c>einstalldocs</c> function will install the files specified by the
<c>DOCS</c> variable (or a default set of files if <c>DOCS</c> is unset)
and by the <c>HTML_DOCS</c> variable.
</dd>
<dt><c>get_libdir</c> support</dt>
<dd>
The <c>get_libdir</c> command outputs the <c>lib*</c> directory basename
suitable for the current ABI.
</dd>
</dl>
</body>
</subsection>
</section>
<section>
<title>EAPI 7</title>
<subsection>
<title>EAPI 7 terminology</title>
<body>
<p>
Documents may use the following terms to better describe dependency and
installation targets.
</p>
<dl>
<dt><c>CHOST</c></dt>
<dd>
The system that will be running the installed package.
</dd>
<dt><c>CBUILD</c></dt>
<dd>
The system used to build packages. When not cross-compiling,
CBUILD == CHOST.
</dd>
<dt><c>CTARGET</c></dt>
<dd>
Used in certain cross-compilations, often empty value.
</dd>
</dl>
</body>
</subsection>
<subsection>
<title>EAPI 7 variables</title>
<body>
<dl>
<dt><c>PORTDIR</c> and <c>ECLASSDIR</c> are removed</dt>
<dd>
<c>PORTDIR</c> and <c>ECLASSDIR</c> are no longer defined and cannot be
used in ebuilds to access these directories.
</dd>
<dt><c>DESTTREE</c> and <c>INSDESTTREE</c> are removed</dt>
<dd>
The unintended exported variables <c>PORTDIR</c> and <c>ECLASSDIR</c>
cannot be used in ebuilds to manipulate installation paths. Use <c>into</c>
or <c>insinto</c>, respectively, instead.
</dd>
<dt><c>D</c>, <c>ED</c>, <c>ROOT</c>, and <c>EROOT</c> modified</dt>
<dd>
These variables no longer contain a trailing slash with <c>EAPI=7</c>.
</dd>
<dt><c>BDEPEND</c> added</dt>
<dd>
Previously, all build-time tools and libraries went into the <c>DEPEND</c>.
Now, built-time dependencies are split into <c>DEPEND</c> and
<c>BDEPEND</c>. The difference is simply that <c>BDEPEND</c> are
dependencies to be executed on the CBUILD. <c>DEPEND</c> remains for other
dependencies, such as libraries, for the CHOST. This improves the
cross-compilation support.
</dd>
<dt><c>BROOT</c> added</dt>
<dd>
<c>BROOT</c> is the absolute path to the root directory, including any
prefix, containing build dependencies satisfied by BDEPEND, typically
executable build tools.
</dd>
<dt><c>SYSROOT</c> and <c>ESYSROOT</c> added</dt>
<dd>
<c>SYSROOT</c> is the location of where dependencies in <c>DEPEND</c> are
installed. <c>ESYSROOT</c> is <c>SYSROOT</c> with <c>EPREFIX</c> appended.
</dd>
<dt><c>ENV_UNSET</c> added</dt>
<dd>
A whitespace delimited list of variables to be removed from the build
environment.
</dd>
</dl>
</body>
</subsection>
<subsection>
<title>EAPI 7 metadata</title>
<body>
<dl>
<dt>Empty groupings are banned</dt>
<dd>
Groupings which are empty, such as <c>DEPEND="|| ( ${empty_var} )"</c>
will now generate an error. Furthermore, conditions within groupings are
more strictly enforced. For example, <c>REQUIRED_USE="|| ( foo? ( bar )
baz? ( zoinks )"</c> would previously work with <c>USE="-foo -baz"</c>
now requires either <c>USE="foo bar"</c> or <c>USE="baz zoinks"</c>.
</dd>
</dl>
</body>
</subsection>
<subsection>
<title>EAPI 7 profiles</title>
<body>
<dl>
<dt><c>package.provided</c> banned</dt>
<dd>
Profiles may no longer contain a <c>package.provided</c> file with
<c>EAPI=7</c>.
</dd>
</dl>
</body>
</subsection>
<subsection>
<title>EAPI 7 helpers</title>
<body>
<dl>
<dt><c>dohtml</c> banned</dt>
<dd>
The <c>dohtml</c> helper has been banned with <c>EAPI=7</c>.
</dd>
<dt><c>dolib</c> and <c>libopts</c> banned</dt>
<dd>
The <c>dolib</c> helper and the associated <c>libopts</c> have been banned
with <c>EAPI=7</c>.
</dd>
<dt><c>has_version</c> and <c>best_version</c> changes</dt>
<dd>
<p>
<c>has_version</c> and <c>best_version</c> now support an optional switch
to determine which type of dependencies to check.
</p>
<ul>
<li><c>-r</c> (the default) will check runtime dependencies (RDEPEND)</li>
<li><c>-d</c> will check CHOST build-time dependencies (DEPEND)</li>
<li><c>-b</c> will check CBUILD build-time dependencies (BDEPEND)</li>
</ul>
</dd>
<dt>Version manipulation and comparison commands</dt>
<dd>
<p>
EAPI=7 introduced three commands for common version number operations.
</p>
<ul>
<li><c>ver_cut</c> obtains substrings of a version string</li>
<li><c>ver_rs</c> replaces separators in a version string</li>
<li><c>ver_test</c> compares two versions</li>
</ul>
<p>
See <uri link="::ebuild-writing/variables/#Version and name formatting issues"/>
for examples of common uses or
<uri link="https://dev.gentoo.org/~mgorny/articles/the-ultimate-guide-to-eapi-7.html#version-manipulation-and-comparison-commands">
an in-depth look</uri>
</p>
</dd>
<dt>New function <c>eqawarn</c></dt>
<dd>
The <c>eqawarn</c> helper has been added with <c>EAPI=7</c>. This function
is to alert developers to a deprecated feature. Previously, this was
contained in <c>eutils</c> eclass which is no longer necessary.
</dd>
<dt>New function <c>dostrip</c></dt>
<dd>
The <c>dostrip</c> helper has been added with <c>EAPI=7</c>. This function
controls whether or not to strip a binary. <c>dostrip -x [file]</c> will
exclude a binary from being stripped. Conversely, when combined with
RESTRICT=strip, <c>dostrip [file]</c> selects a binary file to be stripped.
</dd>
<dt><c>die</c> and <c>assert</c> changes</dt>
<dd>
These commands are now safe to use in a subshell and act as if they were
called in the main process.
</dd>
<dt><c>nonfatal</c> changes</dt>
<dd>
The <c>nonfatal</c> command now works for shell functions and subprocesses.
</dd>
<dt><c>domo</c> behaviour changed</dt>
<dd>
<c>domo</c> (for localizations) now ignores the <c>into</c> directives.
This follows similar commands like <c>doinfo</c> and <c>doman</c>.
</dd>
<dt><c>econf</c> changes</dt>
<dd>
The cross-compilation options <c>--build</c> and <c>--target</c> options
to specify <c>CBUILD</c> and <c>CTARGET</c> respectively have been added
and are retro-active to all EAPIs. In addition, if the build supports
<c>--with-sysroot</c>, the correct value will be passed such that normal
and cross-compilations succeed.
</dd>
</dl>
</body>
</subsection>
</section>
<section>
<title>EAPI 8</title>
<body>
<note>
This section is based on
<uri link="https://mgorny.pl/articles/the-ultimate-guide-to-eapi-8.html">
The ultimate guide to EAPI 8</uri> by Michał Górny.
</note>
</body>
<subsection>
<title>EAPI 8 tree layout</title>
<body>
<dl>
<dt>Less strict naming rules for updates directory</dt>
<dd>
<p>
Up to EAPI 7, the files in the <c>profiles/updates</c> directory had to
follow strict naming by quarters like <c>2Q-2021</c>, indicating the
quarter and the year when they were added. Such a choice of name had the
side effect that lexical sorting of filenames was unsuitable.
</p>
<p>
In EAPI 8, the naming requirement is removed. Eventually, this will allow
switching to a more convenient scheme sorted by year. Different lengths
of time periods will also be possible.
</p>
<p>
Note that this change actually requires changing the repository EAPI
(found in <c>profiles/eapi</c>), so it will not affect Gentoo for at least
the next two years.
</p>
</dd>
</dl>
</body>
</subsection>
<subsection>
<title>EAPI 8 ebuild format</title>
<body>
<dl>
<dt>Bash version is now 5.0</dt>
<dd>
<p>
The Bash version used for ebuilds is changed from 4.2 to 5.0. This means
not only that ebuilds are now permitted to use features provided by the new
Bash version but also the <c>BASH_COMPAT</c> value used for the ebuild
environment is updated, switching the shell behaviour.
</p>
<p>
The only really relevant difference in behaviour is:
</p>
<ul>
<li>
<p>
Quotes are now removed from the RHS argument of a
<c>"${var/.../"..."}"</c> substitution:
</p>
<pre>
var=foo
echo "${var/foo/"bar"}"
</pre>
<p>
The above snippet yields <c>"bar"</c> in Bash 4.2 but just <c>bar</c>
in 4.3+.
</p>
</li>
</ul>
<p>
Potentially interesting new features include:
</p>
<ul>
<li>
<p>
Negative subscripts can now be used to set and unset array elements
(Bash 4.3+):
</p>
<pre>
$ foo=( 1 2 3 )
$ foo[-1]=4
$ unset 'foo[-2]'
$ declare -p foo
declare -a foo=([0]="1" [2]="4")
</pre>
</li>
<li>
<p>
Nameref variables are introduced that work as references to other
variables (4.3+):
</p>
<pre>
$ foo=( 1 2 3 )
$ declare -n bar=foo
$ echo "${bar[@]}"
1 2 3
$ bar[0]=4
$ echo "${foo[@]}"
4 2 3
$ declare -n baz=foo[1]
$ echo "${baz}"
2
$ baz=100
$ echo "${bar[@]}"
4 100 3
</pre>
</li>
<li>
<p>
The <c>[[ -v ... ]]</c> test operator can be used with array indices
to test for array elements being set (4.3+). The two following lines
are now equivalent:
</p>
<pre>
[[ -n ${foo[3]+1} ]]
[[ -v foo[3] ]]
</pre>
</li>
<li>
<p>
<c>mapfile</c> (AKA <c>readarray</c>) now accepts a delimiter via
<c>-d</c>, with a <c>-t</c> option to strip it from read data
(Bash 4.4+). The two following solutions to grab output from
<c>find(1)</c> are now equivalent:
</p>
<pre>
# old solution
local x files=()
while read -d '' -r x; do
files+=( "${x}" )
done < <(find -print0)
# new solution
local files=()
mapfile -d '' -t files < <(find -print0)
</pre>
</li>
<li>
<p>
A new set of transformations is available via <c>${foo@...}</c>
parameter expansion (4.4+), e.g. to print a value with necessary
quoting:
</p>
<pre>
$ var="foo 'bar' baz"
$ echo "${var@Q}"
'foo '\''bar'\'' baz'
</pre>
<p>
For more details, see: <c>info bash</c> or the
<uri link="https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html">
Bash reference manual</uri>.
</p>
</li>
<li>
<p>
<c>local -</c> can be used to limit single-letter (mangled via
<c>set</c>) shell option changes to the scope of the function, and
restore them upon returning from it (4.4+). The following two functions
are now equivalent:
</p>
<pre>
# old solution
func() {
local prev_shopt=$(shopt -p -o noglob)
set -o noglob
${prev_shopt}
}
# new solution
func() {
local -
set -o noglob
}
</pre>
<p>
The complete information on all changes and new features can be found
in the
<uri link="https://git.savannah.gnu.org/cgit/bash.git/tree/NEWS?h=bash-5.0">
Bash 5.0 (and earlier) release notes</uri>.
</p>
</li>
</ul>
</dd>
</dl>
</body>
</subsection>
<subsection>
<title>EAPI 8 variables</title>
<body>
<dl>
<dt>Selective fetch/mirror restriction</dt>
<dd>
<p>
Before EAPI 8, fetch and mirror restrictions applied globally. That is,
if you needed to apply the respective restriction to at least one distfile,
you had to apply it to them all. However, sometimes packages used a
combination of proprietary and free distfiles, the latter including e.g.
third party patches, artwork. Until now, they had to be mirror-restricted
completely.
</p>
<p>
EAPI 8 allows undoing fetch and mirror restriction for individual files.
To use this, set <c>RESTRICT</c> as before, then use the special
<c>fetch+</c> prefix to specify URLs that can be fetched from, or the
<c>mirror+</c> prefix to reenable mirroring of individual files.
</p>
<p>
Similarly to how the <c>fetch</c> restriction implies a <c>mirror</c>
restriction, the <c>mirror</c> override implies a <c>fetch</c> override.
</p>
<codesample lang="ebuild">
EAPI=8
SRC_URI="
${P}.tgz
fetch+https://example.com/${P}-patch-1.tgz
mirror+https://example.com/${P}-fanstuff.tgz"
RESTRICT="fetch"
</codesample>
<p>
The following table summarises the new behaviour:
</p>
<table>
<tr>
<th><c>RESTRICT</c></th>
<th>URI prefix</th>
<th>Fetching</th>
<th>Mirroring</th>
</tr>
<tr>
<ti>(none)</ti>
<ti>(any)</ti>
<ti>allowed</ti>
<ti>allowed</ti>
</tr>
<tr>
<ti rowspan="2">mirror</ti>
<ti>(none) / fetch+</ti>
<ti>allowed</ti>
<ti>prohibited</ti>
</tr>
<tr>
<ti>mirror+</ti>
<ti>allowed</ti>
<ti>allowed</ti>
</tr>
<tr>
<ti rowspan="3">fetch</ti>
<ti>(none)</ti>
<ti>prohibited</ti>
<ti>prohibited</ti>
</tr>
<tr>
<ti>fetch+</ti>
<ti>allowed</ti>
<ti>prohibited</ti>
</tr>
<tr>
<ti>mirror+</ti>
<ti>allowed</ti>
<ti>allowed</ti>
</tr>
</table>
</dd>
<dt>Install-time dependencies (<c>IDEPEND</c>)</dt>
<dd>
<p>
The primary use for install-time dependencies is to specify dependencies
that are needed during the <c>pkg_postinst</c> phase and that can be
unmerged afterwards. That's pretty much the same as <c>RDEPEND</c>, except
for the unmerging part <d/> and uninstalling a few tools did not seem a
goal justifying another dependency type.
</p>
<p>
With cross-compilation support in EAPI 7, a new dependency type focused
on the build host (<c>CBUILD</c>) tools was added <d/> <c>BDEPEND</c>.
Unfortunately, this had missed the important use case of running
executables installed to the target system when cross-compiling.
<c>RDEPEND</c> was no longer a suitable method of pulling in tools for
<c>pkg_postinst</c>; and since <c>BDEPEND</c> is not used when installing
from a binary package, something new was needed.
</p>
<p>
This is where <c>IDEPEND</c> comes in. It is roughly to <c>RDEPEND</c> what
<c>BDEPEND</c> is to <c>DEPEND</c>. Similarly to <c>BDEPEND</c>,
it specifies packages that must be built for the <c>CBUILD</c> triplet
and installed into <c>BROOT</c> (and therefore queried using
<c>has_version -b</c>). However, similarly to <c>RDEPEND</c>, it is used
when the package is being merged rather than built from source.
It is guaranteed to be satisfied throughout <c>pkg_preinst</c> and
<c>pkg_postinst</c>, and it can be uninstalled afterwards.
</p>
<codesample lang="ebuild">
EAPI=8
inherit xdg-utils
IDEPEND="dev-util/desktop-file-utils"
pkg_postinst() {
xdg_desktop_database_update
}
pkg_postrm() {
xdg_desktop_database_update
}
</codesample>
<p>
In the example provided above, the ebuild needs to update the icon cache
upon being installed or uninstalled. By placing the respective tool in
<c>IDEPEND</c>, the ebuild requests it to be available at the time of
<c>pkg_postinst</c>. When cross-compiling, the tool will be built for
<c>CBUILD</c> and therefore directly executable by the ebuild.
</p>
<p>
The dependency types table for EAPI 8 is presented below.
</p>
<table>
<tr>
<th>Dependency type</th>
<th>BDEPEND</th>
<th>IDEPEND</th>
<th>DEPEND</th>
<th>RDEPEND</th>
<th>PDEPEND</th>
</tr>
<tr>
<th>Present at</th>
<ti>build</ti>
<ti>install</ti>
<ti>build</ti>
<ti>install</ti>
<ti>n/a</ti>
</tr>
<tr>
<th>Binary compatible with</th>
<ti colspan="2">CBUILD</ti>
<ti colspan="3">CHOST</ti>
</tr>
<tr>
<th>Base unprefixed path</th>
<ti colspan="2"><c>/</c></ti>
<ti>SYSROOT</ti>
<ti colspan="2">ROOT</ti>
</tr>
<tr>
<th>Relevant offset-prefix</th>
<ti colspan="2">BROOT</ti>
<ti>EPREFIX (unless SYSROOT != ROOT)</ti>
<ti colspan="2">EPREFIX</ti>
</tr>
<tr>
<th>Path combined with prefix</th>
<ti colspan="2">BROOT</ti>
<ti>ESYSROOT</ti>
<ti colspan="2">EROOT</ti>
</tr>
<tr>
<th>PM query command option</th>
<ti colspan="2"><c>-b</c></ti>
<ti><c>-d</c></ti>
<ti colspan="2"><c>-r</c></ti>
</tr>
</table>
</dd>
<dt>
<c>PROPERTIES</c> and <c>RESTRICT</c> are now accumulated across eclasses
</dt>
<dd>
<p>
Up to EAPI 7, <c>PROPERTIES</c> and <c>RESTRICT</c> were treated like
regular Bash variables when sourcing eclasses. This meant that if an eclass
or an ebuild wanted to modify them, they had to explicitly append to them,
e.g. via <c>+=</c>. This was inconsistent with how some other variables
(but not all) were handled, and confusing to developers. For example,
consider the following snippet:
</p>
<codesample lang="ebuild">
EAPI=7
inherit git-r3
PROPERTIES+=" live"
</codesample>
<p>
Note how you needed to append to <c>PROPERTIES</c> set by git-r3 eclass,
otherwise the ebuild would have overwritten it. In EAPI 8, you can finally
do the following instead:
</p>
<codesample lang="ebuild">
EAPI=8
inherit git-r3
PROPERTIES="live"
</codesample>
<p>
Now the complete list of metadata variables accumulated across eclasses
and ebuilds includes: <c>IUSE</c>, <c>REQUIRED_USE</c>, <c>*DEPEND</c>,
<c>PROPERTIES</c>, <c>RESTRICT</c>. Variables that are not treated this way
are: <c>EAPI</c>, <c>HOMEPAGE</c>, <c>SRC_URI</c>, <c>LICENSE</c>,
<c>KEYWORDS</c>. <c>EAPI</c> and <c>KEYWORDS</c> are not supposed to be set
in eclasses; as for the others, there appears to be a valid use case for
eclasses providing default values and the ebuilds being able to override
them.
</p>
</dd>
</dl>
</body>
</subsection>
<subsection>
<title>EAPI 8 phase functions</title>
<body>
<dl>
<dt><c>pkg_*</c> phases now run in a dedicated empty directory</dt>
<dd>
<p>
Before EAPI 8, the initial working directory was specified for <c>src_*</c>
phases only. For other phases (i.e. <c>pkg_*</c> phases), ebuilds were not
supposed to assume any particular directory. In EAPI 8, these phases are
guaranteed to be started in a dedicated empty directory.
</p>
<p>
The idea of using an empty directory is pretty simple <d/> if there are no
files in it, the risk of unexpected and hard to predict interactions of
tools with their current working directory is minimized.
</p>
</dd>
<dt>
<c>PATCHES</c> no longer permits options
</dt>
<dd>
<p>
The <c>eapply</c> invocation in the default <c>src_prepare</c>
implementation has been changed to:
</p>
<codesample lang="ebuild">
eapply -- "${PATCHES[@]}"
</codesample>
<p>
This ensures that all items in the <c>PATCHES</c> variable are treated
as path names. As a side effect, it is no longer possible to specify
<c>patch</c> options via the <c>PATCHES</c> variable. Such hacks were never
used in the Gentoo repository but they have been spotted in
user-contributed ebuilds. The following will no longer work:
</p>
<codesample lang="ebuild">
PATCHES=( -p0 "${FILESDIR}"/${P}-foo.patch )
</codesample>
<p>
Instead, you will need to invoke <c>eapply</c> explicitly, see the example
below. Alternatively, rebase the patch level.
</p>
<codesample lang="ebuild">
src_prepare() {
eapply -p0 "${FILESDIR}"/${P}-foo.patch
eapply_user
}
</codesample>
</dd>
</dl>
</body>
</subsection>
<subsection>
<title>EAPI 8 commands</title>
<body>
<dl>
<dt>New econf-passed options</dt>
<dd>
<p>
The <c>econf</c> helper has been modified to pass two more options to
the configure script if the <c>--help</c> text indicates that they are
supported. These are:
</p>
<ul>
<li><c>--datarootdir="${EPREFIX}"/usr/share</c></li>
<li><c>--disable-static</c></li>
</ul>
<p>
The former option defines the base directory that is used to determine
locations for system/desktop-specific data files, e.g. .desktop files and
various kinds of documentation. This is necessary for ebuilds that override
<c>--prefix</c>, as the default path is relative to it.
</p>
<p>
The latter option disables building static libraries by default. This is
part of the ongoing effort to disable unconditional install of static
libraries
(<uri link="https://projects.gentoo.org/qa/policy-guide/installed-files.html#pg0302">
Gentoo Policy Guide, Installation of static libraries</uri>).
</p>
</dd>
<dt><c>dosym -r</c> to create relative symlinks</dt>
<dd>
<p>
Relative symlink targets tend to be more reliable. Consider the two
following examples:
</p>
<codesample lang="ebuild">
dosym "${EPREFIX}"/usr/lib/frobnicate/frobnicate /usr/bin/frobnicate
dosym ../lib/frobnicate/frobnicate /usr/bin/frobnicate
</codesample>
<p>
The first line creates a symlink using an absolute path. The problem with
that is if you mount your Gentoo system in a subdirectory of your root
filesystem (e.g. for recovery), the symlink will point at the wrong
location. Using relative symlinks (as demonstrated on the second line)
guarantees that the symlink will work independently of where the filesystem
is mounted.
</p>
<p>
There is also fact that you need to explicitly prepend <c>${EPREFIX}</c>
to the absolute paths passed as the first argument of <c>dosym</c>. Using
a relative target avoids the problem altogether and makes it less likely to
forget about the prefix.
</p>
<p>
However, in some instances, determining the relative path could be hard or
inconvenient. This is especially the case if one (or both) of the paths
comes from an external tool. To make it easier, EAPI 8 adds a new <c>-r</c>
option that makes <c>dosym</c> create a relative symlink to the specified
path (similarly to <c>ln -r</c>):
</p>
<codesample lang="ebuild">
dosym -r /usr/lib/frobnicate/frobnicate /usr/bin/frobnicate
</codesample>
<p>
Note that in this case, you do not pass <c>${EPREFIX}</c>. The helper
determines the <e>logical</e> relative path to the first argument and
creates the appropriate relative symlink. It is very important here to
understand that this function does not handle physical paths, i.e. it will
work only if there are no directory symlinks along the way that would
result in <c>..</c> resolving to a different path. For example, the
following will not work:
</p>
<codesample lang="ebuild">
dosym bar/foo /usr/lib/foo
dosym -r /usr/lib/zomg /usr/lib/foo/zomg
</codesample>
<p>
The logical path from <c>/usr/lib/foo/zomg</c> to <c>/usr/lib/zomg</c> is
<c>../zomg</c>. However, since <c>/usr/lib/foo</c> is actually a symlink to
<c>/usr/lib/bar/foo</c>, <c>/usr/lib/foo/..</c> resolves to
<c>/usr/lib/bar</c>. If you need to account for such directory symlinks,
you need to specify the correct path explicitly:
</p>
<codesample lang="ebuild">
dosym bar/foo /usr/lib/foo
dosym ../../zomg /usr/lib/foo/zomg
</codesample>
</dd>
<dt>
<c>insopts</c> and <c>exeopts</c> now apply to <c>doins</c>
and <c>doexe</c> only
</dt>
<dd>
<p>
In previous EAPIs, there was an inconsistency in how <c>insopts</c> and
<c>exeopts</c> applied to various helpers. In particular, the majority of
helpers (e.g. <c>dobin</c>, <c>dodoc</c> and so on) ignored the options
specified via these helpers but a few did not.
</p>
<p>
EAPI 8 changes the behaviour of the following helpers that used to respect
<c>insopts</c> or <c>exeopts</c>:
</p>
<ul>
<li><c>doconfd</c></li>
<li><c>doenvd</c></li>
<li><c>doheader</c></li>
<li><c>doinitd</c></li>
</ul>
<p>
In EAPI 8, they always use the default options. As a result, <c>insopts</c>
now only affects <c>doins</c>/<c>newins</c>, and <c>exeopts</c> only
affects <c>doexe</c>/<c>newexe</c>. Furthermore, <c>diropts</c> does not
affect the directories implicitly created by these helpers.
</p>
</dd>
<dt><c>usev</c> now accepts a second argument</dt>
<dd>
<p>
The <c>usev</c> helper was introduced to provide the historical Portage
behaviour of outputting the USE flag name on match. In EAPI 8, it has been
extended, in order to provide an alternative to three-argument <c>usex</c>
with an empty third argument (the two-argument <c>usex</c> variant uses a
default of <c>no</c> for the false branch).
</p>
<p>
In other words, the following two calls are now equivalent:
</p>
<codesample lang="ebuild">
$(usex foo --enable-foo '')
$(usev foo --enable-foo)
</codesample>
<p>
This is particularly useful with custom build systems that accept
individual <c>--enable</c> or <c>--disable</c> options but not their
counterparts.
</p>
<p>
As a result, <c>usev</c> and <c>usex</c> can now be used to achieve all the
common (and less common) output needs as summarized in the following table.
</p>
<table>
<tr>
<th>Variant</th>
<th>True</th>
<th>False</th>
</tr>
<tr>
<ti>usev <e>flag</e></ti>
<ti><e>flag</e></ti>
<ti></ti>
</tr>
<tr>
<ti>usev <e>flag</e> <e>true</e></ti>
<ti><e>true</e></ti>
<ti></ti>
</tr>
<tr>
<ti>usex <e>flag</e></ti>
<ti><c>yes</c></ti>
<ti><c>no</c></ti>
</tr>
<tr>
<ti>usex <e>flag</e> <e>true</e></ti>
<ti><e>true</e></ti>
<ti><c>no</c></ti>
</tr>
<tr>
<ti>usex <e>flag</e> <e>true</e> <e>false</e></ti>
<ti><e>true</e></ti>
<ti><e>false</e></ti>
</tr>
</table>
</dd>
<dt><c>hasq</c>, <c>hasv</c> and <c>useq</c> functions have been banned</dt>
<dd>
<p>
In its early days, the <c>use</c> helper would print the USE flag name
if it matched, in addition to its boolean exit status. Later, a quiet
<c>useq</c> and a verbose <c>usev</c> helper were added, and <c>use</c> was
made quiet by default. The same changes were applied to <c>has</c>.
</p>
<p>
Fast forward to EAPI 7, there are still three variants of <c>use</c>
and three variants of <c>has</c>. The base variant that is quiet, the
<c>useq</c>/<c>hasq</c> variant that is equivalent to the base variant,
and the verbose <c>usev</c>/<c>hasv</c> variant.
</p>
<p>
Obviously, adding a second argument to <c>hasv</c> was not possible, so its
behaviour would have become inconsistent with <c>usev</c> in EAPI 8. Since
<c>hasv</c> was not used in the Gentoo repository, it has been removed,
along with <c>hasq</c> and <c>useq</c> which were considered deprecated
since 2011.
</p>
</dd>
<dt>unpack removes support for 7-Zip, LHA and RAR formats</dt>
<dd>
<p>
Support for the least commonly used archive formats from <c>unpack</c> has
been removed:
</p>
<ul>
<li>7-Zip (.7z)</li>
<li>LHA (.lha, .lzh)</li>
<li>RAR (.rar)</li>
</ul>
<p>
Packages using these format for distfiles must now unpack them manually.
Using <c>unpacker.eclass</c> is recommended for this.
</p>
</dd>
</dl>
</body>
</subsection>
</section>
</chapter>
</devbook>
|