Source file ContextC.ml
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
(** The core components of the reference implementation build engine.
{3 Implementors of build engine}
You will want to first read
{{:https://discuss.ocaml.org/t/ocaml-version-of-the-build-systems-a-la-carte-paper/17042}OCaml
version of the “Build systems à la carte” paper} first. For thunks we use
the term "build engine", but it is interchangeable with the term "build
system" used in the paper.
The reference build engine uses the same components as
["tests/MlFront_Thunk/alacarte_6_4_test.ml"] to aid in understanding. We use
comments to say where we diverge and also use comments to say what your own
implementation should be doing for efficiency (etc.).
{3 Basic Design}
The ["*.values.json"] build files are input files. Each build file will have
a input {!Alacarte_3_2_apparatus.SourceFormKind} key, and more keys of
{!Alacarte_3_2_apparatus.SourceAssetKind} or
{!Alacarte_3_2_apparatus.SourceAssetKind} are made if the build file has
assets and bundle files. These build files are part of the
{!Alacarte_3_2_apparatus.StoreInfo}, so the build files must be scanned
before a store is initialized. These input keys are {i not} selected by the
user on the command line or inside a form.
Tasks for keys {!Alacarte_3_2_apparatus.UserObjectKind},
{!Alacarte_3_2_apparatus.UserAssetKind} and
{!Alacarte_3_2_apparatus.UserAssetKind} are created from the build files
when the set of tasks are initially assembled. These keys are selectable by
the user on the command line or inside a form. The task assembly happens
after the store is initialized so the tasks can "depend" on the input keys
(ex. {!Alacarte_3_2_apparatus.UserObjectKind} depends on a
{!Alacarte_3_2_apparatus.SourceFormKind} key). And even though the initial
task assembly happens before the build system is given a target key, the
tasks are mutable and can be added on-demand (ie. when a form creates a
dynamic task). *)
let dk_prog = "dk"
(** Any change to the specification of [".values.json"] or change to reference
implementation that would result in an invalid value store requires a change
to the values version. *)
let values_version = "0.1.1"
let (_ :
[ `DeadbadChecksumForZipEntryButNeedBetter of Fmlib_parse.Position.range ])
=
DkZero_Base.BuildToDo
.asset_range_download_of_zip_entry_from_zip_index_needs_a_secure_checksum
Fmlib_parse.Position.(start, start)
open struct
let alwaystrace = false
end
module MakeInitObserver =
MlFront_Thunk.ThunkParsers.Results.MakeObserverWithDiagnoseErrors
(MlFront_Thunk.Diagnose.Diagnose.ConsolePlainStyle)
module Impl = struct
type install_params = { program : string }
module Promise = MlFront_Thunk.Promises.PromiseMinimal
module Log = struct
let src = Logs.Src.create "dk0.runtimec" ~doc:"logs dk0 events"
module L = (val Logs.src_log src : Logs.LOG)
type 'a t = ('a, unit Promise.t) Logs.msgf -> unit Promise.t
let kmsg k ?(src = src) level msgf =
begin
match level with
| Logs.Error -> Logs.incr_err_count ()
| Logs.Warning -> Logs.incr_warn_count ()
| _ -> ()
end;
match Logs.Src.level src with
| None -> k ()
| Some current_level when level > current_level -> k ()
| Some _ ->
let over () = () in
Logs.report src level ~over k msgf
let kunit _ = Promise.return ()
let msg ?src level msgf = kmsg kunit ?src level msgf
let app ?src msgf = kmsg kunit ?src Logs.App msgf
let err ?src msgf = kmsg kunit ?src Logs.Error msgf
let warn ?src msgf = kmsg kunit ?src Logs.Warning msgf
let info ?src msgf = kmsg kunit ?src Logs.Info msgf
let debug ?src msgf = kmsg kunit ?src Logs.Debug msgf
let on_error ?src ?(level = Logs.Error) ? ?tags ~pp ~use t =
Promise.bind t @@ function
| Ok v -> Promise.return v
| Error e ->
kmsg (fun () -> use e) ?src level @@ fun m ->
m ?header ?tags "@[%a@]" pp e
let on_error_msg ?src ?(level = Logs.Error) ? ?tags ~use t =
Promise.bind t @@ function
| Ok v -> Promise.return v
| Error (`Msg e) ->
kmsg use ?src level @@ fun m ->
m ?header ?tags "@[%a@]" Format.pp_print_text e
end
open struct
let logtrace =
let with_info msgf = Log.info ?src:None msgf in
fun ?trace f ->
if alwaystrace || trace = Some true then with_info f
else Promise.return ()
end
module Spawner = BuildSpawner.MakeSpawner (Promise)
module MakeIo = MlFront_Thunk_IoDisk.ThunkIoDisk.Make (Promise)
module Io = MakeIo (Spawner)
module SyncSpawner = BuildSpawner.MakeSpawner (Promise)
module SyncIo = MlFront_Thunk_IoDisk.ThunkIoDisk.Make (Promise) (SyncSpawner)
module SyncReadDirectory =
MlFront_Thunk.ThunkIo.MakeSyncDirectoryReader (Promise) (SyncIo) (SyncIo)
module SyncReadChannel =
MlFront_Thunk.ThunkIo.MakeSyncChannelReader (Promise) (SyncIo) (SyncIo)
module SyncWriteChannel =
MlFront_Thunk.ThunkIo.MakeSyncChannelWriter (Promise) (SyncIo) (SyncIo)
module FileObject = struct
type t = Io.file_object
let file_origin = Io.file_origin
end
let disk_file = Io.disk_file
let disk_dir = Io.disk_dir
module BuildBuiltins' = DkZero_Base.BuildBuiltins.Make (Io)
include DkZero_Base.DataModel.Make (FileObject)
(** Make [K], [O] and [V]. *)
module KMap = Map.Make (K)
module StoreMessages = struct
type k = K.t
type v = V.t
type MlFront_Thunk.BuildConstraints.StateMessage.obj +=
| PostBuildKeyValue of (k * v)
type MlFront_Thunk.BuildConstraints.StateMessage.obj +=
| PostBuildKeyValueAndExecuteThunkAfter of k * v * (unit -> unit)
end
(** We added command-line configuration flags and promoted [store_info] into a
module. *)
module StoreInfo : sig
type t = private { explain : bool; warnings_during_parsing : bool }
val create : explain:bool -> warnings_during_parsing:bool -> t
val explain : t -> bool
val warnings_during_parsing : t -> bool
end = struct
type t = { explain : bool; warnings_during_parsing : bool }
let create ~explain ~warnings_during_parsing =
{ explain; warnings_during_parsing }
let explain { explain; _ } = explain
let warnings_during_parsing { warnings_during_parsing; _ } =
warnings_during_parsing
end
(** https://www.cambridge.org/core/services/aop-cambridge-core/content/view/097CE52C750E69BD16B78C318754C7A4/S0956796820000088a.pdf/build-systems-a-la-carte-theory-and-practice.pdf
Section 3.3
These are {b input keys} ... essentially source files (including
user-supplied build files) found on disk.
But we create dynamic tasks during the initial scan of sourcefiles, so we
have no input keys. *)
let f_store (_info : StoreInfo.t) (key : K.t) : V.t = V.Input_not_found key
module MutableStore =
MlFront_Thunk.BuildSystems.MutableFunctionStoreBuilder
(struct
type i = StoreInfo.t
type k = K.t
type v = V.t
let compare = K.compare
let f = f_store
end)
(StoreMessages)
module StateAsync = struct
type state = MutableStore.t
type 'a promise = 'a Promise.t
let mutate_state (store : state)
(msg : MlFront_Thunk.BuildConstraints.StateMessage.t) =
match MutableStore.mutate_store store msg with
| `Handled -> ()
| _ ->
raise
(Invalid_argument
(Printf.sprintf "[e84a3aed] Unsupported state message: %s"
@@ MlFront_Thunk.BuildConstraints.StateMessage.show msg))
let update (state : state) msgs = List.iter (mutate_state state) msgs
let flush _state = Promise.return ()
end
(** Renamed from [MockStandardBackend] to [EngineBackend]. *)
module EngineBackend = struct
type 'a promise = 'a Promise.t
(** Unlike [MockStandardBackend] we always print journal entries
immediately. This is the reference implementation. Your build system may
choose to buffer journal entries instead and then write them to a
journal file. *)
let flush json_list =
let ( let* ) = Promise.bind in
List.fold_left
(fun i j ->
let* () = i in
Log.app (fun m -> m "[journal] %s" j))
(Promise.return ()) json_list
(** Unlike the original in ["tests/MlFront_Thunk/alacarte_xtraces_test.ml"]
we do not serialize the trace to a string yet, so it can be
pretty-printed where it is caught in [Shell.ml]. *)
let journal_shutdown_in_error ~trace ~exitcode_posix ~exitcode_windows () =
raise
(DkZero_Base.Exceptions.EngineShutdown
{ trace; exitcode_posix; exitcode_windows })
let process_journal_entry_value _ = `Standard
let persist_journal_entry_value _ =
Error
"There should be no additions to the journal_entry_value extensible \
type"
end
module ThunkWriterAsync =
MlFront_Thunk.BuildWriters.Standard.MutableWriterAsync
(Promise)
(EngineBackend)
(** We used [StandardWriterAsync] from
["tests/MlFront_Thunk/alacarte_xtraces_test.ml"] rather than
[SpreadsheetCellWriterAsync], and renamed to [ThunkWriterAsync] *)
module State =
DkZero_Base.State.Make (Promise) (FileObject) (K) (V) (MutableStore)
module StateAccess = struct
open State
let make_from_store = create
let store = store
let is_done = is_done
let set_done = set_done
let create_with_precompiled_traces = create_with_precompiled_traces
end
module Unused = struct
module CAsync =
MlFront_Thunk.BuildConstraints.MonadStateWriterPromiseWithPureSeq
(Promise)
(StateAsync)
(ThunkWriterAsync)
(** We used [EventsAsync] from
["tests/MlFront_Thunk/alacarte_xtraces_test.ml"]. *)
module EventsAsync = struct
let on_fetch_entry (k : K.t) : CAsync.journal_entry_value option =
let open MlFront_Thunk.BuildWriters.Standard in
let f () =
{
info_code = "on-fetch-entry";
message = Format.asprintf "%a" K.pp k;
info_locations = [];
}
in
Some (InfoBacktraceItem f)
end
module BusyAsync =
MlFront_Thunk.BuildSystems.BusyWritingAsyncBuild (MutableStore) (O)
(StoreMessages)
(Promise)
(CAsync)
(EventsAsync)
module TasksAsync =
MlFront_Thunk.BuildSystems.MutableTasksBuilder (CAsync) (K) (V) (O)
end
module type THUNK_INTERPRETER = sig
module C : sig
include
MlFront_Thunk.BuildConstraints.MONAD
with type 'a t =
(State.t * ThunkWriterAsync.journal ->
('a
* MlFront_Thunk.BuildConstraints.StateMessage.t list
* (ThunkWriterAsync.journal_entry_id
* ThunkWriterAsync.journal_entry_value)
MlFront_Thunk.UniqueInsertionList.t)
Promise.t)
Promise.t
val post_entry :
MlFront_Thunk.BuildWriters.Standard.journal_entry_value -> unit t
end
val task_create :
(K.t * ((O.t -> K.t -> V.t C.t) -> V.t C.t)) list ->
(module MlFront_Thunk.BuildSystems.DYNAMIC_TASKS
with type k = K.t
and type vc = V.t C.t
and type lifted_vc = V.t C.t
and type o = O.t
and type up = unit Promise.t)
end
module CSuspending =
MlFront_Thunk.BuildConstraints.MonadStateWriterPromiseWithPureSeq
(Promise)
(struct
include State
type state = t
end)
(ThunkWriterAsync)
module TasksSuspending =
MlFront_Thunk.BuildSystems.MutableTasksBuilder (CSuspending) (K) (V) (O)
(** Based on [backtrace_item_info] and [shutdown] in
["tests/MlFront_Thunk/alacarte_xtraces_test.ml"] *)
module Backtraces (I : THUNK_INTERPRETER) = struct
open MlFront_Thunk.BuildWriters.Standard
let backtrace_item_info code =
I.C.post_entry
(InfoBacktraceItem
(fun () -> { info_code = code; message = ""; info_locations = [] }))
let fail ~error_code ?(cant_do = "") ?(because = "") ?(error_locations = [])
?(recommendations = []) ?(exitcode_posix = 1) ?(exitcode_windows = 1) ()
=
I.C.post_entry
(ShutdownableError
{
error =
{
error_code;
cant_do;
because;
error_locations;
recommendations;
};
exitcode_posix;
exitcode_windows;
})
end
(** This is much simpler compared to original [StoreTrackingInterpreter] in
["tests/MlFront_Thunk/alacarte_3_7_test.ml"] since can we just delegate to
TasksSuspending. We also rename to [ThunkTrackingInterpreter]. *)
module ThunkTrackingInterpreter : THUNK_INTERPRETER = struct
module C = CSuspending
module KeyMap = Map.Make (K)
let task_create :
(K.t * ((O.t -> K.t -> V.t C.t) -> V.t C.t)) list ->
(module MlFront_Thunk.BuildSystems.DYNAMIC_TASKS
with type k = K.t
and type vc = V.t C.t
and type lifted_vc = V.t C.t
and type o = O.t
and type up = unit Promise.t) =
TasksSuspending.create
end
type 'a cont = 'a CSuspending.t
module Cfg = struct
type t = {
mutable does_enter_shell_before_function : unit KMap.t;
threaddir : MlFront_Core.FilePath.t;
absbasepath : MlFront_Core.FilePath.t;
download :
on_fail:
(location_if_checksum_error:Fmlib_parse.Position.range option ->
error_code:string ->
because:string ->
recommendations:string list ->
unit ->
unit cont) ->
file_origin:string ->
file_path:string ->
file_checksum:DkZero_Base.BuildContext.weak_capable_asset_checksum ->
file_offset:int64 option ->
file_sz:(Fmlib_parse.Position.range * int64) option ->
file_trailer:string option ->
origin_mirrors:string * string list ->
MlFront_Progress.Progress.nodeobj ->
MlFront_Core.FilePath.t ->
[ `Downloaded of [ `SHA256 of string * int64 ] | `Failed ] cont;
verbosity : int;
explain : bool;
parsetrace : bool;
rootprogressnode : MlFront_Progress.Progress.nodeobj;
intermediate : bool;
buildlogtrace : bool;
debug_task : bool;
importtrace : bool;
importtrace2 : bool;
sysincludedirs : string list;
workspaceincludedirs : string list;
userincludedirs : string list;
cells : DkZero_Base.Config.cells;
local_packages : MlFront_Core.PackageId.t list;
build_number : string;
long_ids : bool;
integrity : [ `None | `Existence | `Checksum ];
workspacedir : MlFront_Core.FilePath.t;
workspace : DkZero_Base.Config.workspace option;
valuestore : MlFront_Core.FilePath.t;
tracestore : MlFront_Core.FilePath.t;
tracefile : string;
selfassetdir : MlFront_Core.FilePath.t;
install_home : MlFront_Core.FilePath.t;
install_cache : MlFront_Core.FilePath.t;
install_data : MlFront_Core.FilePath.t;
install_config : MlFront_Core.FilePath.t;
install_state : MlFront_Core.FilePath.t;
install_runtime : MlFront_Core.FilePath.t;
rng : Mirage_crypto_rng.g;
build_pubkey : [ `PublicKey of string ];
build_seckey : [ `SecretKey of string ];
metadb : MlFront_Cache.MetaDb.t;
meta_conn : MlFront_Cache.MetaDb.connection;
observer_result :
(module MlFront_Thunk.ThunkParsers.Results.OBSERVER_RESULT);
nobuiltininc : bool;
nosysinc : bool;
builtin_valuesjson : Io.file_object list;
builtin_valueslua : Io.file_object list;
deny_deprecated_function_args : bool;
import : [ `Eager | `Lazy ];
}
let fatal_return ~error_code = function
| `Created | `Deleted -> ()
| `Error s ->
Promise.run_promise
@@ Log.err (fun m -> m "[fatal] [error %s] %s" error_code s);
exit 1
let build_key_pipes_to_newlines s =
DkZero_Base.Assumptions.build_keys_have_no_pipes_and_store_pipe_separated
();
let s = String.trim s in
let s = String.concat "\n" (String.split_on_char '|' s) in
s ^ "\n"
let load_pubkeysource ~keys_env ~build_public_keyfile () =
match keys_env with
| Some prefix -> (
let pubkey_env = prefix ^ "_PUBKEY" in
match Sys.getenv_opt pubkey_env with
| Some pubkey ->
Ok
(`KeysFromEnvironmentPrefix
{
DkZero_Base.Config.keys_env_prefix = prefix;
keys_env_pubkey =
`PublicKey (build_key_pipes_to_newlines pubkey);
})
| None ->
Error
(Printf.sprintf "Environment variable %s not set." pubkey_env))
| None ->
let pubkeyfile_s = MlFront_Core.FilePath.show build_public_keyfile in
if Sys.file_exists pubkeyfile_s then
let pubkey =
In_channel.with_open_bin pubkeyfile_s (fun ic ->
In_channel.input_all ic)
in
Ok (`KeysFromFiles (`PublicKey pubkey))
else
Ok (`KeysFromFiles (`MissingPublicKey build_public_keyfile))
let load_public_key_from_source = function
| `KeysFromEnvironmentPrefix { DkZero_Base.Config.keys_env_pubkey; _ } ->
Ok keys_env_pubkey
| `KeysFromFiles (`PublicKey pk) -> Ok (`PublicKey pk)
| `KeysFromFiles (`MissingPublicKey pkfile) ->
Error
(Printf.sprintf "No public key found at `%s`."
(MlFront_Core.FilePath.show pkfile))
let load_or_generate_keys ~rng ~build_pubkeysource ~build_public_keyfile
~build_secret_keyfile () =
match build_pubkeysource with
| `KeysFromEnvironmentPrefix
{
DkZero_Base.Config.keys_env_prefix = prefix;
DkZero_Base.Config.keys_env_pubkey = pubkey;
} -> (
let seckey_env = prefix ^ "_SECKEY" in
match Sys.getenv_opt seckey_env with
| Some seckey ->
(pubkey, `SecretKey (build_key_pipes_to_newlines seckey))
| None ->
Promise.run_promise
@@ Log.err (fun m ->
m "[signify] FATAL: Environment variable %s not set."
seckey_env);
exit 1)
| `KeysFromFiles (`PublicKey build_pubkey) ->
if Sys.file_exists (MlFront_Core.FilePath.show build_secret_keyfile)
then begin
let seckey =
In_channel.with_open_bin
(MlFront_Core.FilePath.show build_secret_keyfile) (fun ic ->
In_channel.input_all ic)
in
(`PublicKey build_pubkey, `SecretKey seckey)
end
else begin
Promise.run_promise
@@ Log.err (fun m ->
m "[signify] FATAL: Secret key file %s not found."
(MlFront_Core.FilePath.show build_secret_keyfile));
exit 1
end
| `KeysFromFiles (`MissingPublicKey _build_public_keyfile) ->
if Sys.file_exists (MlFront_Core.FilePath.show build_secret_keyfile)
then begin
Promise.run_promise
@@ Log.err (fun m ->
m
"[signify] FATAL: Secret key file %s exists but no \
corresponding public key file. Will not overwrite the \
secret key."
(MlFront_Core.FilePath.show build_secret_keyfile));
exit 1
end
else begin
let ((`PublicKey pubkey, `SecretKey seckey) as keypair) =
Sec.generate_build_keypair ~rng ()
in
Sec.save_build_keypair ~build_public_keyfile ~build_secret_keyfile
~fatal_return keypair;
MlFront_Thunk_IoDisk.ThunkIoDisk.make_directory_recursively
~return:(fatal_return ~error_code:"5696c586")
(MlFront_Core.FilePath.parent build_public_keyfile);
MlFront_Thunk_IoDisk.ThunkIoDisk.make_directory_recursively
~return:(fatal_return ~error_code:"b1f3c9e2")
(MlFront_Core.FilePath.parent build_secret_keyfile);
Out_channel.with_open_bin
(MlFront_Core.FilePath.show build_public_keyfile) (fun ic ->
Out_channel.output_string ic pubkey);
Out_channel.with_open_bin
(MlFront_Core.FilePath.show build_secret_keyfile) (fun ic ->
Out_channel.output_string ic seckey);
Promise.run_promise
@@ Log.app (fun m ->
m
"[signify] New build key pair in %s and %s ...\n\
[signify] Distribute key pair among trusted coworkers \
only!"
(MlFront_Core.FilePath.show build_public_keyfile)
(MlFront_Core.FilePath.show build_secret_keyfile));
(`PublicKey pubkey, `SecretKey seckey)
end
let setup_cachedirs ~rng ~data_dir ~cache_dir () =
match
MlFront_Cache.MetaDb.create ~rng ~name:"build"
~datadir:(MlFront_Core.FilePath.append_exn data_dir "b.1")
~cachedir:(MlFront_Core.FilePath.append_exn cache_dir "b.1")
()
with
| Ok metadb -> metadb
| Error (`WrappableMsg defer) ->
Fmt.epr
"@[<v 2>FATAL: Could not create the metadata database.@ %a@]@."
defer ();
exit 2
let get_keys_dir ~xdg ~global ~workspacedir =
let open MlFront_Core.FilePath in
function
| None ->
if global then append_exn (of_string_exn (Xdg.config_dir xdg)) dk_prog
else append_exn workspacedir "t/k"
| Some dir -> dir
let public_keyfile_name = "build.pub"
let secret_keyfile_name = "build.sec"
let baseconfigure ?data_dir ?cache_dir ?keys_dir ?valuestore ?tracestore
~absbasepath ~global ~entry_unified_script ~keys_env ~integrity
debugmodes =
let xdg = Xdg.create ~env:Sys.getenv_opt () in
let buildlogtrace =
if List.mem `BuildLog debugmodes then Some () else None
in
let parsetrace =
if List.mem `ParseTrace debugmodes then Some () else None
in
let debug_task = if List.mem `Task debugmodes then Some () else None in
let workspacedir_maybe_relto_basedir, workspace =
let entry_opt =
match entry_unified_script with
| None -> None
| Some fp ->
match UnifiedScriptC.load ~absbasepath fp with
| Error msg ->
failwith
(Printf.sprintf "Failed to load unified script: %s\n" msg)
| Ok scriptc -> Some scriptc
in
match
WorkspaceC.get_workspace_relto_basedir ~absbasepath
~entry_unified_script:entry_opt ()
with
| None -> (MlFront_Core.FilePath.empty, None)
| Some (workspace_file, workspace_config) ->
( MlFront_Core.FilePath.parent workspace_file,
Some { DkZero_Base.Config.workspace_file; workspace_config } )
in
let data_dir =
let data_dir_default =
if global then
MlFront_Core.FilePath.(
append_exn (of_string_exn (Xdg.data_dir xdg)) dk_prog |> to_string)
else
MlFront_Core.FilePath.(
append_exn workspacedir_maybe_relto_basedir "t/d" |> to_string)
in
let data_dir_opt =
Option.map MlFront_Core.FilePath.to_string data_dir
in
let s = Option.value ~default:data_dir_default data_dir_opt in
match MlFront_Core.FilePath.of_string s with
| Error msg ->
failwith (Printf.sprintf "Failed to understand data dir: %s" msg)
| Ok dir -> dir
in
let cache_dir =
let cache_dir_default =
if global then
let root_dir = if Sys.win32 then Xdg.state_dir else Xdg.cache_dir in
MlFront_Core.FilePath.(
append_exn (of_string_exn (root_dir xdg)) dk_prog |> to_string)
else
MlFront_Core.FilePath.(
append_exn workspacedir_maybe_relto_basedir "t/c" |> to_string)
in
let cache_dir_opt =
Option.map MlFront_Core.FilePath.to_string cache_dir
in
let s = Option.value ~default:cache_dir_default cache_dir_opt in
match MlFront_Core.FilePath.of_string s with
| Error msg ->
failwith (Printf.sprintf "Failed to understand cache dir: %s" msg)
| Ok dir -> dir
in
let valuestore =
Option.value
~default:(MlFront_Core.FilePath.append_exn data_dir "val.1")
valuestore
in
let tracestore =
Option.value
~default:(MlFront_Core.FilePath.append_exn data_dir "cts.1")
tracestore
in
let build_public_keyfile =
let keys_dir =
get_keys_dir ~xdg ~global
~workspacedir:workspacedir_maybe_relto_basedir keys_dir
in
let open MlFront_Core.FilePath in
append_exn keys_dir public_keyfile_name
in
let build_pubkeysource =
match load_pubkeysource ~keys_env ~build_public_keyfile () with
| Ok pk -> pk
| Error msg ->
failwith (Printf.sprintf "Failed to load public key: %s" msg)
in
DkZero_Base.Config.
{
baseconfig_global = global;
baseconfig_absbasepath = absbasepath;
baseconfig_workspacedir = workspacedir_maybe_relto_basedir;
baseconfig_workspace = workspace;
baseconfig_tracestore = tracestore;
baseconfig_tracefile = "trace";
baseconfig_buildlogtrace = buildlogtrace = Some ();
baseconfig_parsetrace = parsetrace = Some ();
baseconfig_debug_task = debug_task = Some ();
baseconfig_valuestore = valuestore;
baseconfig_build_pubkeysource = build_pubkeysource;
baseconfig_integrity = integrity;
baseconfig_datadir = data_dir;
baseconfig_cachedir = cache_dir;
baseconfig_keysdir = keys_dir;
}
let preconfigure ~baseconfig ~cells ~install ~random_seed () =
let xdg = Xdg.create ~env:Sys.getenv_opt () in
let DkZero_Base.Config.
{
baseconfig_build_pubkeysource;
baseconfig_global = global;
baseconfig_absbasepath;
baseconfig_workspacedir = workspacedir;
baseconfig_datadir = data_dir;
baseconfig_cachedir = cache_dir;
baseconfig_keysdir = keys_dir;
_;
} =
baseconfig
in
let build_public_keyfile, build_secret_keyfile =
let keys_dir = get_keys_dir ~xdg ~global ~workspacedir keys_dir in
let open MlFront_Core.FilePath in
( append_exn keys_dir public_keyfile_name,
append_exn keys_dir secret_keyfile_name )
in
let ( install_home,
install_cache,
install_data,
install_config,
install_state,
install_runtime ) =
let open MlFront_Core.FilePath in
let x = of_string_exn in
match install with
| Some { program } -> (
let y f = append_exn (of_string_exn (f xdg)) program in
let z f = append_exn f program in
( x (Xdg.home_dir xdg),
z cache_dir,
z data_dir,
y Xdg.config_dir,
y Xdg.state_dir,
match Xdg.runtime_dir xdg with
| None -> y Xdg.state_dir
| Some r -> x r ))
| None ->
(x "t/xh", x "t/xc", x "t/xd", x "t/xg", x "t/xs", x "t/xr")
in
let pid = Unix.getpid () in
let selfassetdir =
MlFront_Core.FilePath.of_string_exn (Printf.sprintf "t/x0/%d" pid)
in
let rng = Sec.get_rng ~random_seed () in
MlFront_Thunk_IoDisk.ThunkIoDisk.set_io_rng (fun () ->
let bs = Bytes.create 8 in
Mirage_crypto_rng.generate_into ~g:rng bs 8;
Bytes.get_int64_le bs 0);
let build_pubkey, build_seckey =
load_or_generate_keys ~rng
~build_pubkeysource:baseconfig_build_pubkeysource
~build_public_keyfile ~build_secret_keyfile ()
in
let metadb = setup_cachedirs ~rng ~data_dir ~cache_dir () in
let cells =
List.fold_left
(fun acc (cellname, fp) ->
DkZero_Base.Config.CellMap.add cellname fp acc)
(DkZero_Base.Config.CellMap.singleton "root" baseconfig_absbasepath)
cells
in
DkZero_Base.Config.
{
baseconfig;
preconfig_install_home = install_home;
preconfig_install_cache = install_cache;
preconfig_install_data = install_data;
preconfig_install_config = install_config;
preconfig_install_state = install_state;
preconfig_install_runtime = install_runtime;
preconfig_build_pubkey = build_pubkey;
preconfig_build_seckey = build_seckey;
preconfig_metadb = metadb;
preconfig_rng = rng;
preconfig_cells = cells;
preconfig_selfassetdir = selfassetdir;
}
(** [create ?verbose ~threaddir ~download ()].
[threaddir] is a directory exclusive to the
{b running process and thread}. It is used for temporary directories. *)
let create ?(verbosity = 0) ?explain ?intermediate ?importtrace
?importtrace2 ?nobuiltininc ?nosysinc ?noworkspaceinc ~preconfig
~sysincludedirs ~workspaceincludedirs ~userincludedirs ~local_packages
~build_number ~long_ids ~threaddir ~download ~observer_result
~rootprogressnode ~import () =
let DkZero_Base.Config.
{
baseconfig =
{
baseconfig_global = _;
baseconfig_absbasepath = absbasepath;
baseconfig_workspacedir = workspacedir;
baseconfig_workspace = workspace;
baseconfig_tracestore = tracestore;
baseconfig_tracefile = tracefile;
baseconfig_valuestore = valuestore;
baseconfig_integrity = integrity;
baseconfig_buildlogtrace = buildlogtrace;
baseconfig_debug_task = debug_task;
baseconfig_parsetrace = parsetrace;
baseconfig_build_pubkeysource = _;
baseconfig_datadir = _;
baseconfig_cachedir = _;
baseconfig_keysdir = _;
};
preconfig_selfassetdir = selfassetdir;
preconfig_install_home = install_home;
preconfig_install_cache = install_cache;
preconfig_install_data = install_data;
preconfig_install_config = install_config;
preconfig_install_state = install_state;
preconfig_install_runtime = install_runtime;
preconfig_build_pubkey = build_pubkey;
preconfig_build_seckey = build_seckey;
preconfig_metadb = metadb;
preconfig_rng = rng;
preconfig_cells = cells;
} =
preconfig
in
let meta_conn =
match MlFront_Cache.MetaDb.start_connection metadb with
| Error (`WrappableMsg defer) ->
Fmt.epr
"@[<v 2>FATAL: Could not start connection to the metadata \
database.@;\
%a@]@."
defer ();
exit 1
| Ok conn -> conn
in
{
builtin_valuesjson =
(if nobuiltininc = Some () then []
else BuildBuiltins'.builtin_valuesjson ());
builtin_valueslua =
(if nobuiltininc = Some () then []
else BuildBuiltins'.builtin_valueslua ());
rng;
absbasepath;
sysincludedirs = (if nosysinc = Some () then [] else sysincludedirs);
workspaceincludedirs =
(if noworkspaceinc = Some () then [] else workspaceincludedirs);
userincludedirs;
cells;
local_packages;
build_number;
long_ids;
integrity;
threaddir;
tracestore;
tracefile;
download;
nobuiltininc = nobuiltininc = Some ();
nosysinc = nosysinc = Some ();
verbosity;
rootprogressnode;
explain = explain = Some ();
intermediate = intermediate = Some ();
debug_task;
buildlogtrace;
importtrace = importtrace = Some ();
importtrace2 = importtrace2 = Some ();
parsetrace;
workspacedir;
workspace;
valuestore;
selfassetdir;
install_home;
install_cache;
install_data;
install_config;
install_state;
install_runtime;
build_pubkey;
build_seckey;
metadb;
meta_conn;
observer_result;
does_enter_shell_before_function = KMap.empty;
deny_deprecated_function_args = false;
import;
}
let builtin_valuesjson { builtin_valuesjson; _ } = builtin_valuesjson
let builtin_valueslua { builtin_valueslua; _ } = builtin_valueslua
let absbasepath { absbasepath; _ } = absbasepath
let threaddir { threaddir; _ } = threaddir
let download { download; _ } = download
let verbosity { verbosity; _ } = verbosity
let verbose { verbosity; _ } = verbosity > 0
let rootprogressnode { rootprogressnode; _ } = rootprogressnode
let explain { explain; _ } = explain
let parsetrace { parsetrace; _ } = parsetrace
let intermediate { intermediate; _ } = intermediate
let importtrace { importtrace; _ } = importtrace
let importtrace2 { importtrace2; _ } = importtrace2
let debug_task { debug_task; _ } = debug_task
let buildlogtrace { buildlogtrace; _ } = buildlogtrace
let sysincludedirs { sysincludedirs; _ } = sysincludedirs
let workspaceincludedirs { workspaceincludedirs; _ } = workspaceincludedirs
let userincludedirs { userincludedirs; _ } = userincludedirs
let local_packages { local_packages; _ } = local_packages
let integrity { integrity; _ } = integrity
let tracefile { tracefile; _ } = tracefile
let workspacedir_maybe_relto_basedir { workspacedir; _ } = workspacedir
let workspacefile_maybe_relto_basedir { workspace; _ } =
Option.map
(fun { DkZero_Base.Config.workspace_file; _ } -> workspace_file)
workspace
let workspaceconfig { workspace; _ } =
Option.map
(fun { DkZero_Base.Config.workspace_config; _ } -> workspace_config)
workspace
let availablecells { cells; _ } =
DkZero_Base.Config.CellMap.bindings cells |> List.map fst
let selfassetdir { selfassetdir; _ } = selfassetdir
let install_home { install_home; _ } = install_home
let install_cache { install_cache; _ } = install_cache
let install_data { install_data; _ } = install_data
let install_config { install_config; _ } = install_config
let install_state { install_state; _ } = install_state
let install_runtime { install_runtime; _ } = install_runtime
let rng { rng; _ } = rng
let build_pubkey { build_pubkey; _ } = build_pubkey
let build_seckey { build_seckey; _ } = build_seckey
let build_number { build_number; _ } = build_number
let long_ids { long_ids; _ } = long_ids
let metadb { metadb; _ } = metadb
let meta_conn { meta_conn; _ } = meta_conn
let observer_result { observer_result; _ } = observer_result
let nobuiltininc { nobuiltininc; _ } = nobuiltininc
let nosysinc { nosysinc; _ } = nosysinc
let valuestore_maybe_relto_basedir { valuestore; _ } = valuestore
let tracestore_maybe_relto_basedir { tracestore; _ } = tracestore
let deny_deprecated_function_args { deny_deprecated_function_args; _ } =
deny_deprecated_function_args
let does_enter_shell_before_function { does_enter_shell_before_function; _ }
k =
KMap.mem k does_enter_shell_before_function
(** [set_enter_shell_breakpoint_before_function config key] will trigger the
interactive shell to launch before the next function call(s) of the key
[key], if any. *)
let set_enter_shell_breakpoint_before_function
({ does_enter_shell_before_function; _ } as config) k =
config.does_enter_shell_before_function <-
KMap.add k () does_enter_shell_before_function
let import { import; _ } = import
let threaddir_path_hash_len (_ : t) = 4
end
include Cfg
module BuildPaths' = DkZero_Base.BuildPaths.Make (Cfg)
module Syntax = struct
include Backtraces (ThunkTrackingInterpreter)
let ( let* ) = CSuspending.bind
let lift_promise = CSuspending.lift_promise
let return = CSuspending.return
let get = CSuspending.get
let parallel = CSuspending.parallel
let map = CSuspending.map
type nonrec 'a cont = 'a cont
end
let run_isolated_promise (type a) (p : a CSuspending.promise) : a =
let c = CSuspending.lift_promise p in
let i = StoreInfo.create ~explain:false ~warnings_during_parsing:false in
let store = MutableStore.initialise i in
let ir = StateAccess.make_from_store store in
let p : (a * CSuspending.state) CSuspending.promise =
CSuspending.run_state_async c ir
in
let a, state = Promise.run_promise p in
ignore state;
a
let run_continuation (type a) (kont : a CSuspending.t) (state : State.t) :
a * State.t =
let p : (a * CSuspending.state) CSuspending.promise =
CSuspending.run_state_async kont state
in
Promise.run_promise p
module type THUNK_TASKS =
MlFront_Thunk.BuildSystems.DYNAMIC_TASKS
with type k = K.t
and type lifted_vc = V.t cont
and type vc = V.t cont
and type o = O.t
and type up = unit Promise.t
(** Based on [Spreadsheet2] in
["tests/MlFront_Thunk/alacarte_3_2_apparatus.ml"] *)
module UserBuildProgram (I : THUNK_INTERPRETER) = struct
open Backtraces (I)
let cloudshake_predetermined_tasks =
let open MlFront_Thunk.BuildConstraints.MonadLetSyntax (I.C) in
I.task_create
[
( K.reserved_version_key,
fun _fetch ->
let* () = backtrace_item_info "MlFront_Std.Version" in
I.C.pure (V.create_constant values_version) );
( K.reserved_pingpong_key,
fun _fetch ->
let* () = backtrace_item_info "MlFront_Std.Sample.Ping" in
I.C.pure (V.create_constant "pong") );
( K.reserved_pongping_key,
fun _fetch ->
let* () = backtrace_item_info "MlFront_Std.Sample.Pong" in
I.C.pure (V.create_constant "ping") );
( K.reserved_abc_key,
fun _fetch ->
let* () = backtrace_item_info "MlFront_Std.Sample.Abc" in
I.C.pure (V.create_constant DkZero_Base.Strings.sampleabc_zip) );
( K.reserved_fail_key,
fun _fetch ->
let* () =
fail ~error_code:"4988a923" ~cant_do:"build"
~because:"the Fail task is designed to always fail" ()
in
I.C.pure V.Failure_is_pending );
]
end
let tasks_module =
let module Expr = UserBuildProgram (ThunkTrackingInterpreter) in
Expr.cloudshake_predetermined_tasks
module CPHash = struct
type k = K.t
type v = V.t
type ('k, 'v) key_dependent_hash = (k, v) V.key_dependent_hash
let maybe_cloud_persistent_hash = V.maybe_cloud_persistent_hash
let strong_hash_equal = V.strong_hash_equal
let strong_hash_show = V.strong_hash_show
end
module Trace = struct
type k = K.t
type v = V.t
let k_show = K.show
let v_show = V.show
module C = CSuspending
end
module IR = struct
type t = State.t
let post_record_trace ir k depends result =
let (_ : State.t) = State.post_record_trace ir k depends result in
CSuspending.pure ()
let get_traces_for_key ir k = State.get_traces_for_key ir k
end
module CTAsync =
MlFront_Thunk.BuildTraces.ConstructiveTraceStoreAsyncMinimal
(Trace)
(CPHash)
(IR)
module Events = struct
type k = K.t
type v = V.t
type uc = unit CSuspending.t
type o = O.t
let schedule_key _k = CSuspending.pure ()
open struct
let lead ~first_c depth c =
List.init depth (fun i ->
if i = 0 then first_c ^ " "
else if i = depth - 1 then c ^ " "
else " ")
|> String.concat ""
end
let before_rebuild_key ~candidate_values ~origin k =
let ( let* ) = CSuspending.bind in
let* state = CSuspending.get in
let depth = O.depth origin in
let promise =
if StoreInfo.explain (MutableStore.get_info (State.store state)) then
let first_c =
match O.first origin with
| O.OutsideTaskTrace -> "N|"
| O.User -> "U|"
| O.IncludeFile -> "I|"
| O.Distribution -> "D|"
| O.Values_file _ -> "V|"
| O.Key _ -> "K|"
| O.Rule -> "R|"
in
let lead c = lead ~first_c depth c in
match candidate_values with
| [] ->
Log.debug (fun m ->
m "[explain] %snever built `%s`" (lead "x") (K.show k))
| [ single ] ->
Log.debug (fun m ->
m
"[explain] %sonce built `%s`, but build `%s` does not \
match the authoritative trace"
(lead "!") (K.show k) (V.show single))
| last :: previous ->
Log.debug (fun m ->
m
"[explain] %s%dx built `%s`, but build `%s` and the others \
do not match the authoritative trace"
(lead "!")
(1 + List.length previous)
(K.show k) (V.show last))
else Promise.return ()
in
CSuspending.lift_promise promise
let on_dependency_discovered ~depth ~key ~depends_upon_key =
let ( let* ) = CSuspending.bind in
let* state = CSuspending.get in
let promise =
if StoreInfo.explain (MutableStore.get_info (State.store state)) then
let lead c = lead ~first_c:" |" (depth + 1) c in
Log.debug (fun m ->
m "[explain] %s%s depends on %s" (lead "^") (K.show key)
(K.show depends_upon_key))
else Promise.return ()
in
CSuspending.lift_promise promise
end
module CtRebuilderOfTasks =
MlFront_Thunk.BuildRebuilders.CtRebuilderAsync (IR) (K) (O) (V) (Promise)
(CSuspending)
(Events)
(CTAsync)
module I = struct
type t = StoreInfo.t
end
module KSet = Set.Make (K)
module SuspendingSchedulerOfRebuilderAndTasks =
MlFront_Thunk.BuildSchedulers.SuspendingSchedulerAsync (IR) (K) (KSet) (V)
(O)
(I)
(MutableStore)
(StoreMessages)
(Promise)
(CSuspending)
(Events)
(StateAccess)
let do_run_exn : type a.
t ->
tasks:(module THUNK_TASKS) ->
mk_tasks:
(t ->
tasks:(module THUNK_TASKS) ->
state:State.t ->
(module MlFront_Thunk.ThunkResults.OBSERVER_RESULT) ->
O.t ->
K.t ->
K.t * ((O.t -> K.t -> V.t cont) -> V.t cont)) ->
init:a ->
should_continue:(a -> [< `Continue | `Stop of a ]) ->
fetched:(K.t -> V.t -> a -> a) ->
not_found:
(target:K.t ->
inputkey:K.t ->
(K.t -> V.t cont) ->
State.t ->
a ->
a cont) ->
target_fold:((a cont -> K.t -> a cont) -> a cont -> a cont) ->
O.t ->
a cont =
fun ({ observer_result; _ } as t) ~tasks ~mk_tasks ~init ~should_continue
~fetched ~not_found ~target_fold origin ->
let module I = ThunkTrackingInterpreter in
let module Expr = UserBuildProgram (I) in
let module Tasks = (val tasks : THUNK_TASKS) in
let module CtRebuilder = CtRebuilderOfTasks (Tasks) in
let module SuspendingScheduler =
SuspendingSchedulerOfRebuilderAndTasks (CtRebuilder) (Tasks)
in
let open Syntax in
let* state = get in
let previous_rootprogressnode = State.current_rootprogressnode state in
State.set_current_rootprogressnode state (Some (rootprogressnode t));
let build_async =
SuspendingScheduler.schedule state CtRebuilder.rebuilder
in
let tasks = mk_tasks t ~tasks ~state observer_result in
let toplevel_user_fetch o k : V.t cont =
let open Syntax in
let* state = get in
let* store = lift_promise @@ build_async o tasks k (State.store state) in
return (MutableStore.get_value k store)
in
let open Syntax in
let* result =
target_fold
(fun acc (target : K.t) ->
let* acc = acc in
match should_continue acc with
| `Continue -> begin
let fetch = toplevel_user_fetch origin in
let* v = fetch target in
match v with
| ValuesJsonFile _ | ValuesLuaFile _ | Values _ | ScriptModule _
| Distribution _ | Form _ | Bundle _ | Asset _ | AssetIndex _
| Object _ | Constant _ | Ephemeral_ui_response ->
return (fetched target v acc)
| Input_not_found inputkey ->
let* state = get in
not_found ~target ~inputkey fetch state acc
| Failure_is_pending ->
failwith
"Illegal state. Failure_is_pending should have been \
handled."
end
| `Stop stopvalue -> return stopvalue)
(return init)
in
State.set_current_rootprogressnode state previous_rootprogressnode;
return result
module type SUSPENDING_RESOLVER =
MlFront_Thunk.ThunkAst.RESOLVER with type 'a t = 'a cont
let range_into_problem_location ~(source : Io.file_object) range :
MlFront_Thunk.BuildWriters.Standard.problem_location list cont =
let open Syntax in
let* read_result = lift_promise @@ Io.read_all source in
match read_result with
| `Error _ | `ExceededSizeLimit _ -> return []
| `Content source_code ->
return
[
MlFront_Thunk.BuildWriters.Standard.
{
origin = Some (Io.file_origin source);
source = source_code;
range;
};
]
let mk_resolver ~values_file : (module SUSPENDING_RESOLVER) =
let module M = struct
include CSuspending
let fail range msg =
let open Syntax in
let* error_locations =
range_into_problem_location ~source:values_file range
in
let* () =
fail ~error_code:"72a56622" ~cant_do:"resolve expressions in form"
~because:msg ~error_locations ()
in
failwith
"error [72a56622] should have been raised gracefully. file a issue."
end in
let module R = MlFront_Thunk.ThunkAst.MakeResolver (M) in
(module R : SUSPENDING_RESOLVER)
(** {2 Printing} *)
let print_config config =
let open Format in
let p = fprintf in
let f = std_formatter in
let pp_opt_bool fmt = function
| true -> fprintf fmt "Some ()"
| false -> fprintf fmt "None"
in
let lines s =
let lines = String.split_on_char '\n' s in
List.map MlFront_Thunk.ThunkStrings.trim_right lines
in
let pp_lines fmt s =
List.iteri
(fun i line ->
if i > 0 then fprintf fmt "@;";
fprintf fmt "%s" line)
(lines s)
in
let pp_list =
pp_print_list ~pp_sep:(fun fmt () -> fprintf fmt ";@ ") pp_lines
in
let pp_relfp =
let absfp = absbasepath config in
fun fmt fp ->
match
MlFront_Core.FilePath.relative ~base:absfp ~from:absfp ~to_:fp ()
with
| Ok relfp -> fprintf fmt "./%s" (MlFront_Core.FilePath.to_string relfp)
| Error _ -> MlFront_Core.FilePath.pp fmt fp
in
let just_items ({ items } : DkZero_Base.WorkspaceConfig.t) = items in
let just_declaration
({ declaration; sections = _ } : DkZero_Base.WorkspaceConfig.item) =
declaration
in
p f "@[<v>";
p f "threaddir: %a@;" MlFront_Core.FilePath.pp (threaddir config);
p f "verbose: %a@;" pp_opt_bool (verbose config);
p f "explain: %a@;" pp_opt_bool (explain config);
p f "parsetrace: %a@;" pp_opt_bool (parsetrace config);
p f "intermediate: %a@;" pp_opt_bool (intermediate config);
p f "buildlogtrace: %a@;" pp_opt_bool (buildlogtrace config);
p f "debug_task: %a@;" pp_opt_bool (debug_task config);
p f "importtrace: %a@;" pp_opt_bool (importtrace config);
p f "importtrace2: %a@;" pp_opt_bool (importtrace2 config);
p f "nobuiltininc: %a@;" pp_opt_bool (nobuiltininc config);
p f "nosysinc: %a@;" pp_opt_bool (nosysinc config);
p f "sysincludedirs: [%a]@;" pp_list (sysincludedirs config);
p f "workspaceincludedirs: [@[<hov>%a@]]@;" pp_list
(workspaceincludedirs config);
p f "userincludedirs: [@[<hov>%a@]]@;" pp_list (userincludedirs config);
p f "local_packages: [@[<hov>%a@]]@;" pp_list
(List.map MlFront_Core.PackageId.full_name (local_packages config));
p f "build_number: %s@;" (build_number config);
p f "long_ids: %b@;" (long_ids config);
p f "integrity: %s@;"
(match integrity config with
| `None -> "None"
| `Existence -> "Existence"
| `Checksum -> "Checksum");
p f "workspacedir: %a@;" pp_relfp (workspacedir_maybe_relto_basedir config);
p f "workspacefile: %a@;" (pp_print_option pp_relfp)
(workspacefile_maybe_relto_basedir config);
p f "@[<hov 2>workspaceconfig:@ @[<v>%a@]@]@;"
(pp_print_option
(pp_print_list
~pp_sep:(fun fmt () -> fprintf fmt " ;;@ ")
(fun ppf declaration -> pp_lines ppf (just_declaration declaration))))
(Option.map just_items (workspaceconfig config));
p f "valuestore: %a@;" MlFront_Core.FilePath.pp
(valuestore_maybe_relto_basedir config);
p f "tracestore: %a@;" MlFront_Core.FilePath.pp
(tracestore_maybe_relto_basedir config);
p f "tracefile: %s@;" (tracefile config);
p f "cells: [@[<hov>%a@]]@;"
(pp_print_list
~pp_sep:(fun fmt () -> fprintf fmt ";@ ")
(fun ppf (cellname, fp) ->
fprintf ppf "%s=%a" cellname pp_relfp fp))
(DkZero_Base.Config.CellMap.bindings config.cells);
p f "install_home: %a@;" MlFront_Core.FilePath.pp (install_home config);
p f "install_cache: %a@;" MlFront_Core.FilePath.pp (install_cache config);
p f "install_data: %a@;" MlFront_Core.FilePath.pp (install_data config);
p f "install_config: %a@;" MlFront_Core.FilePath.pp (install_config config);
p f "install_state: %a@;" MlFront_Core.FilePath.pp (install_state config);
p f "install_runtime: %a@;" MlFront_Core.FilePath.pp
(install_runtime config);
p f "build_pubkey: @[%a@]@;"
(pp_print_list ~pp_sep:pp_print_cut (fun ppf v -> fprintf ppf "%s" v))
(match build_pubkey config with `PublicKey s -> lines s);
p f "build_seckey: %s@;"
(match build_seckey config with `SecretKey _ -> "<secret key>");
p f "metadb: %a@;" MlFront_Cache.MetaDb.pp (metadb config);
p f "builtin_valuesjson: [%a]@;"
(pp_print_list
~pp_sep:(fun fmt () -> fprintf fmt ";@ ")
(fun ppf v -> fprintf ppf "%s" (Io.file_origin v)))
(builtin_valuesjson config);
p f "deny_deprecated_function_args: %b@;"
(deny_deprecated_function_args config);
p f "import: %s@;"
(match import config with `Eager -> "Eager" | `Lazy -> "Lazy");
p f "@]"
(** An identifier within the source of a build file and the context for
running a shell command. *)
module ValueContext = struct
type nonrec t = {
id : MlFront_Thunk.ThunkCommand.module_version;
id_range : Fmlib_parse.Position.range;
source : Io.file_object;
source_sha256 : string;
ctx : t;
build_request : DkZero_Base.BuildRequest.t;
}
let create ~id ~source ~source_sha256 ctx ~build_request =
{
id = snd id;
id_range = fst id;
source;
source_sha256;
ctx;
build_request;
}
let debug_reference
{ source; source_sha256; id = _; id_range; ctx = _; build_request = _ }
: K.reference option =
Some
{
reference_range = id_range;
reference_file_sha256 = source_sha256;
reference_transient = Some { reference_file = source };
}
let module_id { id; _ } = id.id
let module_semver { id; _ } = id.version
let ctx { ctx; _ } = ctx
let build_request { build_request; _ } = build_request
let source { source; _ } = source
end
type value_context = ValueContext.t
let of_value_context (vc : ValueContext.t) : t = vc.ctx
let vc_debug_reference vc = ValueContext.debug_reference vc
let vc_module_id vc = ValueContext.module_id vc
let vc_module_semver vc = ValueContext.module_semver vc
let vc_build_request vc = ValueContext.build_request vc
let vc_source vc = ValueContext.source vc
let interactive_spawn = BuildSpawner.interactive_spawn
let with_rootprogressnode ctx rootprogressnode = { ctx with rootprogressnode }
module FileMod' = FileMod.Make (Promise) (Io)
module OutputRequest = struct
type nonrec t = {
ctx : t;
build_request : DkZero_Base.BuildRequest.t;
may_clear_outputdir_if_needed : bool;
}
let create ctx ~build_request ~may_clear_outputdir_if_needed () =
{ ctx; build_request; may_clear_outputdir_if_needed }
let ctx { ctx; _ } = ctx
let build_request { build_request; _ } = build_request
let may_clear_outputdir_if_needed { may_clear_outputdir_if_needed; _ } =
may_clear_outputdir_if_needed
end
module G = MlFront_Thunk.ThunkGlob.Make (Promise) (Io) (Io)
type err = { error_code : string; cant_do : string; because : string }
let fail_if_error =
let open Syntax in
function
| Ok v -> return v
| Error { error_code; cant_do; because } ->
fail ~error_code ~cant_do ~because ()
let is_file_executable ~executables file =
let normalizedentry =
MlFront_Core.FilePath.(of_string_exn (basename file))
in
G.glob_file (List.map snd executables) normalizedentry
let output_progress_label ~action dest =
DkZero_Base.BuildProgress.abbreviate_label
(Printf.sprintf "out: %s %s" action
(MlFront_Core.FilePath.to_string dest))
let ~archive_member () =
DkZero_Base.BuildProgress.abbreviate_label
(Printf.sprintf "out: extract %s" archive_member)
let output_transfer_progress_label ~have_done =
DkZero_Base.BuildProgress.abbreviate_label have_done
let set_output_progress_step ?estimated_total output_progress ~label =
MlFront_Progress.Progress.set_name output_progress label;
MlFront_Progress.Progress.set_completed_items output_progress 0;
match estimated_total with
| Some total ->
MlFront_Progress.Progress.set_estimated_total_items output_progress
total
| None ->
MlFront_Progress.Progress.set_estimated_total_items output_progress 1
let get_value_file ~valuestore ~value_id () =
let return = Promise.return in
match MlFront_Core.FilePath.append valuestore value_id with
| Error _ -> return None
| Ok value_fp ->
if Sys.file_exists (MlFront_Core.FilePath.to_string value_fp) then
return (Some value_fp)
else return None
let rec unzip_and_cache_value ctx ~source range value :
MlFront_Core.FilePath.t option cont =
let open Syntax in
let g ~value_id ~category () =
let* object_archive_opt =
read_value_or_fail ctx ~value_id ~source range ()
in
let metadb = metadb ctx in
match object_archive_opt with
| None -> return None
| Some object_archive -> (
MlFront_Thunk.Assumptions
.mlfront_zipfile_accepts_long_paths_on_windows ();
let srczip =
MlFront_Thunk_IoDisk.ThunkIoDisk.longpath_capable_filepath
~absbasepath:(absbasepath ctx) ~functions:`MlFront_ZipFile
object_archive
in
let dbresult : ((MlFront_Core.FilePath.t, _) result, _) result =
MlFront_Cache.MetaDb.with_sync ~supercategory:"val" metadb
(fun
~data_ops:(module DataOps : MlFront_Cache.MetaOps.S)
~cache_ops:(module CacheOps : MlFront_Cache.MetaOps.S)
->
CacheOps.cache_dir ~category ~key:value_id
~cache_hit:(fun ~dir_for_upsert:_ _cdir -> Ok `Keep)
~cache_miss:(fun ~dir_for_upsert ->
MlFront_Thunk.Assumptions
.mlfront_zipfile_accepts_long_paths_on_windows ();
let destdir_s =
MlFront_Thunk_IoDisk.ThunkIoDisk.longpath_capable_filepath
~absbasepath:(absbasepath ctx)
~functions:`MlFront_ZipFile dir_for_upsert
in
try
MlFront_ZipFile.ZipFile.unzip_exn ~srczip
~destdir:destdir_s ();
Ok `Upsert
with MlFront_ZipFile.ZipFile.ZipError (_zipfile, msg) ->
let defer ppf () =
Format.fprintf ppf
"Unsuccessful unzip of `%s` into `%a`: %s"
(MlFront_Core.FilePath.show object_archive)
MlFront_Core.FilePath.pp dir_for_upsert msg
in
Error (`WrappableMsg defer))
())
in
match dbresult with
| Ok (Ok dir) -> return (Some dir)
| Ok (Error (`WrappableMsg defer)) | Error (`WrappableMsg defer) ->
let* () =
let msg = Format.asprintf "%a" defer () in
fail_cant_unzip_to_dir ~error_code:"128f875b" ~source ~msg
~srczip range
in
return None)
in
match (value : V.t) with
| Object { value_id; value_sha256 = _; value = Some _ } ->
g ~value_id ~category:"object" ()
| Bundle { value_id; value_sha256 = _; value = Some _ } ->
g ~value_id ~category:"bundle" ()
| Asset { value_id; value_sha256 = _; value = Some _ } ->
g ~value_id ~category:"asset" ()
| ScriptModule _ | Distribution _ | Object _ | Constant _ | ValuesJsonFile _
| ValuesLuaFile _ | Values _ | Form _ | Bundle _ | Asset _ | AssetIndex _ ->
let* () =
fail ~error_code:"a5b528dd" ~cant_do:"get value"
~because:
(Format.asprintf "the value is not outputable: %a" V.pp value)
~recommendations:[ "This is a bug. Please file an issue." ]
()
in
return None
| Input_not_found _ | Ephemeral_ui_response | Failure_is_pending ->
let* () =
fail ~error_code:"c04e9687" ~cant_do:"get value"
~because:
(Format.asprintf "the value is not fully specified: %a" V.pp value)
~recommendations:[ "This is a bug. Please file an issue." ]
()
in
return None
and output_value ~output_request ~source ~command_output ~archive_member key
value : unit cont =
let open Syntax in
let output_progress =
MlFront_Progress.Progress.start ~estimated_total:1 ~no_rollup:true
(rootprogressnode (OutputRequest.ctx output_request))
"output"
in
let g ~value_id ~typ () =
let* value_fp_opt =
read_value_or_fail
(OutputRequest.ctx output_request)
~value_id ~source (fst command_output) ()
in
match value_fp_opt with
| None -> return ()
| Some value_fp ->
output_object_bundle_or_asset ~output_progress ~output_request ~source
~command_output
~cant_do:(Printf.sprintf "use value store %s `%s`" typ value_id)
~archive_member value_fp
in
let* () =
match (value : V.t) with
| Object
{
value_id;
value_sha256 = _;
value =
Some
{
object_id = _;
object_slot = _;
object_range = _;
object_origin = _;
};
} ->
g ~value_id ~typ:"object" ()
| Bundle { value_id; value_sha256 = _; value = Some _ } ->
g ~value_id ~typ:"bundle" ()
| Asset
{
value_id;
value_sha256 = _;
value =
Some
{
asset_values_canonical_id = _;
asset_values_file_type = _;
asset_values_file_sha256 = _;
asset_id = _;
asset_path = _;
asset_range = _;
asset_origin_name = _;
asset_mirrors = _;
asset_checksum = _;
};
} ->
g ~value_id ~typ:"asset" ()
| Constant
{
value_id;
value_sha256 = _;
value = Some { constant_transient = Some { constant_value } };
} ->
output_constant ~output_progress ~key ~output_request ~source
~command_output ~archive_member ~constantid:value_id constant_value
| ScriptModule _ | Distribution _ | Object _ | Constant _
| ValuesJsonFile _ | ValuesLuaFile _ | Values _ | Form _ | Bundle _
| Asset _ | AssetIndex _ ->
fail ~error_code:"92f60570" ~cant_do:"output value"
~because:
(Format.asprintf "the value is not outputable: %a" V.pp value)
~recommendations:[ "This is a bug. Please file an issue." ]
()
| Input_not_found _ | Ephemeral_ui_response | Failure_is_pending ->
fail ~error_code:"6d73e0d1" ~cant_do:"output value"
~because:
(Format.asprintf "the value is not fully specified: %a" V.pp value)
~recommendations:[ "This is a bug. Please file an issue." ]
()
in
MlFront_Progress.Progress.end_ output_progress;
return ()
and mkdir ~source ~what range fp =
let open Syntax in
match MlFront_Core.FilePath.rootless_segments fp with
| [] -> return ()
| _ :: _ -> (
let fp_dir = disk_dir fp in
let* createdir_result = lift_promise @@ Io.create_directory fp_dir in
match createdir_result with
| `Error e ->
let* error_locations = range_into_problem_location ~source range in
fail ~error_code:"14019995"
~cant_do:(Printf.sprintf "create %s" what)
~because:e ~error_locations ()
| `Created -> return ())
and rmdir ~source ~what range fp =
let open Syntax in
let fp_dir = disk_dir fp in
let* removedir_result = lift_promise @@ Io.delete_directory fp_dir in
match removedir_result with
| `Error e ->
let* error_locations = range_into_problem_location ~source range in
fail ~error_code:"fb3e2c3e"
~cant_do:(Printf.sprintf "remove %s" what)
~because:e ~error_locations ()
| `Deleted -> return ()
(** Use a value that has just been placed in the value store. The sha256 of
that value is computed on the fly, and depending on the integrity
configuration the value may be validated on the flay. *)
and read_value_or_fail ctx ~value_id ~source range () =
let open Syntax in
let* fp_opt =
lift_promise
@@ get_value_file
~valuestore:(valuestore_maybe_relto_basedir ctx)
~value_id ()
in
begin
let* error_locations = range_into_problem_location ~source range in
match fp_opt with
| None ->
let* () =
fail ~error_code:"98ca2699"
~cant_do:(Printf.sprintf "find cached value `%s`" value_id)
~because:
(Printf.sprintf "it is not present in the value store `%s`"
(MlFront_Core.FilePath.to_string
(valuestore_maybe_relto_basedir ctx)))
~error_locations
~recommendations:
[
"The value may have been evicted from the value store. Try \
rerunning with the `--integrity existence` or the \
`--integrity checksum` option.";
]
()
in
return None
| Some fp ->
return (Some fp)
end
and output_constant ~output_progress ~key ~output_request ~source
~command_output ~archive_member ~constantid constantvalue =
let open Syntax in
let output_range, shell_output =
(command_output
: Fmlib_parse.Position.range
* MlFront_Thunk.ThunkCommand.resolved_shell_output)
in
let write_constantfile ~what fp =
let () =
set_output_progress_step output_progress
~label:(output_progress_label ~action:"write" fp)
in
let* () =
mkdir ~source ~what output_range (MlFront_Core.FilePath.parent fp)
in
let* replace_result =
lift_promise
@@ Io.replace_all_string (disk_file fp) constantvalue 0
(String.length constantvalue)
in
match replace_result with
| `Error e ->
let* error_locations =
range_into_problem_location ~source output_range
in
fail ~error_code:"1f193cdd" ~cant_do:"write constant to file"
~because:e ~error_locations ()
| `IsDirectory _ ->
let* error_locations =
range_into_problem_location ~source output_range
in
fail ~error_code:"d644796b" ~cant_do:"write constant to file"
~because:"the file is a directory" ~error_locations ()
| `WroteBytes -> return ()
in
let stage_constantfile () =
let fp =
MlFront_Core.FilePath.append_exn
(BuildPaths'.resolve_labeled_path
(OutputRequest.ctx output_request)
~build_request:(OutputRequest.build_request output_request)
`StagedConstant)
constantid
in
let* () = write_constantfile ~what:"staging directory for constants" fp in
return fp
in
match archive_member with
| Some archive_member ->
if MlFront_ZipFile.ZipFile.is_string_zip constantvalue then
let* constantfile = stage_constantfile () in
output_from_unindexed_archive_member ~output_progress ~output_request
~source ~command_output
~cant_do:
(Printf.sprintf
"copy the archive member `%s` of the zipped value `%s to the \
output directory"
archive_member
(MlFront_Core.FilePath.to_string constantfile))
~srczip:constantfile archive_member
else
fail_no_archive_member_without_zip ~source ~archive_member
output_range key
| None ->
match shell_output with
| ROutputFile { file; executables } -> begin
match
BuildPaths'.resolved_as_filepath_for_build_request
(OutputRequest.ctx output_request)
~build_request:(OutputRequest.build_request output_request)
file
with
| Ok destination ->
let* () =
write_constantfile ~what:"directory for output file" destination
in
let* mkexec_result =
let is_executable = is_file_executable ~executables destination in
if is_executable then
lift_promise
@@ FileMod'.make_executable
~basedir:(absbasepath (OutputRequest.ctx output_request))
~codesign_tmp:
(BuildPaths'.resolve_user_codesign_path
(OutputRequest.ctx output_request))
~on_error:(fun ~error_code ~cant_do ~because () ->
Promise.return { error_code; cant_do; because })
destination
else return (Ok ())
in
fail_if_error mkexec_result
| Error e -> fail_bad_expression ~source ~because:e output_range
end
| ROutputDir { dir; strip; excludes = _; executables = _ } ->
if MlFront_ZipFile.ZipFile.is_string_zip constantvalue then
let* constantfile = stage_constantfile () in
output_from_filepath ~output_progress ~output_request ~source
~command_output
~cant_do:
(Printf.sprintf
"copy the zipped value to the output directory `%s`"
(MlFront_Core.FilePath.to_string constantfile))
constantfile
else begin
let* () =
if strip <> 0 then
fail_no_strip_without_zip ~strip ~source
(fun ppf () -> Format.fprintf ppf "the constant value")
() output_range key
else return ()
in
match
BuildPaths'.resolved_as_filepath_for_build_request
(OutputRequest.ctx output_request)
~build_request:(OutputRequest.build_request output_request)
dir
with
| Error e -> fail_bad_expression ~source ~because:e output_range
| Ok destination ->
let* () =
write_constantfile ~what:"output directory"
(MlFront_Core.FilePath.append_exn destination "OBJECT")
in
return ()
end
and output_object_bundle_or_asset ~output_progress ~output_request ~source
~command_output ~cant_do ~archive_member sourcevalue =
match archive_member with
| None ->
output_from_filepath ~output_progress ~output_request ~source
~command_output ~cant_do sourcevalue
| Some archive_member ->
output_from_unindexed_archive_member ~output_progress ~output_request
~source ~command_output ~cant_do ~srczip:sourcevalue archive_member
(** Stage the object into an intermediate zipfile and then extract the
file/directory from that intermediate zipfile. *)
and output_from_unindexed_archive_member ~output_progress ~output_request
~source ~command_output ~cant_do ~srczip archive_member =
let open Syntax in
let srczip_s = MlFront_Core.FilePath.to_string srczip in
let destfile =
BuildPaths'.resolve_labeled_path
(OutputRequest.ctx output_request)
~build_request:(OutputRequest.build_request output_request)
(`StagedArchiveMember archive_member)
in
let destfile_s = MlFront_Core.FilePath.to_string destfile in
let* () =
let () =
set_output_progress_step output_progress
~label:(output_progress_extract_label ~archive_member ())
in
try
MlFront_ZipFile.ZipFile.unzip_entry_exn ~srczip:srczip_s
~destfile:(MlFront_Core.FilePath.to_string destfile)
archive_member;
MlFront_Progress.Progress.set_completed_items output_progress 1;
return ()
with MlFront_ZipFile.ZipFile.ZipError (_zipfile, msg) ->
fail_cant_unzip_file ~source ~msg ~srczip:srczip_s ~destfile:destfile_s
~path:archive_member (fst command_output)
in
if Sys.file_exists (MlFront_Core.FilePath.to_string destfile) then
output_from_filepath ~output_progress ~output_request ~source
~command_output ~cant_do destfile
else
fail_archive_member_not_found ~source ~srczip ~cant_do ~archive_member
(fst command_output)
and output_from_filepath ~output_progress ~output_request ~source
~command_output ~cant_do fp =
let open Syntax in
match
(command_output
: Fmlib_parse.Position.range
* MlFront_Thunk.ThunkCommand.resolved_shell_output)
with
| output_range, ROutputFile { file; executables } -> begin
match
BuildPaths'.resolved_as_filepath_for_build_request
(OutputRequest.ctx output_request)
~build_request:(OutputRequest.build_request output_request)
file
with
| Error e -> fail_bad_expression ~source ~because:e output_range
| Ok file ->
let () =
set_output_progress_step output_progress
~label:(output_progress_label ~action:"copy" file)
in
let copy_progress =
MlFront_Progress.Progress.start ~estimated_total:1 ~no_rollup:true
output_progress
(output_transfer_progress_label ~have_done:"MiB copied")
in
let* () =
mkdir ~source ~what:"directory of output file" output_range
(MlFront_Core.FilePath.parent file)
in
let mib = 1_048_576L in
let copy_total_bytes = ref 0L in
let copy_completed_mib = ref 0 in
let on_write_total write_total =
copy_total_bytes := write_total;
let completed_mib = Int64.(to_int (div write_total mib)) in
if completed_mib > !copy_completed_mib then begin
copy_completed_mib := completed_mib;
MlFront_Progress.Progress.set_estimated_total_items
copy_progress (completed_mib + 1);
MlFront_Progress.Progress.set_completed_items copy_progress
completed_mib
end;
Promise.return ()
in
let* () =
copy_file_or_fail ~source ~src:fp ~dest:file ~cant_do
~on_write_total output_range
in
let copy_total_mib =
if !copy_total_bytes = 0L then 1
else Int64.(to_int (div (add !copy_total_bytes (sub mib 1L)) mib))
in
let () =
MlFront_Progress.Progress.set_estimated_total_items copy_progress
copy_total_mib;
MlFront_Progress.Progress.set_completed_items copy_progress
copy_total_mib
in
MlFront_Progress.Progress.end_ copy_progress;
let () =
MlFront_Progress.Progress.set_completed_items output_progress 1
in
let* mkexec_result =
let is_executable = is_file_executable ~executables file in
if is_executable then
lift_promise
@@ FileMod'.make_executable
~basedir:(absbasepath (OutputRequest.ctx output_request))
~codesign_tmp:
(BuildPaths'.resolve_user_codesign_path
(OutputRequest.ctx output_request))
~on_error:(fun ~error_code ~cant_do ~because () ->
Promise.return { error_code; cant_do; because })
file
else return (Ok ())
in
fail_if_error mkexec_result
end
| output_range, ROutputDir { dir; strip; excludes; executables } -> begin
match
BuildPaths'.resolved_as_filepath_for_build_request
(OutputRequest.ctx output_request)
~build_request:(OutputRequest.build_request output_request)
dir
with
| Error e -> fail_bad_expression ~source ~because:e output_range
| Ok destdir ->
let () =
set_output_progress_step output_progress
~label:(output_progress_label ~action:"unzip" destdir)
in
let unzip_progress =
MlFront_Progress.Progress.start ~estimated_total:1 ~no_rollup:true
output_progress
(output_transfer_progress_label ~have_done:"entries unzipped")
in
MlFront_Thunk.Assumptions
.mlfront_zipfile_accepts_long_paths_on_windows ();
let destdir_s =
MlFront_Thunk_IoDisk.ThunkIoDisk.longpath_capable_filepath
~absbasepath:(absbasepath (OutputRequest.ctx output_request))
~functions:`MlFront_ZipFile destdir
in
let sourcevalue_s =
MlFront_Thunk_IoDisk.ThunkIoDisk.longpath_capable_filepath
~absbasepath:(absbasepath (OutputRequest.ctx output_request))
~functions:`MlFront_ZipFile fp
in
if MlFront_ZipFile.ZipFile.is_file_zip sourcevalue_s then
let* () =
if OutputRequest.may_clear_outputdir_if_needed output_request
then
let* () =
rmdir ~source ~what:"output directory" output_range destdir
in
mkdir ~source ~what:"output directory" output_range destdir
else return ()
in
let exclude_globs = List.map snd excludes in
let executable_globs = List.map snd executables in
let last_entry = ref None in
let unzip_total_entries = ref 1 in
let pending_executable_files = ref [] in
try
MlFront_ZipFile.ZipFile.unzip_exn
~on_entry:(fun s isdir _i _n ->
unzip_total_entries := max 1 _n;
let () =
MlFront_Progress.Progress.set_estimated_total_items
unzip_progress _n
in
let () =
MlFront_Progress.Progress.set_completed_items
unzip_progress _i
in
match (isdir, MlFront_Core.FilePath.of_string s) with
| _, Error _ ->
false
| true, Ok _fp ->
true
| false, Ok fp ->
let fp = MlFront_Core.FilePath.normalize fp in
if G.glob_file exclude_globs fp then
false
else begin
last_entry := Some s;
if G.glob_file executable_globs fp then
pending_executable_files :=
s :: !pending_executable_files;
true
end)
~strip ~srczip:sourcevalue_s ~destdir:destdir_s ();
MlFront_Progress.Progress.set_completed_items unzip_progress
!unzip_total_entries;
MlFront_Progress.Progress.end_ unzip_progress;
let () =
MlFront_Progress.Progress.set_completed_items output_progress
1
in
let* mkexec_all_result : (unit, err) result list =
let basedir =
absbasepath (OutputRequest.ctx output_request)
in
let codesign_tmp =
BuildPaths'.resolve_user_codesign_path
(OutputRequest.ctx output_request)
in
lift_promise
@@ Promise.parallel
(List.map
(fun s ->
let fp =
MlFront_Core.FilePath.append_exn destdir s
in
FileMod'.make_executable ~basedir ~codesign_tmp
~on_error:(fun ~error_code ~cant_do ~because () ->
Promise.return { error_code; cant_do; because })
fp)
!pending_executable_files)
in
let (mkexec_firsterror_result : (unit, err) result) =
List.fold_left
(fun acc r ->
match (acc, r) with
| Ok (), Ok () -> Ok ()
| Error e, _ -> Error e
| _, Error e -> Error e)
(Ok ()) mkexec_all_result
in
let* () = fail_if_error mkexec_firsterror_result in
return ()
with MlFront_ZipFile.ZipFile.ZipError (_zipfile, msg) ->
let recommendations =
match DkZero_Base.Execution.os_v3 () with
| Ok (Windows, _slot)
when String.equal msg "file open failed"
|| String.equal msg "file not found" -> (
let common_max_path =
[
"Windows power users may consider turning on long \
path support: \
https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell#registry-setting-to-enable-long-paths";
]
in
match !last_entry with
| None ->
[
Printf.sprintf
"Look inside the zip file and see if any entries \
would exceed 260 (MAX_PATH) characters if \
extracted to the directory `%s`. Shorten the \
directory if needed."
destdir_s;
]
@ common_max_path
| Some last_entry ->
[
Printf.sprintf
"Look inside the zip file and see if the entry \
`%s` would exceed 260 (MAX_PATH) characters if \
extracted to the directory `%s`. Shorten the \
directory if needed."
last_entry destdir_s;
]
@ common_max_path)
| Ok ((OSX | IOS), _slot) -> (
match !last_entry with
| None ->
[
Printf.sprintf
"On macOS, if the zip file generates any .app or \
.bundle directories inside `%s`, they may be \
marked read-only due to macOS code signature \
verification. After unzipping, you may need to \
remove the 'com.apple.macl' extended attribute \
using the 'xattr' command-line tool."
destdir_s;
]
| Some last_entry ->
[
Printf.sprintf
"On macOS, if the zip file generates a file `%s` \
within a .app or .bundle directory inside `%s`, \
it may be marked read-only due to macOS code \
signature verification. After unzipping, you \
may need to remove the 'com.apple.macl' \
extended attribute using the 'xattr' \
command-line tool."
last_entry destdir_s;
])
| _ -> []
in
fail_cant_unzip_to_dir ~recommendations ~error_code:"95c53c91"
~source ~msg ~srczip:sourcevalue_s ~destdir:destdir_s
output_range
else
fail_dest_is_dir_but_source_not_zip ~source ~cant_do output_range
end
and fail_cant_unzip_to_dir ?destdir ?recommendations ~error_code ~source ~msg
~srczip range =
let open Syntax in
let* error_locations = range_into_problem_location ~source range in
fail ?recommendations ~error_code
~cant_do:
(match destdir with
| Some destdir -> Printf.sprintf "unzip `%s` into `%s`" srczip destdir
| None -> Printf.sprintf "unzip `%s`" srczip)
~because:msg ~error_locations ()
and fail_cant_unzip_file ?destfile ~source ~msg ~srczip ~path range =
let open Syntax in
let* error_locations = range_into_problem_location ~source range in
fail ~error_code:"ee3b4e89"
~cant_do:
(match destfile with
| Some destfile ->
Printf.sprintf "unzip `%s` in `%s` to `%s` from `%s`" path srczip
destfile (Sys.getcwd ())
| None ->
Printf.sprintf "unzip `%s` in `%s` from `%s`" path srczip
(Sys.getcwd ()))
~because:msg ~error_locations ()
and fail_no_archive_member_without_zip ~source ~archive_member range key =
let open Syntax in
let* error_locations = range_into_problem_location ~source range in
fail ~error_code:"88de79d8"
~cant_do:
(Format.asprintf "get archive member `%s` from %a" archive_member K.pp
key)
~because:"the constant value is not a zipfile" ~error_locations ()
and fail_no_strip_without_zip ~source ~strip pp_target target range key =
let open Syntax in
let* error_locations = range_into_problem_location ~source range in
fail ~error_code:"6a51c6c0"
~cant_do:(Format.asprintf "strip `%d` levels from %a" strip K.pp key)
~because:(Format.asprintf "%a is not a zipfile" pp_target target)
~error_locations ()
and fail_dest_is_dir_but_source_not_zip ~source ~cant_do range =
let open Syntax in
let* error_locations = range_into_problem_location ~source range in
fail ~error_code:"d105a5c5" ~cant_do
~because:"directories can't be an output if the source is not a zipfile"
~error_locations
~recommendations:
[
"Use `-d DIR` only when the source is a zipfile. Try `-f FILE` \
instead.";
]
()
and fail_archive_member_not_found ~source ~srczip ~cant_do ~archive_member
range =
let open Syntax in
let* error_locations = range_into_problem_location ~source range in
fail ~error_code:"73b4560b" ~cant_do
~because:
(Printf.sprintf "the archive member `%s` was not found" archive_member)
~error_locations
~recommendations:
[
Printf.sprintf
"Use `unzip -l` on Unix or your favorite zip tool (ex. WinZip, \
7zip) on Windows to list the archive members of `%s`. Make sure \
you use the exact name listed, including any `./` prefix."
(MlFront_Core.FilePath.to_string srczip);
]
()
and fail_bad_expression ~source ~because range =
let open Syntax in
let* error_locations = range_into_problem_location ~source range in
fail ~error_code:"42a341f3" ~cant_do:"evaluate the expression" ~because
~error_locations ()
and range_into_problem_location ~source range :
MlFront_Thunk.BuildWriters.Standard.problem_location list cont =
let open Syntax in
let* read_result = lift_promise @@ Io.read_all source in
match read_result with
| `Error _ | `ExceededSizeLimit _ -> return []
| `Content source_code ->
return
[
MlFront_Thunk.BuildWriters.Standard.
{
origin = Some (Io.file_origin source);
source = source_code;
range;
};
]
and copy_file_or_fail ?on_write_total ~source ~src ~dest ~cant_do range =
let open Syntax in
let had_error_because = ref None in
let* () =
lift_promise
@@ Io.copy_or_fail ?on_write_total ~src:(disk_file src)
~dest:(disk_file dest)
~on_error:(fun because ->
had_error_because := Some because;
Promise.return ())
(Promise.return ())
in
match !had_error_because with
| Some because ->
let* error_locations = range_into_problem_location ~source range in
fail ~error_code:"57d1803c" ~cant_do ~because ~error_locations ()
| None -> return ()
let memoize_output ctx ~key ~description ~max_wait_seconds f_populate :
(MlFront_Core.FilePath.t, string) result cont =
let open Syntax in
let trace, pp_trace_descr =
if verbosity ctx >= 3 then
( true,
fun ~dir_for_upsert ppf () ->
Format.fprintf ppf "for `%s` in %a" description
MlFront_Core.FilePath.pp dir_for_upsert )
else if verbosity ctx >= 2 then
( true,
fun ~dir_for_upsert:_ ppf () ->
Format.fprintf ppf "for `%s`" description )
else (false, fun ~dir_for_upsert:_ _ppf () -> ())
in
let {
data_ops = (module DataOps : MlFront_Cache.MetaOps.S_ASYNC);
cache_ops = (module CacheOps : MlFront_Cache.MetaOps.S_ASYNC);
close_db = _;
} : MlFront_Cache.MetaDb.connection =
meta_conn ctx
in
let async_kont_result =
let rec until_not_pending acc_elapsed_seconds =
let firstresult = CacheOps.cache_dir_async ~category:"sub" ~key () in
match firstresult with
| Error e -> return (Error e)
| Ok MlFront_Cache.MetaOps.Pending ->
let* { advised_throttle_sec; elapsed_sec } =
lift_promise @@ Promise.yield ()
in
if acc_elapsed_seconds +. elapsed_sec > max_wait_seconds then
return
(Error
(`WrappableMsg
(fun ppf () ->
Format.fprintf ppf
"Timed-out waiting `%.2f` seconds on cache directory \
lock for `%s`"
max_wait_seconds description)))
else
let* () =
lift_promise
@@ logtrace ~trace (fun l ->
l
"[DkZero_RuntimeC.ContextC] Cache directory for `%s` \
is locked; waiting %.2f seconds"
description advised_throttle_sec)
in
Thread.delay advised_throttle_sec;
until_not_pending (acc_elapsed_seconds +. advised_throttle_sec)
| Ok (MlFront_Cache.MetaOps.Hit { cache_dir }) -> return (Ok cache_dir)
| Ok (MlFront_Cache.MetaOps.Miss { dir_for_upsert; complete }) -> (
let* () =
lift_promise
@@ logtrace ~trace (fun l ->
l "[DkZero_RuntimeC.ContextC] Populating output cache %a"
(pp_trace_descr ~dir_for_upsert)
())
in
let success = ref false in
try
let* () = f_populate dir_for_upsert in
let* () =
lift_promise
@@ logtrace ~trace (fun l ->
l
"[DkZero_RuntimeC.ContextC] Marking output cache %a \
complete"
(pp_trace_descr ~dir_for_upsert)
())
in
success := true;
match complete `Upsert with
| Ok () -> return (Ok dir_for_upsert)
| Error (`WrappableMsg defer) ->
let* () =
let msg = Format.asprintf "%a" defer () in
fail ~error_code:"b0de817c"
~cant_do:"populate cache directory" ~because:msg ()
in
return (Ok dir_for_upsert)
with DkZero_Base.Exceptions.EngineShutdown _ as exn ->
let og = Printexc.get_raw_backtrace () in
(if not !success then
run_isolated_promise
@@ logtrace ~trace (fun l ->
l
"[DkZero_RuntimeC.ContextC] Marking output cache %a \
failed because engine is shutting down: %s"
(pp_trace_descr ~dir_for_upsert)
() (Printexc.to_string exn));
let (_ : _ result) = complete `Fail in
());
Printexc.raise_with_backtrace exn og)
in
until_not_pending 0.0
in
let* async_result = async_kont_result in
match async_result with
| Ok dir_for_upsert -> return (Ok dir_for_upsert)
| Error (`WrappableMsg defer) ->
let msg = Format.asprintf "%a" defer () in
return (Error msg)
let output_get_object ctx ~build_request =
output_value
~output_request:
(OutputRequest.create ctx ~build_request
~may_clear_outputdir_if_needed:true ())
(** The implementation of ["install-object"] mostly the same as
["get-object"].
The real differences are:
+ the output directory is not cleared because
["install-object -d OUTPUTDIR"] needs to accumulate files into the same
directories.
+ how overlapping paths are treated, but that is the responsibility of
{!BuildPaths'.verify_nonoverlapping_subpaths_for_getobject} *)
let output_install_object ctx ~build_request =
output_value
~output_request:
(OutputRequest.create ctx ~build_request
~may_clear_outputdir_if_needed:false ())
let output_post_object ctx ~build_request =
output_value
~output_request:
(OutputRequest.create ctx ~build_request
~may_clear_outputdir_if_needed:true ())
let output_get_bundle ctx ~build_request =
output_value ~archive_member:None
~output_request:
(OutputRequest.create ctx ~build_request
~may_clear_outputdir_if_needed:true ())
let output_get_asset ctx ~build_request =
output_value
~output_request:
(OutputRequest.create ctx ~build_request
~may_clear_outputdir_if_needed:true ())
end
module _ : DkZero_Base.BuildContext.S = Impl