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 | ------------------------------------------------------------------------------
-- --
-- GNATTEST COMPONENTS --
-- --
-- G N A T T E S T . S T U B . S O U R C E _ T A B L E --
-- --
-- B o d y --
-- --
-- Copyright (C) 2011-2019, AdaCore --
-- --
-- GNATTEST is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 2, or (at your option) any later --
-- version. GNATTEST is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY 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, write to the Free Software Foundation, 51 Franklin Street, Fifth --
-- Floor, Boston, MA 02110-1301, USA., --
-- --
-- GNATTEST is maintained by AdaCore (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
pragma Ada_2012;
with Ada.Containers.Indefinite_Ordered_Maps;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with GNATtest.Options; use GNATtest.Options;
with GNATCOLL.Projects; use GNATCOLL.Projects;
with GNATCOLL.VFS; use GNATCOLL.VFS;
with GNATCOLL.Traces; use GNATCOLL.Traces;
with ASIS_UL.Output; use ASIS_UL.Output;
with ASIS_UL.Options; use ASIS_UL.Options;
with Ada.Characters.Handling; use Ada.Characters.Handling;
package body GNATtest.Skeleton.Source_Table is
Me : constant Trace_Handle := Create ("Skeletons.Sources", Default => Off);
-----------------------
-- Source File table --
-----------------------
Sources_Left : Natural := 0;
Total_Sources : Natural := 0;
type SF_Record;
type SF_Record is record
Full_Source_Name : String_Access;
-- This field stores the source name with full directory information
-- in absolute form
Suffixless_Name : String_Access;
-- The source name without directory information and suffix (if any)
-- is used to create the names of the tree file and ALI files
Test_Destination : String_Access;
-- The path to the corresponding test unit location.
Stub_Destination : String_Access;
-- The path to the corresponding stub unit location.
Status : SF_Status;
-- Status of the given source. Initially is set to Waiting, then is
-- changed according to the results of the metrics computation
Corresponding_Body : String_Access := null;
-- Set in Stub Mode for package specs.
Stub_Data_Base_Spec : String_Access;
Stub_Data_Base_Body : String_Access;
-- Different projects in the hierarchy may have different naming
-- schemes, but we won't have the access to this info once ASIS context
-- is generated, so we need to calculate those names beforehand.
Stub_Created : Boolean := False;
Project_Name : String_Access;
-- Name of corresponding project. Only relevant for bodies.
Unit_Name : String_Access := null;
end record;
package Source_File_Table is new
Ada.Containers.Indefinite_Ordered_Maps (String, SF_Record);
Current_Source : String_Access := null;
use String_Set;
use Source_File_Table;
package Source_File_Locations renames String_Set;
SF_Table : Source_File_Table.Map;
-- Source Table itself
SFL_Table : Source_File_Locations.Set;
-- A set of paths to source files. Used for creation of project file.
SF_Process_Iterator : Source_File_Table.Cursor;
SF_Access_Iterator : Source_File_Table.Cursor;
SFL_Iterator : Source_File_Locations.Cursor;
Short_Source_Name_String : String_Access;
Full_Source_Name_String : String_Access;
procedure Reset_Source_Process_Iterator;
-- Sets SF_Iterator to the begining of SF_Table.
type Project_Record is record
Path : String_Access;
Obj_Dir : String_Access;
Stub_Dir : String_Access;
Importing_List : List_Of_Strings.List;
Imported_List : List_Of_Strings.List;
Limited_Withed : String_Set.Set;
Is_Externally_Built : Boolean;
Is_Library : Boolean := False;
Needed_For_Extention : Boolean := False;
end record;
use List_Of_Strings;
package Project_File_Table is new
Ada.Containers.Indefinite_Ordered_Maps (String, Project_Record);
use Project_File_Table;
PF_Table : Project_File_Table.Map;
function Is_Body (Source_Name : String) return Boolean;
-----------------------------
-- Add_Source_To_Process --
-----------------------------
procedure Add_Source_To_Process (Fname : String) is
First_Idx : Natural;
Last_Idx : Natural;
New_SF_Record : SF_Record;
begin
Trace (Me, "adding source: " & Fname);
if not Is_Regular_File (Fname) then
Report_Std ("gnattest: " & Fname & " not found");
return;
end if;
-- Check if we already have a file with the same short name:
Short_Source_Name_String := new String'(Base_Name (Fname));
Full_Source_Name_String :=
new String'(Normalize_Pathname
(Fname,
Resolve_Links => False,
Case_Sensitive => False));
if
Source_Present (Full_Source_Name_String.all) and then
Get_Source_Status (Full_Source_Name_String.all) = Body_Reference
then
Trace (Me, "...replacing body reference");
New_SF_Record := SF_Table.Element (Full_Source_Name_String.all);
SF_Table.Delete (Full_Source_Name_String.all);
New_SF_Record.Status := Waiting;
Insert (SF_Table, Full_Source_Name_String.all, New_SF_Record);
return;
elsif Source_Present (Full_Source_Name_String.all) then
-- Duplicate, just ignore it
return;
end if;
-- Making the new SF_Record
New_SF_Record.Full_Source_Name :=
new String'(Full_Source_Name_String.all);
First_Idx := Short_Source_Name_String'First;
Last_Idx := Short_Source_Name_String'Last;
for J in reverse First_Idx + 1 .. Last_Idx loop
if Short_Source_Name_String (J) = '.' then
Last_Idx := J - 1;
exit;
end if;
end loop;
New_SF_Record.Suffixless_Name :=
new String'(Short_Source_Name_String.all (First_Idx .. Last_Idx));
New_SF_Record.Status := Waiting;
if Stub_Mode_ON then
declare
Given_File : constant GNATCOLL.VFS.Virtual_File :=
Create (+Fname);
Other_File : constant GNATCOLL.VFS.Virtual_File :=
Source_Project_Tree.Other_File (Given_File);
F_Info : constant File_Info :=
Source_Project_Tree.Info (Given_File);
P : Project_Type;
begin
if Given_File /= Other_File
and then Is_Regular_File (Other_File.Display_Full_Name)
then
New_SF_Record.Corresponding_Body :=
new String'(Other_File.Display_Full_Name);
end if;
New_SF_Record.Stub_Data_Base_Spec := new String'
(+
(File_From_Unit
(Project => F_Info.Project,
Unit_Name =>
F_Info.Unit_Name & "." & Stub_Data_Unit_Name,
Part => Unit_Spec,
Language => F_Info.Language,
File_Must_Exist => False)));
New_SF_Record.Stub_Data_Base_Body := new String'
(+
(File_From_Unit
(Project => F_Info.Project,
Unit_Name =>
F_Info.Unit_Name & "." & Stub_Data_Unit_Name,
Part => Unit_Body,
Language => F_Info.Language,
File_Must_Exist => False)));
P := F_Info.Project;
loop
exit when Extending_Project (P) = No_Project;
P := Extending_Project (P);
end loop;
New_SF_Record.Project_Name := new String'(P.Name);
end;
end if;
Insert (SF_Table, Full_Source_Name_String.all, New_SF_Record);
Include
(SFL_Table,
Normalize_Pathname (Name => Dir_Name (Full_Source_Name_String.all),
Resolve_Links => False,
Case_Sensitive => False));
Sources_Left := Sources_Left + 1;
Total_Sources := Total_Sources + 1;
Free (Short_Source_Name_String);
Free (Full_Source_Name_String);
end Add_Source_To_Process;
-------------------------
-- Add_Body_To_Process --
-------------------------
procedure Add_Body_To_Process
(Fname : String; Pname : String; Uname : String)
is
First_Idx : Natural;
Last_Idx : Natural;
New_SF_Record : SF_Record;
begin
Trace (Me, "adding " & Fname & " from project " & Pname);
-- Check if we already have a file with the same short name:
Short_Source_Name_String := new String'(Base_Name (Fname));
Full_Source_Name_String :=
new String'(Normalize_Pathname
(Fname,
Resolve_Links => False,
Case_Sensitive => False));
-- Making the new SF_Record
New_SF_Record.Full_Source_Name :=
new String'(Full_Source_Name_String.all);
First_Idx := Short_Source_Name_String'First;
Last_Idx := Short_Source_Name_String'Last;
for J in reverse First_Idx + 1 .. Last_Idx loop
if Short_Source_Name_String (J) = '.' then
Last_Idx := J - 1;
exit;
end if;
end loop;
New_SF_Record.Suffixless_Name :=
new String'(Short_Source_Name_String.all (First_Idx .. Last_Idx));
New_SF_Record.Status := To_Stub_Body;
New_SF_Record.Project_Name := new String'(Pname);
New_SF_Record.Unit_Name := new String'(Uname);
Insert (SF_Table, Full_Source_Name_String.all, New_SF_Record);
Include
(SFL_Table,
Normalize_Pathname (Name => Dir_Name (Full_Source_Name_String.all),
Resolve_Links => False,
Case_Sensitive => False));
Free (Short_Source_Name_String);
Free (Full_Source_Name_String);
end Add_Body_To_Process;
------------------------
-- Add_Body_Reference --
------------------------
procedure Add_Body_Reference (Fname : String) is
First_Idx : Natural;
Last_Idx : Natural;
New_SF_Record : SF_Record;
begin
Trace (Me, "adding source (as reference): " & Fname);
if not Is_Regular_File (Fname) then
Report_Std ("gnattest: " & Fname & " not found");
return;
end if;
Short_Source_Name_String := new String'(Base_Name (Fname));
Full_Source_Name_String :=
new String'(Normalize_Pathname
(Fname,
Resolve_Links => False,
Case_Sensitive => False));
-- Already present specs should not be overridden
if
SF_Table.Find
(Full_Source_Name_String.all) /= Source_File_Table.No_Element
then
return;
end if;
-- Making the new SF_Record
New_SF_Record.Full_Source_Name :=
new String'(Full_Source_Name_String.all);
First_Idx := Short_Source_Name_String'First;
Last_Idx := Short_Source_Name_String'Last;
for J in reverse First_Idx + 1 .. Last_Idx loop
if Short_Source_Name_String (J) = '.' then
Last_Idx := J - 1;
exit;
end if;
end loop;
New_SF_Record.Suffixless_Name :=
new String'(Short_Source_Name_String.all (First_Idx .. Last_Idx));
New_SF_Record.Status := Body_Reference;
declare
Given_File : constant GNATCOLL.VFS.Virtual_File :=
Create (+Fname);
Other_File : constant GNATCOLL.VFS.Virtual_File :=
Source_Project_Tree.Other_File (Given_File);
F_Info : constant File_Info :=
Source_Project_Tree.Info (Given_File);
P : Project_Type;
begin
if Given_File /= Other_File
and then Is_Regular_File (Other_File.Display_Full_Name)
then
New_SF_Record.Corresponding_Body :=
new String'(Other_File.Display_Full_Name);
end if;
New_SF_Record.Stub_Data_Base_Spec := new String'
(+
(File_From_Unit
(Project => F_Info.Project,
Unit_Name =>
F_Info.Unit_Name & "." & Stub_Data_Unit_Name,
Part => Unit_Spec,
Language => F_Info.Language,
File_Must_Exist => False)));
New_SF_Record.Stub_Data_Base_Body := new String'
(+
(File_From_Unit
(Project => F_Info.Project,
Unit_Name =>
F_Info.Unit_Name & "." & Stub_Data_Unit_Name,
Part => Unit_Body,
Language => F_Info.Language,
File_Must_Exist => False)));
P := F_Info.Project;
loop
exit when Extending_Project (P) = No_Project;
P := Extending_Project (P);
end loop;
New_SF_Record.Project_Name := new String'(P.Name);
New_SF_Record.Unit_Name := new String'(F_Info.Unit_Name);
end;
Insert (SF_Table, Full_Source_Name_String.all, New_SF_Record);
if not Main_Units.Is_Empty then
Sources_Left := Sources_Left + 1;
Total_Sources := Total_Sources + 1;
end if;
Free (Short_Source_Name_String);
Free (Full_Source_Name_String);
end Add_Body_Reference;
----------------
-- Is_Empty --
----------------
function SF_Table_Empty return Boolean is
Empty : constant Boolean := Is_Empty (SF_Table);
Cur : Source_File_Table.Cursor;
begin
if Empty then
return Empty;
else
Cur := SF_Table.First;
while Cur /= Source_File_Table.No_Element loop
if Element (Cur).Status /= To_Stub_Body then
return False;
end if;
Next (Cur);
end loop;
return True;
end if;
end SF_Table_Empty;
--------------------------------------
-- Enforce_Custom_Project_Extention --
--------------------------------------
procedure Enforce_Custom_Project_Extention
(File_Name : String;
Subroot_Stub_Prj : String;
Current_Source_Infix : String)
is
Short_Name : constant String := Base_Name (File_Name);
Excluded_Sources : String_Set.Set := String_Set.Empty_Set;
Current_Proj_Present_Sources : String_Set.Set := String_Set.Empty_Set;
Processed_Projects : String_Set.Set := String_Set.Empty_Set;
SS_Cur : String_Set.Cursor;
Subroot_Prj_Name : constant String :=
Get_Source_Project_Name (File_Name);
procedure Process_Project (Proj : String);
procedure Set_Present_Subset_For_Project (Proj : String);
procedure Process_Project (Proj : String) is
Cur, I_Cur : List_Of_Strings.Cursor;
E_Cur : String_Set.Cursor;
Arg_Proj : Project_Record;
Relative_P_Path, Relative_I_Path : String_Access;
begin
if Processed_Projects.Contains (Proj) then
return;
end if;
Processed_Projects.Include (Proj);
Arg_Proj := PF_Table.Element (Proj);
if Proj = Subroot_Prj_Name then
-- The root of the subtree is extended by the test driver project.
goto Process_Imported;
end if;
if Arg_Proj.Needed_For_Extention then
declare
F : File_Array_Access;
begin
Append
(F,
GNATCOLL.VFS.Create
(+(Arg_Proj.Stub_Dir.all)));
Append
(F,
GNATCOLL.VFS.Create
(+(Arg_Proj.Stub_Dir.all
& Directory_Separator
& Unit_To_File_Name
(Stub_Project_Prefix & Current_Source_Infix & Proj))));
if Arg_Proj.Is_Library then
Append
(F,
GNATCOLL.VFS.Create
(+(Arg_Proj.Stub_Dir.all
& Directory_Separator
& Unit_To_File_Name
(Stub_Project_Prefix
& Current_Source_Infix
& Proj
& "_lib"))));
end if;
Create_Dirs (F);
end;
Relative_P_Path := new String'
(+Relative_Path
(Create (+Arg_Proj.Path.all),
Create (+Arg_Proj.Stub_Dir.all)));
Trace
(Me,
"Creating "
& Arg_Proj.Stub_Dir.all
& Directory_Separator
& Unit_To_File_Name
(Stub_Project_Prefix & Current_Source_Infix & Proj)
& ".gpr");
Create
(Arg_Proj.Stub_Dir.all
& Directory_Separator
& Unit_To_File_Name
(Stub_Project_Prefix & Current_Source_Infix & Proj)
& ".gpr");
I_Cur := Arg_Proj.Imported_List.First;
while I_Cur /= List_Of_Strings.No_Element loop
if
PF_Table.Element
(List_Of_Strings.Element (I_Cur)).Needed_For_Extention
then
declare
Imported_Sub_Project : constant String :=
PF_Table.Element
(List_Of_Strings.Element (I_Cur)).Stub_Dir.all
& Directory_Separator
& To_Lower (Stub_Project_Prefix
& Current_Source_Infix
& List_Of_Strings.Element (I_Cur))
& ".gpr";
begin
if List_Of_Strings.Element (I_Cur) = Subroot_Prj_Name then
Relative_I_Path := new String'
(+Relative_Path (Create (+Subroot_Stub_Prj),
Create (+Arg_Proj.Stub_Dir.all)));
else
Relative_I_Path := new String'
(+Relative_Path (Create (+Imported_Sub_Project),
Create (+Arg_Proj.Stub_Dir.all)));
end if;
end;
if Arg_Proj.Limited_Withed.Contains
(List_Of_Strings.Element (I_Cur))
then
S_Put
(0,
"limited with """
& Relative_I_Path.all
& """;");
else
S_Put
(0,
"with """
& Relative_I_Path.all
& """;");
end if;
Put_New_Line;
end if;
Next (I_Cur);
end loop;
S_Put
(0,
"project "
& Stub_Project_Prefix
& Current_Source_Infix
& Proj
& " extends """
& Relative_P_Path.all
& """ is");
Put_New_Line;
S_Put (3, "for Source_Dirs use (""."");");
Put_New_Line;
Set_Present_Subset_For_Project (Proj);
E_Cur := Current_Proj_Present_Sources.First;
if E_Cur /= String_Set.No_Element then
S_Put (3, "for Source_Files use (");
Put_New_Line;
else
S_Put (3, "for Source_Files use ();");
Put_New_Line;
end if;
while E_Cur /= String_Set.No_Element loop
if not Excluded_Test_Data_Files.Contains
(Get_Source_Stub_Data_Spec (String_Set.Element (E_Cur)))
then
S_Put
(6,
""""
& Base_Name
(Get_Source_Stub_Data_Spec (String_Set.Element (E_Cur)))
& """,");
Put_New_Line;
end if;
if not Excluded_Test_Data_Files.Contains
(Get_Source_Stub_Data_Body (String_Set.Element (E_Cur)))
then
S_Put
(6,
""""
& Base_Name
(Get_Source_Stub_Data_Body (String_Set.Element (E_Cur)))
& """,");
Put_New_Line;
end if;
S_Put
(6,
""""
& Base_Name (Get_Source_Body (String_Set.Element (E_Cur)))
& """");
Next (E_Cur);
if E_Cur = String_Set.No_Element then
S_Put (0, ");");
else
S_Put (0, ",");
end if;
Put_New_Line;
end loop;
S_Put
(3,
"for Object_Dir use """
& Unit_To_File_Name
(Stub_Project_Prefix & Current_Source_Infix & Proj)
& """;");
Put_New_Line;
if Arg_Proj.Is_Library then
S_Put
(3,
"for Library_Dir use """
& Unit_To_File_Name
(Stub_Project_Prefix
& Current_Source_Infix & Proj & "_lib")
& """;");
Put_New_Line;
S_Put
(3,
"for Library_Name use """
& Unit_To_File_Name
(Stub_Project_Prefix & Current_Source_Infix & Proj)
& """;");
Put_New_Line;
end if;
Put_New_Line;
E_Cur := Current_Proj_Present_Sources.First;
if E_Cur /= String_Set.No_Element then
S_Put (3, "package Coverage is");
Put_New_Line;
S_Put (6, "for Excluded_Units use (");
Put_New_Line;
while E_Cur /= String_Set.No_Element loop
S_Put
(9,
""""
& Get_Source_Unit_Name
(Get_Source_Body (String_Set.Element (E_Cur)))
& """");
Next (E_Cur);
if E_Cur = String_Set.No_Element then
S_Put (0, ");");
else
S_Put (0, ",");
end if;
Put_New_Line;
end loop;
S_Put (3, "end Coverage;");
Put_New_Line;
end if;
S_Put
(0,
"end "
& Stub_Project_Prefix
& Current_Source_Infix
& Proj
& ";");
Close_File;
end if;
<<Process_Imported>>
Cur := Arg_Proj.Imported_List.First;
while Cur /= List_Of_Strings.No_Element loop
Process_Project (List_Of_Strings.Element (Cur));
Next (Cur);
end loop;
end Process_Project;
procedure Set_Present_Subset_For_Project (Proj : String) is
Cur : Source_File_Table.Cursor := SF_Table.First;
begin
Current_Proj_Present_Sources.Clear;
while Cur /= Source_File_Table.No_Element loop
declare
Key : constant String := Source_File_Table.Key (Cur);
begin
if Source_File_Table.Element (Cur).Project_Name.all = Proj
and then not Is_Body (Key)
and then Source_Stubbed (Key)
and then not Excluded_Sources.Contains (Base_Name (Key))
then
Current_Proj_Present_Sources.Include
(Source_File_Table.Key (Cur));
end if;
end;
Next (Cur);
end loop;
end Set_Present_Subset_For_Project;
begin
Union (Excluded_Sources, Default_Stub_Exclusion_List);
if Stub_Exclusion_Lists.Contains (Short_Name) then
Union (Excluded_Sources, Stub_Exclusion_Lists.Element (Short_Name));
end if;
if Excluded_Sources.Is_Empty then
Trace
(Me,
"No special extending project subtree needed for" & Short_Name);
return;
end if;
Trace
(Me, "Creating extending project subtree for source " & Short_Name);
if Verbose then
Trace (Me, "Current infix is " & Current_Source_Infix);
Trace (Me, "Root of subtree is " & Subroot_Prj_Name);
Trace (Me, "excluded sources are:");
Increase_Indent (Me);
SS_Cur := Excluded_Sources.First;
while SS_Cur /= String_Set.No_Element loop
Trace (Me, String_Set.Element (SS_Cur));
Next (SS_Cur);
end loop;
Decrease_Indent (Me);
end if;
Process_Project (Subroot_Prj_Name);
end Enforce_Custom_Project_Extention;
-------------------------------
-- Enforce_Project_Extention --
-------------------------------
procedure Enforce_Project_Extention
(Prj_Name : String;
Subroot_Stub_Prj : String;
Current_Project_Infix : String)
is
Processed_Projects : String_Set.Set := String_Set.Empty_Set;
Current_Proj_Present_Sources : String_Set.Set := String_Set.Empty_Set;
procedure Process_Project (Proj : String);
procedure Set_Present_Subset_For_Project (Proj : String);
procedure Set_Present_Subset_For_Project (Proj : String) is
Cur : Source_File_Table.Cursor := SF_Table.First;
begin
Current_Proj_Present_Sources.Clear;
while Cur /= Source_File_Table.No_Element loop
declare
Key : constant String := Source_File_Table.Key (Cur);
begin
if Source_File_Table.Element (Cur).Project_Name.all = Proj
and then not Is_Body (Key)
and then Source_Stubbed (Key)
and then not
Default_Stub_Exclusion_List.Contains (Base_Name (Key))
then
Current_Proj_Present_Sources.Include
(Source_File_Table.Key (Cur));
end if;
end;
Next (Cur);
end loop;
end Set_Present_Subset_For_Project;
procedure Process_Project (Proj : String) is
Relative_P_Path, Relative_I_Path : String_Access;
Arg_Proj : Project_Record;
Cur, I_Cur : List_Of_Strings.Cursor;
E_Cur : String_Set.Cursor;
begin
if Processed_Projects.Contains (Proj) then
return;
end if;
Processed_Projects.Include (Proj);
Arg_Proj := PF_Table.Element (Proj);
if Proj = Prj_Name then
-- The root of the subtree is extended by the test driver project.
goto Process_Imported;
end if;
-- generating stuff
if Arg_Proj.Needed_For_Extention then
declare
F : File_Array_Access;
begin
Append
(F,
GNATCOLL.VFS.Create
(+(Arg_Proj.Stub_Dir.all)));
Append
(F,
GNATCOLL.VFS.Create
(+(Arg_Proj.Stub_Dir.all
& Directory_Separator
& Unit_To_File_Name
(Stub_Project_Prefix & Current_Project_Infix & Proj))));
if Arg_Proj.Is_Library then
Append
(F,
GNATCOLL.VFS.Create
(+(Arg_Proj.Stub_Dir.all
& Directory_Separator
& Unit_To_File_Name
(Stub_Project_Prefix
& Current_Project_Infix
& Proj
& "_lib"))));
end if;
Create_Dirs (F);
end;
Relative_P_Path := new String'
(+Relative_Path
(Create (+Arg_Proj.Path.all),
Create (+Arg_Proj.Stub_Dir.all)));
Trace
(Me,
"Creating "
& Arg_Proj.Stub_Dir.all
& Directory_Separator
& Unit_To_File_Name
(Stub_Project_Prefix & Current_Project_Infix & Proj)
& ".gpr");
Create
(Arg_Proj.Stub_Dir.all
& Directory_Separator
& Unit_To_File_Name
(Stub_Project_Prefix & Current_Project_Infix & Proj)
& ".gpr");
I_Cur := Arg_Proj.Imported_List.First;
while I_Cur /= List_Of_Strings.No_Element loop
if
PF_Table.Element
(List_Of_Strings.Element (I_Cur)).Needed_For_Extention
then
declare
Imported_Sub_Project : constant String :=
PF_Table.Element
(List_Of_Strings.Element (I_Cur)).Stub_Dir.all
& Directory_Separator
& To_Lower (Stub_Project_Prefix
& Current_Project_Infix
& List_Of_Strings.Element (I_Cur))
& ".gpr";
begin
if List_Of_Strings.Element (I_Cur) = Prj_Name then
Relative_I_Path := new String'
(+Relative_Path (Create (+Subroot_Stub_Prj),
Create (+Arg_Proj.Stub_Dir.all)));
else
Relative_I_Path := new String'
(+Relative_Path (Create (+Imported_Sub_Project),
Create (+Arg_Proj.Stub_Dir.all)));
end if;
end;
if Arg_Proj.Limited_Withed.Contains
(List_Of_Strings.Element (I_Cur))
then
S_Put
(0,
"limited with """
& Relative_I_Path.all
& """;");
else
S_Put
(0,
"with """
& Relative_I_Path.all
& """;");
end if;
Put_New_Line;
end if;
Next (I_Cur);
end loop;
S_Put
(0,
"project "
& Stub_Project_Prefix
& Current_Project_Infix
& Proj
& " extends """
& Relative_P_Path.all
& """ is");
Put_New_Line;
S_Put (3, "for Source_Dirs use (""."");");
Put_New_Line;
Set_Present_Subset_For_Project (Proj);
E_Cur := Current_Proj_Present_Sources.First;
if E_Cur /= String_Set.No_Element then
S_Put (3, "for Source_Files use (");
Put_New_Line;
else
S_Put (3, "for Source_Files use ();");
Put_New_Line;
end if;
while E_Cur /= String_Set.No_Element loop
if not Excluded_Test_Data_Files.Contains
(Get_Source_Stub_Data_Spec (String_Set.Element (E_Cur)))
then
S_Put
(6,
""""
& Base_Name
(Get_Source_Stub_Data_Spec (String_Set.Element (E_Cur)))
& """,");
Put_New_Line;
end if;
if not Excluded_Test_Data_Files.Contains
(Get_Source_Stub_Data_Body (String_Set.Element (E_Cur)))
then
S_Put
(6,
""""
& Base_Name
(Get_Source_Stub_Data_Body (String_Set.Element (E_Cur)))
& """,");
Put_New_Line;
end if;
S_Put
(6,
""""
& Base_Name (Get_Source_Body (String_Set.Element (E_Cur)))
& """");
Next (E_Cur);
if E_Cur = String_Set.No_Element then
S_Put (0, ");");
else
S_Put (0, ",");
end if;
Put_New_Line;
end loop;
S_Put
(3,
"for Object_Dir use """
& Unit_To_File_Name
(Stub_Project_Prefix & Current_Project_Infix & Proj)
& """;");
Put_New_Line;
if Arg_Proj.Is_Library then
S_Put
(3,
"for Library_Dir use """
& Unit_To_File_Name
(Stub_Project_Prefix
& Current_Project_Infix & Proj & "_lib")
& """;");
Put_New_Line;
S_Put
(3,
"for Library_Name use """
& Unit_To_File_Name
(Stub_Project_Prefix & Current_Project_Infix & Proj)
& """;");
Put_New_Line;
end if;
Put_New_Line;
E_Cur := Current_Proj_Present_Sources.First;
if E_Cur /= String_Set.No_Element then
S_Put (3, "package Coverage is");
Put_New_Line;
S_Put (6, "for Excluded_Units use (");
Put_New_Line;
while E_Cur /= String_Set.No_Element loop
S_Put
(9,
""""
& Get_Source_Unit_Name
(Get_Source_Body (String_Set.Element (E_Cur)))
& """");
Next (E_Cur);
if E_Cur = String_Set.No_Element then
S_Put (0, ");");
else
S_Put (0, ",");
end if;
Put_New_Line;
end loop;
S_Put (3, "end Coverage;");
Put_New_Line;
end if;
S_Put
(0,
"end "
& Stub_Project_Prefix
& Current_Project_Infix
& Proj
& ";");
Close_File;
end if;
<<Process_Imported>>
Cur := Arg_Proj.Imported_List.First;
while Cur /= List_Of_Strings.No_Element loop
Process_Project (List_Of_Strings.Element (Cur));
Next (Cur);
end loop;
end Process_Project;
begin
Process_Project (Prj_Name);
end Enforce_Project_Extention;
---------------------------
-- Get_Imported_Projects --
---------------------------
function Get_Imported_Projects (Project_Name : String)
return List_Of_Strings.List
is
begin
return Project_File_Table.Element
(PF_Table, Project_Name).Imported_List;
end Get_Imported_Projects;
----------------------------
-- Get_Importing_Projects --
----------------------------
function Get_Importing_Projects (Project_Name : String)
return List_Of_Strings.List
is
begin
return Project_File_Table.Element
(PF_Table, Project_Name).Importing_List;
end Get_Importing_Projects;
----------------------
-- Get_Project_Path --
----------------------
function Get_Project_Path (Project_Name : String) return String is
begin
return Project_File_Table.Element
(PF_Table, Project_Name).Path.all;
end Get_Project_Path;
--------------------------
-- Get_Project_Stub_Dir --
--------------------------
function Get_Project_Stub_Dir (Project_Name : String) return String is
begin
return Project_File_Table.Element
(PF_Table, Project_Name).Stub_Dir.all;
end Get_Project_Stub_Dir;
---------------------
-- Get_Source_Body --
---------------------
function Get_Source_Body (Source_Name : String) return String
is
SN : constant String :=
Normalize_Pathname
(Name => Source_Name,
Resolve_Links => False,
Case_Sensitive => False);
SFR : SF_Record;
begin
if Source_Present (SN) then
SFR := Source_File_Table.Element (SF_Table, SN);
else
Report_Std
("warning: "
& Source_Name
& " is not a source of argument project");
Report_Std
(" cannot create stub");
return "";
end if;
if SFR.Corresponding_Body = null then
return "";
else
return SFR.Corresponding_Body.all;
end if;
end Get_Source_Body;
-----------------------------
-- Get_Source_Output_Dir --
-----------------------------
function Get_Source_Output_Dir (Source_Name : String) return String
is
SN : constant String :=
Normalize_Pathname
(Name => Source_Name,
Resolve_Links => False,
Case_Sensitive => False);
SR : constant SF_Record := Source_File_Table.Element (SF_Table, SN);
begin
if SR.Test_Destination = null then
return "";
else
return SR.Test_Destination.all;
end if;
end Get_Source_Output_Dir;
------------------------
-- Get_Source_Project --
------------------------
function Get_Source_Project_Name (Source_Name : String) return String
is
SN : constant String :=
Normalize_Pathname
(Name => Source_Name,
Resolve_Links => False,
Case_Sensitive => False);
begin
return Source_File_Table.Element
(SF_Table, SN).Project_Name.all;
end Get_Source_Project_Name;
--------------------------
-- Get_Source_Unit_Name --
--------------------------
function Get_Source_Unit_Name (Source_Name : String) return String
is
SN : constant String :=
Normalize_Pathname
(Name => Source_Name,
Resolve_Links => False,
Case_Sensitive => False);
begin
return Source_File_Table.Element
(SF_Table, SN).Unit_Name.all;
end Get_Source_Unit_Name;
-------------------------
-- Get_Source_Stub_Dir --
-------------------------
function Get_Source_Stub_Dir (Source_Name : String) return String
is
SN : constant String :=
Normalize_Pathname
(Name => Source_Name,
Resolve_Links => False,
Case_Sensitive => False);
begin
return Source_File_Table.Element
(SF_Table, SN).Stub_Destination.all;
end Get_Source_Stub_Dir;
-------------------------------
-- Get_Source_Stub_Data_Body --
-------------------------------
function Get_Source_Stub_Data_Body (Source_Name : String) return String
is
SN : constant String :=
Normalize_Pathname
(Name => Source_Name,
Resolve_Links => False,
Case_Sensitive => False);
begin
return Source_File_Table.Element
(SF_Table, SN).Stub_Data_Base_Body.all;
end Get_Source_Stub_Data_Body;
-------------------------------
-- Get_Source_Stub_Data_Spec --
-------------------------------
function Get_Source_Stub_Data_Spec (Source_Name : String) return String
is
SN : constant String :=
Normalize_Pathname
(Name => Source_Name,
Resolve_Links => False,
Case_Sensitive => False);
begin
return Source_File_Table.Element
(SF_Table, SN).Stub_Data_Base_Spec.all;
end Get_Source_Stub_Data_Spec;
-------------------------
-- Get_Source_Status --
-------------------------
function Get_Source_Status (Source_Name : String) return SF_Status
is
SN : constant String :=
Normalize_Pathname
(Name => Source_Name,
Resolve_Links => False,
Case_Sensitive => False);
begin
return Source_File_Table.Element
(SF_Table, SN).Status;
end Get_Source_Status;
----------------------------------
-- Get_Source_Suffixless_Name --
----------------------------------
function Get_Source_Suffixless_Name (Source_Name : String) return String
is
SN : constant String :=
Normalize_Pathname
(Name => Source_Name,
Resolve_Links => False,
Case_Sensitive => False);
begin
return Source_File_Table.Element
(SF_Table, SN).Suffixless_Name.all;
end Get_Source_Suffixless_Name;
------------------------------
-- Initialize_Project_Table --
------------------------------
procedure Initialize_Project_Table is
Iter, Importing, Imported : Project_Iterator;
P, P2 : Project_Type;
Attr : constant Attribute_Pkg_String := Build ("", "externally_built");
begin
Trace (Me, "Initialize_Project_Table");
Increase_Indent (Me);
Iter := Start (Source_Project_Tree.Root_Project);
while Current (Iter) /= No_Project loop
P := Current (Iter);
Trace (Me, "processing " & P.Name);
if Extending_Project (P) /= No_Project then
-- We do not want extended projects in the table.
goto Next_Project;
end if;
declare
PR : Project_Record;
begin
if Has_Attribute (P, Attr) then
if To_Lower (Attribute_Value (P, Attr)) = "true" then
PR.Is_Externally_Built := True;
-- Nothing should be done for sources of externally built
-- projects, so no point in calculating obj dirs and so on.
goto Add_Project;
end if;
end if;
PR.Is_Externally_Built := False;
if P = Source_Project_Tree.Root_Project then
PR.Needed_For_Extention := True;
end if;
if Has_Attribute (P, Library_Name_Attribute)
and then Attribute_Value (P, Library_Name_Attribute) /= ""
then
PR.Is_Library := True;
end if;
PR.Path := new String'(P.Project_Path.Display_Full_Name);
PR.Obj_Dir := new String'(P.Object_Dir.Display_Full_Name);
if Is_Absolute_Path (Stub_Dir_Name.all) then
PR.Stub_Dir := new String'
(Stub_Dir_Name.all
& Directory_Separator
& P.Name);
else
PR.Stub_Dir := new String'
(P.Object_Dir.Display_Full_Name
& Stub_Dir_Name.all
& Directory_Separator
& P.Name);
end if;
Increase_Indent (Me, "imported projects:");
P2 := P;
while P2 /= No_Project loop
Imported :=
P2.Start (Direct_Only => True, Include_Extended => False);
while Current (Imported) /= No_Project loop
PR.Imported_List.Append (Current (Imported).Name);
if Is_Limited_With (Imported) then
PR.Limited_Withed.Include (Current (Imported).Name);
end if;
Trace (Me, Current (Imported).Name);
Next (Imported);
end loop;
P2 := Extended_Project (P2);
end loop;
Decrease_Indent (Me);
Importing := P.Find_All_Projects_Importing (Direct_Only => True);
Increase_Indent (Me, "importing projects:");
while Current (Importing) /= No_Project loop
PR.Importing_List.Append (Current (Importing).Name);
Trace (Me, Current (Importing).Name);
Next (Importing);
end loop;
Decrease_Indent (Me);
<<Add_Project>>
PF_Table.Include (P.Name, PR);
end;
<<Next_Project>>
Next (Iter);
end loop;
Decrease_Indent (Me);
end Initialize_Project_Table;
-------------
-- Is_Body --
-------------
function Is_Body (Source_Name : String) return Boolean
is
SN : constant String :=
Normalize_Pathname
(Name => Source_Name,
Resolve_Links => False,
Case_Sensitive => False);
begin
return Source_File_Table.Element
(SF_Table, SN).Corresponding_Body = null;
end Is_Body;
----------------------------------------
-- Mark_Projects_With_Stubbed_Sources --
----------------------------------------
procedure Mark_Projects_With_Stubbed_Sources is
S_Cur : Source_File_Table.Cursor := SF_Table.First;
PR : Project_Record;
Processed_Projects : String_Set.Set;
P_Cur : Project_File_Table.Cursor;
procedure Process_Project (S : String);
procedure Process_Project (S : String) is
Cur : List_Of_Strings.Cursor;
Local_PR : Project_Record;
begin
Trace (Me, "Process_Project " & S);
if Processed_Projects.Contains (S) then
return;
end if;
Processed_Projects.Include (S);
if PF_Table.Element (S).Is_Externally_Built then
-- Nothing to do for those.
return;
end if;
Local_PR := PF_Table.Element (S);
Local_PR.Needed_For_Extention := True;
PF_Table.Replace (S, Local_PR);
Cur := Local_PR.Importing_List.First;
while Cur /= List_Of_Strings.No_Element loop
Process_Project (List_Of_Strings.Element (Cur));
Next (Cur);
end loop;
end Process_Project;
begin
Trace (Me, "Mark_Projects_With_Stubbed_Sources");
Increase_Indent (Me);
-- First, mark all projects that have sources that have been stubbed.
while S_Cur /= Source_File_Table.No_Element loop
if Source_File_Table.Element (S_Cur).Stub_Created then
PR :=
PF_Table.Element
(Source_File_Table.Element (S_Cur).Project_Name.all);
PR.Needed_For_Extention := True;
Trace
(Me,
Source_File_Table.Element (S_Cur).Project_Name.all
& " has stubbed sources");
PF_Table.Replace
(Source_File_Table.Element (S_Cur).Project_Name.all,
PR);
end if;
Next (S_Cur);
end loop;
-- Now we need to also mark all projects that are imported by any
-- of already marked ones.
P_Cur := PF_Table.First;
while P_Cur /= Project_File_Table.No_Element loop
if
not Processed_Projects.Contains (Project_File_Table.Key (P_Cur))
and then Project_File_Table.Element (P_Cur).Needed_For_Extention
then
Process_Project (Project_File_Table.Key (P_Cur));
end if;
Next (P_Cur);
end loop;
Decrease_Indent (Me);
end Mark_Projects_With_Stubbed_Sources;
-------------------------
-- Mark_Sourse_Stubbed --
-------------------------
procedure Mark_Sourse_Stubbed (Source_Name : String) is
SF_Rec : SF_Record;
SN : constant String :=
Normalize_Pathname
(Name => Source_Name,
Resolve_Links => False,
Case_Sensitive => False);
begin
SF_Rec := Source_File_Table.Element (SF_Table, SN);
SF_Rec.Stub_Created := True;
Replace (SF_Table, SN, SF_Rec);
end Mark_Sourse_Stubbed;
---------------------------------
-- Next_Non_Processed_Source --
---------------------------------
function Next_Non_Processed_Source return String is
Cur : Source_File_Table.Cursor := Source_File_Table.No_Element;
begin
Reset_Source_Process_Iterator;
loop
if Cur = Source_File_Table.No_Element and then
Source_File_Table.Element (SF_Process_Iterator).Status = Pending
then
Cur := SF_Process_Iterator;
end if;
if
Source_File_Table.Element (SF_Process_Iterator).Status = Waiting
then
Free (Current_Source);
Current_Source := new String'(Key (SF_Process_Iterator));
return Key (SF_Process_Iterator);
end if;
Next (SF_Process_Iterator);
exit when SF_Process_Iterator = Source_File_Table.No_Element;
end loop;
if Cur /= Source_File_Table.No_Element then
Free (Current_Source);
Current_Source := new String'(Key (Cur));
return Key (Cur);
end if;
Free (Current_Source);
return "";
end Next_Non_Processed_Source;
-----------------------------
-- Get_Current_Source_Spec --
-----------------------------
function Get_Current_Source_Spec return String is
begin
if Current_Source = null then
return "";
else
return Current_Source.all;
end if;
end Get_Current_Source_Spec;
----------------------------
-- Next_Source_Location --
----------------------------
function Next_Source_Location return String is
Cur : Source_File_Locations.Cursor;
begin
if SFL_Iterator /= Source_File_Locations.No_Element then
Cur := SFL_Iterator;
Source_File_Locations.Next (SFL_Iterator);
return Source_File_Locations.Element (Cur);
else
return "";
end if;
end Next_Source_Location;
------------------------
-- Next_Source_Name --
------------------------
function Next_Source_Name return String is
Cur : Source_File_Table.Cursor;
begin
if SF_Access_Iterator /= Source_File_Table.No_Element then
Cur := SF_Access_Iterator;
Source_File_Table.Next (SF_Access_Iterator);
return Key (Cur);
else
return "";
end if;
end Next_Source_Name;
----------------------
-- Project_Extended --
----------------------
function Project_Extended (Project_Name : String) return Boolean is
begin
return Project_File_Table.Element
(PF_Table, Project_Name).Needed_For_Extention;
end Project_Extended;
-------------------
-- Report_Source --
-------------------
procedure Report_Source (S : String) is
Im : constant String := Natural'Image (Sources_Left - 1);
SN : constant String :=
Normalize_Pathname
(Name => S,
Resolve_Links => False,
Case_Sensitive => False);
begin
Trace (Me, "reporting source: " & S);
if not Source_Present (SN) then
return;
end if;
if Progress_Indicator_Mode then
declare
Current : constant Integer := Total_Sources - Sources_Left + 1;
Percent : String :=
Integer'Image ((Current * 100) / Total_Sources);
begin
Percent (1) := '(';
Info
("completed" & Integer'Image (Current) & " out of"
& Integer'Image (Total_Sources) & " "
& Percent & "%)...");
end;
end if;
begin
Sources_Left := Sources_Left - 1;
exception
when Constraint_Error =>
Report_Err ("gnattest: inconsistent state of sources detected");
raise Fatal_Error;
end;
if Verbose then
Report_Std
("[" & Im (2 .. Im'Last) & "] " & Base_Name (SN));
end if;
end Report_Source;
-------------------------------
-- Reset_Location_Iterator --
-------------------------------
procedure Reset_Location_Iterator is
begin
SFL_Iterator := First (SFL_Table);
end Reset_Location_Iterator;
-----------------------------
-- Reset_Source_Iterator --
-----------------------------
procedure Reset_Source_Iterator is
begin
SF_Access_Iterator := First (SF_Table);
end Reset_Source_Iterator;
-------------------------------------
-- Reset_Source_Process_Iterator --
-------------------------------------
procedure Reset_Source_Process_Iterator is
begin
SF_Process_Iterator := First (SF_Table);
end Reset_Source_Process_Iterator;
------------------
-- Set_Status --
------------------
procedure Set_Source_Status (Source_Name : String;
New_Status : SF_Status) is
SF_Rec : SF_Record;
SN : constant String :=
Normalize_Pathname
(Name => Source_Name,
Resolve_Links => False,
Case_Sensitive => False);
begin
SF_Rec := Source_File_Table.Element (SF_Table, SN);
SF_Rec.Status := New_Status;
Replace (SF_Table, SN, SF_Rec);
end Set_Source_Status;
-------------------------
-- Set_Subdir_Output --
-------------------------
procedure Set_Subdir_Output is
SF_Rec : SF_Record;
Tmp_Str : String_Access;
SF_Rec_Key : String_Access;
Cur : Source_File_Table.Cursor := SF_Table.First;
begin
Increase_Indent (Me, "Set_Subdir_Output");
loop
exit when Cur = Source_File_Table.No_Element;
SF_Rec := Source_File_Table.Element (Cur);
SF_Rec_Key := new String'(Key (Cur));
Trace (Me, "processing: " & SF_Rec_Key.all);
Tmp_Str := new String'(Dir_Name (SF_Rec.Full_Source_Name.all));
SF_Rec.Test_Destination :=
new String'(Tmp_Str.all &
Test_Subdir_Name.all &
Directory_Separator);
Replace (SF_Table, SF_Rec_Key.all, SF_Rec);
Source_File_Table.Next (Cur);
Free (SF_Rec_Key);
Free (Tmp_Str);
end loop;
Decrease_Indent (Me);
end Set_Subdir_Output;
-------------------------
-- Set_Separate_Root --
-------------------------
procedure Set_Separate_Root (Max_Common_Root : String) is
SF_Rec : SF_Record;
Tmp_Str : String_Access;
SF_Rec_Key : String_Access;
Cur : Source_File_Table.Cursor := SF_Table.First;
Idx : Integer;
begin
Increase_Indent (Me, "Set_Separate_Root");
loop
exit when Cur = Source_File_Table.No_Element;
SF_Rec := Source_File_Table.Element (Cur);
SF_Rec_Key := new String'(Key (Cur));
Trace (Me, "processing: " & SF_Rec_Key.all);
Tmp_Str := new String'(Dir_Name (SF_Rec.Full_Source_Name.all));
Idx := Max_Common_Root'Last + 1;
SF_Rec.Test_Destination :=
new String'(Separate_Root_Dir.all &
Directory_Separator &
Tmp_Str.all (Idx .. Tmp_Str.all'Last));
Replace (SF_Table, SF_Rec_Key.all, SF_Rec);
Source_File_Table.Next (Cur);
Free (SF_Rec_Key);
Free (Tmp_Str);
end loop;
Decrease_Indent (Me);
end Set_Separate_Root;
-----------------------
-- Set_Direct_Output --
-----------------------
procedure Set_Direct_Output is
SF_Rec : SF_Record;
Tmp_Str : String_Access;
SF_Rec_Key : String_Access;
Cur : Source_File_Table.Cursor := SF_Table.First;
Project : Project_Type;
TD_Name : constant Virtual_File :=
GNATCOLL.VFS.Create (+Test_Dir_Name.all);
begin
loop
exit when Cur = Source_File_Table.No_Element;
SF_Rec := Source_File_Table.Element (Cur);
SF_Rec_Key := new String'(Key (Cur));
if TD_Name.Is_Absolute_Path then
SF_Rec.Test_Destination := new String'(Test_Dir_Name.all);
else
Project := GNATCOLL.Projects.Project (Info
(Source_Project_Tree,
GNATCOLL.VFS.Create (+SF_Rec.Full_Source_Name.all)));
SF_Rec.Test_Destination := new String'
(Project.Object_Dir.Display_Full_Name & Test_Dir_Name.all);
end if;
Replace (SF_Table, SF_Rec_Key.all, SF_Rec);
Source_File_Table.Next (Cur);
Free (SF_Rec_Key);
Free (Tmp_Str);
end loop;
end Set_Direct_Output;
----------------------------
-- Set_Direct_Stub_Output --
----------------------------
procedure Set_Direct_Stub_Output is
SF_Rec : SF_Record;
Tmp_Str : String_Access;
SF_Rec_Key : String_Access;
Cur : Source_File_Table.Cursor := SF_Table.First;
Project : Project_Type;
TD_Name : constant Virtual_File :=
GNATCOLL.VFS.Create (+Stub_Dir_Name.all);
begin
loop
exit when Cur = Source_File_Table.No_Element;
SF_Rec := Source_File_Table.Element (Cur);
SF_Rec_Key := new String'(Key (Cur));
Project := GNATCOLL.Projects.Project
(Info (Source_Project_Tree,
GNATCOLL.VFS.Create (+SF_Rec.Full_Source_Name.all)));
loop
exit when Extending_Project (Project) = No_Project;
Project := Extending_Project (Project);
end loop;
-- Better use subdirs to separate stubs from different projects.
if TD_Name.Is_Absolute_Path then
SF_Rec.Stub_Destination := new String'
(Stub_Dir_Name.all
& Directory_Separator
& Project.Name);
else
SF_Rec.Stub_Destination := new String'
(Project.Object_Dir.Display_Full_Name
& Stub_Dir_Name.all
& Directory_Separator
& Project.Name);
end if;
Replace (SF_Table, SF_Rec_Key.all, SF_Rec);
Source_File_Table.Next (Cur);
Free (SF_Rec_Key);
Free (Tmp_Str);
end loop;
end Set_Direct_Stub_Output;
--------------------
-- Set_Output_Dir --
--------------------
procedure Set_Output_Dir (Source_Name : String; Output_Dir : String) is
SF_Rec : SF_Record;
SN : constant String :=
Normalize_Pathname
(Name => Source_Name,
Resolve_Links => False,
Case_Sensitive => False);
begin
Trace (Me, "Set_Output_Dir for " & Source_Name);
SF_Rec := SF_Table.Element (SN);
SF_Rec.Test_Destination := new String'(Output_Dir);
Replace (SF_Table, SN, SF_Rec);
end Set_Output_Dir;
---------------------------
-- Set_Parallel_Output --
---------------------------
procedure Set_Parallel_Output is
SF_Rec : SF_Record;
Tmp_Str : String_Access;
SF_Rec_Key : String_Access;
Cur : Source_File_Table.Cursor := SF_Table.First;
Idx_F : Integer;
begin
loop
exit when Cur = Source_File_Table.No_Element;
SF_Rec := Source_File_Table.Element (Cur);
SF_Rec_Key := new String'(Key (Cur));
Tmp_Str := new String'(Dir_Name (SF_Rec.Full_Source_Name.all));
Idx_F := Tmp_Str.all'First;
for Idx_L in reverse Idx_F .. Tmp_Str.all'Last - 1 loop
if Tmp_Str.all (Idx_L) = Directory_Separator then
SF_Rec.Test_Destination :=
new String'(Tmp_Str.all (Idx_F .. Idx_L) &
Test_Dir_Prefix.all &
Tmp_Str.all (Idx_L + 1 .. Tmp_Str.all'Last - 1) &
Test_Dir_Suffix.all);
exit;
end if;
end loop;
Replace (SF_Table, SF_Rec_Key.all, SF_Rec);
Source_File_Table.Next (Cur);
Free (SF_Rec_Key);
Free (Tmp_Str);
end loop;
end Set_Parallel_Output;
----------------------
-- Source_Present --
----------------------
function Source_Present (Source_Name : String) return Boolean is
SN : constant String :=
Normalize_Pathname
(Name => Source_Name,
Resolve_Links => False,
Case_Sensitive => False);
begin
return Contains (SF_Table, SN);
end Source_Present;
--------------------
-- Source_Stubbed --
--------------------
function Source_Stubbed (Source_Name : String) return Boolean is
SN : constant String :=
Normalize_Pathname
(Name => Source_Name,
Resolve_Links => False,
Case_Sensitive => False);
begin
return Source_File_Table.Element
(SF_Table, SN).Stub_Created;
end Source_Stubbed;
end GNATtest.Skeleton.Source_Table;
|