Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crate config conflicts errors #1208

Merged
merged 2 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/alire/alire-crate_configuration.adb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,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 @@ -792,15 +793,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.Var_Map.Contains (Name) then
Expand All @@ -819,14 +820,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.Set_By := +(Set_By);
end if;
end;
end Set_Value;
Expand All @@ -852,7 +855,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 @@ -145,9 +145,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 @@ -144,7 +144,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 = ["example@example.com"]
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 = ["example@example.com"]
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 = ["example@example.com"]
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 = ["example@example.com"]
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 = ["example@example.com"]
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 = ["example@example.com"]
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 = ["example@example.com"]
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 = ["example@example.com"]
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