Skip to content

Commit

Permalink
Merge branch 'topic/gnatkp_target_rts' into 'master'
Browse files Browse the repository at this point in the history
Require explicit runtime and target when running GNATKP

Closes #234

See merge request eng/libadalang/langkit-query-language!265
  • Loading branch information
HugoGGuerrier committed Aug 14, 2024
2 parents a00bfe0 + 18789e4 commit e004e3b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
14 changes: 10 additions & 4 deletions lkql_checker/doc/gnatcheck_rm/using_gnatcheck.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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=<my_target> --RTS=<my_runtime>
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
Expand All @@ -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=<my_target> --RTS=<my_runtime>
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=<my_runtime>
will only enable detectors relevant to GNAT Pro 21.2 and to the ``powerpc-elf``
target.
Expand All @@ -846,14 +846,20 @@ using the switch ``-rules``:

.. code-block:: none
gnatkp -Pproject -rules +Rkp_xxxx_xxx [+Rkp_xxxx_xxx]
gnatkp -Pproject --target=<my_target> --RTS=<my_runtime> -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
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
Expand Down
2 changes: 1 addition & 1 deletion lkql_checker/src/gnatcheck-projects.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 9 additions & 4 deletions lkql_checker/src/gnatcheck_main.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions testsuite/drivers/gnatcheck_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit e004e3b

Please sign in to comment.