Skip to content

Commit

Permalink
Fix config conflict (#1247)
Browse files Browse the repository at this point in the history
* Fix crate config conflicts errors (#1208)

* Alire.Properties.Configurations: print boolean values in lowercase

To match casing of TOML files where they come from.

* Alire.Crate_Configuration: fix, improve, and test value conflicts

 - TOML value comparison was incorrect (use Equals function now)
 - The "set by" info was incorrect
 - Error message now show the conflicting values

* Set macOS version to 10.15 for CI

To avoid compiler issue with Xcode 14.
  • Loading branch information
Fabien-Chouteau authored Nov 18, 2022
1 parent 1cb9b7b commit a126091
Show file tree
Hide file tree
Showing 21 changed files with 186 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
build:
name: CI on macOS

runs-on: macos-latest
runs-on: macos-10.15

steps:
- name: Check out repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
matrix:
os:
- macos-latest
- macos-10.15
- ubuntu-latest
- windows-latest

Expand Down
26 changes: 15 additions & 11 deletions src/alire/alire-crate_configuration.adb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ package body Alire.Crate_Configuration is
(Profile_Maps.Key (Cursor),
(Name => +Builtin_Build_Profile.Name,
Value => TOML.Create_String
(To_Lower_Case (Profile_Maps.Element (Cursor)'Img))));
(To_Lower_Case (Profile_Maps.Element (Cursor)'Img))),
Set_By => "Build profile map");
end loop;

end Make_Build_Profile_Map;
Expand Down Expand Up @@ -656,15 +657,15 @@ package body Alire.Crate_Configuration is
-- Set_Value --
---------------

procedure Set_Value (This : in out Global_Config;
Crate : Crate_Name;
Val : Assignment)
procedure Set_Value (This : in out Global_Config;
Crate : Crate_Name;
Val : Assignment;
Set_By : String)
is
Val_Name_Lower : constant String := To_Lower_Case (+Val.Name);
Crate_Str : constant String := +Crate;
Name : constant Unbounded_String := (+Crate_Str) & "." & Val_Name_Lower;
begin

-- TODO check if setting configuration of a dependency

if not This.Map.Contains (Name) then
Expand All @@ -683,14 +684,16 @@ package body Alire.Crate_Configuration is
"'" & " for type " & Image (Ref.Type_Def.Element));
end if;

if Ref.Value /= No_TOML_Value and then Ref.Value /= Val.Value then
if Ref.Value.Is_Present and then not Ref.Value.Equals (Val.Value)
then
Raise_Checked_Error
("Conflicting value for configuration variable '" &
(+Name) & "' from '" & (+Ref.Set_By) & "' and '"
& (+Crate) & "'.");
(+Name) & "' from '" & (+Ref.Set_By) & "' (" &
Image (Ref.Value) & ") and '"
& Set_By & "' (" & Image (Val.Value) & ").");
else
Ref.Value := Val.Value;
Ref.Set_By := +(+Crate);
Ref.Value := Val.Value;
Ref.Set_By := +(Set_By);
end if;
end;
end Set_Value;
Expand All @@ -716,7 +719,8 @@ package body Alire.Crate_Configuration is
Config_Value_Assignment (Prop);
begin
for Elt of List.List loop
This.Set_Value (To_Name (+List.Crate), Elt);
This.Set_Value (To_Name (+List.Crate), Elt,
Set_By => As_String (Crate));
end loop;
end;
end loop;
Expand Down
7 changes: 4 additions & 3 deletions src/alire/alire-crate_configuration.ads
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ private
Root : in out Roots.Root;
Crate : Crate_Name);

procedure Set_Value (This : in out Global_Config;
Crate : Crate_Name;
Val : Assignment);
procedure Set_Value (This : in out Global_Config;
Crate : Crate_Name;
Val : Assignment;
Set_By : String);

procedure Load_Settings (This : in out Global_Config;
Root : in out Roots.Root;
Expand Down
2 changes: 1 addition & 1 deletion src/alire/alire-properties-configurations.adb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ package body Alire.Properties.Configurations is
when TOML_String =>
return Val.As_String;
when TOML_Boolean =>
return Val.As_Boolean'Img;
return To_Lower_Case (Val.As_Boolean'Img);
when TOML_Float =>
return Image (Val.As_Float);
when TOML_Integer =>
Expand Down
3 changes: 3 additions & 0 deletions src/alire/alire-properties-configurations.ads
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ package Alire.Properties.Configurations with Preelaborate is
function Typedef_From_Enum return Config_Type_Definition;

function String_Typedef (Name : String) return Config_Type_Definition;

function Image (Val : TOML.TOML_Value) return String;

private

type Config_Entry is new Properties.Property with record
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
description = "\"Hello, world!\" demonstration project"
name = "hello_world"
version = "0.1.0"
licenses = "GPL-3.0-only"
maintainers = ["[email protected]"]
maintainers-logins = ["mylogin"]
executables=['main']

[origin]
url = "file:."

[[depends-on]]
libcrate_config_b = "*"
libcrate_config_c = "*"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "1.1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
description = "crate config demonstration project"
name = "libcrate_config_a"
version = "1.0.0"
licenses = "GPL-3.0-only"
maintainers = ["[email protected]"]
maintainers-logins = ["mylogin"]

[origin]
url = "file:."

[configuration.variables]
Var_Bool = {type="Boolean"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
description = "crate config demonstration project"
name = "libcrate_config_b"
version = "1.0.0"
licenses = "GPL-3.0-only"
maintainers = ["[email protected]"]
maintainers-logins = ["mylogin"]

[[depends-on]]
libcrate_config_a = "*"

[origin]
url = "file:."

[configuration.values]
libcrate_config_a.Var_Bool = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
description = "crate config demonstration project"
name = "libcrate_config_c"
version = "1.0.0"
licenses = "GPL-3.0-only"
maintainers = ["[email protected]"]
maintainers-logins = ["mylogin"]

[[depends-on]]
libcrate_config_a = "*"

[origin]
url = "file:."

[configuration.values]
libcrate_config_a.Var_Bool = false
24 changes: 24 additions & 0 deletions testsuite/tests/crate_config/value_conflict/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Test that two crates setting the same config var to the different values is not
ok.
"""

from drivers.alr import run_alr
from drivers.asserts import assert_match

import os
import platform

p = run_alr('get', 'hello_world', complain_on_error=False)
assert p.status != 0, "alr should have errored"

print(p.out)
assert_match(".*\n"
"ERROR: Conflicting value for configuration variable"
" 'libcrate_config_a.var_bool'"
" from 'libcrate_config_b' \(true\)"
" and 'libcrate_config_c' \(false\).*"
,
p.out)

print('SUCCESS')
4 changes: 4 additions & 0 deletions testsuite/tests/crate_config/value_conflict/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: python-script
indexes:
my_index:
in_fixtures: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
description = "\"Hello, world!\" demonstration project"
name = "hello_world"
version = "0.1.0"
licenses = "GPL-3.0-only"
maintainers = ["[email protected]"]
maintainers-logins = ["mylogin"]
executables=['main']

[origin]
url = "file:."

[[depends-on]]
libcrate_config_b = "*"
libcrate_config_c = "*"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "1.1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
description = "crate config demonstration project"
name = "libcrate_config_a"
version = "1.0.0"
licenses = "GPL-3.0-only"
maintainers = ["[email protected]"]
maintainers-logins = ["mylogin"]

[origin]
url = "file:."

[configuration.variables]
Var_Bool = {type="Boolean", default=true}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
description = "crate config demonstration project"
name = "libcrate_config_b"
version = "1.0.0"
licenses = "GPL-3.0-only"
maintainers = ["[email protected]"]
maintainers-logins = ["mylogin"]

[[depends-on]]
libcrate_config_a = "*"

[origin]
url = "file:."

[configuration.values]
libcrate_config_a.Var_Bool = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
description = "crate config demonstration project"
name = "libcrate_config_c"
version = "1.0.0"
licenses = "GPL-3.0-only"
maintainers = ["[email protected]"]
maintainers-logins = ["mylogin"]

[[depends-on]]
libcrate_config_a = "*"

[origin]
url = "file:."

[configuration.values]
libcrate_config_a.Var_Bool = false
13 changes: 13 additions & 0 deletions testsuite/tests/crate_config/value_match/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Test that two crates setting the same config var to the same value is ok.
"""

from drivers.alr import run_alr
from drivers.asserts import assert_match

import os
import platform

p = run_alr('get', 'hello_world')

print('SUCCESS')
4 changes: 4 additions & 0 deletions testsuite/tests/crate_config/value_match/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: python-script
indexes:
my_index:
in_fixtures: false
4 changes: 2 additions & 2 deletions testsuite/tests/show/jekyll/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
'{name: \'Var5\', type: \'Integer range -1 .. 1\', default: "0"},\n'
'{name: \'Var6\', type: \'Real range -1.00000000000000E+00 .. 1.00000000000000E+00\', default: "0.00000000000000E+00"},\n'
'{name: \'Var7\', type: \'Real range -inf .. +inf\', default: "0.00000000000000E+00"}]\n'
'configuration_values: [{crate: \'hello\', settings: [{name: \'Var1\', value: "TRUE"}]},\n'
'{crate: \'libhello\', settings: [{name: \'Var1\', value: "FALSE"}]}]\n'
'configuration_values: [{crate: \'hello\', settings: [{name: \'Var1\', value: "true"}]},\n'
'{crate: \'libhello\', settings: [{name: \'Var1\', value: "false"}]}]\n'
'\n'
'---\n'
'This is an example of long description in a multi-line string.\n'
Expand Down

0 comments on commit a126091

Please sign in to comment.