diff --git a/lkql_checker/doc/gnatcheck_rm/using_gnatcheck.rst b/lkql_checker/doc/gnatcheck_rm/using_gnatcheck.rst index c68902869..1979fb117 100644 --- a/lkql_checker/doc/gnatcheck_rm/using_gnatcheck.rst +++ b/lkql_checker/doc/gnatcheck_rm/using_gnatcheck.rst @@ -813,7 +813,7 @@ registered for this version, via the switch ``--kp-version``. For example: .. code-block:: none - gnatkp -Pproject --kp-version=21.2 + gnatkp -Pproject --kp-version=21.2 --target= --RTS= will run all detectors relevant to GNAT Pro 21.2 on all files in the project. The list of detectors will be displayed as info messages, and will @@ -826,14 +826,14 @@ additionally the ``-h`` switch, e.g.: .. code-block:: none - gnatkp --kp-version=21.2 -h + gnatkp --kp-version=21.2 -h --target= --RTS= You can also combine the ``--kp-version`` switch with the ``--target`` switch to filter out detectors not relevant for your target, e.g: .. code-block:: none - gnatkp -Pproject --kp-version=21.2 --target=powerpc-elf + gnatkp -Pproject --kp-version=21.2 --target=powerpc-elf --RTS= will only enable detectors relevant to GNAT Pro 21.2 and to the ``powerpc-elf`` target. @@ -846,7 +846,7 @@ using the switch ``-rules``: .. code-block:: none - gnatkp -Pproject -rules +Rkp_xxxx_xxx [+Rkp_xxxx_xxx] + gnatkp -Pproject --target= --RTS= -rules +Rkp_xxxx_xxx [+Rkp_xxxx_xxx] where ``kp_xxxx_xxx`` is the name of a relevant known-problem to detect. You can get the list of available detectors via the command ``gnatkp -h``. When @@ -854,6 +854,12 @@ combined with the ``--kp-version`` and possibly ``--target`` switches, ``gnatkp -h`` will only list the detectors relevant to the version (and target) specified. +.. attention:: + + You must provide explicit target and runtime (either through the command-line + or with a provided project file) when running GNATKP to ensure the result + soundness. + You can check via the GNAT Tracker interface which known problems are relevant to your version of GNAT and your target before deciding which known problems may impact you: most known problems are only relevant to a diff --git a/lkql_checker/src/gnatcheck-projects.adb b/lkql_checker/src/gnatcheck-projects.adb index e9a90fd05..4ee5255b6 100644 --- a/lkql_checker/src/gnatcheck-projects.adb +++ b/lkql_checker/src/gnatcheck-projects.adb @@ -499,7 +499,7 @@ package body Gnatcheck.Projects is Gnatcheck.Projects.Aggregate.Collect_Aggregated_Projects (My_Project.Tree); - Set_Unbounded_String (Target, String (My_Project.Tree.Target)); + Target := To_Unbounded_String (String (My_Project.Tree.Target)); end if; My_Project.Tree.Update_Sources (Messages => Log); diff --git a/lkql_checker/src/gnatcheck_main.adb b/lkql_checker/src/gnatcheck_main.adb index e5e1e608d..d4a5a25eb 100644 --- a/lkql_checker/src/gnatcheck_main.adb +++ b/lkql_checker/src/gnatcheck_main.adb @@ -468,11 +468,18 @@ begin Process_Rule_Options; - -- Force some switches for gnatkp + -- Force some switches and perform some checks for gnatkp if Gnatkp_Mode then Max_Diagnoses := 0; Log_Mode := False; + + if Target = Null_Unbounded_String + or else RTS_Path = Null_Unbounded_String + then + Error ("missing explicit target and/or runtime"); + OS_Exit (E_Error); + end if; end if; Set_Log_File; @@ -518,9 +525,7 @@ begin Gnatcheck.Rules.Rule_Table.Clean_Up; Close_Log_File; - OS_Exit (if Tool_Failures /= 0 - or else - Detected_Internal_Error /= 0 + OS_Exit (if Tool_Failures /= 0 or else Detected_Internal_Error /= 0 then E_Error elsif Missing_Rule_File_Detected then E_Missing_Rule_File elsif Bad_Rule_Detected then E_Missing_Rule diff --git a/testsuite/drivers/gnatcheck_driver.py b/testsuite/drivers/gnatcheck_driver.py index aeb39e59d..48983222a 100644 --- a/testsuite/drivers/gnatcheck_driver.py +++ b/testsuite/drivers/gnatcheck_driver.py @@ -128,6 +128,8 @@ class GnatcheckDriver(BaseDriver): - ``label`` (str): An arbitrary label to add at the top of the gnatcheck output. - ``worker``: Provide a custom worker for the GNATcheck run. + - ``gnatkp_autoconfig`` (bool): Whether to automatically configure the + target and runtime when running in "gnatkp" mode. Default is True. - ``jobs`` (int): The number of jobs to forward to the GNATcheck command. - ``project`` (str): GPR build file to use (if any). @@ -263,6 +265,13 @@ def run_one_test(test_data: dict[str, any]) -> None: if pre_python: capture_exec_python(pre_python) + # If the executable is gantkp, we must provide an explicit runtime + # and target + if exe == "gnatkp" and test_data.get('gnatkp_autoconfig', True): + if not self.is_codepeer: + args.append(f"--target={self.env.build.platform}") + args.append("--RTS=native") + # Set the codepeer target if needed if self.is_codepeer: args.append("--target=codepeer")