Skip to content

Commit dc687bb

Browse files
committed
GNATCheckWorker: make JSON instances object distinct from diagnostics
This change allows to pass non-critical diagnostics from the worker to the driver.
1 parent 9d99f91 commit dc687bb

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

lkql_checker/src/gnatcheck-compiler.adb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,19 @@ package body Gnatcheck.Compiler is
606606
Error (Line (15 .. Line_Len));
607607
Detected_Internal_Error := @ + 1;
608608
Errors := True;
609+
elsif Line_Len >= 23
610+
and then Line (1 .. 23) = "WORKER_JSON_INSTANCES: "
611+
then
612+
-- Ignore the JSON instances data. This is analyzed in
613+
-- Process_LKQL_Rule_File.
614+
615+
-- The current line can be longer than Line_Len, skip the rest of
616+
-- the line if that's the case.
617+
if Line_Len = Line'Length then
618+
Skip_Line (File);
619+
else
620+
null;
621+
end if;
609622
else
610623
Analyze_Line (Line (1 .. Line_Len));
611624
end if;

lkql_checker/src/gnatcheck-rules-rule_table.adb

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ package body Gnatcheck.Rules.Rule_Table is
922922
Parser_Pid : Process_Id;
923923
Waited_Pid : Process_Id;
924924
Success : Boolean;
925+
Analyze_Error : Boolean;
925926
Config_JSON : Read_Result;
926927

927928
procedure Rule_Object_Mapper
@@ -952,12 +953,35 @@ package body Gnatcheck.Rules.Rule_Table is
952953
Error ("can not call the LKQL rule file parser");
953954
Rule_Option_Problem_Detected := True;
954955
else
955-
Config_JSON := Read (Read_File (JSON_Config_File_Name).all);
956+
declare
957+
Worker_Output_File : File_Type;
958+
begin
959+
Open (Worker_Output_File, In_File, JSON_Config_File_Name);
960+
961+
while not End_Of_File (Worker_Output_File) loop
962+
declare
963+
Line : constant String := Get_Line (Worker_Output_File);
964+
begin
965+
if Line (1 .. 23) = "WORKER_JSON_INSTANCES: " then
966+
Config_JSON := Read (Line (24 .. Line'Last));
967+
exit;
968+
end if;
969+
end;
970+
end loop;
971+
972+
Close (Worker_Output_File);
973+
end;
974+
975+
-- Process diagnostics from worker's output
976+
Analyze_Output (JSON_Config_File_Name, Analyze_Error);
956977

957978
-- If the JSON parsing failed, it means that LKQL rule file
958-
-- processing failed and diagnostics are in the output file.
959-
if not Config_JSON.Success then
960-
Analyze_Output (JSON_Config_File_Name, Success);
979+
-- processing failed and diagnostics are in the output file and
980+
-- they have been already processed.
981+
if Analyze_Error
982+
or else not Config_JSON.Success
983+
or else Config_JSON.Value = JSON_Null
984+
then
961985
Rule_Option_Problem_Detected := True;
962986

963987
-- Else, populate the global rule table with the rule config

lkql_jit/cli/src/main/java/com/adacore/lkql_jit/cli/GNATCheckWorker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ protected int executeScript(Context.Builder contextBuilder) {
209209
.map(e -> Map.entry(e.getKey(), e.getValue().toJson()))
210210
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
211211
);
212-
System.out.println(jsonInstances);
212+
System.out.println("WORKER_JSON_INSTANCES: " + jsonInstances);
213213
} catch (LKQLRuleFileError e) {
214214
System.out.println(e.getMessage());
215215
}

0 commit comments

Comments
 (0)