178
178
function Parse_Compiler_Driver_Command
179
179
(Context : in out Parsing_Context;
180
180
Tmp_Dir : Temporary_Directory;
181
- Command : String_Vectors.Vector) return Compilation_Database;
181
+ Args : String_Vectors.Vector) return Compilation_Database;
182
182
-- Parse a compiler driver command
183
183
184
184
function Parse_Compilation_Command
203
203
Config : Instrumentation_Config) return String_Sets.Set;
204
204
-- Return the list of coverage buffer symbols in the link closure
205
205
206
+ procedure Run_Original_Compiler
207
+ (Context : Parsing_Context;
208
+ Args : String_Vectors.Vector);
209
+ -- Run the wrapped compiler with the given Args
210
+
206
211
-- --------------
207
212
-- Split_Args --
208
213
-- --------------
247
252
function Parse_Compiler_Driver_Command
248
253
(Context : in out Parsing_Context;
249
254
Tmp_Dir : Temporary_Directory;
250
- Command : String_Vectors.Vector) return Compilation_Database
255
+ Args : String_Vectors.Vector) return Compilation_Database
251
256
is
257
+ use type String_Vectors.Vector;
252
258
Result : Compilation_Database;
253
259
Parsed_Link_Command : Boolean := False;
254
260
Commands_Filename : constant String :=
258
264
-- the command we are intercepting is a compile / link target and not
259
265
-- a preprocessing / -### action.
260
266
261
- declare
262
- Arguments : String_Vectors.Vector;
263
- begin
264
- Arguments.Append_Vector (Command);
265
- Arguments.Delete_First;
266
- Arguments.Prepend (+" -###" );
267
- Run_Command
268
- (+Context.Orig_Compiler_Driver,
269
- Arguments,
270
- " gnatcov" ,
271
- Output_File => Commands_Filename);
272
- end ;
267
+ Run_Command
268
+ (+Context.Orig_Compiler_Driver,
269
+ String_Vectors.To_Vector (+" -###" , 1 ) & Args,
270
+ " gnatcov" ,
271
+ Output_File => Commands_Filename);
273
272
274
273
-- Then, parse the files containing the list of launched commands, using
275
274
-- the following heuristics:
287
286
Line : constant String := Get_Line (Commands_File);
288
287
Command : constant String_Vectors.Vector := Split_Args (Line);
289
288
begin
289
+ if Line = " " then
290
+ goto Continue;
291
+ end if ;
290
292
if Ends_With (Command.First_Element, " cc1" )
291
293
or else Ends_With (Command.First_Element, " cc1plus" )
292
294
then
321
323
(Parse_Link_Command (Context, Command));
322
324
Parsed_Link_Command := True;
323
325
end if ;
326
+ <<Continue>>
324
327
end ;
325
328
end loop ;
326
329
end ;
379
382
Cur := Next (Cur);
380
383
end loop ;
381
384
382
- -- Error out if the parsing failed
383
-
384
- if Length (Result.Filename) = 0 then
385
- Outputs.Fatal_Error
386
- (" Could not find source file in compilation command: "
387
- & Img (Command));
388
- elsif Length (Result.Target) = 0 then
389
- Outputs.Fatal_Error
390
- (" Could not find output file in compilation command: "
391
- & Img (Command));
385
+ if Length (Result.Filename) = 0
386
+ or else Length (Result.Target) = 0
387
+ then
388
+ return No_Compilation_Command;
392
389
end if ;
393
390
Context.Source_Mapping.Include (Result.Target, Result.Filename);
394
391
return Result;
622
619
return Result;
623
620
end Coverage_Buffer_Symbols ;
624
621
622
+ -- -------------------------
623
+ -- Run_Original_Compiler --
624
+ -- -------------------------
625
+
626
+ procedure Run_Original_Compiler
627
+ (Context : Parsing_Context;
628
+ Args : String_Vectors.Vector) is
629
+ begin
630
+ Run_Command
631
+ (Command => +Context.Orig_Compiler_Driver,
632
+ Arguments => Args,
633
+ Origin_Command_Name => " compiler" );
634
+ end Run_Original_Compiler ;
635
+
625
636
Compiler_Wrapper_Dir : constant String := Containing_Directory
626
637
(GNAT.OS_Lib.Locate_Exec_On_Path (Command_Name).all );
627
638
-- Directory that contains the current program
635
646
Instr_Dir : Temporary_Directory;
636
647
-- Directory holding instrumentation artefacts
637
648
638
- Command : String_Vectors.Vector;
639
- -- Original compiler driver invocation
640
-
641
649
Comp_DB : Compilation_Database;
642
650
643
651
Prj : Prj_Desc;
@@ -665,21 +673,30 @@ begin
665
673
Tag_Provider := Tag_Providers.Create (Default_Tag_Provider_Name);
666
674
Traces_Files.Update_Current_Trace_Kind (Traces_Files.Source_Trace_File);
667
675
676
+ Context.Orig_Compiler_Driver :=
677
+ Instr_Config.Compiler_Drivers.Element
678
+ (+Ada.Directories.Simple_Name (Command_Name));
679
+
668
680
-- Load the command line
669
681
670
- Command.Append (+Command_Name);
671
682
for I in 1 .. Argument_Count loop
672
683
Compiler_Driver_Opts.Append (+Argument (I));
673
684
end loop ;
674
- Command.Append_Vector (Compiler_Driver_Opts);
675
685
676
- Context.Orig_Compiler_Driver :=
677
- Instr_Config.Compiler_Drivers.Element
678
- (+Ada.Directories.Simple_Name (Command_Name));
686
+ -- If this driver invocation is not meant to compile a source file, there
687
+ -- is no instrumentation to do: just run the original driver and exit.
688
+
689
+ for Arg of Compiler_Driver_Opts loop
690
+ if +Arg in " -###" | " -E" then
691
+ Run_Original_Compiler (Context, Compiler_Driver_Opts);
692
+ return ;
693
+ end if ;
694
+ end loop ;
679
695
680
696
-- Parse the compiler driver invocation
681
697
682
- Comp_DB := Parse_Compiler_Driver_Command (Context, Instr_Dir, Command);
698
+ Comp_DB :=
699
+ Parse_Compiler_Driver_Command (Context, Instr_Dir, Compiler_Driver_Opts);
683
700
684
701
-- Generate an artificial project description to pass compiler
685
702
-- switches and default spec / body suffixes.
@@ -803,10 +820,8 @@ begin
803
820
804
821
declare
805
822
Output_Dir : constant String := +Prj.Output_Dir;
806
- New_Args : String_Vectors.Vector := Command.Copy ;
823
+ New_Args : String_Vectors.Vector := Compiler_Driver_Opts ;
807
824
begin
808
- New_Args.Delete_First;
809
-
810
825
New_Args.Prepend (" -I" & Instr_Config.GNATcov_RTS_Include_Dir);
811
826
812
827
if Comp_DB.Link_Command /= No_Link_Command then
@@ -878,10 +893,7 @@ begin
878
893
Args_Compilation.Append (Instr_Artifact);
879
894
Args_Compilation.Append (+" -o" );
880
895
Args_Compilation.Append (+Instr_Artifact_Object_Name);
881
- Run_Command
882
- (Command => +Context.Orig_Compiler_Driver,
883
- Arguments => Args_Compilation,
884
- Origin_Command_Name => " compiler wrapper" );
896
+ Run_Original_Compiler (Context, Args_Compilation);
885
897
886
898
Context.Instrumentation_Objects
887
899
.Reference (Comp_Command.Filename)
@@ -894,10 +906,7 @@ begin
894
906
895
907
-- Finally, run the alternate compiler driver invocation
896
908
897
- Run_Command
898
- (Command => +Context.Orig_Compiler_Driver,
899
- Arguments => New_Args,
900
- Origin_Command_Name => " compiler" );
909
+ Run_Original_Compiler (Context, New_Args);
901
910
902
911
if Comp_DB.Link_Command = No_Link_Command then
903
912
0 commit comments