Skip to content

Commit

Permalink
Merge branch 'topic/cs0038355' into 'master'
Browse files Browse the repository at this point in the history
Add the ability to pass '-from' and '-from-lkql' to the same GNATcheck run

Closes #218

See merge request eng/libadalang/langkit-query-language!169
  • Loading branch information
HugoGGuerrier committed Feb 8, 2024
2 parents 3290909 + 675f846 commit 0c61a9c
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 19 deletions.
19 changes: 19 additions & 0 deletions lkql_checker/doc/gnatcheck_rm/using_gnatcheck.rst
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ The following options control the processing performed by ``gnatcheck``.
for more information about configuring rules with an LKQL file.


.. note::

You can provide ``-from-lkql`` and ``-from`` to the same GNATcheck run. This will
combine specified rules in both files.

The default behavior is that all the rule checks are disabled.

If a rule option is given in a rule file, it can contain spaces and line breaks.
Expand Down Expand Up @@ -406,6 +411,20 @@ containing arguments for a run of the rule.
gnatcheck_rule_2: [{param_1: "Hello", param_2: "World"}]
}

.. attention::

Please note that the provided rule names (that are object keys) must strictly be
lowercase, following the LKQL parsing rules.
Moreover, you cannot provide the same key twice; thus, the following code will
result in a runtime error.

::

val rules = @{
gnatcheck_rule_1,
gnatcheck_rule_1: [{param_1: "Hello", param_2: "World"}]
}

You can use the ``alias_name`` key in an argument object to define an alias for the
rule.

Expand Down
6 changes: 3 additions & 3 deletions lkql_checker/src/gnatcheck-compiler.adb
Original file line number Diff line number Diff line change
Expand Up @@ -1482,11 +1482,11 @@ package body Gnatcheck.Compiler is
Num_Args := @ + 1;
Args (Num_Args) :=
new String'("--rules-from=" & LKQL_Rule_File_Name.all);
else
Num_Args := @ + 1;
Args (Num_Args) := new String'("--rules-from=" & Rule_File);
end if;

Num_Args := @ + 1;
Args (Num_Args) := new String'("--rules-from=" & Rule_File);

if Debug_Mode then
-- For debug purposes, we don't want to put the full path to the
-- worker command, if it is a full path. We just want the base name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static class Args implements Callable<Integer> {
public List<String> rulesDirs = new ArrayList<>();

@CommandLine.Option(names = "--rules-from", description = "The file containing the rules")
public String rulesFrom = null;
public List<String> rulesFroms = null;

@CommandLine.Option(names = "--files-from", description = "The file containing the files")
public String filesFrom = null;
Expand Down Expand Up @@ -249,15 +249,17 @@ protected int executeScript(Context.Builder contextBuilder) {
}

// Set the rule to apply
if (!this.args.rulesFrom.isEmpty()) {
if (this.args.rulesFrom.endsWith(".lkql")) {
contextBuilder.option("lkql.LKQLRuleFile", this.args.rulesFrom);
} else {
final List<String> allRules = new ArrayList<>();
final List<String> allArgs = new ArrayList<>();
processRuleSpecificationFile(this.args.rulesFrom, allRules, allArgs);
contextBuilder.option("lkql.rules", String.join(",", allRules));
contextBuilder.option("lkql.rulesArgs", String.join(";", allArgs));
for (var rulesFrom : this.args.rulesFroms) {
if (!rulesFrom.isEmpty()) {
if (rulesFrom.endsWith(".lkql")) {
contextBuilder.option("lkql.LKQLRuleFile", rulesFrom);
} else {
final List<String> allRules = new ArrayList<>();
final List<String> allArgs = new ArrayList<>();
processRuleSpecificationFile(rulesFrom, allRules, allArgs);
contextBuilder.option("lkql.rules", String.join(",", allRules));
contextBuilder.option("lkql.rulesArgs", String.join(";", allArgs));
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions testsuite/tests/gnatcheck/lkql_rules_config/ada_code.adb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ procedure Ada_Code is
Const_C : constant Int := 1;

Decl : Integer := 10;

X : array (1 .. 10) of Integer; -- FLAG
begin
Decl := @ + 12; -- NOFLAG because not in SPARK mode

Expand Down
1 change: 1 addition & 0 deletions testsuite/tests/gnatcheck/lkql_rules_config/rules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
+RAnonymous_Arrays
4 changes: 3 additions & 1 deletion testsuite/tests/gnatcheck/lkql_rules_config/spark_code.adb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ procedure Spark_Code
is
A : String := "hello";

X : array (1 .. 10) of Integer; -- FLAG

procedure Foo
with Pre => A'Image = "hello", -- NOFLAG because in ghost code
Post => A'Image = "hello"; -- NOFLAG because in ghost code
Expand All @@ -14,4 +16,4 @@ begin
Decl := @ + 12; -- FLAG
goto Next; -- NOFLAG because in SPARK mode
<<Next>>
end Name;
end Name;
12 changes: 7 additions & 5 deletions testsuite/tests/gnatcheck/lkql_rules_config/test.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ ada_code.adb:2:09: Int does not end with type suffix _T [identifier_suffixes]
ada_code.adb:5:09: Int_A does not end with access suffix _PTR [identifier_suffixes]
ada_code.adb:6:09: Int_PTR does not end with access suffix _A [identifier_suffixes]
ada_code.adb:8:04: Const does not end with constant suffix _C [identifier_suffixes]
ada_code.adb:17:04: goto statement [goto_statements]
spark_code.adb:11:07: Ada 2022 construct forbidden outside of ghost code [ada_2022_in_ghost_code]
spark_code.adb:11:15: A does not end with constant suffix _C [identifier_suffixes]
spark_code.adb:12:15: B does not end with constant suffix _C [identifier_suffixes]
spark_code.adb:14:12: Ada 2022 construct forbidden outside of ghost code [ada_2022_in_ghost_code]
ada_code.adb:13:08: anonymous array type [anonymous_arrays]
ada_code.adb:19:04: goto statement [goto_statements]
spark_code.adb:6:08: anonymous array type [anonymous_arrays]
spark_code.adb:13:07: Ada 2022 construct forbidden outside of ghost code [ada_2022_in_ghost_code]
spark_code.adb:13:15: A does not end with constant suffix _C [identifier_suffixes]
spark_code.adb:14:15: B does not end with constant suffix _C [identifier_suffixes]
spark_code.adb:16:12: Ada 2022 construct forbidden outside of ghost code [ada_2022_in_ghost_code]
1 change: 1 addition & 0 deletions testsuite/tests/gnatcheck/lkql_rules_config/test.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
driver: gnatcheck
project: prj.gpr
lkql_rule_file: config.lkql
rule_file: rules.txt
format: brief
show_rule: True

0 comments on commit 0c61a9c

Please sign in to comment.