File: MANIFEST-FORMAT.md

package info (click to toggle)
debputy 0.1.81
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,748 kB
  • sloc: python: 66,966; sh: 164; perl: 155; makefile: 43; ansic: 5
file content (2878 lines) | stat: -rw-r--r-- 122,290 bytes parent folder | download | duplicates (2)
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
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878

<!--
  THIS FILE IS AUTO-GENERATED; Please edit MANIFEST-FORMAT.md.j2 instead or the `debputy` command
  generating this out.

  REGENERATE WITH:

    debputy internal-command process-template docs/MANIFEST-FORMAT.md.j2 MANIFEST-FORMAT.md

-->

# The debputy manifest format

_This is [reference documentation] and is primarily useful if you have an idea of what you are looking for._
_If you are new to `debputy`, maybe you want to read [GETTING-STARTED-WITH-dh-debputy.md](GETTING-STARTED-WITH-dh-debputy.md) first._

<!-- To writers and reviewers: Check the documentation against https://documentation.divio.com/ -->


## Prerequisites

This guide assumes familiarity with Debian packaging in general.  Notably, you should understand
the different between a (Debian) source package and a (Debian) binary package (e.g., `.deb`) plus
how these concepts relates to `debian/control` (the source control file).

Additionally, the reader is expected to have an understanding of globs and substitution variables.

It is probably very useful to have an understanding on how a binary package is
assembled.  While `debputy` handles the assembly for you, this document will not go in details
with this. Prior experience with `debhelper` (notably the `dh`-style `debian/rules`) may be
useful but should not be a strict requirement.


# The basic manifest

The manifest is a YAML document with a dictionary at the top level layer.  As usual with YAML
versions, you can choose to leave it implicit.  All manifests must include a manifest version, which
will enable the format to change over time.  For now, there is only one version (`0.1`) and you have
to include the line:

    manifest-version: "0.1"


On its own, the manifest containing only `manifest-version: "..."` will not do anything.  So if you
end up only having the `manifest-version` key in the manifest, you can just remove the manifest and
rely entirely on the built-in rules.

## Feature limitations due to Integration Mode

The `debputy` program is build around different integration modes as documented
[INTEGRATION-MODES.md](INTEGRATION-MODES.md). Certain features require a certain integration
mode to work, which the documentation mention where relevant.

# Path matching rules

Most of the manifest is about declaring rules for a given path such as "foo must be a symlink"
or "bar must be owned by root:tty and have mode 02755".

The manifest contains the following types of matches:

 1) Exact path matches.  These specify the path inside the Debian package exactly without any
    form of wildcards (e.g., `*` or `?`).  However, they can use substitution variables.
    Examples include:
    * `usr/bin/sudo`
    * `usr/lib/{{DEB_HOST_MULTIARCH}}/libfoo.so`

    Having a leading `/` is optional.  I.e. `/usr/bin/sudo` and `usr/bin/sudo` are considered the
    same path.

 2) Glob based path matches.  These specify a rule that match any path that matches a given
    glob.  These rules must contain a glob character (e.g., `*`) _and_ a `/`. Examples include:

    * `foo/*`
    * `foo/*.txt`
    * `usr/lib/{{DEB_HOST_MULTIARCH}}/lib*.so*`

    Note that if the glob does not contain a `/`, then it falls into the Basename glob rule
    below.

 3) Basename glob matches.  These specify a rule that match any path where the basename matches
    a given glob.  They must contain a glob character (e.g., `*`) but either must not have a
    `/` in them at all or start with `**/` and not have any `/` from there.
    Examples include:

    * `"*.la"`
    * `"**/*.md"`
    * `"**/LICENSE"`

    The examples use explicit quoting because YAML often interprets `*` as an anchor rule in the
    places where you are likely to use this kind of glob.  The use of the `**/`-prefix is
    optional when the basename is a glob.  If you wanted to match all paths with the basename
    of exactly `LICENSE`, then you have to use the prefix (that is, use `**/LICENSE`) as `LICENSE`
    would be interpreted as an exact match for a top-level path.

However, there are also cases where these matching rules can cause conflicts.  This is covered
in the [Conflict resolution](#conflict-resolution) section below.


## Limitations on debputy path rules

Path rules:

 1) Must match relatively to the package root.
 2) Never resolves a symlink.
    * If `bin/ls` is a symlink, then `bin/ls` matches the symlink (and never the target)
    * If `bin` is a symlink, then `bin/ls` (or `bin/*`) would fail to match, because
      matching would require resolving the symlink.

These limitations are in place because of implementation details in `debputy`.


## Conflict resolution

The manifest can contain seemly mutually exclusive rules.  As an example, if you ask for
`foo/symlink` to be a symlink but also state that you want to remove `foo` entirely
from the Debian package then the manifest now has two mutually exclusive requests.

To resolve these problems, `debputy` generally relies on ordered instructions to
resolve conflicts. Consider `installations` and `transformations`:

   1. `installations` (ordered list using "first match wins")
   2. `package.<package-name>.transformations` (ordered list using "all matching rules applies")

The "first match wins" rule means the first rule that applies will be used for that match
and no further rules will be used for that match.

The "all matching rules applies" rule means that each rule is applied in order.  Often
this behaves like a simple case of either "first match wins" or "last match wins" (depending
on the context).

Note for transformation rules, an early rule can change the file system layout, which will
affect whether a later rule matches.  This is similar to how shell globs commands work:

      $ rm usr/lib/libfoo.la
      $ chmod 0644 usr/lib/*

Here the glob used with `chmod` will not match `usr/lib/libfoo.la` because it was removed.
As noted, a similar logic applies to transformation rules.

## All definitions must be used

Whenever you define a request or rule in the manifest, `debputy` will insist on it being used
at least once.  The exception to this rule being conditional rules where the condition
evaluates to `false` in which case the rule does not trigger an error when unused.

This is useful for several reasons:

 1. The definition may have been shadowed by another rule and would have been ignored otherwise
 2. The definition may no longer be useful, but its present might confuse a future reader of
    the manifest.

In all cases, `debputy` will tell you if a definition was unused and where you can find that
definition.

## debputy globs

In general, the following rules applies to globs in `debputy`.

 * The `*` match 0 or more times any characters except `/`.
 * The `?` match exactly one character except `/`.
 * The glob `foo/*` matches _everything_ inside `foo/` including hidden files (i.e., paths starting
   with `.`) unlike `bash`/`sh` globs. However, `foo/*` does _not_ match `foo/` itself (this latter
   part matches `bash`/`sh` behavior and should be unsurprising).
 * For the special-cases where `**` is supported, then `**` matches zero or more levels of directories.
   This means that `foo/**/*` match any path beneath `foo` (but still not `foo`).  This is mostly relevant
   for built-in path matches as it is currently not possible to define `foo/**/...` patterns in the manifest.

Note that individual rules (such as `clean-after-removal`) may impose special cases to how globs
work. The rules will explicitly list if they divert from the above listed glob rules.

# Rules for substituting manifest variables

The `debputy` tool supports substitution in various places (usually paths) via the following
rules.  That means:

 1) All substitutions must start with `{{` and end with `}}`.  The part between is
    the `MANIFEST_VARIABLE` and must match the regular expression `[A-Za-z0-9][-_:0-9A-Za-z]*`.
    Note that you can use space around the variable name if you feel that increases readability.
    (That is, `{{ FOO }}` can be used as an alternative to `{{FOO}}`).
 2) The `MANIFEST_VARIABLE` will be result from a set of built-in variables and the variables from
    `dpkg-architecture`.
 3) You can use `{{token:DOUBLE_OPEN_CURLY_BRACE}}` and `{{token:DOUBLE_CLOSE_CURLY_BRACE}}` (built-in
    variables)  if you want a literal `{{` or `}}`  would otherwise have triggered an undesired expansion.
 4) All `{{MANIFEST_VARIABLE}}` must refer to a defined variable.
    - You can see the full list of `debputy` and plugin provided manifest variables via:
      `debputy plugin list manifest-variables`. The manifest itself can declare its own variables
      beyond that list. Please refer to the [Manifest Variables](#manifest-variables-variables)
      section manifest variables declared inside the manifest.
 5) There are no expression syntax inside the `{{ ... }}` (unlike jinja2 and other template languages).
    This rule may be changed in the future (with a new manifest version).

Keep in mind that substitution _cannot_ be used everywhere.  There are specific places where
it can be used.  Also, substitution _cannot be used_ to introduce globs into paths.  When a
substitution occurs inside a path all characters inserted are treated as literal characters.

Note: While manifest variables can be substituted into various places in the `debputy` manifest, they
are distinct from `dpkg`'s "substvars" (`man 5 deb-substvars`) that are used in the `debian/control`
file.

## Built-in or common substitution variables

 * `{{token:NEWLINE}}` or `{{token:NL}}` expands to a literal newline (LF) `\n`.
 * `{{token:TAB}}` expands to a literal tab `\t`.
 * `{{token:OPEN_CURLY_BRACE}}`  / `{{token:CLOSE_CURLY_BRACE}}` expand to `{` / `}`
 * `{{token:DOUBLE_OPEN_CURLY_BRACE}}` / `{{token:DOUBLE_CLOSE_CURLY_BRACE}}` expands to `{{` / `}}`.
 * `{{PACKAGE}}` expands to the binary package name of the current binary package. This substitution
   only works/applies when the substitution occurs in the context of a concrete binary package.
 * Plus any of the variables produced by `dpkg-architecture`, such as `{{DEB_HOST_MULTIARCH}}`.

The following variables from `/usr/share/dpkg/pkg-info.mk` (`dpkg`) are also available:

 * DEB_SOURCE (as `{{DEB_SOURCE}}`)
 * DEB_VERSION (as `{{DEB_VERSION}}`)
 * DEB_VERSION_EPOCH_UPSTREAM (as `{{DEB_VERSION_EPOCH_UPSTREAM}}`)
 * DEB_VERSION_UPSTREAM_REVISION (as `{{DEB_VERSION_UPSTREAM_REVISION}}`)
 * DEB_VERSION_UPSTREAM (as `{{DEB_VERSION_UPSTREAM}}`)
 * SOURCE_DATE_EPOCH (as `{{SOURCE_DATE_EPOCH}}`)

These have the same definition as those from the `dpkg` provided makefile.


# Restrictions on defining ownership of paths

In some parts of the manifest, you can specify which user or group should have ownership of
a given path.  As an example, you can define a directory to be owned by `root` with group `tty`
(think `chown root:tty <some/path>`).

Ownership is generally defined via the keys `owner` and `group`.  For each of them, you can use
one of the following formats:

 1) A name (e.g., `owner: root`).
 2) An id (e.g., `owner: 0`). Please avoid using quotes around the ID in YAML as that can
    cause `debputy` to read the number as a name.
 3) A name and an id with a colon in between (e.g., `owner: "root:0"`).  The name must always
    come first here.  You may have to quote the value to prevent the YAML parser from being
    confused.

All three forms are valid and provide the same result.  Unless you have a compelling reason to
pick a particular form, the name-only is recommended for simplicity.  Notably, it does not
require your co-maintainer or future you to remember what the IDs mean.

Regardless of which form you pick:

 1) The provided owner must be defined by Debian `base-passwd` file, which are the only users guaranteed
    to be present on every Debian system.
    * Concretely, `debputy` verifies the input against `/usr/share/base-passwd/passwd.master` and
      `/usr/share/base-passwd/group.master` (except for `root` / `0` as an optimization).

 2) If the `name:id` form is used, then the name and the id values must match.  I.e., `root:2` would
    be invalid as the id for `root` is defined to be `0` in the `base-passwd` data files.

 3) The `debputy` tool maintains a `deny`-list of owners that it refuses even though `base-passwd`
    defines them. As a notable non-exhaustive example, `debputy` considers `nobody` or id `65534`
    (the ID of `nobody` / `nogroup`) to be invalid owners.


# Conditional rules

There are cases, where a given rule should only apply in certain cases - such as only when a given
build profile is active (`DEB_BUILD_PROFILES` / `dpkg-buildpackage -P`).  For rules that
*support being conditional*, the condition is generally defined via the `when:` key and the condition
is then described beneath the `when:`.

As an example:

    packages:
        util-linux:
            transformations:
            - create-symlink
                  path: sbin/agetty
                  target: /sbin/getty
                  when:
                      # On Hurd, the package "hurd" ships "sbin/getty".
                      arch-matches: '!hurd-any'


When the condition under `when:` resolves to `true`, the rule will and must be used.  When the
condition resolves to `false`, the rule will not be applied even if it could have been.  However,
the rule may still be "partially" evaluated.  As an example, for installation rules, the source
patterns will still be evaluated to reserve what it would have matched, so that following rules
behave deterministically regardless of how the condition evaluates.

Note that conditions are *not* used as a conflict resolution and as such two conditional rules
can still cause conflicts even though their conditions are mutually exclusive.  This may be
changed in a later version of `debputy` provided `debputy` can assert the two conditions
are mutually exclusive.

The `when:` key has either a mapping, a list or a string as value depending on the condition.
Each supported condition is described in the following subsections.


## Architecture match condition `arch-matches`

Sometimes, a rule needs to be conditional on the architecture.
This can be done by using the `arch-matches` rule. In 99.99%
of the cases, `arch-matches` will be form you are looking for
and practically behaves like a comparison against
`dpkg-architecture -qDEB_HOST_ARCH`.

For the cross-compiling specialists or curious people: The
`arch-matches` rule behaves like a `package-context-arch-matches`
in the context of a binary package and like
`source-context-arch-matches` otherwise. The details of those
are covered in their own keywords.

Integration mode availability: any integration mode
## Explicit source or binary package context architecture match condition `source-context-arch-matches`, `package-context-arch-matches` (mapping)

**These are special-case conditions**. Unless you know that you have a very special-case,
you should probably use `arch-matches` instead. These conditions are aimed at people with
corner-case special architecture needs. It also assumes the reader is familiar with the
`arch-matches` condition.

To understand these rules, here is a quick primer on `debputy`'s concept of "source context"
vs "(binary) package context" architecture.  For a native build, these two contexts are the
same except that in the package context an `Architecture: all` package always resolve to
`all` rather than `DEB_HOST_ARCH`. As a consequence, `debputy` forbids `arch-matches` and
`package-context-arch-matches` in the context of an `Architecture: all` package as a warning
to the packager that condition does not make sense.

In the very rare case that you need an architecture condition for an `Architecture: all` package,
you can use `source-context-arch-matches`. However, this means your `Architecture: all` package
is not reproducible between different build hosts (which has known to be relevant for some
very special cases).

Additionally, for the 0.0001% case you are building a cross-compiling compiler (that is,
`DEB_HOST_ARCH != DEB_TARGET_ARCH` and you are working with `gcc` or similar) `debputy` can be
instructed (opt-in) to use `DEB_TARGET_ARCH` rather than `DEB_HOST_ARCH` for certain packages when
evaluating an architecture condition in context of a binary package. This can be useful if the
compiler produces supporting libraries that need to be built for the `DEB_TARGET_ARCH` rather than
the `DEB_HOST_ARCH`.  This is where `arch-matches` or `package-context-arch-matches` can differ
subtly from `source-context-arch-matches` in how they evaluate the condition.  This opt-in currently
relies on setting `X-DH-Build-For-Type: target` for each of the relevant packages in
`debian/control`.  However, unless you are a cross-compiling specialist, you will probably never
need to care about nor use any of this.

Accordingly, the possible conditions are:

 * `arch-matches`: This is the form recommended to laymen and as the default use-case. This
   conditional acts `package-context-arch-matches` if the condition is used in the context
   of a binary package. Otherwise, it acts as `source-context-arch-matches`.

 * `source-context-arch-matches`: With this conditional, the provided architecture constraint is compared
   against the build time provided host architecture (`dpkg-architecture -qDEB_HOST_ARCH`). This can
   be useful when an `Architecture: all` package needs an architecture condition for some reason.

 * `package-context-arch-matches`: With this conditional, the provided architecture constraint is compared
   against the package's resolved architecture. This condition can only be used in the context of a binary
   package (usually, under `packages.<name>.`).  If the package is an `Architecture: all` package, the
   condition will fail with an error as the condition always have the same outcome. For all other
   packages, the package's resolved architecture is the same as the build time provided host architecture
   (`dpkg-architecture -qDEB_HOST_ARCH`).

   - However, as noted above there is a special case for when compiling a cross-compiling compiler, where
     this behaves subtly different from `source-context-arch-matches`.

All conditions are used the same way as `arch-matches`. Simply replace `arch-matches` with the other
condition. See the `arch-matches` description for an example.

Integration mode availability: any integration mode

## Active build profile match condition (`build-profiles-matches`)

The `build-profiles-matches` condition is used to assert whether the
active build profiles (`DEB_BUILD_PROFILES` / `dpkg-buildpackage -P`)
matches a given build profile restriction.

Integration mode availability: any integration mode

## Can run produced binaries (`can-execute-compiled-binaries`)

The `can-execute-compiled-binaries` condition is used to assert the build
can assume that all compiled binaries can be run as-if they were native
binaries. For native builds, this condition always evaluates to `true`.
For cross builds, the condition is generally evaluates to `false`.  However,
there are special-cases where binaries can be run during cross-building.
Accordingly, this condition is subtly different from the `cross-compiling`
condition.

Note this condition should *not* be used when you know the binary has been
built for the build architecture (`DEB_BUILD_ARCH`) or for determining
whether build-time tests should be run (for build-time tests, please use
the `run-build-time-tests` condition instead). Some upstream build systems
are advanced enough to distinguish building a final product vs. building
a helper tool that needs to run during build.  The latter will often be
compiled by a separate compiler (often using `$(CC_FOR_BUILD)`,
`cc_for_build` or similar variable names in upstream build systems for
that compiler).

Integration mode availability: any integration mode

## Cross-Compiling condition (`cross-compiling`)

The `cross-compiling` condition is used to determine if the current build is
performing a cross build (i.e., `DEB_BUILD_GNU_TYPE` != `DEB_HOST_GNU_TYPE`).
Often this has consequences for what is possible to do.

Note if you specifically want to know:

 * whether build-time tests should be run, then please use the
   `run-build-time-tests` condition.
 * whether compiled binaries can be run as if it was a native binary, please
   use the `can-execute-compiled-binaries` condition instead.  That condition
   accounts for cross-building in its evaluation.

Integration mode availability: any integration mode

## Whether build time tests should be run (`run-build-time-tests`)

The `run-build-time-tests` condition is used to determine whether (build
time) tests should be run for this build.  This condition roughly
translates into whether `nocheck` is present in `DEB_BUILD_OPTIONS`.

In general, the manifest *should not* prevent build time tests from being
run during cross-builds.

Integration mode availability: any integration mode

## Negated condition (`not`)

It is possible to negate a condition via the `not` condition.

As an example:

    packages:
      util-linux:
        transformations:
        - create-symlink
            path: sbin/getty
            target: /sbin/agetty
            when:
              # On Hurd, the package "hurd" ships "sbin/getty".
              # This example happens to also be alternative to `arch-marches: '!hurd-any`
              not:
                arch-matches: 'hurd-any'

The `not` condition is specified as a mapping, where the key is `not` and the
value is a nested condition.

Integration mode availability: any integration mode

## All or any of a list of conditions (`all-of`/`any-of`)

It is possible to aggregate conditions using the `all-of` or `any-of`
condition. These provide `X and Y` and `X or Y` semantics (respectively).

    packages:
      util-linux:
        transformations:
        - create-symlink
            path: sbin/getty
            target: /sbin/agetty
            when:
              # Only ship getty on linux except for s390(x)
              all-of:
              - arch-matches: 'linux-any'
              - arch-matches: '!s390 !s390x'

The `all-of` and `any-of` conditions are specified as lists, where each entry
is a nested condition. The lists need at least 2 entries as with fewer entries
the `all-of` and `any-of` conditions are redundant.

Integration mode availability: any integration mode


# Packager provided definitions

For more complex manifests or packages, it is possible define some common attributes for reuse.

## Manifest Variables (`variables`)

It is possible to provide custom manifest variables via the `variables` attribute.  An example:

    manifest-version: '0.1'
    definitions:
      variables:
        LIBPATH: "/usr/lib/{{DEB_HOST_MULTIARCH}}"
        SONAME: "1"
    installations:
      - install:
           source: build/libfoo.so.{{SONAME}}*
           # The quotes here is for the YAML parser's sake.
           dest-dir: "{{LIBPATH}}"
           into: libfoo{{SONAME}}

The value of the `variables` key must be a mapping, where each key is a new variable name and
the related value is the value of said key. The keys must be valid variable name and not shadow
existing variables (that is, variables such as `PACKAGE` and `DEB_HOST_MULTIARCH` *cannot* be
redefined). The value for each variable *can* refer to *existing* variables as seen in the
example above.

As usual, `debputy` will insist that all declared variables must be used.

Limitations:
 * When declaring variables that depends on another variable declared in the manifest, the
   order is important. The variables are resolved from top to bottom.
 * When a manifest variable depends on another manifest variable, the existing variable is
   currently always resolved in source context. As a consequence, some variables such as
   `{{PACKAGE}}` cannot be used when defining a variable. This restriction may be
   lifted in the future.

Integration mode availability: any integration mode


# Interacting with upstream build system

In the `full` integration mode, `debputy` also attempts to interact with the upstream build
systems (if any). In other integration modes, then it is generally `dh` that manages the
upstream build system (via the `dh_auto_*` commands). By default, `debputy` in the `full`
integration mode will auto-detect a supported build system and apply some defaults for a
build. However, in some cases, you may need to tweak some settings, which will covered
with these rules.

## Default Build Environment (`default-build-environment`)

Define the environment variables used in all build commands that uses the default
environment.

The environment definition can be used to tweak the environment variables used by the
build commands. An example:

    default-build-environment:
      set:
        ENV_VAR: foo
        ANOTHER_ENV_VAR: bar

The environment definition has multiple attributes for setting environment variables
which determines when the definition is applied. The resulting environment is the
result of the following order of operations.

  1. The environment `debputy` received from its parent process.
  2. Apply all the variable definitions from `set` (if the attribute is present)
  3. Apply all computed variables (such as variables from `dpkg-buildflags`).
  4. Apply all the variable definitions from `override` (if the attribute is present)
  5. Remove all variables listed in `unset` (if the attribute is present).

Accordingly, both `override` and `unset` will overrule any computed variables while
`set` will be overruled by any computed variables.

Note that these variables are not available via manifest substitution (they are only
visible to build commands). They are only available to build commands.

Attributes:
 - `set` (optional): Mapping of string

   A mapping of environment variables to be set.

   Note these environment variables are set before computed variables (such
   as `dpkg-buildflags`) are provided. They can affect the content of the
   computed variables, but they cannot overrule them. If you need to overrule
   a computed variable, please use `override` instead.

 - `override` (optional): Mapping of string

   A mapping of environment variables to set.

   Similar to `set`, but it can overrule computed variables like those from
   `dpkg-buildflags`.

 - `unset` (optional): List of string

   A list of environment variables to unset.

   Any environment variable named here will be unset. No warnings or errors
   will be raised if a given variable was not set.


Integration mode availability: full

## Build Environments (`build-environments`)

Define named environments to set the environment for any build commands that needs
a non-default environment.

The environment definitions can be used to tweak the environment variables used by the
build commands. An example:

    build-environments:
      - name: custom-env
        set:
          ENV_VAR: foo
          ANOTHER_ENV_VAR: bar
    builds:
      - autoconf:
          environment: custom-env

The environment definition has multiple attributes for setting environment variables
which determines when the definition is applied. The resulting environment is the
result of the following order of operations.

  1. The environment `debputy` received from its parent process.
  2. Apply all the variable definitions from `set` (if the attribute is present)
  3. Apply all computed variables (such as variables from `dpkg-buildflags`).
  4. Apply all the variable definitions from `override` (if the attribute is present)
  5. Remove all variables listed in `unset` (if the attribute is present).

Accordingly, both `override` and `unset` will overrule any computed variables while
`set` will be overruled by any computed variables.

Note that these variables are not available via manifest substitution (they are only
visible to build commands). They are only available to build commands.

List where each element has the following attributes:
 - `name` (required): string

   The name of the environment

   The name is used to reference the environment from build rules.

 - `set` (optional): Mapping of string

   A mapping of environment variables to be set.

   Note these environment variables are set before computed variables (such
   as `dpkg-buildflags`) are provided. They can affect the content of the
   computed variables, but they cannot overrule them. If you need to overrule
   a computed variable, please use `override` instead.

 - `override` (optional): Mapping of string

   A mapping of environment variables to set.

   Similar to `set`, but it can overrule computed variables like those from
   `dpkg-buildflags`.

 - `unset` (optional): List of string

   A list of environment variables to unset.

   Any environment variable named here will be unset. No warnings or errors
   will be raised if a given variable was not set.


Integration mode availability: full

## Build rules (`builds`)

Define how to build the upstream part of the package. Usually this is done via "build systems",
which also defines the clean rules.

A simple example is:

```yaml
    builds:
      - autoconf:
          configure-args:
            - "--enable-foo"
            - "--without=bar"
```

Multiple builds are supported out of box. Here an example of how the build rules
for `libpam-krb5` might look.

```yaml
    builds:
      - autoconf:
          for: libpam-krb5
          install-directly-to-package: true
          configure-args:
            - "--enable-reduced-depends"
            - "--with-krb5-include=/usr/include/mit-krb5"
            - "--with-krb5-lib=/usr/lib/{{DEB_HOST_MULTIARCH}}/mit-krb5"
            - "--with-kadm-client-include=/usr/include/mit-krb5"
            - "--with-kadm-client-lib=/usr/lib/{{DEB_HOST_MULTIARCH}}/mit-krb5"
      - autoconf:
          for: libpam-heimdal
          install-directly-to-package: true
          configure-args:
            - "--enable-reduced-depends"
            - "--with-krb5-include=/usr/include/heimdal"
            - "--with-krb5-lib=/usr/lib/{{DEB_HOST_MULTIARCH}}/heimdal"
            - "--with-kadm-client-include=/usr/include/heimdal"
            - "--with-kadm-client-lib=/usr/lib/{{DEB_HOST_MULTIARCH}}/heimdal"
```

Integration mode availability: full


### Autoconf Build System (`autoconf`)

Run an autoconf-based build system as the upstream build system.

This build rule will attempt to use autoreconf to update the `configure`
script before running the `configure` script if needed. Otherwise, it
follows the classic `./configure && make && make install` pattern.

The build rule uses "out of source" builds by default since it is easier
and more reliable for clean and makes it easier to support multiple
builds (that is, two or more build systems for the same source package).
This is in contract to `debhelper`, which defaults to "in source" builds
for `autoconf`. If you need that behavior, please set
`perform-in-source-build: true`.

Attributes:
 - `configure-args` (optional): List of string

   Arguments to be passed to the `configure` script.

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.

 - `install-directly-to-package` (optional): boolean

   Whether the build system should install all upstream content directly into the package.

   This option is mostly useful for disabling said behavior by setting the attribute to `false`.
   The attribute conditionally defaults to `true` when the build only applies to one package.
   If explicitly set to `true`, then this build step must apply to exactly one package (usually
   implying that `for` is set to that package when the source builds multiple packages).

   When `true`, this behaves similar to `dh_auto_install --destdir=debian/PACKAGE`.

 - `perform-in-source-build` (optional): boolean

   Whether the build system should use "in source" or "out of source" build.

   This is mostly useful for forcing "in source" builds for build systems that default to
   "out of source" builds like `autoconf`.

   The default depends on the build system and the value of the `build-directory` attribute
   (if supported by the build system).

 - `build-directory` (optional): FileSystemExactMatchRule

   The build directory to use for the build.

   By default, `debputy` will derive a build directory automatically if the build system needs
   it. However, it can be useful if you need to reference the directory name from other parts
   of the manifest or want a "better" name than `debputy` comes up with.

 - `test-rule` (optional): TestRule

   Whether to run tests at build time

   When omitted, build time tests are run when the build system detects any provided
   the builder has not skipped tests (by using DEB_BUILD_OPTIONS=nocheck, etc.).

 - `name` (optional): string

   The name of the build step.

   The name is used for multiple things, such as:
     1) If you ever need to reference the build elsewhere, the name will be used.
     2) When `debputy` references the build in log output and error, it will use the name.
     3) It is used as defaults for when `debputy` derives build and `DESTDIR` directories
        for the build.

 - `for` (optional): PackageSelector or a list of PackageSelector

   Which packages this build step applies to.

   The value should be either a package name mentioned in `debian/control`,
   a package selection (such as `arch:all` or `package-type:deb`), or
   a list of these names or selections. The listed values should be a
   subset of the binary packages listed in `debian/control`.

   When the attribute is omitted, then the step applies to all packages
   listed in `debian/control`.

   This attribute enables 'debputy` to skip the build step when none of
   the relevant packages are being built as well as provide defaults
   (such as search directories for the `installations` feature)

 - `environment` (optional): BuildEnvironmentDefinition

   Specify that this build step uses the named environment

   If omitted, the default environment will be used. If no default environment is present,
   then this option is mandatory.


Integration mode availability: full

### Make Build System

Run a plain `make` file with nothing else.

This build system will attempt to use `make` to leverage instructions
in a makefile (such as, `Makefile` or `GNUMakefile`).

By default, the makefile build system assumes it should use "in-source"
build semantics. If needed be, an explicit `build-directory` can be
provided if the `Makefile` is not in the source folder but instead in
some other directory.

Attributes:
 - `directory` (optional): FileSystemExactMatchRule

   The directory from which to run make if it is not the source root

   This works like using `make -C DIRECTORY ...` (or `cd DIRECTORY && make ...`).

 - `build-target` (optional): string

   The target name to use for the "build" step.

   If omitted, `make` will be run without any explicit target leaving it to decide
   the default.

 - `test-target` (optional): string

   The target name to use for the "test" step.

   If omitted, `make check` or `make test` will be used if it looks like `make`
   will accept one of those targets. Otherwise, the step will be skipped.

 - `install-target` (optional): string

   The target name to use for the "install" step.

   If omitted, `make install` will be used if it looks like `make` will accept that target.
   Otherwise, the step will be skipped.

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.

 - `install-directly-to-package` (optional): boolean

   Whether the build system should install all upstream content directly into the package.

   This option is mostly useful for disabling said behavior by setting the attribute to `false`.
   The attribute conditionally defaults to `true` when the build only applies to one package.
   If explicitly set to `true`, then this build step must apply to exactly one package (usually
   implying that `for` is set to that package when the source builds multiple packages).

   When `true`, this behaves similar to `dh_auto_install --destdir=debian/PACKAGE`.

 - `test-rule` (optional): TestRule

   Whether to run tests at build time

   When omitted, build time tests are run when the build system detects any provided
   the builder has not skipped tests (by using DEB_BUILD_OPTIONS=nocheck, etc.).

 - `name` (optional): string

   The name of the build step.

   The name is used for multiple things, such as:
     1) If you ever need to reference the build elsewhere, the name will be used.
     2) When `debputy` references the build in log output and error, it will use the name.
     3) It is used as defaults for when `debputy` derives build and `DESTDIR` directories
        for the build.

 - `for` (optional): PackageSelector or a list of PackageSelector

   Which packages this build step applies to.

   The value should be either a package name mentioned in `debian/control`,
   a package selection (such as `arch:all` or `package-type:deb`), or
   a list of these names or selections. The listed values should be a
   subset of the binary packages listed in `debian/control`.

   When the attribute is omitted, then the step applies to all packages
   listed in `debian/control`.

   This attribute enables 'debputy` to skip the build step when none of
   the relevant packages are being built as well as provide defaults
   (such as search directories for the `installations` feature)

 - `environment` (optional): BuildEnvironmentDefinition

   Specify that this build step uses the named environment

   If omitted, the default environment will be used. If no default environment is present,
   then this option is mandatory.


Integration mode availability: full

### Perl "Build.PL" Build System (`perl-build`)

Build using the `Build.PL` Build system used by some Perl packages.

This build rule will attempt to use the `Build.PL` script to build the
upstream code.

Attributes:
 - `configure-args` (optional): List of string

   Arguments to be passed to the `Build.PL` script.

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.

 - `install-directly-to-package` (optional): boolean

   Whether the build system should install all upstream content directly into the package.

   This option is mostly useful for disabling said behavior by setting the attribute to `false`.
   The attribute conditionally defaults to `true` when the build only applies to one package.
   If explicitly set to `true`, then this build step must apply to exactly one package (usually
   implying that `for` is set to that package when the source builds multiple packages).

   When `true`, this behaves similar to `dh_auto_install --destdir=debian/PACKAGE`.

 - `test-rule` (optional): TestRule

   Whether to run tests at build time

   When omitted, build time tests are run when the build system detects any provided
   the builder has not skipped tests (by using DEB_BUILD_OPTIONS=nocheck, etc.).

 - `name` (optional): string

   The name of the build step.

   The name is used for multiple things, such as:
     1) If you ever need to reference the build elsewhere, the name will be used.
     2) When `debputy` references the build in log output and error, it will use the name.
     3) It is used as defaults for when `debputy` derives build and `DESTDIR` directories
        for the build.

 - `for` (optional): PackageSelector or a list of PackageSelector

   Which packages this build step applies to.

   The value should be either a package name mentioned in `debian/control`,
   a package selection (such as `arch:all` or `package-type:deb`), or
   a list of these names or selections. The listed values should be a
   subset of the binary packages listed in `debian/control`.

   When the attribute is omitted, then the step applies to all packages
   listed in `debian/control`.

   This attribute enables 'debputy` to skip the build step when none of
   the relevant packages are being built as well as provide defaults
   (such as search directories for the `installations` feature)

 - `environment` (optional): BuildEnvironmentDefinition

   Specify that this build step uses the named environment

   If omitted, the default environment will be used. If no default environment is present,
   then this option is mandatory.


Integration mode availability: full

### Perl "MakeMaker" Build System (`perl-makemaker`)

Build using the "MakeMaker" Build system used by some Perl packages.

This build rule will attempt to use the `Makefile.PL` script to build the
upstream code.

Attributes:
 - `configure-args` (optional): List of string

   Arguments to be passed to the `Makefile.PL` script.

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.

 - `install-directly-to-package` (optional): boolean

   Whether the build system should install all upstream content directly into the package.

   This option is mostly useful for disabling said behavior by setting the attribute to `false`.
   The attribute conditionally defaults to `true` when the build only applies to one package.
   If explicitly set to `true`, then this build step must apply to exactly one package (usually
   implying that `for` is set to that package when the source builds multiple packages).

   When `true`, this behaves similar to `dh_auto_install --destdir=debian/PACKAGE`.

 - `test-rule` (optional): TestRule

   Whether to run tests at build time

   When omitted, build time tests are run when the build system detects any provided
   the builder has not skipped tests (by using DEB_BUILD_OPTIONS=nocheck, etc.).

 - `name` (optional): string

   The name of the build step.

   The name is used for multiple things, such as:
     1) If you ever need to reference the build elsewhere, the name will be used.
     2) When `debputy` references the build in log output and error, it will use the name.
     3) It is used as defaults for when `debputy` derives build and `DESTDIR` directories
        for the build.

 - `for` (optional): PackageSelector or a list of PackageSelector

   Which packages this build step applies to.

   The value should be either a package name mentioned in `debian/control`,
   a package selection (such as `arch:all` or `package-type:deb`), or
   a list of these names or selections. The listed values should be a
   subset of the binary packages listed in `debian/control`.

   When the attribute is omitted, then the step applies to all packages
   listed in `debian/control`.

   This attribute enables 'debputy` to skip the build step when none of
   the relevant packages are being built as well as provide defaults
   (such as search directories for the `installations` feature)

 - `environment` (optional): BuildEnvironmentDefinition

   Specify that this build step uses the named environment

   If omitted, the default environment will be used. If no default environment is present,
   then this option is mandatory.


Integration mode availability: full

### Debhelper Build System (`debhelper`)

Delegate to a debhelper provided build system

This build rule will attempt to use the `dh_auto_*` tools to build the
upstream code. By default, `dh_auto_*` will use auto-detection to determine
which build system they will use. This can be overridden by the
`dh-build-system` attribute.

Attributes:
 - `dh-build-system` (optional): string

   Which debhelper build system to use. This attribute is passed to
   the `dh_auto_*` commands as the `-S` parameter, so any value valid
   for that will be accepted.

   Note that many debhelper build systems require extra build
   dependencies before they can be used. Please consult the documentation
   of the relevant debhelper build system for details.

 - `configure-args` (optional): List of string

   Arguments to be passed to underlying configuration command
    (via `dh_auto_configure -- <configure-args`).

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.

 - `install-directly-to-package` (optional): boolean

   Whether the build system should install all upstream content directly into the package.

   This option is mostly useful for disabling said behavior by setting the attribute to `false`.
   The attribute conditionally defaults to `true` when the build only applies to one package.
   If explicitly set to `true`, then this build step must apply to exactly one package (usually
   implying that `for` is set to that package when the source builds multiple packages).

   When `true`, this behaves similar to `dh_auto_install --destdir=debian/PACKAGE`.

 - `build-directory` (optional): FileSystemExactMatchRule

   The build directory to use for the build.

   By default, `debputy` will derive a build directory automatically if the build system needs
   it. However, it can be useful if you need to reference the directory name from other parts
   of the manifest or want a "better" name than `debputy` comes up with.

 - `test-rule` (optional): TestRule

   Whether to run tests at build time

   When omitted, build time tests are run when the build system detects any provided
   the builder has not skipped tests (by using DEB_BUILD_OPTIONS=nocheck, etc.).

 - `name` (optional): string

   The name of the build step.

   The name is used for multiple things, such as:
     1) If you ever need to reference the build elsewhere, the name will be used.
     2) When `debputy` references the build in log output and error, it will use the name.
     3) It is used as defaults for when `debputy` derives build and `DESTDIR` directories
        for the build.

 - `for` (optional): PackageSelector or a list of PackageSelector

   Which packages this build step applies to.

   The value should be either a package name mentioned in `debian/control`,
   a package selection (such as `arch:all` or `package-type:deb`), or
   a list of these names or selections. The listed values should be a
   subset of the binary packages listed in `debian/control`.

   When the attribute is omitted, then the step applies to all packages
   listed in `debian/control`.

   This attribute enables 'debputy` to skip the build step when none of
   the relevant packages are being built as well as provide defaults
   (such as search directories for the `installations` feature)

 - `environment` (optional): BuildEnvironmentDefinition

   Specify that this build step uses the named environment

   If omitted, the default environment will be used. If no default environment is present,
   then this option is mandatory.


Integration mode availability: full

### CMake Build System (`cmake`)

Run an cmake-based build system as the upstream build system.

The build rule uses "out of source" builds.

Attributes:
 - `configure-args` (optional): List of string

   Arguments to be passed to the `cmake` command.

 - `target-build-system` (required): One of the following literal values: `make`, `ninja`

   Which build system should `cmake` should delegate the build system to.
   In `cmake` terms, this is a Generator (the `-G` option).

   Supported options are:
    * `make` - GNU Make
    * `ninja` - Ninja

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.

 - `install-directly-to-package` (optional): boolean

   Whether the build system should install all upstream content directly into the package.

   This option is mostly useful for disabling said behavior by setting the attribute to `false`.
   The attribute conditionally defaults to `true` when the build only applies to one package.
   If explicitly set to `true`, then this build step must apply to exactly one package (usually
   implying that `for` is set to that package when the source builds multiple packages).

   When `true`, this behaves similar to `dh_auto_install --destdir=debian/PACKAGE`.

 - `build-directory` (optional): FileSystemExactMatchRule

   The build directory to use for the build.

   By default, `debputy` will derive a build directory automatically if the build system needs
   it. However, it can be useful if you need to reference the directory name from other parts
   of the manifest or want a "better" name than `debputy` comes up with.

 - `test-rule` (optional): TestRule

   Whether to run tests at build time

   When omitted, build time tests are run when the build system detects any provided
   the builder has not skipped tests (by using DEB_BUILD_OPTIONS=nocheck, etc.).

 - `name` (optional): string

   The name of the build step.

   The name is used for multiple things, such as:
     1) If you ever need to reference the build elsewhere, the name will be used.
     2) When `debputy` references the build in log output and error, it will use the name.
     3) It is used as defaults for when `debputy` derives build and `DESTDIR` directories
        for the build.

 - `for` (optional): PackageSelector or a list of PackageSelector

   Which packages this build step applies to.

   The value should be either a package name mentioned in `debian/control`,
   a package selection (such as `arch:all` or `package-type:deb`), or
   a list of these names or selections. The listed values should be a
   subset of the binary packages listed in `debian/control`.

   When the attribute is omitted, then the step applies to all packages
   listed in `debian/control`.

   This attribute enables 'debputy` to skip the build step when none of
   the relevant packages are being built as well as provide defaults
   (such as search directories for the `installations` feature)

 - `environment` (optional): BuildEnvironmentDefinition

   Specify that this build step uses the named environment

   If omitted, the default environment will be used. If no default environment is present,
   then this option is mandatory.


Integration mode availability: full

### Meson Build System (`meson`)

Run an meson-based build system as the upstream build system.

The build rule uses "out of source" builds.

Attributes:
 - `configure-args` (optional): List of string

   Arguments to be passed to the `meson` command.

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.

 - `install-directly-to-package` (optional): boolean

   Whether the build system should install all upstream content directly into the package.

   This option is mostly useful for disabling said behavior by setting the attribute to `false`.
   The attribute conditionally defaults to `true` when the build only applies to one package.
   If explicitly set to `true`, then this build step must apply to exactly one package (usually
   implying that `for` is set to that package when the source builds multiple packages).

   When `true`, this behaves similar to `dh_auto_install --destdir=debian/PACKAGE`.

 - `build-directory` (optional): FileSystemExactMatchRule

   The build directory to use for the build.

   By default, `debputy` will derive a build directory automatically if the build system needs
   it. However, it can be useful if you need to reference the directory name from other parts
   of the manifest or want a "better" name than `debputy` comes up with.

 - `test-rule` (optional): TestRule

   Whether to run tests at build time

   When omitted, build time tests are run when the build system detects any provided
   the builder has not skipped tests (by using DEB_BUILD_OPTIONS=nocheck, etc.).

 - `name` (optional): string

   The name of the build step.

   The name is used for multiple things, such as:
     1) If you ever need to reference the build elsewhere, the name will be used.
     2) When `debputy` references the build in log output and error, it will use the name.
     3) It is used as defaults for when `debputy` derives build and `DESTDIR` directories
        for the build.

 - `for` (optional): PackageSelector or a list of PackageSelector

   Which packages this build step applies to.

   The value should be either a package name mentioned in `debian/control`,
   a package selection (such as `arch:all` or `package-type:deb`), or
   a list of these names or selections. The listed values should be a
   subset of the binary packages listed in `debian/control`.

   When the attribute is omitted, then the step applies to all packages
   listed in `debian/control`.

   This attribute enables 'debputy` to skip the build step when none of
   the relevant packages are being built as well as provide defaults
   (such as search directories for the `installations` feature)

 - `environment` (optional): BuildEnvironmentDefinition

   Specify that this build step uses the named environment

   If omitted, the default environment will be used. If no default environment is present,
   then this option is mandatory.


Integration mode availability: full

### QT "qmake" Build System (`qmake`)

Build using the "qmake" by QT.

Attributes:
 - `configure-args` (optional): List of string

   Arguments to be passed to the `qmake` command.

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.

 - `install-directly-to-package` (optional): boolean

   Whether the build system should install all upstream content directly into the package.

   This option is mostly useful for disabling said behavior by setting the attribute to `false`.
   The attribute conditionally defaults to `true` when the build only applies to one package.
   If explicitly set to `true`, then this build step must apply to exactly one package (usually
   implying that `for` is set to that package when the source builds multiple packages).

   When `true`, this behaves similar to `dh_auto_install --destdir=debian/PACKAGE`.

 - `perform-in-source-build` (optional): boolean

   Whether the build system should use "in source" or "out of source" build.

   This is mostly useful for forcing "in source" builds for build systems that default to
   "out of source" builds like `autoconf`.

   The default depends on the build system and the value of the `build-directory` attribute
   (if supported by the build system).

 - `build-directory` (optional): FileSystemExactMatchRule

   The build directory to use for the build.

   By default, `debputy` will derive a build directory automatically if the build system needs
   it. However, it can be useful if you need to reference the directory name from other parts
   of the manifest or want a "better" name than `debputy` comes up with.

 - `test-rule` (optional): TestRule

   Whether to run tests at build time

   When omitted, build time tests are run when the build system detects any provided
   the builder has not skipped tests (by using DEB_BUILD_OPTIONS=nocheck, etc.).

 - `name` (optional): string

   The name of the build step.

   The name is used for multiple things, such as:
     1) If you ever need to reference the build elsewhere, the name will be used.
     2) When `debputy` references the build in log output and error, it will use the name.
     3) It is used as defaults for when `debputy` derives build and `DESTDIR` directories
        for the build.

 - `for` (optional): PackageSelector or a list of PackageSelector

   Which packages this build step applies to.

   The value should be either a package name mentioned in `debian/control`,
   a package selection (such as `arch:all` or `package-type:deb`), or
   a list of these names or selections. The listed values should be a
   subset of the binary packages listed in `debian/control`.

   When the attribute is omitted, then the step applies to all packages
   listed in `debian/control`.

   This attribute enables 'debputy` to skip the build step when none of
   the relevant packages are being built as well as provide defaults
   (such as search directories for the `installations` feature)

 - `environment` (optional): BuildEnvironmentDefinition

   Specify that this build step uses the named environment

   If omitted, the default environment will be used. If no default environment is present,
   then this option is mandatory.


Integration mode availability: full

### QT "qmake6" Build System (`qmake6`)

Build using the "qmake6" from the `qmake6` package.  This is like the `qmake` system
but is specifically for QT6.

Attributes:
 - `configure-args` (optional): List of string

   Arguments to be passed to the `qmake6` command.

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.

 - `install-directly-to-package` (optional): boolean

   Whether the build system should install all upstream content directly into the package.

   This option is mostly useful for disabling said behavior by setting the attribute to `false`.
   The attribute conditionally defaults to `true` when the build only applies to one package.
   If explicitly set to `true`, then this build step must apply to exactly one package (usually
   implying that `for` is set to that package when the source builds multiple packages).

   When `true`, this behaves similar to `dh_auto_install --destdir=debian/PACKAGE`.

 - `perform-in-source-build` (optional): boolean

   Whether the build system should use "in source" or "out of source" build.

   This is mostly useful for forcing "in source" builds for build systems that default to
   "out of source" builds like `autoconf`.

   The default depends on the build system and the value of the `build-directory` attribute
   (if supported by the build system).

 - `build-directory` (optional): FileSystemExactMatchRule

   The build directory to use for the build.

   By default, `debputy` will derive a build directory automatically if the build system needs
   it. However, it can be useful if you need to reference the directory name from other parts
   of the manifest or want a "better" name than `debputy` comes up with.

 - `test-rule` (optional): TestRule

   Whether to run tests at build time

   When omitted, build time tests are run when the build system detects any provided
   the builder has not skipped tests (by using DEB_BUILD_OPTIONS=nocheck, etc.).

 - `name` (optional): string

   The name of the build step.

   The name is used for multiple things, such as:
     1) If you ever need to reference the build elsewhere, the name will be used.
     2) When `debputy` references the build in log output and error, it will use the name.
     3) It is used as defaults for when `debputy` derives build and `DESTDIR` directories
        for the build.

 - `for` (optional): PackageSelector or a list of PackageSelector

   Which packages this build step applies to.

   The value should be either a package name mentioned in `debian/control`,
   a package selection (such as `arch:all` or `package-type:deb`), or
   a list of these names or selections. The listed values should be a
   subset of the binary packages listed in `debian/control`.

   When the attribute is omitted, then the step applies to all packages
   listed in `debian/control`.

   This attribute enables 'debputy` to skip the build step when none of
   the relevant packages are being built as well as provide defaults
   (such as search directories for the `installations` feature)

 - `environment` (optional): BuildEnvironmentDefinition

   Specify that this build step uses the named environment

   If omitted, the default environment will be used. If no default environment is present,
   then this option is mandatory.


Integration mode availability: full


## Test rules (`builds.*.test-rule`)

Build systems can be associated with a `test-rule`, which adds a maintainer restriction running
the build time test suite.

### Skip build time tests (`skip-tests`)

Skip all build time tests.

Example:

```yaml
...:
    # The tests require internet access and cannot be run at build time.
    test-rule: skip-tests
```

Integration mode availability: any integration mode

### Conditionally skip build time tests (`skip-tests-when`)

The `skip-tests-when` test rule accepts a conditional. When that conditional evaluates to
true, the build time tests will be skipped. Otherwise, they will be run as usual.

Note if you want to only run the tests when the conditional evaluates to `true`,
then wrap the conditional with `not:`.

Example:

```yaml
...:
    # Only run for linux-any (`DEB_HOST_ARCH`).
    test-rule:
      skip-tests-when:
        not:
          arch-matches: "linux-any"
```

Integration mode availability: any integration mode


# Installations (`installations`)

For source packages building a single binary, the `dh_auto_install` from debhelper will default to
providing everything from upstream's install in the binary package.  The `debputy` tool matches this
behavior and accordingly, the `installations` feature is only relevant in this case when you need to
manually specify something upstream's install did not cover.

For sources, that build multiple binaries, where `dh_auto_install` does not detect anything to install,
or when `dh_auto_install --destdir debian/tmp` is used, the `installations` section of the manifest is
used to declare what goes into which binary package. An example:

    installations:
      - install:
            sources: "usr/bin/foo"
            into: foo
      - install:
            sources: "usr/*"
            into: foo-extra

All installation rules are processed in order (top to bottom).  Once a path has been matched, it can
no longer be matched by future rules.  In the above example, then `usr/bin/foo` would be in the `foo`
package while everything in `usr` *except* `usr/bin/foo` would be in `foo-extra`.  If these had been
ordered in reverse, the `usr/bin/foo` rule would not have matched anything and caused `debputy`
to reject the input as an error on that basis.  This behavior is similar to "DEP-5" copyright files,
except the order is reversed ("DEP-5" uses "last match wins", where here we are doing "first match wins")

In the rare case that some path need to be installed into two packages at the same time, then this is
generally done by changing `into` into a list of packages.

All installations are currently run in *source* package context.  This implies that:

  1) No package specific substitutions are available. Notably `{{PACKAGE}}` cannot be resolved.
  2) All conditions are evaluated in source context.  For 99.9% of users, this makes no difference,
     but there is a cross-build feature that changes the "per package" architecture which is affected.

This is a limitation that should be fixed in `debputy`.

Another feature of `debputy` installation rules is that the match rule is always applied even when
the rule is "disabled" by a condition (such as the package being arch:all and the build does not
cover arch:all binaries). This is required to avoid false positives errors when testing for paths
that might have been overlooked. The code will not install the matched paths anywhere, just mark
them as reserved by the package that is not being built. This behavior is similar to that of
`dh_install`, which is also aimed at preventing a similar false positive with `dh_missing`.

**Attention debhelper users**: Note the difference between `dh_install` (etc.) vs. `debputy` on
overlapping matches for installation.

Integration mode availability: dh-sequence-zz-debputy, full


## Install rule search directories

Most install rules apply their patterns against search directories such as `debian/tmp` by default.

The default search directory order (highest priority first) is:

 1) The upstream install directory (usually, `debian/tmp`)
 2) The source package root directory (`.`)

Each search directory is tried in order.  When a pattern matches an entry in a search directory (even
if that entry is reserved by another package), further search directories will *not* be tried. As an example,
consider the pattern `usr/bin/foo*` and the files:

  `SOURCE_ROOT/debian/tmp/usr/bin/foo.sh`
  `SOURCE_ROOT/usr/bin/foo.pl`

Here the pattern will only match `SOURCE_ROOT/debian/tmp/usr/bin/foo.sh` and not `SOURCE_ROOT/usr/bin/foo.pl`.

## Automatic discard rules

The `debputy` framework provides some built-in discard rules that are applied by default during installation
time.  These are always active and implicit, but can be overwritten by exact path matches for install rules.

The `debputy` tool itself provides the following discard rules:

 * Discard of `.la` files. Their use is rare but not unheard of. You may need to overwrite this.
 * Discard of python byte code (such as `__pycache__` directories).
 * Discard of editor backup files (such as `*~`, `*.bak`, etc.).
 * Discard of Version control files (such as `.gitignore`, etc.).
 * Discard of GNU info's `dir` (`usr/share/info/dir`) as it causes file conflicts with other packages.
 * Discard of `DEBIAN` directory.

Note: Third-party plugins may provide additional automatic discard rules. Please use
`debputy plugin list automatic-discard-rules` to see all known automatic discard rules.

If you find yourself needing a particular path installed that has been discarded by default, you can overrule
the default discard by spelling out the path. As an example, if you needed to install a `libfoo.la` file,
you could do:

    installations:
      - install:
            sources:
            # By-pass automatic discard of `libfoo.la` - globs *cannot* be used!
             - "usr/lib/libfoo.la"
             - "usr/lib/libfoo*.so*"
            into: libfoo1

## Generic install (`install`)

The generic `install` rule can be used to install arbitrary paths into packages
and is *similar* to how `dh_install` from debhelper works.  It is a two "primary" uses.

  1) The classic "install into directory" similar to the standard `dh_install`
  2) The "install as" similar to `dh-exec`'s `foo => bar` feature.

The `install` rule installs a path exactly once into each package it acts on. In
the rare case that you want to install the same source *multiple* times into the
*same* packages, please have a look at `multi-dest-install`.

Attributes:
 - `source` (conditional): FileSystemMatchRule
   `sources` (conditional): List of string

   A path match (`source`) or a list of path matches (`sources`) defining the
   source path(s) to be installed. The path match(es) can use globs.  Each match
   is tried against default search directories.
    - When a symlink is matched, then the symlink (not its target) is installed
      as-is.  When a directory is matched, then the directory is installed along
      with all the contents that have not already been installed somewhere.

 - `dest-dir` (optional): FileSystemExactMatchRule

   A path defining the destination *directory*.  The value *cannot* use globs, but can
   use substitution.  If neither `as` nor `dest-dir` is given, then `dest-dir` defaults
   to the directory name of the `source`.

 - `into` (optional): string or a list of string

   Either a package name or a list of package names for which these paths should be
   installed.  This key is conditional on whether there are multiple binary packages listed
   in `debian/control`.  When there is only one binary package, then that binary is the
   default for `into`. Otherwise, the key is required.

 - `as` (optional): FileSystemExactMatchRule

   A path defining the path to install the source as. This is a full path.  This option
   is mutually exclusive with `dest-dir` and `sources` (but not `source`).  When `as` is
   given, then `source` must match exactly one "not yet matched" path.

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.


This rule enforces the following restrictions:
 - The rule must use exactly one of: `source`, `sources`
 - The attribute `as` cannot be used with any of: `dest-dir`, `sources`

Integration mode availability: any integration mode

## Install documentation (`install-docs`)

This install rule resemble that of `dh_installdocs`.  It is a shorthand over the generic
`install` rule with the following key features:

 1) The default `dest-dir` is to use the package's documentation directory (usually something
    like `/usr/share/doc/{{PACKAGE}}`, though it respects the "main documentation package"
    recommendation from Debian Policy). The `dest-dir` or `as` can be set in case the
    documentation in question goes into another directory or with a concrete path.  In this
    case, it is still "better" than `install` due to the remaining benefits.
 2) The rule comes with pre-defined conditional logic for skipping the rule under
    `DEB_BUILD_OPTIONS=nodoc`, so you do not have to write that conditional yourself.
 3) The `into` parameter can be omitted as long as there is a exactly one non-`udeb`
    package listed in `debian/control`.

With these two things in mind, it behaves just like the `install` rule.

Note: It is often worth considering to use a more specialized version of the `install-docs`
rule when one such is available. If you are looking to install an example or a man page,
consider whether `install-examples` or `install-man` might be a better fit for your
use-case.

Attributes:
 - `source` (conditional): FileSystemMatchRule
   `sources` (conditional): List of string

   A path match (`source`) or a list of path matches (`sources`) defining the
   source path(s) to be installed. The path match(es) can use globs.  Each match
   is tried against default search directories.
    - When a symlink is matched, then the symlink (not its target) is installed
      as-is.  When a directory is matched, then the directory is installed along
      with all the contents that have not already been installed somewhere.

    - **CAVEAT**: Specifying `source: examples` where `examples` resolves to a
      directory for `install-examples` will give you an `examples/examples`
      directory in the package, which is rarely what you want. Often, you
      can solve this by using `examples/*` instead. Similar for `install-docs`
      and a `doc` or `docs` directory.

 - `dest-dir` (optional): FileSystemExactMatchRule

   A path defining the destination *directory*.  The value *cannot* use globs, but can
   use substitution.  If neither `as` nor `dest-dir` is given, then `dest-dir` defaults
   to the relevant package documentation directory (a la `/usr/share/doc/{{PACKAGE}}`).

 - `into` (optional): string or a list of string

   Either a package name or a list of package names for which these paths should be
   installed as documentation.  This key is conditional on whether there are multiple
   (non-`udeb`) binary packages listed in `debian/control`.  When there is only one
   (non-`udeb`) binary package, then that binary is the default for `into`. Otherwise,
   the key is required.

 - `as` (optional): FileSystemExactMatchRule

   A path defining the path to install the source as. This is a full path.  This option
   is mutually exclusive with `dest-dir` and `sources` (but not `source`).  When `as` is
   given, then `source` must match exactly one "not yet matched" path.

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).
   This condition will be combined with the built-in condition provided by these rules
   (rather than replacing it).


This rule enforces the following restrictions:
 - The rule must use exactly one of: `source`, `sources`
 - The attribute `as` cannot be used with any of: `dest-dir`, `sources`

Integration mode availability: any integration mode

## Install examples (`install-examples`)

This install rule resemble that of `dh_installexamples`.  It is a shorthand over the generic `
install` rule with the following key features:

 1) It pre-defines the `dest-dir` that respects the "main documentation package" recommendation from
    Debian Policy. The `install-examples` will use the `examples` subdir for the package documentation
    dir.
 2) The rule comes with pre-defined conditional logic for skipping the rule under
    `DEB_BUILD_OPTIONS=nodoc`, so you do not have to write that conditional yourself.
 3) The `into` parameter can be omitted as long as there is a exactly one non-`udeb`
    package listed in `debian/control`.

With these two things in mind, it behaves just like the `install` rule.

Attributes:
 - `source` (conditional): FileSystemMatchRule
   `sources` (conditional): List of string

   A path match (`source`) or a list of path matches (`sources`) defining the
   source path(s) to be installed. The path match(es) can use globs.  Each match
   is tried against default search directories.
    - When a symlink is matched, then the symlink (not its target) is installed
      as-is.  When a directory is matched, then the directory is installed along
      with all the contents that have not already been installed somewhere.

    - **CAVEAT**: Specifying `source: examples` where `examples` resolves to a
      directory for `install-examples` will give you an `examples/examples`
      directory in the package, which is rarely what you want. Often, you
      can solve this by using `examples/*` instead. Similar for `install-docs`
      and a `doc` or `docs` directory.

 - `into` (optional): string or a list of string

   Either a package name or a list of package names for which these paths should be
   installed as examples.  This key is conditional on whether there are (non-`udeb`)
   multiple binary packages listed in `debian/control`.  When there is only one
   (non-`udeb`) binary package, then that binary is the default for `into`.
   Otherwise, the key is required.

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).
   This condition will be combined with the built-in condition provided by these rules
   (rather than replacing it).


This rule enforces the following restrictions:
 - The rule must use exactly one of: `source`, `sources`

Integration mode availability: any integration mode

## Install man pages (`install-man`)

Install rule for installing man pages similar to `dh_installman`. It is a shorthand
over the generic `install` rule with the following key features:

 1) The rule can only match files (notably, symlinks cannot be matched by this rule).
 2) The `dest-dir` is computed per source file based on the man page's section and
    language.
 3) The `into` parameter can be omitted as long as there is a exactly one non-`udeb`
    package listed in `debian/control`.
 4) The rule comes with man page specific attributes such as `language` and `section`
    for when the auto-detection is insufficient.
 5) The rule comes with pre-defined conditional logic for skipping the rule under
    `DEB_BUILD_OPTIONS=nodoc`, so you do not have to write that conditional yourself.

With these things in mind, the rule behaves similar to the `install` rule.

Attributes:
 - `source` (conditional): FileSystemMatchRule
   `sources` (conditional): List of string

   A path match (`source`) or a list of path matches (`sources`) defining the
   source path(s) to be installed. The path match(es) can use globs.  Each match
   is tried against default search directories.
    - When a symlink is matched, then the symlink (not its target) is installed
      as-is.  When a directory is matched, then the directory is installed along
      with all the contents that have not already been installed somewhere.

 - `into` (optional): string or a list of string

   Either a package name or a list of package names for which these paths should be
   installed as man pages.  This key is conditional on whether there are multiple (non-`udeb`)
   binary packages listed in `debian/control`.  When there is only one (non-`udeb`) binary
   package, then that binary is the default for `into`. Otherwise, the key is required.

 - `section` (optional): integer

   If provided, it must be an integer between 1 and 9 (both inclusive), defining the
   section the man pages belong overriding any auto-detection that `debputy` would
   have performed.

 - `language` (optional): string

   If provided, it must be either a 2 letter language code (such as `de`), a 5 letter
   language + dialect code (such as `pt_BR`), or one of the special keywords `C`,
   `derive-from-path`, or `derive-from-basename`.  The default is `derive-from-path`.
      - When `language` is `C`, then the man pages are assumed to be "untranslated".
      - When `language` is a language code (with or without dialect), then all man pages
        matched will be assumed to be translated to that concrete language / dialect.
      - When `language` is `derive-from-path`, then `debputy` attempts to derive the
        language from the path (`man/<language>/man<section>`).  This matches the
        default of `dh_installman`. When no language can be found for a given source,
        `debputy` behaves like language was `C`.
      - When `language` is `derive-from-basename`, then `debputy` attempts to derive
        the language from the basename (`foo.<language>.1`) similar to `dh_installman`
        previous default.  When no language can be found for a given source, `debputy`
        behaves like language was `C`.  Note this is prone to false positives where
        `.pl`, `.so` or similar two-letter extensions gets mistaken for a language code
        (`.pl` can both be "Polish" or "Perl Script", `.so` can both be "Somali" and
        "Shared Object" documentation).  In this configuration, such extensions are
        always assumed to be a language.

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.


This rule enforces the following restrictions:
 - The rule must use exactly one of: `source`, `sources`

Integration mode availability: any integration mode

## Discard (or exclude) upstream provided paths (`discard`)

When installing paths from `debian/tmp` into packages, it might be useful to ignore
some paths that you never need installed.  This can be done with the `discard` rule.

Once a path is discarded, it cannot be matched by any other install rules.  A path
that is discarded, is considered handled when `debputy` checks for paths you might
have forgotten to install.  The `discard` feature is therefore *also* replaces the
`debian/not-installed` file used by `debhelper` and `cdbs`.

Attributes:
 - `path` (conditional): FileSystemMatchRule
   `paths` (conditional): List of string

   A path match (`path`) or a list of path matches (`paths`) defining the source
   path(s) that should not be installed anywhere. The path match(es) can use globs.
   - When a symlink is matched, then the symlink (not its target) is discarded as-is.
     When a directory is matched, then the directory is discarded along with all the
     contents that have not already been installed somewhere.

 - `search-dir` (optional): FileSystemExactMatchRule
   `search-dirs` (optional): List of string

   A path (`search-dir`) or a list to paths (`search-dirs`) that defines
   which search directories apply to. This attribute is primarily useful
   for source packages that uses "per package search dirs", and you want
   to restrict a discard rule to a subset of the relevant search dirs.
   Note all listed search directories must be either an explicit search
   requested by the packager or a search directory that `debputy`
   provided automatically (such as `debian/tmp`). Listing other paths
   will make `debputy` report an error.
   - Note that the `path` or `paths` must match at least one entry in
     any of the search directories unless *none* of the search directories
     exist (or the condition in `required-when` evaluates to false). When
     none of the search directories exist, the discard rule is silently
     skipped. This special-case enables you to have discard rules only
     applicable to certain builds that are only performed conditionally.

 - `required-when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules). The discard
   rule is always applied. When the conditional is present and evaluates to false,
   the discard rule can silently match nothing.When the condition is absent, *or*
   it evaluates to true, then each pattern provided must match at least one path.


This rule enforces the following restrictions:
 - The rule must use exactly one of: `path`, `paths`
 - The following attributes are mutually exclusive: `search-dir`, `search-dirs`

Integration mode availability: any integration mode

## Multi destination install (`multi-dest-install`)

The `multi-dest-install` is a variant of the generic `install` rule that installs sources
into multiple destination paths. This is needed for the rare case where you want a
path to be installed *twice* (or more) into the *same* package. The rule is a two
"primary" uses.

  1) The classic "install into directory" similar to the standard `dh_install`,
     except you list 2+ destination directories.
  2) The "install as" similar to `dh-exec`'s `foo => bar` feature, except you list
     2+ `as` names.

Attributes:
 - `source` (conditional): FileSystemMatchRule
   `sources` (conditional): List of string

   A path match (`source`) or a list of path matches (`sources`) defining the
   source path(s) to be installed. The path match(es) can use globs.  Each match
   is tried against default search directories.
    - When a symlink is matched, then the symlink (not its target) is installed
      as-is.  When a directory is matched, then the directory is installed along
      with all the contents that have not already been installed somewhere.

 - `dest-dirs` (optional): List of string

   A list of paths defining the destination *directories*.  The value *cannot* use
   globs, but can use substitution. It is mutually exclusive with `as` but must be
   provided if `as` is not provided. The attribute must contain at least two paths
   (if you do not have two paths, you want `install`).

 - `into` (optional): string or a list of string

   Either a package name or a list of package names for which these paths should be
   installed.  This key is conditional on whether there are multiple binary packages listed
   in `debian/control`.  When there is only one binary package, then that binary is the
   default for `into`. Otherwise, the key is required.

 - `as` (optional): List of string

   A list of paths, which defines all the places the source will be installed.
   Each path must be a full path without globs (but can use substitution).
   This option is mutually exclusive with `dest-dirs` and `sources` (but not
   `source`).  When `as` is given, then `source` must match exactly one
   "not yet matched" path. The attribute must contain at least two paths
   (if you do not have two paths, you want `install`).

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.


This rule enforces the following restrictions:
 - The rule must use exactly one of: `source`, `sources`
 - The attribute `as` cannot be used with any of: `dest-dirs`, `sources`

Integration mode availability: any integration mode


# Binary package rules

Inside the manifest, the `packages` mapping can be used to define requests for the binary packages
you want `debputy` to produce.  Each key inside `packages` must be the name of a binary package
defined in `debian/control`.  The value is a dictionary defining which features that `debputy`
should apply to that binary package.  An example could be:


    packages:
        foo:
            transformations:
                - create-symlink:
                      path: usr/share/foo/my-first-symlink
                      target: /usr/share/bar/symlink-target
                - create-symlink:
                      path: usr/lib/{{DEB_HOST_MULTIARCH}}/my-second-symlink
                      target: /usr/lib/{{DEB_HOST_MULTIARCH}}/baz/symlink-target
        bar:
            transformations:
            - create-directories:
               - some/empty/directory.d
               - another/empty/integration-point.d
            - create-directories:
                 path: a/third-empty/directory.d
                 owner: www-data
                 group: www-data

In this case, `debputy` will create some symlinks inside the `foo` package and some directories for
the `bar` package.  The following subsections define the keys you can use under each binary package.


## Transformations (`transformations`)

You can define a `transformations` under the package definition, which is a list a transformation
rules.  An example:

    packages:
        foo:
            transformations:
              - remove: 'usr/share/doc/{{PACKAGE}}/INSTALL.md'
              - move:
                    source: bar/*
                    target: foo/


Transformations are ordered and are applied in the listed order.  A path can be matched by multiple
transformations; how that plays out depends on which transformations are applied and in which order.
A quick summary:

 - Transformations that modify the file system layout affect how path matches in later transformations.
   As an example, `move` and `remove` transformations affects what globs and path matches expand to in
   later transformation rules.

 - For other transformations generally the latter transformation overrules the earlier one, when they
   overlap or conflict.

Integration mode availability: any integration mode

### Remove transformation rule (`remove`)

The remove transformation rule is mostly only useful for single binary source packages,
where everything from upstream's build system is installed automatically into the package.
In those case, you might find yourself with some files that are _not_ relevant for the
Debian package (but would be relevant for other distros or for non-distro local builds).
Common examples include `INSTALL` files or `LICENSE` files (when they are just a subset
of `debian/copyright`).

In the manifest, you can ask `debputy` to remove paths from the debian package by using
the `remove` transformation rule.

Note that `remove` removes paths from future glob matches and transformation rules.

Attributes:
 - `path` (conditional): FileSystemMatchRule
   `paths` (conditional): List of string

   A path match (`path`) or a list of path matches (`paths`) defining the
   path(s) inside the package that should be removed. The path match(es)
   can use globs.
   - When a symlink is matched, then the symlink (not its target) is removed
     as-is.  When a directory is matched, then the directory is removed
     along with all the contents.

 - `keep-empty-parent-dirs` (optional): boolean

   A boolean determining whether to prune parent directories that become
   empty as a consequence of this rule.  When provided and `true`, this
   rule will leave empty directories behind. Otherwise, if this rule
   causes a directory to become empty that directory will be removed.

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).
   This condition will be combined with the built-in condition provided by these rules
   (rather than replacing it).


This rule enforces the following restrictions:
 - The rule must use exactly one of: `path`, `paths`

Integration mode availability: any integration mode

### Move transformation rule (`move`)

The move transformation rule is mostly only useful for single binary source packages,
where everything from upstream's build system is installed automatically into the package.
In those case, you might find yourself with some files that need to be renamed to match
Debian specific requirements.

This can be done with the `move` transformation rule, which is a rough emulation of the
`mv` command line tool.

Attributes:
 - `source` (required): FileSystemMatchRule

   A path match defining the source path(s) to be renamed.  The value can use globs
   and substitutions.

 - `target` (required): FileSystemExactMatchRule

   A path defining the target path.  The value *cannot* use globs, but can use
   substitution. If the target ends with a literal `/` (prior to substitution),
   the target will *always* be a directory.

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.


Integration mode availability: any integration mode

### Create symlinks transformation rule (`create-symlink`)

Often, the upstream build system will provide the symlinks for you.  However,
in some cases, it is useful for the packager to define distribution specific
symlinks. This can be done via the `create-symlink` transformation rule.

Attributes:
 - `path` (required): FileSystemExactMatchRule

   The path that should be a symlink.  The path may contain substitution
   variables such as `{{DEB_HOST_MULTIARCH}}` but _cannot_ use globs.
   Parent directories are implicitly created as necessary.
   * Note that if `path` already exists, the behavior of this
     transformation depends on the value of `replacement-rule`.

 - `target` (required): SymlinkTarget

   Where the symlink should point to. The target may contain substitution
   variables such as `{{DEB_HOST_MULTIARCH}}` but _cannot_ use globs.
   The link target is _not_ required to exist inside the package.
   * The `debputy` tool will normalize the target according to the rules
     of the Debian Policy.  Use absolute or relative target at your own
     preference.

 - `replacement-rule` (optional): One of the following literal values: `error-if-exists`, `error-if-directory`, `abort-on-non-empty-directory`, `discard-existing`

    This attribute defines how to handle if `path` already exists. It can
    be set to one of the following values:
       - `error-if-exists`: When `path` already exists, `debputy` will
          stop with an error.  This is similar to `ln -s` semantics.
       - `error-if-directory`: When `path` already exists, **and** it is
          a directory, `debputy` will stop with an error. Otherwise,
          remove the `path` first and then create the symlink.  This is
          similar to `ln -sf` semantics.
       - `abort-on-non-empty-directory` (default): When `path` already
          exists, then it will be removed provided it is a non-directory
          **or** an *empty* directory and the symlink will then be
          created.  If the path is a *non-empty* directory, `debputy`
          will stop with an error.
       - `discard-existing`: When `path` already exists, it will be
          removed. If the `path` is a directory, all its contents will
          be removed recursively along with the directory. Finally,
          the symlink is created. This is similar to having an explicit
          `remove` rule just prior to the `create-symlink` that is
          conditional on `path` existing (plus the condition defined in
          `when` if any).

   Keep in mind, that `replacement-rule` only applies if `path` exists.
   If the symlink cannot be created, because a part of `path` exist and
   is *not* a directory, then `create-symlink` will fail regardless of
   the value in `replacement-rule`.

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.


Integration mode availability: any integration mode

### Create directories transformation rule (`create-directories`)

NOTE: This transformation is only really needed if you need to create an empty
directory somewhere in your package as an integration point.  All `debputy`
transformations will create directories as required.

In most cases, upstream build systems and `debputy` will create all the relevant
directories.  However, in some rare cases you may want to explicitly define a path
to be a directory.  Maybe to silence a linter that is warning you about a directory
being empty, or maybe you need an empty directory that nothing else is creating for
you. This can be done via the `create-directories` transformation rule.

Unless you have a specific need for the mapping form, you are recommended to use the
shorthand form of just listing the directories you want created.

Attributes:
 - `path` (conditional): FileSystemExactMatchRule
   `paths` (conditional): List of string

   A path (`path`) or a list of path (`paths`) defining the path(s) inside the
   package that should be created as directories. The path(es) _cannot_ use globs
   but can use substitution variables.  Parent directories are implicitly created
   (with owner `root:root` and mode `0755` - only explicitly listed directories
   are affected by the owner/mode options)

 - `owner` (optional): one-of: integer, string

   Denotes the owner of the directory (but _not_ what is inside the directory).
   Default is "root".

 - `group` (optional): one-of: integer, string

   Denotes the group of the directory (but _not_ what is inside the directory).
   Default is "root".

 - `mode` (optional): FileSystemMode

   Denotes the mode of the directory (but _not_ what is inside the directory).
   Note that numeric mode must always be given as a string (i.e., with quotes).
   Symbolic mode can be used as well. If symbolic mode uses a relative
   definition (e.g., `o-rx`), then it is relative to the directory's current mode
   (if it already exists) or `0755` if the directory is created by this
   transformation.  The default is "0755".

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.


This rule enforces the following restrictions:
 - The rule must use exactly one of: `path`, `paths`

Integration mode availability: any integration mode

### Change path owner/group or mode (`path-metadata`)

The `debputy` command normalizes the path metadata (such as ownership and mode) similar
to `dh_fixperms`.  For most packages, the default is what you want.  However, in some
cases, the package has a special case or two that `debputy` does not cover.  In that
case, you can tell `debputy` to use the metadata you want by using the `path-metadata`
transformation.

Common use-cases include setuid/setgid binaries (such `usr/bin/sudo`) or/and static
ownership (such as /usr/bin/write).

Attributes:
 - `path` (conditional): FileSystemMatchRule
   `paths` (conditional): List of string

   A path match (`path`) or a list of path matches (`paths`) defining the path(s)
   inside the package that should be affected. The path match(es) can use globs
   and substitution variables. Special-rules for matches:
   - Symlinks are never followed and will never be matched by this rule.
   - Directory handling depends on the `recursive` attribute.

 - `owner` (optional): one-of: integer, string

   Denotes the owner of the paths matched by `path` or `paths`. When omitted,
   no change of owner is done.

 - `group` (optional): one-of: integer, string

   Denotes the group of the paths matched by `path` or `paths`. When omitted,
   no change of group is done.

 - `mode` (optional): FileSystemMode

   Denotes the mode of the paths matched by `path` or `paths`. When omitted,
   no change in mode is done. Note that numeric mode must always be given as
   a string (i.e., with quotes).  Symbolic mode can be used as well. If
   symbolic mode uses a relative definition (e.g., `o-rx`), then it is
   relative to the matched path's current mode.

 - `capabilities` (optional): Capability

   Denotes a Linux capability that should be applied to the path. When provided,
   `debputy` will cause the capability to be applied to all *files* denoted by
   the `path`/`paths` attribute on install (via `postinst configure`) provided
   that `setcap` is installed on the system when the `postinst configure` is
   run.
   - If any non-file paths are matched, the `capabilities` will *not* be applied
     to those paths.


 - `capability-mode` (optional): FileSystemMode

    Denotes the mode to apply to the path *if* the Linux capability denoted in
   `capabilities` was successfully applied. If omitted, it defaults to `a-s` as
   generally capabilities are used to avoid "setuid"/"setgid" binaries. The
   `capability-mode` is relative to the *final* path mode (the mode of the path
   in the produced `.deb`). The `capability-mode` attribute cannot be used if
   `capabilities` is omitted.

 - `recursive` (optional): boolean

   When a directory is matched, then the metadata changes are applied to the
   directory itself. When `recursive` is `true`, then the transformation is
   *also* applied to all paths beneath the directory. The default value for
   this attribute is `false`.

 - `when` (optional): ManifestCondition

   A condition as defined in [Conditional rules](#conditional-rules).

   The conditional will disable the entire rule when the conditional evaluates to false.


This rule enforces the following restrictions:
 - The rule must use exactly one of: `path`, `paths`

Integration mode availability: any integration mode


## Define how services in the package will be handled (`services`)

If you have non-standard requirements for certain services in the package, you can define those via
the `services` attribute. The `services` attribute is a list of service rules. Example:

    packages:
        foo:
            services:
              - service: "foo"
                enable-on-install: false
              - service: "bar"
                on-upgrade: stop-then-start

List where each element has the following attributes:
 - `service` (required): string

   Name of the service to match. The name is usually the basename of the service file.
   However, aliases can also be used for relevant system managers. When aliases **and**
   multiple service managers are involved, then the rule will apply to all matches.
   For details on aliases, please see
   [Service managers and aliases](#service-managers-and-aliases).

     - Note: For systemd, the `.service` suffix can be omitted from name, but other
       suffixes such as `.timer` cannot.

 - `type-of-service` (optional): string

   The type of service this rule applies to. To act on a `systemd` timer, you would
   set this to `timer` (etc.). Each service manager defines its own set of types
   of services.

 - `service-scope` (optional): One of the following literal values: `system`, `user`

   The scope of the service. It must be either `system` and `user`.
   - Note: The keyword is defined to support `user`, but `debputy` does not support `user`
     services at the moment (the detection logic is missing).

 - `service-manager` (optional): string
   `service-managers` (optional): List of string

   Which service managers this rule is for. When omitted, all service managers with this
   service will be affected. This can be used to specify separate rules for the same
   service under different service managers.
   - When this attribute is explicitly given, then all the listed service managers must
     provide at least one service matching the definition. In contrast, when it is omitted,
     then all service manager integrations are consulted but as long as at least one
     service is matched by at least one service manager, the rule is accepted.

 - `enable-on-install` (optional): boolean

   Whether to automatically enable the service on installation. Note: This does
   **not** affect whether the service will be started nor how restarts during
   upgrades will happen.
   - If omitted, the plugin detecting the service decides the default.

 - `start-on-install` (optional): boolean

   Whether to automatically start the service on installation. Whether it is
   enabled or how upgrades are handled have separate attributes.
   - If omitted, the plugin detecting the service decides the default.

 - `on-upgrade` (optional): One of the following literal values: `do-nothing`, `reload`, `restart`, `stop-then-start`

   How `debputy` should handle the service during upgrades. The default depends on the
   plugin detecting the service. Valid values are:

   - `do-nothing`: During an upgrade, the package should not attempt to stop, reload or
      restart the service.
   - `reload`: During an upgrade, prefer reloading the service rather than restarting
      if possible. Note that the result may become `restart` instead if the service
      manager integration determines that `reload` is not supported.
   - `restart`: During an upgrade, `restart` the service post upgrade. The service
      will be left running during the upgrade process.
   - `stop-then-start`: Stop the service before the upgrade, perform the upgrade and
      then start the service.


This rule enforces the following restrictions on each element in the list:
 - The following attributes are mutually exclusive: `service-manager`, `service-managers`

Integration mode availability: dh-sequence-zz-debputy, full


### Service managers and aliases

When defining a service rule, you can use any name that any of the relevant service managers would call the
service. As an example, consider a package that has the following services:

 * A `sysvinit` service called `foo`
 * A `systemd` service called `bar.service` with `Alias=foo.service` in its definition.

Here, depending on which service managers are relevant to the rule, you can use different names to match.
When the rule applies to the `systemd` service manager, then either of the following names can be used:

 * `bar.service` (the "canonical" name in the systemd world)
 * `foo.service` (the defined alias)
 * `bar` + `foo` (automatic aliases based on the above)

Now, if rule *also* applies to the `sysvinit` service manager, then any of those 4 names would cause the
rule to apply to both the `systemd` and the `sysvinit` services.

To show concrete examples:

    ...:
            services:
              # Only applies to systemd. Either of the 4 names would have work.
              - service: "foo.service"
                on-upgrade: stop-then-start
                service-manager: systemd

    ...:
            services:
              # Only applies to sysvinit. Must use `foo` since the 3 other names only applies when systemd
              # is involved.
              - service: "foo"
                on-upgrade: stop-then-start
                service-manager: sysvinit

    ...:
            services:
              # Applies to both systemd and sysvinit; this works because the `systemd` service provides an
              # alias for `foo`. If the systemd service did not have that alias, only the `systemd` service
              # would have been matched.
              - service: bar
                enable-on-install: false

## Custom binary version (`binary-version`)

In the *rare* case that you need a binary package to have a custom version, you can use
the `binary-version:` key to describe the desired package version.  An example being:

    packages:
        foo:
            # The foo package needs a different epoch because we took it over from a different
            # source package with higher epoch version
            binary-version: '1:{{DEB_VERSION_UPSTREAM_REVISION}}'

Use this feature sparingly as it is generally not possible to undo as each version must be
monotonously higher than the previous one. This feature translates into `-v` option for
`dpkg-gencontrol`.

The value for the `binary-version` key is a string that defines the binary version.  Generally,
you will want it to contain one of the versioned related substitution variables such as
`{{DEB_VERSION_UPSTREAM_REVISION}}`.  Otherwise, you will have to remember to bump the version
manually with each upload as versions cannot be reused and the package would not support binNMUs
either.

Integration mode availability: any integration mode

## Remove runtime created paths on purge or post removal (`clean-after-removal`)

For some packages, it is necessary to clean up some run-time created paths. Typical use cases are
deleting log files, cache files, or persistent state. This can be done via the `clean-after-removal`.
An example being:

    packages:
        foo:
            clean-after-removal:
            - /var/log/foo/*.log
            - /var/log/foo/*.log.gz
            - path: /var/log/foo/
              ignore-non-empty-dir: true
            - /etc/non-conffile-configuration.conf
            - path: /var/cache/foo
              recursive: true

The `clean-after-removal` key accepts a list, where each element is either a mapping, a string or a list
of strings. When an element is a mapping, then the following key/value pairs are applicable:

 * `path` or `paths` (required): A path match (`path`) or a list of path matches (`paths`) defining the
   path(s) that should be removed after clean. The path match(es) can use globs and manifest variables.
   Every path matched will by default be removed via `rm -f` or `rmdir` depending on whether the path
   provided ends with a *literal* `/`. Special-rules for matches:
    - Glob is interpreted by the shell, so shell (`/bin/sh`) rules apply to globs rather than
      `debputy`'s glob rules.  As an example, `foo/*` will **not** match `foo/.hidden-file`.
    - `debputy` cannot evaluate whether these paths/globs will match the desired paths (or anything at
      all). Be sure to test the resulting package.
    - When a symlink is matched, it is not followed.
    - Directory handling depends on the `recursive` attribute and whether the pattern ends with a literal
      "/".
    - `debputy` has restrictions on the globs being used to prevent rules that could cause massive damage
      to the system.

 * `recursive` (optional): When `true`, the removal rule will use `rm -fr` rather than `rm -f` or `rmdir`
    meaning any directory matched will be deleted along with all of its contents.

 * `ignore-non-empty-dir` (optional): When `true`, each path must be or match a directory (and as a
   consequence each path must with a literal `/`). The affected directories will be deleted only if they
   are empty. Non-empty directories will be skipped. This option is mutually exclusive with `recursive`.

 * `delete-on` (optional, defaults to `purge`): This attribute defines when the removal happens. It can
   be set to one of the following values:
   - `purge`: The removal happens with the package is being purged. This is the default. At a technical
     level, the removal occurs at `postrm purge`.
   - `removal`: The removal happens immediately after the package has been removed. At a technical level,
     the removal occurs at `postrm remove`.

This feature resembles the concept of `rpm`'s `%ghost` files.

Integration mode availability: dh-sequence-zz-debputy, full

## Custom installation time search directories (`installation-search-dirs`)

For source packages that does multiple build, it can be an advantage to provide a custom list of
installation-time search directories. This can be done via the `installation-search-dirs` key. A common
example is building  the source twice with different optimization and feature settings where the second
build is for the `debian-installer` (in the form of a `udeb` package). A sample manifest snippet could
look something like:

    installations:
    - install:
        # Because of the search order (see below), `foo` installs `debian/tmp/usr/bin/tool`,
        # while `foo-udeb` installs `debian/tmp-udeb/usr/bin/tool` (assuming both paths are
        # available). Note the rule can be split into two with the same effect if that aids
        # readability or understanding.
        source: usr/bin/tool
        into:
          - foo
          - foo-udeb
    packages:
        foo-udeb:
            installation-search-dirs:
            - debian/tmp-udeb


The `installation-search-dirs` key accepts a list, where each element is a path (str) relative from the
source root to the directory that should be used as a search directory (absolute paths are still interpreted
as relative to the source root).  This list should contain all search directories that should be applicable
for this package (except the source root itself, which is always appended after the provided list). If the
key is omitted, then `debputy` will provide a default  search order (In the `dh` integration, the default
is the directory `debian/tmp`).

If a non-existing or non-directory path is listed, then it will be skipped (info-level note). If the path
exists and is a directory, it will also be checked for "not-installed" paths.

Integration mode availability: dh-sequence-zz-debputy, full

## Built-Using dependency relations (`built-using`)

Generate a `Built-Using` dependency relation on the
build dependencies selected by the `sources-for`, which
may contain a `*` wildcard matching any number of
arbitrary characters.

The `built-using` should be used for static linking
where license of dependency libraries require the
exact source to be retained. Usually these libraries
will be under the license terms like GNU GPL.

packages:
  PKG:
    built-using:
    - sources-for: foo-*-source   # foo-3.1.0-source
    - sources-for: librust-*-dev  # several matches
    - sources-for: foo
      when:                       # foo is always installed
        arch-matches: amd64       # but only used on amd64

Either of these conditions prevents the generation:
* PKG is not part of the current build because of its
  `Architecture` or `Build-Profiles` fields.
* The match in `Build-Depends` carries an
  architecture or build profile restriction that does
  not match the current run.
* The match in `Build-Depends` is not installed.
  This should only happen inside alternatives, see below.
* The manifest item carries a `when:` condition that
  evaluates to false. This may be useful when the match
  must be installed for unrelated reasons.

Matches are searched in the `Build-Depends` field of
the source package, and either `Build-Depends-Indep`
or `Build-Depends-Arch` depending on PKG.

In alternatives like `a | b`, each option may match
separately.  This is a compromise between
reproducibility on automatic builders (where the set
of installed package is constant), and least surprise
during local builds (where `b` may be installed
alone). There seems to be no one-size fits all
solution when both are installed.

Architecture qualifiers and version restrictions in
`Build-Depends` are ignored. The only allowed
co-installations require a common source and version.

List where each element has the following attributes:

Integration mode availability: dh-sequence-zz-debputy, full

## Static-Built-Using dependency relations (`static-built-using`)

Generate a `Static-Built-Using` dependency relation on the
build dependencies selected by the `sources-for`, which
may contain a `*` wildcard matching any number of
arbitrary characters.

The `static-built-using` should be used for static linking
where license of dependency libraries do not require the
exact source to be retained. This is usually libraries under
permissive libraries like Apache-2.0 or MIT/X11/Expat.

packages:
  PKG:
    static-built-using:
    - sources-for: foo-*-source   # foo-3.1.0-source
    - sources-for: librust-*-dev  # several matches
    - sources-for: foo
      when:                       # foo is always installed
        arch-matches: amd64       # but only used on amd64

Either of these conditions prevents the generation:
* PKG is not part of the current build because of its
  `Architecture` or `Build-Profiles` fields.
* The match in `Build-Depends` carries an
  architecture or build profile restriction that does
  not match the current run.
* The match in `Build-Depends` is not installed.
  This should only happen inside alternatives, see below.
* The manifest item carries a `when:` condition that
  evaluates to false. This may be useful when the match
  must be installed for unrelated reasons.

Matches are searched in the `Build-Depends` field of
the source package, and either `Build-Depends-Indep`
or `Build-Depends-Arch` depending on PKG.

In alternatives like `a | b`, each option may match
separately.  This is a compromise between
reproducibility on automatic builders (where the set
of installed package is constant), and least surprise
during local builds (where `b` may be installed
alone). There seems to be no one-size fits all
solution when both are installed.

Architecture qualifiers and version restrictions in
`Build-Depends` are ignored. The only allowed
co-installations require a common source and version.

List where each element has the following attributes:

Integration mode availability: dh-sequence-zz-debputy, full


# Remove paths during clean (`remove-during-clean`)

When the clean logic does not cover all the paths generated during build,
the `remove-during-clean` keyword can be used to add a list of additional paths to
remove. An example could be:

```yaml
      remove-during-clean:
      - config.h
      - build/
      - docs/*.html
```

Each element in the list is a path or a glob pattern and each matched path will
be removed. To avoid accidental removals of directories, any element in the list
intended to remove directories must end with a literal `/`.

Integration mode availability: full


# Type listing

During the documentation, you may see references to a types such as `ManifestCondition` or `TestRule`.

The documentation for these are:

 * [`ManifestCondition`](#conditional-rules)
 * [`BuildRule`](#build-rules-builds) or [`BuildSystemRule`](#build-rules-builds)
 * [`TestRule`](#test-rules-buildstest-rule)
 * [`InstallRule`](#installations-installations)
 * [`TransformationRule`](#transformations-transformations)

Additionally, there are some type mappings such as `OctalMode`. These are documented below.

## Base types

These are the base types, which you may see.

 * `string`: A simple string. Often accepts substitutions in form of `{{VARIABLE}}`.
 * `int`: An integer.
 * `list of X`: A list of `X`, where `X` is a separate type.
 * `mapping of X`: A mapping. The keys are always `string` and the values are of type `X`,
   where `X` is a separate type.

## Type mappings

Here are some named types used in the documentation.

### Type Mapping: BinaryPackage [string]

Name of a package in debian/control

### Type Mapping: BuildEnvironmentDefinition [string]

Reference to a build environment defined in `build-environments`

### Type Mapping: Capability [string]

The value is a Linux capability parsable by cap_from_text on the host system.

With `libcap2` installed, `debputy` will attempt to parse the value and provide
warnings if the value cannot be parsed by `libcap2`. However, `debputy` will
currently never emit hard errors for unknown capabilities.

#### Example values

 * "cap_chown=p"
 * "cap_chown=ep"
 * "cap_kill-pe"
 * "=ep cap_chown-e cap_kill-ep"

### Type Mapping: FileSystemExactMatchRule [string]

A file system match that does **not** expand globs.

Manifest variable substitution will be applied. However, globs will not be expanded.
Any glob metacharacters will be interpreted as a literal part of path.

Note that a directory can be matched via this type. Whether the rule using this type
recurse into the directory depends on the usage and is not defined by this type.
Related, if value for this rule ends with a literal "/", then the definition can
*only* match directories (similar to the shell).

#### Example values

 * "usr/bin/dpkg"
 * "usr/share/foo/"
 * "usr/share/foo/data.txt"

### Type Mapping: FileSystemExactNonDirMatchRule [string]

A file system match that does **not** expand globs and must not match a directory.

Manifest variable substitution will be applied. However, globs will not be expanded.
Any glob metacharacters will be interpreted as a literal part of path.

This is like FileSystemExactMatchRule except that the match will fail if the
provided path matches a directory. Since a directory cannot be matched, it is an error
for any input to end with a "/" as only directories can be matched if the path ends
with a "/".

#### Example values

 * "usr/bin/dh_debputy"
 * "usr/share/foo/data.txt"

### Type Mapping: FileSystemMatchRule [string]

A generic file system path match with globs.

Manifest variable substitution will be applied and glob expansion will be performed.

The match will be read as one of the following cases:

  - Exact path match if there is no globs characters like `usr/bin/debputy`
  - A basename glob like `*.txt` or `**/foo`
  - A generic path glob otherwise like `usr/lib/*.so*`

Except for basename globs, all matches are always relative to the root directory of
the match, which is typically the package root directory or a search directory.

For basename globs, any path matching that basename beneath the package root directory
or relevant search directories will match.

Please keep in mind that:

  * glob patterns often have to be quoted as YAML interpret the glob metacharacter as
    an anchor reference.

  * Directories can be matched via this type. Whether the rule using this type
    recurse into the directory depends on the usage and not this type. Related, if
    value for this rule ends with a literal "/", then the definition can *only* match
    directories (similar to the shell).

  * path matches involving glob expansion are often subject to different rules than
    path matches without them. As an example, automatic discard rules does not apply
    to exact path matches, but they will filter out glob matches.

#### Example values

 * "usr/bin/debputy"
 * "*.txt"
 * "**/foo"
 * "usr/lib/*.so*"
 * "usr/share/foo/data-*/"

### Type Mapping: FileSystemMode [string]

A file system mode either in the form of an octal mode or a symbolic mode.

#### Example values

 * "a+x"
 * "u=rwX,go=rX"
 * "0755"

### Type Mapping: OctalMode [string]

A file system mode using the octal mode representation. Must always be a provided as a string (that is, quoted).

#### Example values

 * "0644"
 * "0755"

### Type Mapping: PackageSelector [string]

Match a package or set of a packages from debian/control

The simplest package selector is the name of a binary package from `debian/control`.
However, selections can also match multiple packages based on a given criteria, such
as `arch:all`/`arch:any` (matches packages where the `Architecture` field is set to
`all` or is not set to `all` respectively) or `package-type:deb` / `package-type:udeb`
(matches packages where `Package-Type` is set to `deb` or is set to `udeb`
respectively).

### Type Mapping: StaticFileSystemGroup [integer | string]

File system group reference that is part of the passwd base data (such as "root").

The group can be provided in either of the following three forms:

 * A name (recommended), such as "root"
 * The GID in the form of an integer (that is, no quoting), such as 0 (for "root")
 * The name and the GID separated by colon such as "root:0" (for "root").

Note in the last case, the `debputy` will validate that the name and the GID match.

Some owners (such as "nobody") are deliberately disallowed.

#### Example values

 * "root"
 * 0
 * "root:0"
 * "tty"

### Type Mapping: StaticFileSystemOwner [integer | string]

File system owner reference that is part of the passwd base data (such as "root").

The group can be provided in either of the following three forms:

 * A name (recommended), such as "root"
 * The UID in the form of an integer (that is, no quoting), such as 0 (for "root")
 * The name and the UID separated by colon such as "root:0" (for "root").

Note in the last case, the `debputy` will validate that the name and the UID match.

Some owners (such as "nobody") are deliberately disallowed.

#### Example values

 * "root"
 * 0
 * "root:0"
 * "bin"

### Type Mapping: SymlinkTarget [string]

A symlink target.

Manifest variable substitution will be applied. This is distinct from an exact file
system match in that a symlink target is not relative to the package root by default
(explicitly prefix for "/" for absolute path targets)

Note that `debputy` will policy normalize symlinks when assembling the deb, so
use of relative or absolute symlinks comes down to preference.

#### Example values

 * "../foo"
 * "/usr/share/doc/bar"

## Other type mappings

If you see a type that is not listed anywhere in this document, then it might be from a third-party
plugin. Try one of the following commands to resolve it:

 * `debputy plugin show type-mappings <TypeMapping>`
 * `debputy plugin show p-m-r <attribute-name>` (or `debputy plugin show p-m-r <BaseType>::<attribute-name>`)

You can also do this with `debputy` provided types. As an example `debputy plugin show type-mappings OctalMode`
or `debputy plugin show p-m-r install-man` (a.k.a. `debputy plugin show p-m-r InstallRule::install-man`).

[reference documentation]: https://documentation.divio.com/reference/