Skip to content

Commit 212121e

Browse files
committed
Always use target defined by the provided GPR file
1 parent 32d7df2 commit 212121e

File tree

15 files changed

+209
-9
lines changed

15 files changed

+209
-9
lines changed

lkql_checker/src/gnatcheck-projects.adb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ package body Gnatcheck.Projects is
589589
raise Parameter_Error;
590590
end if;
591591

592+
-- Use the runtime path provided through the project file
592593
if RTS_Path = Null_Unbounded_String
593594
and then My_Project.Tree.Runtime (Ada_Language) /= ""
594595
then
@@ -597,6 +598,11 @@ package body Gnatcheck.Projects is
597598
(String (My_Project.Tree.Runtime (Ada_Language)));
598599
end if;
599600

601+
-- Use the target specified through the project file or the config file
602+
if Target = Null_Unbounded_String then
603+
Target := To_Unbounded_String (String (My_Project.Tree.Target));
604+
end if;
605+
600606
if Load_Sources then
601607
if My_Project.Tree.Root_Project.Kind = K_Aggregate then
602608
-- We cannot load sources when the number of aggregated projects
@@ -607,7 +613,6 @@ package body Gnatcheck.Projects is
607613
Gnatcheck.Projects.Aggregate.Collect_Aggregated_Projects
608614
(My_Project.Tree);
609615

610-
Target := To_Unbounded_String (String (My_Project.Tree.Target));
611616
end if;
612617

613618
if not My_Project.Tree.Update_Sources then

testsuite/drivers/gnatcheck_driver.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,16 @@ class GnatcheckDriver(BaseDriver):
129129
- ``worker``: Provide a custom worker for the GNATcheck run.
130130
- ``gnatkp_autoconfig`` (bool): Whether to automatically configure the
131131
target and runtime when running in "gnatkp" mode. Default is True.
132+
- ``auto_codepeer_target`` (bool): Whether to automatically add the
133+
codepeer target when the test is run in CodePeer mode. Default is
134+
True.
132135
- ``in_tty`` (bool): Whether to run GNATcheck in a pseudo TTY using the
133136
``pty`` Python module.
134137
135138
- ``jobs`` (int): The number of jobs to forward to the GNATcheck command.
136139
- ``project`` (str): GPR build file to use (if any).
140+
- ``target`` (str): The target to forward to LibGPR for project
141+
resolution.
137142
- ``subdirs`` (str): The directory to forward to GNATcheck `--subdirs`
138143
option.
139144
- ``input_sources`` (list[str]): Ada files to analyze (if explicit,
@@ -166,6 +171,8 @@ class GnatcheckDriver(BaseDriver):
166171
- ``extra_rule_options`` (list[str]): Extra arguments for the rules
167172
section.
168173
174+
- ``canonicalize_worker`` (bool): Whether to replace the GNATcheck worker
175+
name by a constant string in then test output. Default is True.
169176
- ``pre_python``/``post_python`` (str): Python code to be executed
170177
before/after the test.
171178
- ``list_dirs`` (list[str]): A list of directories to display the content
@@ -296,15 +303,24 @@ def run_one_test(test_data: dict[str, any]) -> None:
296303
if pre_python:
297304
capture_exec_python(pre_python)
298305

299-
# If the executable is gantkp, we must provide an explicit runtime
306+
# Set the target if one has been provided
307+
if test_data.get('target'):
308+
args.append(f"--target={test_data['target']}")
309+
310+
# If the executable is gnatkp, we must provide an explicit runtime
300311
# and target
301312
if exe == "gnatkp" and test_data.get('gnatkp_autoconfig', True):
302-
if not self.is_codepeer:
313+
if not self.is_codepeer and not test_data.get('target'):
303314
args.append(f"--target={self.env.host.triplet}")
304315
args.append("--RTS=default")
305316

306-
# Set the codepeer target if needed
307-
if self.is_codepeer:
317+
# Set the codepeer target if needed and no other one has been
318+
# provided.
319+
if (
320+
self.is_codepeer and
321+
test_data.get('auto_codepeer_target', True)
322+
and not test_data.get('target')
323+
):
308324
args.append("--target=codepeer")
309325

310326
# Set the "--show-rule" flag according to the test
@@ -415,6 +431,16 @@ def run_one_test(test_data: dict[str, any]) -> None:
415431
exec_output = p.out
416432
status_code = p.status
417433

434+
# If required, canonicalize gnatcheck worker name in the output
435+
if test_data.get('canonicalize_worker', True):
436+
worker = " ".join(
437+
[
438+
P.basename(self.gnatcheck_worker_exe[0]),
439+
*self.gnatcheck_worker_exe[1:],
440+
]
441+
)
442+
exec_output = exec_output.replace(worker, "<gnatcheck_worker_exe>")
443+
418444
# Then read GNATcheck report file if there is one
419445
report_file_content = ""
420446
parse_output_for_flags = True

testsuite/tests/gnatcheck/gpr_config_file/config.cgpr

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
-- This gpr configuration file was generated by gprconfig
2-
-- using this command line:
3-
-- gprconfig prj.gpr
4-
-- from /home/guerrier/Documents/AdaCore/test/
51
configuration project Default is
62
for Default_Language use "Ada";
73
for Runtime_Dir ("Ada") use "dir";
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
configuration project Default is
2+
for Default_Language use "Ada";
3+
for Runtime_Dir ("Ada") use "dir";
4+
for Target use "x86_64-linux";
5+
6+
package Naming is
7+
for Spec_Suffix ("Ada") use ".ads";
8+
for Body_Suffix ("Ada") use ".adb";
9+
10+
for Body_Suffix ("Asm") use ".s";
11+
for Body_Suffix ("Asm2") use ".asm";
12+
for Body_Suffix ("Asm_Cpp") use ".S";
13+
14+
for Body_Suffix ("C") use ".c";
15+
for Spec_Suffix ("C") use ".h";
16+
17+
for Spec_Suffix ("C++") use ".hh";
18+
for Body_Suffix ("C++") use ".cpp";
19+
20+
for Body_Suffix ("Fortran") use ".f";
21+
22+
for Casing use "lowercase";
23+
for Dot_Replacement use "-";
24+
end Naming;
25+
end Default;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
procedure Main is
2+
begin
3+
goto Lbl; -- FLAG (3)
4+
<<Lbl>>
5+
end Main;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
With target in project file and no other target
2+
===============================================
3+
4+
gnatcheck: kb: warning: can't find a toolchain for the following configuration: language 'Ada', target 'x86_64-linux', default runtime
5+
gnatcheck: "with_target.gpr" processing failed
6+
try "gnatcheck --help" for more information.
7+
>>>program returned status code 2
8+
9+
With target in project file and the codepeer target in command-line
10+
===================================================================
11+
12+
<gnatcheck_worker_exe> -Pwith_target.gpr --target=codepeer -d --files-from=/gnatcheck/gnatcheck-files1.TMP --rules-from=/gnatcheck/gnatcheck-rules0.TMP
13+
main.adb:3:04: goto statement
14+
15+
With target in config file
16+
==========================
17+
18+
gnatcheck: config.cgpr:4:19: error: --target: 'codepeer' is different from the target value in the configuration project 'x86_64-linux'
19+
<gnatcheck_worker_exe> -Pwithout_target.gpr --target=codepeer -d --files-from=/gnatcheck/gnatcheck-files1.TMP --rules-from=/gnatcheck/gnatcheck-rules0.TMP
20+
main.adb:3:04: goto statement
21+
22+
With target through command-line
23+
================================
24+
25+
gnatcheck: kb: warning: can't find a toolchain for the following configuration: language 'Ada', target 'x86_64-linux', default runtime
26+
gnatcheck: "without_target.gpr" processing failed
27+
try "gnatcheck --help" for more information.
28+
>>>program returned status code 2
29+
30+
Without any target specified
31+
============================
32+
33+
<gnatcheck_worker_exe> -Pwithout_target.gpr --target=codepeer -d --files-from=/gnatcheck/gnatcheck-files1.TMP --rules-from=/gnatcheck/gnatcheck-rules0.TMP
34+
main.adb:3:04: goto statement
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
driver: gnatcheck
2+
control:
3+
- [SKIP,
4+
"os == 'windows' or not is_codepeer",
5+
"This test must be run with Codepeer on Linux"]
6+
format: brief
7+
extra_args:
8+
- -d
9+
rules:
10+
- +RGoto_Statements
11+
tests:
12+
- label: With target in project file and no other target
13+
project: with_target.gpr
14+
auto_codepeer_target: False
15+
- label: With target in project file and the codepeer target in command-line
16+
project: with_target.gpr
17+
auto_codepeer_target: True
18+
- label: With target in config file
19+
project: without_target.gpr
20+
gpr_config_file: config.cgpr
21+
- label: With target through command-line
22+
project: without_target.gpr
23+
target: x86_64-linux
24+
- label: Without any target specified
25+
project: without_target.gpr
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project With_Target is
2+
for Target use "x86_64-linux";
3+
end With_Target;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project Without_Target is
2+
end Without_Target;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
configuration project Default is
2+
for Default_Language use "Ada";
3+
for Runtime_Dir ("Ada") use "dir";
4+
for Target use "x86_64-linux";
5+
6+
package Naming is
7+
for Spec_Suffix ("Ada") use ".ads";
8+
for Body_Suffix ("Ada") use ".adb";
9+
10+
for Body_Suffix ("Asm") use ".s";
11+
for Body_Suffix ("Asm2") use ".asm";
12+
for Body_Suffix ("Asm_Cpp") use ".S";
13+
14+
for Body_Suffix ("C") use ".c";
15+
for Spec_Suffix ("C") use ".h";
16+
17+
for Spec_Suffix ("C++") use ".hh";
18+
for Body_Suffix ("C++") use ".cpp";
19+
20+
for Body_Suffix ("Fortran") use ".f";
21+
22+
for Casing use "lowercase";
23+
for Dot_Replacement use "-";
24+
end Naming;
25+
end Default;

0 commit comments

Comments
 (0)