Skip to content

Commit 3b57b4a

Browse files
committed
Add 'Lkql_Path' GPR attribute handling
1 parent e0b7d7d commit 3b57b4a

File tree

6 files changed

+51
-1
lines changed

6 files changed

+51
-1
lines changed

lkql_checker/doc/gnatcheck_rm/using_gnatcheck.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,16 @@ GNATcheck:
368368
file defining this attribute, then, an error is emitted and ``gnatcheck``
369369
will exit with an error code.
370370

371+
``Lkql_Path``
372+
Value is a list of directories to add to the ``LKQL_PATH`` environment
373+
variable when GNATcheck is spawning the LKQL engine. This variable is
374+
used to resolve module importations in LKQL sources. If not absolute, paths
375+
provided through this attribute are relatives to the project file defining
376+
it.
377+
378+
This attributes may work combined with the ``--lkql-path`` switch, in that
379+
case, all directories are added to the ``LKQL_PATH`` environment variable.
380+
371381
``Switches``
372382
Index is a language name. Value is a list of additional switches to be used
373383
when invoking ``gnatcheck``.
@@ -388,6 +398,7 @@ GNATcheck:
388398
* ``-eL``
389399
* ``-r, --rule [rule_name]`` (use ``Rules`` attribute instead)
390400
* ``--rule-file=filename`` (use ``Rule_File`` attribute instead)
401+
* ``--lkql-path=dir`` (use ``Lkql_Path`` attributes instead)
391402
* ``--target`` (use the ``Target`` GPR attribute instead)
392403
* ``--RTS`` (use the ``Runtime`` GPR attribute instead)
393404

lkql_checker/src/gnatcheck-projects.adb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ package body Gnatcheck.Projects is
7070
(GPR2."+" ("Check"), GPR2."+" ("Rules"));
7171
Rule_File_Attr : constant GPR2.Q_Attribute_Id :=
7272
(GPR2."+" ("Check"), GPR2."+" ("Rule_File"));
73+
Lkql_Path_Attr : constant GPR2.Q_Attribute_Id :=
74+
(GPR2."+" ("Check"), GPR2."+" ("Lkql_Path"));
7375
Default_Switches_Attr : constant GPR2.Q_Attribute_Id :=
7476
(GPR2."+" ("Check"), GPR2."+" ("Default_Switches"));
7577
Switches_Attr : constant GPR2.Q_Attribute_Id :=
@@ -274,6 +276,17 @@ package body Gnatcheck.Projects is
274276
end;
275277
end if;
276278

279+
-- Process the LKQL path
280+
if Proj.Has_Attribute (Lkql_Path_Attr) then
281+
List_Val := Load_List_Attribute (Lkql_Path_Attr);
282+
for Path of List_Val.all loop
283+
Additional_Lkql_Paths.Append
284+
(if Is_Absolute_Path (Path.all)
285+
then Path.all
286+
else Gnatcheck_Prj.Get_Project_Relative_File (Path.all));
287+
end loop;
288+
end if;
289+
277290
-- Process additional GNATcheck switches
278291
if Proj.Has_Attribute (Switches_Attr, Ada_Idx) then
279292
List_Val := Load_List_Attribute (Switches_Attr, Indexed => True);
@@ -753,6 +766,17 @@ package body Gnatcheck.Projects is
753766
(Rule_File_Attr,
754767
"Value is the name of an LKQL rule file to use when running "
755768
& "GNATcheck in this project.");
769+
Add
770+
(Lkql_Path_Attr,
771+
Index_Type => GPR2.Project.Registry.Attribute.No_Index,
772+
Value => List,
773+
Value_Case_Sensitive => True,
774+
Is_Allowed_In => Everywhere);
775+
GPR2.Project.Registry.Attribute.Description.Set_Attribute_Description
776+
(Lkql_Path_Attr,
777+
"Value is a list of directories to add to the LKQL_PATH environment "
778+
& "variable when GNATcheck is spawning the LKQL engine. This "
779+
& "variable is used to resolve module importations in LKQL sources.");
756780
Add
757781
(Switches_Attr,
758782
Index_Type => Language_Index,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
project Prj is
2+
package Check is
3+
for Rule_File use "without_overlapping.lkql";
4+
for Lkql_Path use ("rule_configs");
5+
end Check;
6+
end Prj;

testsuite/tests/gnatcheck/lkql_rules_config/combine_rule_files/test.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ main.adb:3:04: rule violation: redundant null statement [redundant_null_statemen
1919
main.adb:4:04: rule violation: goto statement [goto_statements]
2020
main.adb:9:07: rule violation: goto statement [goto_statements]
2121

22+
Providing search paths through the GPR file
23+
===========================================
24+
25+
main.adb:3:04: rule violation: redundant null statement [redundant_null_statements]
26+
main.adb:4:04: rule violation: goto statement [goto_statements]
27+
main.adb:9:07: rule violation: goto statement [goto_statements]
28+
2229
Rule file with an invalid importation
2330
=====================================
2431

testsuite/tests/gnatcheck/lkql_rules_config/combine_rule_files/test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ tests:
2020
extra_args:
2121
- --lkql-path
2222
- rule_configs
23+
- label: Providing search paths through the GPR file
24+
project: prj
2325

2426
# Error testing
2527
- label: Rule file with an invalid importation
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"packages":[{"attributes":[{"attribute_def":{"builtin":false,"config_concatenable":false,"empty_value":"ALLOW","has_default_in":{"abstract":false,"aggregate":false,"aggregate_library":false,"configuration":false,"library":false,"standard":false},"index_optional":false,"index_type":"LANGUAGE_INDEX","inherit_from_extended":"NOT_INHERITED","is_allowed_in":{"abstract":true,"aggregate":true,"aggregate_library":true,"configuration":true,"library":true,"standard":true},"is_toolchain_config":false,"value":"LIST","value_case_sensitive":true,"value_is_set":false},"attribute_descr":"Index is a language name. Value is a list of switches to be used when invoking 'gnatcheck' for a source of the language, if there is no applicable attribute Switches.","attribute_name":"Default_Switches"},{"attribute_def":{"builtin":false,"config_concatenable":false,"empty_value":"ALLOW","has_default_in":{"abstract":false,"aggregate":false,"aggregate_library":false,"configuration":false,"library":false,"standard":false},"index_optional":false,"index_type":"LANGUAGE_INDEX","inherit_from_extended":"NOT_INHERITED","is_allowed_in":{"abstract":true,"aggregate":true,"aggregate_library":true,"configuration":true,"library":true,"standard":true},"is_toolchain_config":false,"value":"LIST","value_case_sensitive":true,"value_is_set":false},"attribute_descr":"Index is a language name. Value is a list of switches to be used when invoking 'gnatcheck' for a source of the language.","attribute_name":"Switches"},{"attribute_def":{"builtin":false,"config_concatenable":false,"empty_value":"ALLOW","has_default_in":{"abstract":false,"aggregate":false,"aggregate_library":false,"configuration":false,"library":false,"standard":false},"index_optional":false,"index_type":"NO_INDEX","inherit_from_extended":"NOT_INHERITED","is_allowed_in":{"abstract":true,"aggregate":true,"aggregate_library":true,"configuration":true,"library":true,"standard":true},"is_toolchain_config":false,"value":"LIST","value_case_sensitive":false,"value_is_set":false},"attribute_descr":"Value is a list of GNATcheck rule names to enable when running GNATcheck on this project.","attribute_name":"Rules"},{"attribute_def":{"builtin":false,"config_concatenable":false,"empty_value":"ALLOW","has_default_in":{"abstract":false,"aggregate":false,"aggregate_library":false,"configuration":false,"library":false,"standard":false},"index_optional":false,"index_type":"NO_INDEX","inherit_from_extended":"NOT_INHERITED","is_allowed_in":{"abstract":true,"aggregate":true,"aggregate_library":true,"configuration":true,"library":true,"standard":true},"is_toolchain_config":false,"value":"SINGLE","value_case_sensitive":true,"value_is_set":false},"attribute_descr":"Value is the name of an LKQL rule file to use when running GNATcheck in this project.","attribute_name":"Rule_File"}],"package_descr":"This package specifies the options used when calling the checking tool 'gnatcheck'. Its attribute Default_Switches has the same semantics as for the package Builder. The first string should always be -rules to specify that all the other options belong to the -rules section of the parameters to 'gnatcheck'.","package_name":"Check","projects_kind":{"abstract":true,"aggregate":true,"aggregate_library":true,"configuration":true,"library":true,"standard":true}},{"attributes":[{"attribute_def":{"builtin":false,"config_concatenable":false,"empty_value":"ALLOW","has_default_in":{"abstract":false,"aggregate":false,"aggregate_library":false,"configuration":false,"library":false,"standard":false},"index_optional":false,"index_type":"NO_INDEX","inherit_from_extended":"NOT_INHERITED","is_allowed_in":{"abstract":true,"aggregate":true,"aggregate_library":true,"configuration":true,"library":true,"standard":true},"is_toolchain_config":false,"value":"LIST","value_case_sensitive":true,"value_is_set":false},"attribute_descr":"If you want to override ada default file extensions (ada, ads, adb, spc & bdy), use this attribute which includes a list of file patterns where you can specify the following meta characters: * : matches any string of 0 or more characters, ? : matches any character, [list of chars] : matches any character listed, [char-char] : matches any character in given range, [^list of chars] : matches any character not listed. These patterns are case insensitive.","attribute_name":"File_Patterns"}],"package_descr":"This package specifies the options used when calling the tool 'codepeer'.","package_name":"Codepeer","projects_kind":{"abstract":true,"aggregate":true,"aggregate_library":true,"configuration":true,"library":true,"standard":true}}]}
1+
{"packages":[{"attributes":[{"attribute_def":{"builtin":false,"config_concatenable":false,"empty_value":"ALLOW","has_default_in":{"abstract":false,"aggregate":false,"aggregate_library":false,"configuration":false,"library":false,"standard":false},"index_optional":false,"index_type":"LANGUAGE_INDEX","inherit_from_extended":"NOT_INHERITED","is_allowed_in":{"abstract":true,"aggregate":true,"aggregate_library":true,"configuration":true,"library":true,"standard":true},"is_toolchain_config":false,"value":"LIST","value_case_sensitive":true,"value_is_set":false},"attribute_descr":"Index is a language name. Value is a list of switches to be used when invoking 'gnatcheck' for a source of the language, if there is no applicable attribute Switches.","attribute_name":"Default_Switches"},{"attribute_def":{"builtin":false,"config_concatenable":false,"empty_value":"ALLOW","has_default_in":{"abstract":false,"aggregate":false,"aggregate_library":false,"configuration":false,"library":false,"standard":false},"index_optional":false,"index_type":"LANGUAGE_INDEX","inherit_from_extended":"NOT_INHERITED","is_allowed_in":{"abstract":true,"aggregate":true,"aggregate_library":true,"configuration":true,"library":true,"standard":true},"is_toolchain_config":false,"value":"LIST","value_case_sensitive":true,"value_is_set":false},"attribute_descr":"Index is a language name. Value is a list of switches to be used when invoking 'gnatcheck' for a source of the language.","attribute_name":"Switches"},{"attribute_def":{"builtin":false,"config_concatenable":false,"empty_value":"ALLOW","has_default_in":{"abstract":false,"aggregate":false,"aggregate_library":false,"configuration":false,"library":false,"standard":false},"index_optional":false,"index_type":"NO_INDEX","inherit_from_extended":"NOT_INHERITED","is_allowed_in":{"abstract":true,"aggregate":true,"aggregate_library":true,"configuration":true,"library":true,"standard":true},"is_toolchain_config":false,"value":"LIST","value_case_sensitive":false,"value_is_set":false},"attribute_descr":"Value is a list of GNATcheck rule names to enable when running GNATcheck on this project.","attribute_name":"Rules"},{"attribute_def":{"builtin":false,"config_concatenable":false,"empty_value":"ALLOW","has_default_in":{"abstract":false,"aggregate":false,"aggregate_library":false,"configuration":false,"library":false,"standard":false},"index_optional":false,"index_type":"NO_INDEX","inherit_from_extended":"NOT_INHERITED","is_allowed_in":{"abstract":true,"aggregate":true,"aggregate_library":true,"configuration":true,"library":true,"standard":true},"is_toolchain_config":false,"value":"SINGLE","value_case_sensitive":true,"value_is_set":false},"attribute_descr":"Value is the name of an LKQL rule file to use when running GNATcheck in this project.","attribute_name":"Rule_File"},{"attribute_def":{"builtin":false,"config_concatenable":false,"empty_value":"ALLOW","has_default_in":{"abstract":false,"aggregate":false,"aggregate_library":false,"configuration":false,"library":false,"standard":false},"index_optional":false,"index_type":"NO_INDEX","inherit_from_extended":"NOT_INHERITED","is_allowed_in":{"abstract":true,"aggregate":true,"aggregate_library":true,"configuration":true,"library":true,"standard":true},"is_toolchain_config":false,"value":"LIST","value_case_sensitive":true,"value_is_set":false},"attribute_descr":"Value is a list of directories to add to the LKQL_PATH environment variable when GNATcheck is spawning the LKQL engine. This variable is used to resolve module importations in LKQL sources.","attribute_name":"Lkql_Path"}],"package_descr":"This package specifies the options used when calling the checking tool 'gnatcheck'. Its attribute Default_Switches has the same semantics as for the package Builder. The first string should always be -rules to specify that all the other options belong to the -rules section of the parameters to 'gnatcheck'.","package_name":"Check","projects_kind":{"abstract":true,"aggregate":true,"aggregate_library":true,"configuration":true,"library":true,"standard":true}},{"attributes":[{"attribute_def":{"builtin":false,"config_concatenable":false,"empty_value":"ALLOW","has_default_in":{"abstract":false,"aggregate":false,"aggregate_library":false,"configuration":false,"library":false,"standard":false},"index_optional":false,"index_type":"NO_INDEX","inherit_from_extended":"NOT_INHERITED","is_allowed_in":{"abstract":true,"aggregate":true,"aggregate_library":true,"configuration":true,"library":true,"standard":true},"is_toolchain_config":false,"value":"LIST","value_case_sensitive":true,"value_is_set":false},"attribute_descr":"If you want to override ada default file extensions (ada, ads, adb, spc & bdy), use this attribute which includes a list of file patterns where you can specify the following meta characters: * : matches any string of 0 or more characters, ? : matches any character, [list of chars] : matches any character listed, [char-char] : matches any character in given range, [^list of chars] : matches any character not listed. These patterns are case insensitive.","attribute_name":"File_Patterns"}],"package_descr":"This package specifies the options used when calling the tool 'codepeer'.","package_name":"Codepeer","projects_kind":{"abstract":true,"aggregate":true,"aggregate_library":true,"configuration":true,"library":true,"standard":true}}]}

0 commit comments

Comments
 (0)