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
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329 | ------------------------------------------------------------------------------
-- --
-- GPR TECHNOLOGY --
-- --
-- Copyright (C) 2012-2021, AdaCore --
-- --
-- This is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. This software is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
-- License for more details. You should have received a copy of the GNU --
-- General Public License distributed with GNAT; see file COPYING. If not, --
-- see <http://www.gnu.org/licenses/>. --
-- --
------------------------------------------------------------------------------
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Containers.Indefinite_Vectors; use Ada;
with Ada.Containers.Vectors;
with Ada.Directories; use Ada.Directories;
with Ada.Strings.Equal_Case_Insensitive;
with Ada.Strings.Fixed; use Ada.Strings;
with Ada.Strings.Less_Case_Insensitive;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO; use Ada.Text_IO;
with GNAT.MD5; use GNAT.MD5;
with GNAT.OS_Lib;
with GNAT.String_Split;
with GPR.Names; use GPR.Names;
with GPR.Opt;
with GPR.Osint; use GPR.Osint;
with GPR.PP; use GPR.PP;
with GPR.Snames; use GPR.Snames;
with GPR.Tree;
with GPR.Util; use GPR.Util;
with GPR.Version; use GPR.Version;
with Gpr_Build_Util; use Gpr_Build_Util;
package body Gprinstall.Install is
use GNAT;
package String_Vector is
new Containers.Indefinite_Vectors (Positive, String);
package Seen_Set renames GPR.String_Sets;
Content : String_Vector.Vector;
-- The content of the project, this is used when creating the project
-- and is needed to ease the project section merging when installing
-- multiple builds.
Initial_Buffer_Size : constant := 100;
-- Arbitrary value for the initial size of the buffer below
Buffer : GNAT.OS_Lib.String_Access := new String (1 .. Initial_Buffer_Size);
Buffer_Last : Natural := 0;
Agg_Manifest : Text_IO.File_Type;
-- Manifest file for main aggregate project
Line_Manifest : Text_IO.Count := 0;
Line_Agg_Manifest : Text_IO.Count := 0;
-- Keep lines when opening the manifest files. This is used by the rollback
-- routine when an error occurs while copying the files.
Objcopy_Exec : constant String :=
(if Target_Name = null
then "objcopy"
else Target_Name.all & "-objcopy");
-- Name of objcopy executable, possible a cross one
Strip_Exec : constant String :=
(if Target_Name = null
then "strip"
else Target_Name.all & "-strip");
-- Name of strip executable, possible a cross one
Objcopy : constant OS_Lib.String_Access :=
OS_Lib.Locate_Exec_On_Path (Objcopy_Exec);
Strip : constant OS_Lib.String_Access :=
OS_Lib.Locate_Exec_On_Path (Strip_Exec);
procedure Double_Buffer;
-- Double the size of the Buffer
procedure Write_Char (C : Character);
-- Append character C to the Buffer. Double the buffer if needed
procedure Write_Eol;
-- Append the content of the Buffer as a line to Content and empty the
-- Buffer.
procedure Write_Str (S : String);
-- Append S to the buffer. Double the buffer if needed
Installed : Name_Id_Set.Set;
-- Record already installed project
Prep_Suffix : constant String := ".prep";
type Type_Node;
type Type_Node_Ref is access Type_Node;
type Type_Node is record
String_Type : Project_Node_Id := Empty_Project_Node;
Next : Type_Node_Ref;
end record;
-------------
-- Process --
-------------
procedure Process
(Tree : GPR.Project_Tree_Ref;
Node_Tree : GPR.Project_Node_Tree_Ref;
Project : GPR.Project_Id)
is
Windows_Target : constant Boolean :=
Get_Name_String
(Project.Config.Shared_Lib_Suffix) = ".dll";
Pcks : constant Package_Table.Table_Ptr := Tree.Shared.Packages.Table;
Strs : constant String_Element_Table.Table_Ptr :=
Tree.Shared.String_Elements.Table;
Vels : constant Variable_Element_Table.Table_Ptr :=
Tree.Shared.Variable_Elements.Table;
-- Local values for the given project, these are initially set with the
-- default values. It is updated using the Install package found in the
-- project if any.
Active : Boolean := True;
-- Whether installation is active or not (Install package's attribute)
Side_Debug : Boolean := Gprinstall.Side_Debug;
-- Whether to extract debug symbols from executables and shared
-- libraries. Default to global value.
Prefix_Dir : Param := Dup (Global_Prefix_Dir);
Exec_Subdir : Param := Dup (Global_Exec_Subdir);
Lib_Subdir : Param := Dup (Global_Lib_Subdir);
ALI_Subdir : Param := Dup (Global_ALI_Subdir);
Link_Lib_Subdir : Param := Dup (Global_Link_Lib_Subdir);
Sources_Subdir : Param := Dup (Global_Sources_Subdir);
Project_Subdir : Param := Dup (Global_Project_Subdir);
Install_Mode : Param := Dup (Global_Install_Mode);
Install_Name : Param := Dup (Global_Install_Name);
Install_Project : Boolean := Global_Install_Project;
type Items is (Source, Object, Dependency, Library, Executable);
Copy : array (Items) of Boolean := (others => False);
-- What should be copied from a project, this depends on the actual
-- project kind and the mode (usage, dev) set for the install.
Man : Text_IO.File_Type;
-- File where manifest for this project is kept
-- Keeping track of artifacts to install
type Artifacts_Data is record
Destination, Filename : Name_Id;
Required : Boolean;
end record;
package Artifacts_Set is
new Containers.Vectors (Positive, Artifacts_Data);
Artifacts : Artifacts_Set.Vector;
Excluded_Naming : Seen_Set.Set;
-- This set contains names of Ada unit to exclude from the generated
-- package Naming. This is needed to avoid renaming for bodies which
-- are not installed when the minimum installation (-m) is used. In
-- this case there is two points to do:
--
-- 1. the installed .ali must use the spec naming
--
-- 2. the naming convention for the body must be excluded from the
-- generated project.
procedure Copy_File
(From, To, File : String;
From_Ver : String := "";
Sym_Link : Boolean := False;
Executable : Boolean := False;
Extract_Debug : Boolean := False);
-- Copy file From into To, if Sym_Link is set a symbolic link is
-- created. If Executable is set, the destination file exec attribute
-- is set. When Extract_Debug is set to True the debug information
-- for the executable is written in a side file.
function Dir_Name (Suffix : Boolean := True) return String;
-- Returns the name of directory where project files are to be
-- installed. This name is the name of the project. If Suffix is
-- True then the build name is also returned.
function Cat
(Dir : Path_Name_Type; File : File_Name_Type) return String;
pragma Inline (Cat);
-- Returns the string which is the catenation of Dir and File
function Sources_Dir (Build_Name : Boolean := True) return String;
-- Returns the full pathname to the sources destination directory
function Exec_Dir return String;
-- Returns the full pathname to the executable destination directory
function Lib_Dir (Build_Name : Boolean := True) return String;
-- Returns the full pathname to the library destination directory
function ALI_Dir (Build_Name : Boolean := True) return String;
-- Returns the full pathname to the library destination directory
function Link_Lib_Dir return String;
-- Returns the full pathname to the lib symlib directory
function Project_Dir return String;
-- Returns the full pathname to the project destination directory
procedure Check_Install_Package;
-- Check Project's install package and overwrite the default values of
-- the corresponding variables above.
procedure Copy_Files;
-- Do the file copies for the project's sources, objects, library,
-- executables.
procedure Create_Project (Project : Project_Id);
-- Create install project for the given project
procedure Add_To_Manifest
(Pathname : String;
Aggregate_Only : Boolean := False);
-- Add filename to manifest
function Get_Library_Filename return File_Name_Type;
-- Returns the actual file name for the library
function Has_Sources (Project : Project_Id) return Boolean;
pragma Inline (Has_Sources);
-- Returns True if the project contains sources
function Bring_Sources (Project : Project_Id) return Boolean;
-- Returns True if Project gives visibility to some sources directly or
-- indirectly via the with clauses.
function Main_Binary (Source : Name_Id) return String;
-- Give the source name found in the Main attribute, returns the actual
-- binary as built by gprbuild. This routine looks into the Builder
-- switches for a the Executable attribute.
function Is_Install_Active (Project : Project_Id) return Boolean;
-- Returns True if the Project is active, that is there is no attribute
-- Active set to False in the Install package.
procedure Open_Check_Manifest
(File : out Text_IO.File_Type; Current_Line : out Text_IO.Count);
-- Check that manifest file can be used
procedure Rollback_Manifests;
-- Rollback manifest files (for current project or/and aggregate one)
function For_Dev return Boolean is (Install_Mode.V.all = "dev");
-------------
-- ALI_Dir --
-------------
function ALI_Dir (Build_Name : Boolean := True) return String is
Install_Name_Dir : constant String :=
(if Install_Name.Default
then ""
else Install_Name.V.all & "/");
begin
if Is_Absolute_Path (ALI_Subdir.V.all) then
return ALI_Subdir.V.all & Install_Name_Dir;
elsif not ALI_Subdir.Default or else not Build_Name then
return Prefix_Dir.V.all & ALI_Subdir.V.all & Install_Name_Dir;
else
return Ensure_Directory
(Prefix_Dir.V.all & ALI_Subdir.V.all & Install_Name_Dir
& Dir_Name);
end if;
end ALI_Dir;
---------------------
-- Add_To_Manifest --
---------------------
procedure Add_To_Manifest
(Pathname : String;
Aggregate_Only : Boolean := False) is
begin
if not Aggregate_Only and then not Is_Open (Man) then
Open_Check_Manifest (Man, Line_Manifest);
end if;
-- Append entry into manifest
declare
function N (Str : String) return String
is (Normalize_Pathname (Str, Case_Sensitive => False));
MD5 : constant String := File_MD5 (Pathname);
Path : constant String := Containing_Directory (Pathname);
File : constant String := Simple_Name (Pathname);
begin
if not Aggregate_Only and then Is_Open (Man) then
Put_Line
(Man,
MD5 & ' '
& Util.Relative_Path
(N (Path), Containing_Directory (N (Name (Man))))
& File);
end if;
if Is_Open (Agg_Manifest) then
Put_Line
(Agg_Manifest,
MD5 & ' '
& Util.Relative_Path
(N (Path), Containing_Directory (N (Name (Agg_Manifest))))
& File);
end if;
end;
end Add_To_Manifest;
-------------------
-- Bring_Sources --
-------------------
function Bring_Sources (Project : Project_Id) return Boolean is
begin
if Has_Sources (Project) then
return True;
else
declare
List : Project_List := Project.All_Imported_Projects;
begin
while List /= null loop
if Has_Sources (List.Project) then
return True;
end if;
List := List.Next;
end loop;
end;
end if;
return False;
end Bring_Sources;
---------------------------
-- Check_Install_Package --
---------------------------
procedure Check_Install_Package is
Pck : Package_Id := Project.Decl.Packages;
procedure Replace
(P : in out Param;
Val : Name_Id;
Is_Dir : Boolean := True;
Normalize : Boolean := False);
pragma Inline (Replace);
-- Set Var with Value, free previous pointer
-------------
-- Replace --
-------------
procedure Replace
(P : in out Param;
Val : Name_Id;
Is_Dir : Boolean := True;
Normalize : Boolean := False)
is
V : constant String := Get_Name_String (Val);
begin
if V /= "" then
Free (P.V);
P := (new String'
((if Is_Dir
then (if Normalize
then Ensure_Directory (Normalize_Pathname (V))
else Ensure_Directory (V))
else V)),
Default => False);
end if;
end Replace;
begin
Look_Install_Package : while Pck /= No_Package loop
if Pcks (Pck).Decl /= No_Declarations
and then Pcks (Pck).Name = Name_Install
then
-- Found Install package, check attributes
declare
Id : Variable_Id := Pcks (Pck).Decl.Attributes;
begin
while Id /= No_Variable loop
declare
V : constant Variable := Vels (Id);
begin
if V.Name = Name_Prefix then
-- If Install.Prefix is a relative path, it is made
-- relative to the global prefix.
declare
Value : constant String :=
Get_Name_String (V.Value.Value);
Res : Name_Id;
Changed : Boolean := False;
begin
if Is_Absolute_Path (Value) then
if Global_Prefix_Dir.Default then
Res := V.Value.Value;
Changed := True;
end if;
else
Set_Name_Buffer (Global_Prefix_Dir.V.all);
Add_Str_To_Name_Buffer (Value);
Res := Name_Find;
Changed := True;
end if;
if Changed then
Replace (Prefix_Dir, Res, Normalize => True);
end if;
end;
elsif V.Name = Name_Exec_Subdir
and then Global_Exec_Subdir.Default
then
Replace (Exec_Subdir, V.Value.Value);
elsif V.Name = Name_Lib_Subdir
and then Global_Lib_Subdir.Default
then
Replace (Lib_Subdir, V.Value.Value);
elsif V.Name = Name_ALI_Subdir
and then Global_ALI_Subdir.Default
then
Replace (ALI_Subdir, V.Value.Value);
elsif V.Name = Name_Link_Lib_Subdir
and then Global_Link_Lib_Subdir.Default
then
Replace (Link_Lib_Subdir, V.Value.Value);
elsif V.Name = Name_Sources_Subdir
and then Global_Sources_Subdir.Default
then
Replace (Sources_Subdir, V.Value.Value);
elsif V.Name = Name_Project_Subdir
and then Global_Project_Subdir.Default
then
Replace (Project_Subdir, V.Value.Value);
elsif V.Name = Name_Mode
and then Global_Install_Mode.Default
then
Replace (Install_Mode, V.Value.Value);
elsif V.Name = Name_Install_Name
and then Global_Install_Name.Default
then
Replace
(Install_Name, V.Value.Value, Is_Dir => False);
elsif V.Name = Name_Active then
declare
Val : constant String :=
To_Lower
(Get_Name_String (V.Value.Value));
begin
if Val = "false" then
Active := False;
else
Active := True;
end if;
end;
elsif V.Name = Name_Side_Debug then
declare
Val : constant String :=
To_Lower
(Get_Name_String (V.Value.Value));
begin
if Val = "true" then
Side_Debug := True;
else
Side_Debug := False;
end if;
end;
elsif V.Name = Name_Install_Project then
declare
Val : constant String :=
To_Lower
(Get_Name_String (V.Value.Value));
begin
if Val = "false" then
Install_Project := False;
else
Install_Project := True;
end if;
end;
end if;
end;
Id := Vels (Id).Next;
end loop;
end;
-- Now check arrays
declare
Id : Array_Id := Pcks (Pck).Decl.Arrays;
begin
while Id /= No_Array loop
declare
V : constant Array_Data :=
Tree.Shared.Arrays.Table (Id);
begin
if V.Name in
Name_Artifacts | Name_Required_Artifacts
then
declare
Eid : Array_Element_Id := V.Value;
begin
while Eid /= No_Array_Element loop
declare
E : constant Array_Element :=
Tree.Shared.Array_Elements.Table
(Eid);
S : String_List_Id := E.Value.Values;
begin
while S /= Nil_String loop
Artifacts.Append
(Artifacts_Data'
(E.Index, Strs (S).Value,
Required =>
(if V.Name = Name_Artifacts
then False else True)));
S := Strs (S).Next;
end loop;
end;
Eid := Tree.Shared.Array_Elements.
Table (Eid).Next;
end loop;
end;
end if;
end;
Id := Tree.Shared.Arrays.Table (Id).Next;
end loop;
end;
exit Look_Install_Package;
end if;
Pck := Pcks (Pck).Next;
end loop Look_Install_Package;
-- Now check if Lib_Subdir is set and not ALI_Subdir as in this case
-- we want ALI_Subdir to be equal to Lib_Subdir.
if not Lib_Subdir.Default
and then ALI_Subdir.Default
then
ALI_Subdir := Dup (Lib_Subdir);
end if;
end Check_Install_Package;
--------------
-- Dir_Name --
--------------
function Dir_Name (Suffix : Boolean := True) return String is
function Get_Suffix return String;
-- Returns a suffix if needed
----------------
-- Get_Suffix --
----------------
function Get_Suffix return String is
begin
-- .default is always omitted from the directory name
if Suffix and then Build_Name.all /= "default" then
return '.' & Build_Name.all;
else
return "";
end if;
end Get_Suffix;
begin
return Get_Name_String (Project.Name) & Get_Suffix;
end Dir_Name;
---------------------------
-- Get_Library_Filenaame --
---------------------------
function Get_Library_Filename return File_Name_Type is
begin
-- Library prefix
if not Is_Static (Project)
and then Project.Config.Shared_Lib_Prefix /= No_File
then
Get_Name_String (Project.Config.Shared_Lib_Prefix);
else
Set_Name_Buffer ("lib");
end if;
-- Library name
Get_Name_String_And_Append (Project.Library_Name);
-- Library suffix
if Is_Static (Project)
and then Project.Config.Archive_Suffix /= No_File
then
Get_Name_String_And_Append (Project.Config.Archive_Suffix);
elsif not Is_Static (Project)
and then Project.Config.Shared_Lib_Suffix /= No_File
then
Get_Name_String_And_Append (Project.Config.Shared_Lib_Suffix);
else
Add_Str_To_Name_Buffer (".so");
end if;
return Name_Find;
end Get_Library_Filename;
-----------------------
-- Is_Install_Active --
-----------------------
function Is_Install_Active (Project : Project_Id) return Boolean is
Pck : Package_Id := Project.Decl.Packages;
begin
Look_Install_Package : while Pck /= No_Package loop
if Pcks (Pck).Decl /= No_Declarations
and then Pcks (Pck).Name = Name_Install
then
-- Found Install package, check attributes
declare
Id : Variable_Id := Pcks (Pck).Decl.Attributes;
begin
while Id /= No_Variable loop
declare
V : constant Variable := Vels (Id);
begin
if V.Name = Name_Active then
declare
Val : constant String :=
To_Lower
(Get_Name_String (V.Value.Value));
begin
if Val = "false" then
return False;
else
return True;
end if;
end;
end if;
end;
Id := Vels (Id).Next;
end loop;
end;
exit Look_Install_Package;
end if;
Pck := Pcks (Pck).Next;
end loop Look_Install_Package;
-- If not defined, the default is active
return True;
end Is_Install_Active;
-----------------
-- Main_Binary --
-----------------
function Main_Binary (Source : Name_Id) return String is
function Get_Exec_Suffix return String;
-- Return the target executable suffix
---------------------
-- Get_Exec_Suffix --
---------------------
function Get_Exec_Suffix return String is
begin
if Project.Config.Executable_Suffix = No_Name then
return "";
else
return Get_Name_String (Project.Config.Executable_Suffix);
end if;
end Get_Exec_Suffix;
Builder_Package : constant Package_Id :=
Value_Of
(Name_Builder, Project.Decl.Packages,
Project_Tree.Shared);
Value : Variable_Value;
begin
if Builder_Package /= No_Package then
Value := Value_Of
(Name => Source,
Attribute_Or_Array_Name => Name_Executable,
In_Package => Builder_Package,
Shared => Project_Tree.Shared);
if Value = Nil_Variable_Value then
-- If not found and name has an extension
declare
Name : constant String := Get_Name_String (Source);
S : Name_Id;
begin
if Name /= Base_Name (Name) then
Set_Name_Buffer (Base_Name (Name));
S := Name_Find;
Value := Value_Of
(Name => S,
Attribute_Or_Array_Name => Name_Executable,
In_Package => Builder_Package,
Shared => Project_Tree.Shared);
end if;
end;
end if;
end if;
if Value = Nil_Variable_Value then
declare
Simple_Name : constant String :=
Get_Name_String (Source);
Last : Positive := Simple_Name'First;
begin
-- Cut executable name at the first . (extension). Note that
-- this is not necessary the first base-name as we may have
-- multiple dots in the source when using non standard naming.
-- For example, having "main.2.ada" whe want to get on "main".
while Last < Simple_Name'Last
and then Simple_Name (Last + 1) /= '.'
loop
Last := Last + 1;
end loop;
return Simple_Name (Simple_Name'First .. Last)
& Get_Exec_Suffix;
end;
else
return Get_Name_String (Value.Value) & Get_Exec_Suffix;
end if;
end Main_Binary;
-----------------
-- Has_Sources --
-----------------
function Has_Sources (Project : Project_Id) return Boolean is
begin
return Project.Source_Dirs /= Nil_String
or else Project.Qualifier = Aggregate_Library;
end Has_Sources;
--------------
-- Exec_Dir --
--------------
function Exec_Dir return String is
begin
if Is_Absolute_Path (Exec_Subdir.V.all) then
return Exec_Subdir.V.all;
else
return Prefix_Dir.V.all & Exec_Subdir.V.all;
end if;
end Exec_Dir;
-------------
-- Lib_Dir --
-------------
function Lib_Dir (Build_Name : Boolean := True) return String is
Install_Name_Dir : constant String :=
(if Install_Name.Default
then ""
else Install_Name.V.all & "/");
begin
if Is_Absolute_Path (Lib_Subdir.V.all) then
return Lib_Subdir.V.all & Install_Name_Dir;
elsif not Lib_Subdir.Default or else not Build_Name then
return Prefix_Dir.V.all & Lib_Subdir.V.all & Install_Name_Dir;
else
return Ensure_Directory
(Prefix_Dir.V.all & Lib_Subdir.V.all & Install_Name_Dir
& Dir_Name);
end if;
end Lib_Dir;
------------------
-- Link_Lib_Dir --
------------------
function Link_Lib_Dir return String is
begin
if Is_Absolute_Path (Link_Lib_Subdir.V.all) then
return Link_Lib_Subdir.V.all;
else
return Prefix_Dir.V.all & Link_Lib_Subdir.V.all;
end if;
end Link_Lib_Dir;
-----------------
-- Sources_Dir --
-----------------
function Sources_Dir (Build_Name : Boolean := True) return String is
Install_Name_Dir : constant String :=
(if Install_Name.Default
then ""
else Install_Name.V.all & "/");
begin
if Is_Absolute_Path (Sources_Subdir.V.all) then
return Sources_Subdir.V.all & Install_Name_Dir;
elsif not Sources_Subdir.Default or else not Build_Name then
return Prefix_Dir.V.all & Sources_Subdir.V.all & Install_Name_Dir;
else
return Ensure_Directory
(Prefix_Dir.V.all & Sources_Subdir.V.all & Install_Name_Dir
& Dir_Name);
end if;
end Sources_Dir;
-----------------
-- Project_Dir --
-----------------
function Project_Dir return String is
begin
if Is_Absolute_Path (Project_Subdir.V.all) then
return Project_Subdir.V.all;
else
return Prefix_Dir.V.all & Project_Subdir.V.all;
end if;
end Project_Dir;
---------
-- Cat --
---------
function Cat
(Dir : Path_Name_Type; File : File_Name_Type) return String is
begin
return Get_Name_String (Dir) & Get_Name_String (File);
end Cat;
---------------
-- Copy_File --
---------------
procedure Copy_File
(From, To, File : String;
From_Ver : String := "";
Sym_Link : Boolean := False;
Executable : Boolean := False;
Extract_Debug : Boolean := False)
is
Dest_Filename : aliased String := To & File;
begin
if Sym_Link and then On_Windows then
Put ("Internal error: cannot use symbolic links on Windows");
New_Line;
Finish_Program (Project_Tree, E_Fatal);
end if;
if not Sym_Link
and then Exists (Dest_Filename)
and then not Force_Installations
and then File_MD5 (From) /= File_MD5 (Dest_Filename)
then
Put ("file ");
Put (File);
Put (" exists, use -f to overwrite");
New_Line;
Finish_Program (Project_Tree, E_Fatal);
end if;
if Dry_Run or else Opt.Verbose_Mode then
if Sym_Link then
Put ("ln -s ");
else
Put ("cp ");
end if;
Put (From);
Put (" ");
Put (Dest_Filename);
New_Line;
end if;
if not Dry_Run then
-- If file exists and is read-only, first remove it
if not Sym_Link and then Exists (Dest_Filename) then
if not Is_Writable_File (Dest_Filename) then
Set_Writable (Dest_Filename);
end if;
declare
Success : Boolean;
begin
Delete_File (Dest_Filename, Success);
if not Success then
Put ("cannot overwrite ");
Put (Dest_Filename);
Put (" check permissions");
New_Line;
Finish_Program (Project_Tree, E_Fatal);
end if;
end;
end if;
if not Sym_Link and then not Exists (From) then
Put ("file ");
Put (From);
Put (" does not exist, build may not be complete");
New_Line;
Finish_Program (Project_Tree, E_Fatal);
end if;
if (not Sym_Link and then not Exists (To))
or else (Sym_Link and then not Exists (From))
then
if Create_Dest_Dir then
begin
if Sym_Link then
Create_Path (Containing_Directory (From));
else
Create_Path (To);
end if;
exception
when Text_IO.Use_Error =>
-- Cannot create path, permission issue
Put ("cannot create destination directory ");
Put (if Sym_Link
then Containing_Directory (From)
else To);
Put (" check permissions");
New_Line;
Finish_Program (Project_Tree, E_Fatal);
end;
else
Put_Line
(Standard_Error,
"target directory "
& To & " does not exist, use -p to create");
Finish_Program (Project_Tree, E_Fatal);
end if;
end if;
-- Do copy
if Sym_Link then
Create_Sym_Link (From, To & File);
-- Add file to manifest
if Install_Manifest then
Add_To_Manifest (From);
end if;
if From_Ver /= "" then
Create_Sym_Link (From_Ver, To & File);
if Install_Manifest then
Add_To_Manifest (From_Ver);
end if;
end if;
else
begin
Ada.Directories.Copy_File
(Source_Name => From,
Target_Name => Dest_Filename,
Form => "preserve=timestamps");
exception
when Text_IO.Use_Error =>
Put_Line
("cannot overwrite file " & Dest_Filename
& " check permissions.");
Finish_Program (Project_Tree, E_Fatal);
end;
if Executable then
Set_Executable
(Dest_Filename, Mode => S_Owner + S_Group + S_Others);
-- Furthermore, if we have an executable and we ask for
-- separate debug symbols we do it now.
-- The commands to run are:
-- $ objcopy --only-keep-debug <exec> <exec>.debug
-- $ strip <exec>
-- $ objcopy --add-gnu-debuglink=<exec>.debug <exec>
if Extract_Debug then
if Objcopy = null then
Put_Line
(Objcopy_Exec & " not found, "
& "cannot create side debug file for "
& Dest_Filename);
elsif Strip = null then
Put_Line
(Strip_Exec & " not found, "
& "cannot create side debug file for "
& Dest_Filename);
else
declare
Keep_Debug : aliased String :=
"--only-keep-debug";
Dest_Debug : aliased String :=
Dest_Filename & ".debug";
Link_Debug : aliased String :=
"--add-gnu-debuglink=" & Dest_Debug;
Success : Boolean;
Args : Argument_List (1 .. 3);
begin
-- 1. copy the debug symbols:
Args (1) := Keep_Debug'Unchecked_Access;
Args (2) := Dest_Filename'Unchecked_Access;
Args (3) := Dest_Debug'Unchecked_Access;
OS_Lib.Spawn (Objcopy.all, Args, Success);
if Success then
-- Record the debug file in the manifest
if Install_Manifest then
Add_To_Manifest (Dest_Debug);
end if;
-- 2. strip original executable
Args (1) := Dest_Filename'Unchecked_Access;
OS_Lib.Spawn (Strip.all, Args (1 .. 1), Success);
if Success then
-- 2. link debug symbols file with original
-- file.
Args (1) := Link_Debug'Unchecked_Access;
Args (2) := Dest_Filename'Unchecked_Access;
OS_Lib.Spawn
(Objcopy.all, Args (1 .. 2), Success);
if not Success then
Put_Line
(Objcopy_Exec & " error, "
& "cannot link debug symbol file with"
& " original executable "
& Dest_Filename);
end if;
else
Put_Line
(Strip_Exec & " error, "
& "cannot remove debug symbols from "
& Dest_Filename);
end if;
else
Put_Line
(Objcopy_Exec & " error, "
& "cannot create side debug file for "
& Dest_Filename);
end if;
end;
end if;
end if;
end if;
-- Add file to manifest
if Install_Manifest then
Add_To_Manifest (Dest_Filename);
end if;
end if;
end if;
end Copy_File;
----------------
-- Copy_Files --
----------------
procedure Copy_Files is
procedure Copy_Project_Sources (Project : Project_Id);
-- Copy sources from the given project
procedure Copy_Source (Sid : Source_Id);
procedure Copy_Artifacts
(Pathname, Destination : String;
Required : Boolean);
-- Copy items from the artifacts attribute
Source_Copied : Name_Id_Set.Set;
--------------------------
-- Copy_Project_Sources --
--------------------------
procedure Copy_Project_Sources (Project : Project_Id) is
function Is_Ada (Sid : Source_Id) return Boolean with Inline;
-- Returns True if Sid is an Ada source
function Is_Part_Of_Aggregate_Lib
(Aggregate_Lib_Project : Project_Id;
Sid : Source_Id) return Boolean;
-- Returns True if Sid is part of the aggregate lib project. That
-- is, Sid project is one of the aggregated projects.
------------
-- Is_Ada --
------------
function Is_Ada (Sid : Source_Id) return Boolean is
begin
return Sid.Language /= null
and then Get_Name_String (Sid.Language.Name) = "ada";
end Is_Ada;
------------------------------
-- Is_Part_Of_Aggregate_Lib --
------------------------------
function Is_Part_Of_Aggregate_Lib
(Aggregate_Lib_Project : Project_Id;
Sid : Source_Id) return Boolean
is
P : Aggregated_Project_List :=
Aggregate_Lib_Project.Aggregated_Projects;
begin
while P /= null loop
if P.Project = Sid.Project then
return True;
end if;
P := P.Next;
end loop;
return False;
end Is_Part_Of_Aggregate_Lib;
Iter : Source_Iterator;
Sid : Source_Id;
begin
if Project.Qualifier = Aggregate_Library then
Iter := For_Each_Source (Tree, Locally_Removed => False);
else
Iter := For_Each_Source
(Tree, Project, Locally_Removed => False);
end if;
loop
Sid := Element (Iter);
exit when Sid = No_Source;
Initialize_Source_Record (Sid);
-- Skip sources that are removed/excluded and sources not
-- part of the interface for standalone libraries.
if (Project.Qualifier /= Aggregate_Library
or else (Is_Part_Of_Aggregate_Lib (Project, Sid)
and then Is_Install_Active (Sid.Project)))
and then (Project.Standalone_Library = No
or else Sid.Declared_In_Interfaces)
then
if All_Sources then
Copy_Source (Sid);
elsif Sid.Naming_Exception = Yes then
-- When a naming exception is present for a body which
-- is not installed we must exclude the Naming from the
-- generated project.
Excluded_Naming.Include (Get_Name_String (Sid.Unit.Name));
end if;
-- Objects / Deps
if not Sources_Only
and then (Other_Part (Sid) = null or else Sid.Kind /= Spec)
then
if Copy (Object)
and then Sid.Kind /= Sep
and then Sid.Compilable = Yes
then
Copy_File
(From => Cat
(Get_Object_Directory
((if Sid.Object_Project = No_Project
then Sid.Project
else Sid.Object_Project), False),
Sid.Object),
To => Lib_Dir,
File => Get_Name_String (Sid.Object));
end if;
-- Only install Ada .ali files (always name the .ali
-- against the spec file).
if Copy (Dependency)
and then Sid.Kind /= Sep
and then Is_Ada (Sid)
then
declare
Proj : Project_Id := Sid.Project;
Ssid : Source_Id;
begin
if Other_Part (Sid) = null
or else Sid.Naming_Exception = No
or else All_Sources
then
Ssid := Sid;
else
Ssid := Other_Part (Sid);
end if;
if Project.Qualifier = Aggregate_Library then
Proj := Project;
end if;
Copy_File
(From => Cat
(Get_Object_Directory
((if Sid.Object_Project = No_Project
or else Project.Qualifier =
Aggregate_Library
then Proj
else Sid.Object_Project), Project.Library),
Sid.Dep_Name),
To => (if Proj.Library
then ALI_Dir
else Lib_Dir),
File => Get_Name_String (Ssid.Dep_Name));
end;
end if;
end if;
end if;
Next (Iter);
end loop;
end Copy_Project_Sources;
-----------------
-- Copy_Source --
-----------------
procedure Copy_Source (Sid : Source_Id) is
begin
if Copy (Source) and then Is_Install_Active (Sid.Project) then
declare
Prep_Filename : constant String :=
Cat
(Get_Object_Directory
(Sid.Project, False),
Sid.File) & Prep_Suffix;
begin
if not Source_Copied.Contains (Name_Id (Sid.Path.Name)) then
Source_Copied.Insert (Name_Id (Sid.Path.Name));
Copy_File
(From => (if Exists (Prep_Filename)
then Prep_Filename
else Get_Name_String (Sid.Path.Display_Name)),
To => Sources_Dir,
File => Get_Name_String (Sid.Display_File));
end if;
end;
end if;
end Copy_Source;
--------------------
-- Copy_Artifacts --
--------------------
procedure Copy_Artifacts
(Pathname, Destination : String;
Required : Boolean)
is
procedure Copy_Entry (E : Directory_Entry_Type);
-- Copy file pointed by E
function Get_Directory (Fullname : String) return String;
-- Returns the directory containing fullname. Note that we
-- cannot use the standard Containing_Directory as filename
-- can be a pattern and not be allowed in filename.
function Get_Pattern return String;
-- Return filename of pattern from Filename below
Something_Copied : Boolean := False;
-- Keep track if something has been copied or not. If an artifact
-- is coming from Required_Artifacts we must ensure that there is
-- actually something copied if we have a directory or wildcards.
----------------
-- Copy_Entry --
----------------
procedure Copy_Entry (E : Directory_Entry_Type) is
Fullname : constant String := Full_Name (E);
Dest_Dir : constant String :=
(if Is_Absolute_Path (Destination)
then Destination
else Prefix_Dir.V.all & Destination);
begin
if Kind (E) = Directory
and then Simple_Name (E) /= "."
and then Simple_Name (E) /= ".."
then
Copy_Artifacts
(Fullname & "/*",
Dest_Dir & Simple_Name (E) & '/',
Required);
elsif Kind (E) = Ordinary_File then
Copy_File
(From => Fullname,
To => Dest_Dir,
File => Simple_Name (Fullname),
Executable => Is_Executable_File (Fullname));
if Required then
Something_Copied := True;
end if;
end if;
end Copy_Entry;
-------------------
-- Get_Directory --
-------------------
function Get_Directory (Fullname : String) return String is
K : Natural := Fullname'Last;
begin
while K > 0
and then not Is_Directory_Separator (Fullname (K))
loop
K := K - 1;
end loop;
pragma Assert (K > 0);
return Fullname (Fullname'First .. K);
end Get_Directory;
-----------------
-- Get_Pattern --
-----------------
function Get_Pattern return String is
K : Natural := Pathname'Last;
begin
while K > 0
and then not Is_Directory_Separator (Pathname (K))
loop
K := K - 1;
end loop;
if K = 0 then
return Pathname;
else
return Pathname (K + 1 .. Pathname'Last);
end if;
end Get_Pattern;
begin
Ada.Directories.Search
(Directory => Get_Directory (Pathname),
Pattern => Get_Pattern,
Process => Copy_Entry'Access);
if Required and not Something_Copied then
Rollback_Manifests;
Fail_Program
(Project_Tree,
"error: file does not exist '" & Pathname & ''',
Flush_Messages => False);
end if;
exception
when Text_IO.Name_Error =>
if Required then
Rollback_Manifests;
Fail_Program
(Project_Tree,
"warning: file does not exist '" & Pathname & ''',
Flush_Messages => False);
else
Put_Line
("warning: file does not exist '" & Pathname & ''');
end if;
end Copy_Artifacts;
procedure Copy_Interfaces is new For_Interface_Sources (Copy_Source);
function Cat (Dir, File : String) return String is
(if File = "" then "" else Dir & File);
-- Returns Dir & File if File is not empty or "" otherwise
begin
if Has_Sources (Project) then
-- Install the project and the extended projects if any
declare
P : Project_Id := Project;
begin
while P /= No_Project loop
if not All_Sources then
Copy_Interfaces (Tree, P);
end if;
Copy_Project_Sources (P);
P := P.Extends;
end loop;
end;
end if;
-- Copy library
if Copy (Library) and not Sources_Only then
if not Is_Static (Project)
and then Project.Lib_Internal_Name /= No_Name
and then Project.Library_Name /= Project.Lib_Internal_Name
then
if Windows_Target then
-- No support for version, do a simple copy
Copy_File
(From => Cat
(Project.Library_Dir.Display_Name,
Get_Library_Filename),
To => Lib_Dir,
File => Get_Name_String (Get_Library_Filename),
Executable => True,
Extract_Debug => Side_Debug);
else
Copy_File
(From => Cat
(Project.Library_Dir.Display_Name,
File_Name_Type (Project.Lib_Internal_Name)),
To => Lib_Dir,
File =>
Get_Name_String (Project.Lib_Internal_Name),
Executable => True,
Extract_Debug => Side_Debug);
Copy_File
(From => Lib_Dir
& Get_Name_String (Get_Library_Filename),
To => Lib_Dir,
File => Get_Name_String (Project.Lib_Internal_Name),
From_Ver => Cat (Lib_Dir,
Major_Id_Name
(Get_Name_String (Get_Library_Filename),
Get_Name_String (Project.Lib_Internal_Name))),
Sym_Link => True);
end if;
else
Copy_File
(From => Cat
(Project.Library_Dir.Display_Name,
Get_Library_Filename),
To => Lib_Dir,
File => Get_Name_String (Get_Library_Filename),
Executable => not Is_Static (Project),
Extract_Debug =>
Side_Debug and then not Is_Static (Project));
end if;
-- On Windows copy the shared libraries into the bin directory
-- for it to be found in the PATH when running executable. On non
-- Windows platforms add a symlink into the lib directory.
if not Is_Static (Project) and then Add_Lib_Link then
if Windows_Target then
if Lib_Dir /= Exec_Dir then
Copy_File
(From => Lib_Dir
& Get_Name_String (Get_Library_Filename),
To => Exec_Dir,
File =>
Get_Name_String (Get_Library_Filename),
Executable => True,
Extract_Debug => False);
end if;
elsif Link_Lib_Dir /= Lib_Dir then
if On_Windows then
Copy_File
(From => Lib_Dir
& Get_Name_String (Get_Library_Filename),
To => Link_Lib_Dir,
File => Get_Name_String (Get_Library_Filename),
Sym_Link => False);
else
Copy_File
(From => Link_Lib_Dir
& Get_Name_String (Get_Library_Filename),
To => Lib_Dir,
File => Get_Name_String (Get_Library_Filename),
Sym_Link => True);
end if;
-- Copy also the versioned library if any
if Project.Lib_Internal_Name /= No_Name
and then Project.Library_Name /= Project.Lib_Internal_Name
then
if On_Windows then
Copy_File
(From =>
Lib_Dir
& Get_Name_String (Project.Lib_Internal_Name),
To => Link_Lib_Dir,
File =>
Get_Name_String (Project.Lib_Internal_Name),
From_Ver => Cat (Link_Lib_Dir,
Major_Id_Name
(Get_Name_String (Get_Library_Filename),
Get_Name_String (Project.Lib_Internal_Name))),
Sym_Link => False);
else
Copy_File
(From =>
Link_Lib_Dir
& Get_Name_String (Project.Lib_Internal_Name),
To => Lib_Dir,
File =>
Get_Name_String (Project.Lib_Internal_Name),
From_Ver => Cat (Link_Lib_Dir,
Major_Id_Name
(Get_Name_String (Get_Library_Filename),
Get_Name_String (Project.Lib_Internal_Name))),
Sym_Link => True);
end if;
end if;
end if;
end if;
end if;
-- Copy executable(s)
if Copy (Executable) and not Sources_Only then
Mains.Reset;
declare
M : Main_Info := Mains.Next_Main;
begin
while M /= No_Main_Info loop
if M.Project in Project | Project.Extends then
declare
Bin : constant String :=
Main_Binary (Name_Id (M.File));
begin
Copy_File
(From =>
Get_Name_String
(Project.Exec_Directory.Display_Name) & Bin,
To => Exec_Dir,
File => Bin,
Executable => True,
Extract_Debug => Side_Debug);
end;
end if;
M := Mains.Next_Main;
end loop;
end;
end if;
-- Copy artifacts
for E of Artifacts loop
declare
Destination : constant String :=
Ensure_Directory
(Get_Name_String (E.Destination));
Filename : constant String :=
Get_Name_String (E.Filename);
begin
Copy_Artifacts
(Get_Name_String (Project.Directory.Name) & Filename,
Destination,
E.Required);
end;
end loop;
end Copy_Files;
--------------------
-- Create_Project --
--------------------
procedure Create_Project (Project : Project_Id) is
Filename : constant String :=
Project_Dir
& Base_Name (Get_Name_String (Project.Path.Display_Name))
& ".gpr";
Gprinstall_Tag : constant String :=
"This project has been generated by GPRINSTALL";
Line : Unbounded_String;
function "+"
(Item : String) return Unbounded_String renames To_Unbounded_String;
function "-"
(Item : Unbounded_String) return String renames To_String;
procedure Create_Packages;
-- Create packages that are needed, currently Naming and part of
-- Linker is generated for the installed project.
procedure Create_Variables;
-- Create global variables
function Image
(Name : Name_Id;
Id : Array_Element_Id) return String;
-- Returns Id image
function Image (Id : Variable_Id) return String;
-- Returns Id image
function Image (Var : Variable_Value) return String;
-- Returns Id image
procedure Read_Project;
-- Read project and set Content accordingly
procedure Write_Project;
-- Write content into project
procedure Add_Empty_Line;
pragma Inline (Add_Empty_Line);
function Naming_Case_Alternative
(Proj : Project_Id) return String_Vector.Vector;
-- Returns the naming case alternative for this project configuration
function Linker_Case_Alternative
(Proj : Project_Id) return String_Vector.Vector;
-- Returns the linker case alternative for this project configuration
function Data_Attributes return String_Vector.Vector;
-- Returns the attributes for the sources, objects and library
function Get_Languages return String;
-- Returns the list of languages
function Get_Package
(Project : Project_Id; Pkg_Name : Name_Id) return Package_Id;
-- Returns the package Name for the given project
function Get_Build_Line (Vars, Default : String) return String;
-- Returns the build line for Var1 and possibly Var2 if not empty
-- string. Default is the default build name.
--------------------
-- Add_Empty_Line --
--------------------
procedure Add_Empty_Line is
begin
if Content.Element (Content.Last_Index) /= "" then
Content.Append ("");
end if;
end Add_Empty_Line;
--------------------
-- Get_Build_Line --
--------------------
function Get_Build_Line (Vars, Default : String) return String is
use Strings.Fixed;
Variables : String_Split.Slice_Set;
Line : Unbounded_String;
begin
Line := +" BUILD : BUILD_KIND := ";
if not No_Build_Var then
String_Split.Create (Variables, Vars, ",");
if Vars = "" then
-- No variable specified, use default value
Line := Line & "external(""";
Line := Line & To_Upper (Dir_Name (Suffix => False));
Line := Line & "_BUILD"", ";
else
for K in 1 .. String_Split.Slice_Count (Variables) loop
Line := Line & "external(""";
Line := Line & String_Split.Slice (Variables, K) & """, ";
end loop;
end if;
end if;
Line := Line & '"' & Default & '"';
if not No_Build_Var then
Line := Line
& (+(Natural (String_Split.Slice_Count (Variables)) * ')'));
end if;
Line := Line & ';';
return -Line;
end Get_Build_Line;
---------------------
-- Create_Packages --
---------------------
procedure Create_Packages is
procedure Create_Naming (Proj : Project_Id);
-- Create the naming package
procedure Create_Linker (Proj : Project_Id);
-- Create the linker package if needed
-------------------
-- Create_Naming --
-------------------
procedure Create_Naming (Proj : Project_Id) is
P : constant Package_Id := Get_Package (Proj, Name_Naming);
begin
Content.Append (" package Naming is");
if P /= No_Package then
-- Attributes
declare
V : Variable_Id := Pcks (P).Decl.Attributes;
begin
while V /= No_Variable loop
Content.Append (" " & Image (V));
V := Vels (V).Next;
end loop;
end;
end if;
Content.Append (" case BUILD is");
if P /= No_Package then
Content.Append_Vector (Naming_Case_Alternative (Proj));
end if;
Content.Append (" end case;");
Content.Append (" end Naming;");
Add_Empty_Line;
end Create_Naming;
-------------------
-- Create_Linker --
-------------------
procedure Create_Linker (Proj : Project_Id) is
P : constant Package_Id := Get_Package (Proj, Name_Linker);
begin
Content.Append (" package Linker is");
Content.Append (" case BUILD is");
-- Attribute Linker_Options only if set
if P /= No_Package then
Content.Append_Vector (Linker_Case_Alternative (Proj));
end if;
Content.Append (" end case;");
Content.Append (" end Linker;");
Add_Empty_Line;
end Create_Linker;
begin
Create_Naming (Project);
Create_Linker (Project);
end Create_Packages;
----------------------
-- Create_Variables --
----------------------
procedure Create_Variables is
Vars : Variable_Id;
Types : Type_Node_Ref := null;
Current : Type_Node_Ref;
Max_Len : Natural := 0;
begin
Vars := Project.Decl.Variables;
Var_Loop : while Vars /= No_Variable loop
declare
V : constant Variable := Vels (Vars);
begin
-- Compute variable's name maximum length
if V.Value.Kind in Single | List then
Max_Len := Natural'Max
(Max_Len, Get_Name_String (V.Name)'Length);
end if;
-- Check if a typed variable
if GPR.Tree.Present (V.Value.String_Type) then
Current := Types;
Type_Loop : while Current /= null loop
exit Type_Loop when
Current.String_Type = V.Value.String_Type;
Current := Current.Next;
end loop Type_Loop;
if Current = null then
Types := new Type_Node'
(String_Type => V.Value.String_Type,
Next => Types);
end if;
end if;
Vars := V.Next;
end;
end loop Var_Loop;
-- Output the types if any
Current := Types;
while Current /= null loop
Pretty_Print
(Project => Current.String_Type,
In_Tree => Node_Tree,
Increment => 2,
Eliminate_Empty_Case_Constructions => False,
Minimize_Empty_Lines => False,
W_Char => Write_Char'Access,
W_Eol => Write_Eol'Access,
W_Str => Write_Str'Access,
Backward_Compatibility => False,
Id => No_Project,
Max_Line_Length => 79,
Initial_Indent => 3);
Write_Eol;
Current := Current.Next;
end loop;
-- Finally output variables
Vars := Project.Decl.Variables;
while Vars /= No_Variable loop
declare
V : constant Variable := Vels (Vars);
begin
if V.Value.Kind in Single | List then
Write_Str (" " & Get_Name_String (V.Name));
Write_Str
(To_String
((Max_Len - Get_Name_String (V.Name)'Length) * ' '));
if GPR.Tree.Present (V.Value.String_Type) then
Write_Str (" : ");
Write_Str
(Get_Name_String
(GPR.Tree.Name_Of
(V.Value.String_Type, Node_Tree)));
end if;
Write_Str (" := " & Image (V.Value));
Write_Eol;
end if;
Vars := V.Next;
end;
end loop;
end Create_Variables;
---------------------
-- Data_Attributes --
---------------------
function Data_Attributes return String_Vector.Vector is
procedure Gen_Dir_Name
(P : Param; Line : in out Unbounded_String);
-- Generate dir name
------------------
-- Gen_Dir_Name --
------------------
procedure Gen_Dir_Name
(P : Param; Line : in out Unbounded_String) is
begin
if P.Default then
-- This is the default value, add Dir_Name
Line := Line & Dir_Name (Suffix => False);
-- Furthermore, if the build name is "default" do not output
if Build_Name.all /= "default" then
Line := Line & "." & Build_Name.all;
end if;
end if;
end Gen_Dir_Name;
V : String_Vector.Vector;
Line : Unbounded_String;
begin
V.Append (" when """ & Build_Name.all & """ =>");
-- Project sources
Line := +" for Source_Dirs use (""";
if Has_Sources (Project) then
Line := Line
& Relative_Path
(Sources_Dir (Build_Name => False), To => Project_Dir);
Gen_Dir_Name (Sources_Subdir, Line);
end if;
Line := Line & """);";
V.Append (-Line);
-- Project objects and/or library
if Project.Library then
Line := +" for Library_Dir use """;
else
Line := +" for Object_Dir use """;
end if;
Line := Line
& Relative_Path
(Lib_Dir (Build_Name => False), To => Project_Dir);
Gen_Dir_Name (Lib_Subdir, Line);
Line := Line & """;";
V.Append (-Line);
if Project.Library then
-- If ALI are in a different location, set the corresponding
-- attribute.
if Lib_Dir /= ALI_Dir then
Line := +" for Library_ALI_Dir use """;
Line := Line
& Relative_Path
(ALI_Dir (Build_Name => False), To => Project_Dir);
Gen_Dir_Name (ALI_Subdir, Line);
Line := Line & """;";
V.Append (-Line);
end if;
Line := +" for Library_Kind use """;
Line := Line & Image (Project.Library_Kind);
Line := Line & """;";
V.Append (-Line);
if Project.Standalone_Library /= No then
if not Is_Static (Project) then
Line := +" for Library_Standalone use """;
Line := Line & To_Lower
(Standalone'Image (Project.Standalone_Library));
Line := Line & """;";
V.Append (-Line);
end if;
-- And then generates the interfaces
declare
First : Boolean := True;
V : constant Variable_Value :=
Value_Of (Name_Interfaces,
Project.Decl.Attributes,
Tree.Shared);
procedure Source_Interface (Source : Source_Id);
----------------------
-- Source_Interface --
----------------------
procedure Source_Interface (Source : Source_Id) is
begin
if Source.Unit /= No_Unit_Index then
if not First then
Append (Line, ", ");
else
First := False;
end if;
Append (Line, """");
Append (Line, Get_Name_String (Source.Unit.Name));
Append (Line, """");
end if;
end Source_Interface;
procedure List_Interfaces is
new For_Interface_Sources (Source_Interface);
begin
if V /= Nil_Variable_Value
and then not V.Default
and then V.Values /= Nil_String
then
Line := +" for Interfaces use ";
pragma Assert (V.Kind = List);
Append (Line, Image (V));
else
Line := +" for Library_Interface use (";
List_Interfaces (Tree, Project);
Append (Line, ");");
end if;
end;
V.Append (-Line);
end if;
end if;
return V;
end Data_Attributes;
-------------------
-- Get_Languages --
-------------------
function Get_Languages return String is
package Lang_Set is new Containers.Indefinite_Ordered_Sets
(String,
Strings.Less_Case_Insensitive, Strings.Equal_Case_Insensitive);
Langs : Lang_Set.Set;
procedure For_Project (Project : Project_Id);
-- Add languages for the given project
-----------------
-- For_Project --
-----------------
procedure For_Project (Project : Project_Id) is
L : Language_Ptr := Project.Languages;
begin
while L /= null loop
if L.Config.Compiler_Driver /= No_File
and then Get_Name_String (L.Config.Compiler_Driver) /= ""
then
Langs.Include (Get_Name_String (L.Display_Name));
end if;
L := L.Next;
end loop;
end For_Project;
begin
-- First adds language for the main project
For_Project (Project);
-- If we are dealing with an aggregate library, adds the languages
-- from all aggregated projects.
if Project.Qualifier = Aggregate_Library then
declare
Agg : Aggregated_Project_List := Project.Aggregated_Projects;
begin
while Agg /= null loop
For_Project (Agg.Project);
Agg := Agg.Next;
end loop;
end;
end if;
declare
Res : Unbounded_String;
First : Boolean := True;
begin
for V of Langs loop
if not First then
Res := Res & ", ";
end if;
Res := Res & '"' & V & '"';
First := False;
end loop;
return To_String (Res);
end;
end Get_Languages;
-----------------
-- Get_Package --
-----------------
function Get_Package
(Project : Project_Id; Pkg_Name : Name_Id) return Package_Id
is
Pck : Package_Id := Project.Decl.Packages;
begin
while Pck /= No_Package loop
if Pcks (Pck).Decl /= No_Declarations
and then Pcks (Pck).Name = Pkg_Name
then
return Pck;
end if;
Pck := Pcks (Pck).Next;
end loop;
return No_Package;
end Get_Package;
-----------
-- Image --
-----------
function Image
(Name : Name_Id;
Id : Array_Element_Id) return String
is
E : constant Array_Element :=
Tree.Shared.Array_Elements.Table (Id);
begin
return "for " & Get_Name_String (Name)
& " (""" & Get_Name_String (E.Index)
& """) use " & Image (E.Value);
end Image;
function Image (Id : Variable_Id) return String is
V : constant Variable_Value := Vels (Id).Value;
begin
if V.Default then
return "";
else
return "for " & Get_Name_String (Vels (Id).Name) & " use "
& Image (V);
end if;
end Image;
function Image (Var : Variable_Value) return String is
begin
case Var.Kind is
when Single =>
return '"' & Get_Name_String (Var.Value) & '"'
& (if Var.Index = 0 then "" else " at" & Var.Index'Img)
& ';';
when List =>
declare
V : Unbounded_String;
L : String_List_Id := Var.Values;
First : Boolean := True;
begin
Append (V, "(");
while L /= Nil_String loop
if not First then
Append (V, ", ");
else
First := False;
end if;
Append
(V, '"' & Get_Name_String (Strs (L).Value) & '"');
if Strs (L).Index > 0 then
Append (V, " at" & Strs (L).Index'Img);
end if;
L := Strs (L).Next;
end loop;
Append (V, ");");
return To_String (V);
end;
when Undefined =>
return "";
end case;
end Image;
-----------------------------
-- Linker_Case_Alternative --
-----------------------------
function Linker_Case_Alternative
(Proj : Project_Id) return String_Vector.Vector
is
use type Ada.Containers.Count_Type;
procedure Linker_For (Pck : Package_Id);
-- Handle the linker options for this package
procedure Append (Values : String_List_Id);
-- Add values if any
procedure Add_Library_Options (Proj : Project_Id);
-- For a library project, add the Library_Options
procedure Opts_Append (Opt : String);
-- Add options only if it was not appended before into Opts
Seen : Seen_Set.Set;
-- Records the attribute generated to avoid duplicate when
-- handling aggregated projects.
R : String_Vector.Vector;
Opts : String_Vector.Vector;
-------------------------
-- Add_Library_Options --
-------------------------
procedure Add_Library_Options (Proj : Project_Id) is
begin
if Proj.Library then
declare
V : constant Variable_Value :=
Value_Of (Name_Library_Options,
Proj.Decl.Attributes,
Tree.Shared);
begin
if V /= Nil_Variable_Value then
Append (V.Values);
end if;
end;
end if;
end Add_Library_Options;
-----------------
-- Opts_Append --
-----------------
procedure Opts_Append (Opt : String) is
Position : Seen_Set.Cursor;
Inserted : Boolean;
begin
Seen.Insert (Opt, Position, Inserted);
if Inserted then
Opts.Append (Opt);
end if;
end Opts_Append;
------------
-- Append --
------------
procedure Append (Values : String_List_Id) is
L : String_List_Id := Values;
begin
while L /= Nil_String loop
Opts_Append (Get_Name_String (Strs (L).Value));
L := Strs (L).Next;
end loop;
end Append;
----------------
-- Linker_For --
----------------
procedure Linker_For (Pck : Package_Id) is
V : Variable_Id := Pcks (Pck).Decl.Attributes;
begin
while V /= No_Variable loop
if Vels (V).Name = Name_Linker_Options then
Append (Vels (V).Value.Values);
end if;
V := Vels (V).Next;
end loop;
end Linker_For;
begin
R.Append (" when """ & Build_Name.all & """ =>");
Linker_For (Get_Package (Proj, Name_Linker));
-- For libraries we want to add the library options here
Add_Library_Options (Proj);
if Proj.Qualifier = Aggregate_Library then
declare
Agg : Aggregated_Project_List :=
Project.Aggregated_Projects;
begin
while Agg /= null loop
Linker_For (Get_Package (Agg.Project, Name_Linker));
-- Likewise for all aggregated libraries
Add_Library_Options (Agg.Project);
Agg := Agg.Next;
end loop;
end;
end if;
-- We also want to add the externally built libraries without
-- sources (referencing system libraries for example).
declare
L : Project_List := Project.All_Imported_Projects;
begin
while L /= null loop
if L.Project.Library
and then L.Project.Externally_Built
and then not Bring_Sources (L.Project)
then
Opts_Append
("-L" & Get_Name_String (L.Project.Library_Dir.Name));
Opts_Append
("-l" & Get_Name_String (L.Project.Library_Name));
end if;
L := L.Next;
end loop;
end;
if Opts.Length = 0 then
-- No linker alternative found, add null statement
R.Append (" null;");
else
declare
O_List : Unbounded_String;
begin
for O of Opts loop
if O_List /= Null_Unbounded_String then
Append (O_List, ", ");
end if;
Append (O_List, '"' & O & '"');
end loop;
R.Append
(" for Linker_Options use ("
& To_String (O_List) & ");");
end;
end if;
return R;
end Linker_Case_Alternative;
-----------------------------
-- Naming_Case_Alternative --
-----------------------------
function Naming_Case_Alternative
(Proj : Project_Id) return String_Vector.Vector
is
procedure Naming_For (Pck : Package_Id);
-- Handle the naming scheme for this package
function Is_Language_Active (Lang : String) return Boolean;
-- Returns True if Lang is active in the installed project
Seen : Seen_Set.Set;
-- Records the attribute generated to avoid duplicate when
-- handling aggregated projects.
V : String_Vector.Vector;
-- Contains the final result returned
Languages : constant String :=
Characters.Handling.To_Lower (Get_Languages);
-- Languages for the generated projects
------------------------
-- Is_Language_Active --
------------------------
function Is_Language_Active (Lang : String) return Boolean is
begin
return Strings.Fixed.Index
(Languages,
Characters.Handling.To_Lower (Lang)) /= 0;
end Is_Language_Active;
----------------
-- Naming_For --
----------------
procedure Naming_For (Pck : Package_Id) is
A : Array_Id := Pcks (Pck).Decl.Arrays;
N, I : Name_Id;
E : Array_Element_Id;
begin
-- Arrays
while A /= No_Array loop
N := Tree.Shared.Arrays.Table (A).Name;
E := Tree.Shared.Arrays.Table (A).Value;
I := Tree.Shared.Array_Elements.Table (E).Index;
while E /= No_Array_Element loop
-- Check if this naming is not to be filtered-out. This
-- is a special case when a renaming is given for a
-- body. See Excluded_Name comments.
if (N /= Name_Body
or else
not Excluded_Naming.Contains (Get_Name_String (I)))
and then
(N not in Name_Spec_Suffix
| Name_Body_Suffix
| Name_Separate_Suffix
or else Is_Language_Active
(Get_Name_String
(Tree.Shared.Array_Elements.Table (E).Index)))
then
declare
Decl : constant String := Image (N, E);
begin
if not Seen.Contains (Decl) then
V.Append (" " & Decl);
Seen.Include (Decl);
end if;
end;
end if;
E := Tree.Shared.Array_Elements.Table (E).Next;
end loop;
A := Tree.Shared.Arrays.Table (A).Next;
end loop;
end Naming_For;
begin
V.Append (" when """ & Build_Name.all & """ =>");
Naming_For (Get_Package (Proj, Name_Naming));
if Proj.Qualifier = Aggregate_Library then
declare
Agg : Aggregated_Project_List :=
Project.Aggregated_Projects;
begin
while Agg /= null loop
Naming_For (Get_Package (Agg.Project, Name_Naming));
Agg := Agg.Next;
end loop;
end;
end if;
return V;
end Naming_Case_Alternative;
------------------
-- Read_Project --
------------------
procedure Read_Project is
Max_Buffer : constant := 1_024;
File : File_Type;
Buffer : String (1 .. Max_Buffer);
Last : Natural;
begin
Open (File, In_File, Filename);
while not End_Of_File (File) loop
declare
L : Unbounded_String;
begin
loop
Get_Line (File, Buffer, Last);
Append (L, Buffer (1 .. Last));
exit when Last < Max_Buffer
or else End_Of_Line (File);
end loop;
Content.Append (To_String (L));
end;
end loop;
Close (File);
end Read_Project;
-------------------
-- Write_Project --
-------------------
procedure Write_Project is
F : File_Access := Standard_Output;
File : aliased File_Type;
begin
if not Dry_Run then
if not Exists (Project_Dir) then
Create_Path (Project_Dir);
end if;
Create (File, Out_File, Filename);
F := File'Unchecked_Access;
end if;
for K in Content.First_Index .. Content.Last_Index loop
Put_Line (F.all, Content.Element (K));
end loop;
if not Dry_Run then
Close (File);
end if;
end Write_Project;
type Section_Kind is (Top, Naming, Linker);
Project_Exists : constant Boolean := Exists (Filename);
Current_Section : Section_Kind := Top;
Pos : String_Vector.Cursor;
Generated : Boolean := False;
begin
if Dry_Run or else Opt.Verbose_Mode then
New_Line;
Put ("Project ");
Put (Filename);
if Dry_Run then
Put_Line (" would be installed");
else
Put_Line (" installed");
end if;
New_Line;
end if;
-- If project exists, read it and check the generated status
if Project_Exists then
Read_Project;
-- First check that this project has been generated by gprbuild,
-- if not exit with an error as we cannot modify a project created
-- manually and we do not want to overwrite it.
Pos := Content.First;
Check_Generated_Status :
while String_Vector.Has_Element (Pos) loop
if Fixed.Index
(String_Vector.Element (Pos), Gprinstall_Tag) /= 0
then
Generated := True;
exit Check_Generated_Status;
end if;
String_Vector.Next (Pos);
end loop Check_Generated_Status;
if not Generated and then not Force_Installations then
Put ("non gprinstall project file ");
Put (Filename);
Put (" exists, use -f to overwrite");
New_Line;
Finish_Program (Project_Tree, E_Fatal);
end if;
end if;
if Project_Exists and then Generated then
if not Has_Sources (Project) then
-- Nothing else to do in this case
return;
end if;
if Opt.Verbose_Mode then
Put_Line ("project file exists, merging new build");
end if;
-- Do merging for new build, we need to add an entry into the
-- BUILD_KIND type and a corresponding case entry in the naming
-- and Linker package.
Parse_Content :
while String_Vector.Has_Element (Pos) loop
declare
BN : constant String := Build_Name.all;
Line : constant String := String_Vector.Element (Pos);
P, L : Natural;
begin
if Fixed.Index (Line, "type BUILD_KIND is (") /= 0 then
-- This is the "type BUILD_KIND" line, add new build name
-- First check if the current build name already exists
if Fixed.Index (Line, """" & BN & """") = 0 then
-- Get end of line
P := Fixed.Index (Line, ");");
if P = 0 then
Fail_Program
(Project_Tree,
"cannot parse the BUILD_KIND line");
else
Content.Replace_Element
(Pos,
Line (Line'First .. P - 1)
& ", """ & BN & """);");
end if;
end if;
elsif Fixed.Index (Line, ":= external(") /= 0 then
-- This is the BUILD line, get build vars
declare
Default : Unbounded_String;
begin
-- Get default value
L := Fixed.Index
(Line, """", Going => Strings.Backward);
P := Fixed.Index
(Line (Line'First .. L - 1), """",
Going => Strings.Backward);
Default := +Line (P + 1 .. L - 1);
Content.Replace_Element
(Pos,
Get_Build_Line
((if Build_Vars = null
then ""
else Build_Vars.all), -Default));
end;
elsif Fixed.Index (Line, "package Naming is") /= 0 then
Current_Section := Naming;
elsif Fixed.Index (Line, "package Linker is") /= 0 then
Current_Section := Linker;
elsif Fixed.Index (Line, "case BUILD is") /= 0 then
-- Add new case section for the new build name
case Current_Section is
when Naming =>
String_Vector.Next (Pos);
Content.Insert_Vector
(Pos, Naming_Case_Alternative (Project));
when Linker =>
String_Vector.Next (Pos);
Content.Insert_Vector
(Pos, Linker_Case_Alternative (Project));
when Top =>
-- For the Sources/Lib attributes
String_Vector.Next (Pos);
Content.Insert_Vector (Pos, Data_Attributes);
end case;
elsif Fixed.Index (Line, "when """ & BN & """ =>") /= 0 then
-- Found a when with the current build name, this is a
-- previous install overwritten by this one. Remove this
-- section. Note that this removes sections from all
-- packages Naming and Linker, and from project level
-- case alternative.
Count_And_Delete : declare
use type Containers.Count_Type;
function End_When (L : String) return Boolean;
-- Return True if L is the end of a when alternative
--------------
-- End_When --
--------------
function End_When (L : String) return Boolean is
P : constant Natural :=
Strings.Fixed.Index_Non_Blank (L);
Len : constant Natural := L'Length;
begin
return P > 0
and then
((P + 4 <= Len
and then L (P .. P + 4) = "when ")
or else
(P + 8 <= Len
and then L (P .. P + 8) = "end case;"));
end End_When;
N : Containers.Count_Type := 0;
P : String_Vector.Cursor := Pos;
begin
-- The number of line to delete are from Pos to the
-- first line starting with a "when".
loop
String_Vector.Next (P);
N := N + 1;
exit when End_When (String_Vector.Element (P));
end loop;
Content.Delete (Pos, N);
end Count_And_Delete;
end if;
end;
String_Vector.Next (Pos);
end loop Parse_Content;
else
-- Project does not exist, or it exists, was not generated by
-- gprinstall and -f used. In this case it will be overwritten by
-- a generated project.
Content.Clear;
-- Tag project as generated by gprbuild
Content.Append
("-- " & Gprinstall_Tag & ' ' & Gpr_Version_String);
Add_Empty_Line;
-- Handle with clauses, generate a with clauses only for project
-- bringing some visibility to sources. No need for doing this for
-- aggregate projects.
if Project.Qualifier /= Aggregate_Library then
declare
L : Project_List := Project.Imported_Projects;
begin
while L /= null loop
if Has_Sources (L.Project)
and then Is_Install_Active (L.Project)
then
Content.Append
("with """
& Base_Name
(Get_Name_String (L.Project.Path.Display_Name))
& """;");
end if;
L := L.Next;
end loop;
end;
end if;
-- In all cases adds externally built projects
declare
L : Project_List := Project.All_Imported_Projects;
begin
while L /= null loop
if Has_Sources (L.Project)
and then L.Project.Externally_Built
then
Content.Append
("with """
& Base_Name
(Get_Name_String (L.Project.Path.Display_Name))
& """;");
end if;
L := L.Next;
end loop;
end;
Add_Empty_Line;
-- Project name
if Project.Library then
Line := +"library ";
else
if Has_Sources (Project) then
Line := +"standard ";
else
Line := +"abstract ";
end if;
end if;
Line := Line & "project ";
Line := Line & Get_Name_String (Project.Display_Name);
Line := Line & " is";
Content.Append (-Line);
if Has_Sources (Project) or Project.Library then
-- BUILD variable
Content.Append
(" type BUILD_KIND is (""" & Build_Name.all & """);");
Line := +Get_Build_Line
(Vars =>
(if Build_Vars = null then "" else Build_Vars.all),
Default => Build_Name.all);
Content.Append (-Line);
-- Add languages, for an aggregate library we want all unique
-- languages from all aggregated libraries.
if Has_Sources (Project) then
Add_Empty_Line;
Content.Append
(" for Languages use (" & Get_Languages & ");");
end if;
-- Build_Suffix used to avoid .default as suffix
Add_Empty_Line;
Content.Append (" case BUILD is");
Content.Append_Vector (Data_Attributes);
Content.Append (" end case;");
Add_Empty_Line;
-- Library Name
if Project.Library then
Content.Append
(" for Library_Name use """
& Get_Name_String (Project.Library_Name)
& """;");
-- Issue the Library_Version only if needed
if not Is_Static (Project)
and then Project.Lib_Internal_Name /= No_Name
and then Project.Library_Name /= Project.Lib_Internal_Name
then
Content.Append
(" for Library_Version use """
& Get_Name_String (Project.Lib_Internal_Name)
& """;");
end if;
end if;
-- Packages
if Has_Sources (Project) then
Add_Empty_Line;
Create_Packages;
end if;
-- Set as not installable
Add_Empty_Line;
Content.Append (" package Install is");
Content.Append (" for Active use ""False"";");
Content.Append (" end Install;");
-- Externally Built
if not Sources_Only then
Add_Empty_Line;
Content.Append (" for Externally_Built use ""True"";");
end if;
else
-- This is an abstract project
Content.Append (" for Source_Dirs use ();");
end if;
-- Variables
Add_Empty_Line;
Create_Variables;
-- Close project
Content.Append
("end " & Get_Name_String (Project.Display_Name) & ";");
end if;
-- Write new project if needed
Write_Project;
if not Dry_Run and then Install_Manifest then
-- Add project file to manifest
Add_To_Manifest (Filename);
end if;
end Create_Project;
-------------------------
-- Open_Check_Manifest --
-------------------------
procedure Open_Check_Manifest
(File : out Text_IO.File_Type; Current_Line : out Text_IO.Count)
is
Dir : constant String := Project_Dir & "manifests";
Name : constant String := Dir & DS & Install_Name.V.all;
Prj_Sig : constant String :=
File_MD5 (Get_Name_String (Project.Path.Display_Name));
Buf : String (1 .. 128);
Last : Natural;
begin
-- Check whether the manifest does not exist in this case
if Exists (Name) then
-- If this manifest is the same of the current aggregate
-- one, do not try to reopen it.
if not Is_Open (Agg_Manifest)
or else Normalize_Pathname
(Text_IO.Name (Agg_Manifest),
Case_Sensitive => False)
/= Normalize_Pathname (Name, Case_Sensitive => False)
then
Open (File, In_File, Name);
Get_Line (File, Buf, Last);
if Last >= Message_Digest'Length
and then
(Buf (1 .. 2) /= Sig_Line
or else Buf (3 .. Message_Digest'Last + 2) /= Prj_Sig)
and then Install_Name.Default
and then Install_Project
then
Put_Line
("Project already installed, either:");
Put_Line
(" - uninstall first using --uninstall option");
Put_Line
(" - install under another name, use --install-name");
Put_Line
(" - force installation under the same name, "
& "use --install-name=" & Install_Name.V.all);
Finish_Program (Project_Tree, E_Fatal);
end if;
Reset (File, Append_File);
Current_Line := Line (File);
end if;
else
Create_Path (Dir);
Create (File, Out_File, Name);
Current_Line := 1;
Put_Line (File, Sig_Line & Prj_Sig);
end if;
exception
when Text_IO.Use_Error =>
Put_Line
("cannot open or create the manifest file "
& Project_Subdir.V.all & Install_Name.V.all);
Put_Line ("check permissions on this location");
Finish_Program (Project_Tree, E_Fatal);
end Open_Check_Manifest;
------------------------
-- Rollback_Manifests --
------------------------
procedure Rollback_Manifests is
Content : String_Vector.Vector;
procedure Rollback_Manifest
(File : in out Text_IO.File_Type; Line : Text_IO.Count);
-----------------------
-- Rollback_Manifest --
-----------------------
procedure Rollback_Manifest
(File : in out Text_IO.File_Type; Line : Text_IO.Count)
is
use type Ada.Containers.Count_Type;
Dir : constant String :=
Containing_Directory (Name (File)) & DS;
Buffer : String (1 .. 4_096);
Last : Natural;
begin
-- Set manifest file in Read mode
Reset (File, Text_IO.In_File);
while not End_Of_File (File) loop
Get_Line (File, Buffer, Last);
if Text_IO.Line (File) = 2
or else Text_IO.Line (File) < Line
then
-- Record file to be kept in manifest
Content.Append (Buffer (1 .. Last));
else
-- Delete file
declare
Filename : constant String :=
Dir
& Buffer
(GNAT.MD5.Message_Digest'Length + 2
.. Last);
begin
Ada.Directories.Delete_File (Filename);
Delete_Empty_Directory
(Prefix_Dir.V.all, Containing_Directory (Filename));
end;
end if;
end loop;
-- There is nothing left in the manifest file (only the signature
-- line), remove it, otherwise we create the new manifest file
-- containing only the previous content.
if Content.Length = 1 then
declare
Manifest_Filename : constant String := Name (File);
begin
Delete (File);
-- Delete manifest directories if empty
Delete_Empty_Directory
(Prefix_Dir.V.all,
Containing_Directory (Manifest_Filename));
end;
else
-- Set manifest file back to Write mode
Reset (File, Text_IO.Out_File);
for C of Content loop
Text_IO.Put_Line (File, C);
end loop;
Close (File);
end if;
end Rollback_Manifest;
begin
if Is_Open (Man) then
Rollback_Manifest (Man, Line_Manifest);
end if;
if Is_Open (Agg_Manifest) then
Rollback_Manifest (Agg_Manifest, Line_Agg_Manifest);
end if;
end Rollback_Manifests;
Is_Project_To_Install : Boolean;
-- Whether the project is to be installed
begin
-- Empty Content
Content.Delete_First (Count => Ada.Containers.Count_Type'Last);
-- First look for the Install package and set up the local values
-- accordingly.
Check_Install_Package;
-- The default install name is the name of the project without
-- extension.
if Install_Name.Default then
Install_Name.V :=
new String'((Base_Name (Get_Name_String (Project.Path.Name))));
end if;
-- Skip non active project and externally built ones
Is_Project_To_Install := Active
and (Bring_Sources (Project)
or Project.Externally_Built);
-- If we have an aggregate project we just install separately all
-- aggregated projects.
if Project.Qualifier = Aggregate then
-- If this is the main project and is an aggregate project, create
-- the corresponding manifest.
if Project = Main_Project
and then Main_Project.Qualifier = Aggregate
and then Install_Manifest
then
Open_Check_Manifest (Agg_Manifest, Line_Agg_Manifest);
end if;
declare
L : Aggregated_Project_List := Project.Aggregated_Projects;
begin
while L /= null loop
Process (L.Tree, L.Node_Tree, L.Project);
L := L.Next;
end loop;
end;
-- Nothing more to do for an aggregate project
return;
end if;
if not Installed.Contains (Project.Name) then
Installed.Include (Project.Name);
if not Opt.Quiet_Output then
if Is_Project_To_Install then
Put ("Install");
elsif Opt.Verbose_Mode then
Put ("Skip");
end if;
if Is_Project_To_Install or Opt.Verbose_Mode then
Put (" project ");
Put (Get_Name_String (Project.Display_Name));
if Build_Name.all /= "default" then
Put (" - " & Build_Name.all);
end if;
end if;
if not Is_Project_To_Install and Opt.Verbose_Mode then
Put (" (not active)");
end if;
if Is_Project_To_Install or Opt.Verbose_Mode then
New_Line;
end if;
end if;
-- If this is not an active project, just return now
if not Is_Project_To_Install then
return;
end if;
-- What should be copied
Copy :=
(Source => For_Dev,
Object => For_Dev
and then Project.Mains = Nil_String
and then Project.Qualifier /= Library
and then Project.Qualifier /= Aggregate_Library
and then not Project.Library,
Dependency => For_Dev and then Project.Mains = Nil_String,
Library => Project.Library
and then
((For_Dev and then Is_Static (Project))
or else not Is_Static (Project)),
Executable => Project.Mains /= Nil_String);
-- Copy all files from the project
Copy_Files;
-- A project file is only needed in developer mode
if For_Dev and then Install_Project then
Create_Project (Project);
end if;
-- Add manifest into the main aggregate project manifest
if Is_Open (Man) then
if Is_Open (Agg_Manifest) then
declare
Filename : constant String :=
Project_Dir & "manifests"
& DS & Simple_Name (Name (Man));
begin
Close (Man);
Add_To_Manifest (Filename, Aggregate_Only => True);
end;
else
Close (Man);
end if;
end if;
-- Handle all projects recursively if needed
if Recursive then
declare
L : Project_List := Project.Imported_Projects;
begin
while L /= null loop
Process (Tree, Node_Tree, L.Project);
L := L.Next;
end loop;
end;
end if;
end if;
Free (Prefix_Dir);
Free (Sources_Subdir);
Free (Lib_Subdir);
Free (Exec_Subdir);
Free (Project_Subdir);
end Process;
-------------------
-- Double_Buffer --
-------------------
procedure Double_Buffer is
New_Buffer : constant GNAT.OS_Lib.String_Access :=
new String (1 .. Buffer'Last * 2);
begin
New_Buffer (1 .. Buffer_Last) := Buffer (1 .. Buffer_Last);
Free (Buffer);
Buffer := New_Buffer;
end Double_Buffer;
----------------
-- Write_Char --
----------------
procedure Write_Char (C : Character) is
begin
if Buffer_Last = Buffer'Last then
Double_Buffer;
end if;
Buffer_Last := Buffer_Last + 1;
Buffer (Buffer_Last) := C;
end Write_Char;
---------------
-- Write_Eol --
---------------
procedure Write_Eol is
begin
Content.Append (New_Item => (Buffer (1 .. Buffer_Last)));
Buffer_Last := 0;
end Write_Eol;
---------------
-- Write_Str --
---------------
procedure Write_Str (S : String) is
begin
while Buffer_Last + S'Length > Buffer'Last loop
Double_Buffer;
end loop;
Buffer (Buffer_Last + 1 .. Buffer_Last + S'Length) := S;
Buffer_Last := Buffer_Last + S'Length;
end Write_Str;
end Gprinstall.Install;
|