From 059b672a031f504f3caab384aadc783057cf3124 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Thu, 1 Mar 2018 19:27:58 +0100 Subject: [PATCH] Conditional properties working --- index/alire-index-alire.ads | 25 ++- index/alire-index-dak.ads | 232 --------------------- index/alire-index-example_dependencies.ads | 14 -- index/alire-index-pragmarc.ads | 40 ---- index/alire-index-rxada.ads | 24 --- src/alire-conditional-vectors.adb | 42 ++++ src/alire-conditional-vectors.ads | 30 +++ src/alire-conditional.ads | 27 ++- src/alire-conditions.ads | 12 ++ src/alire-index.adb | 4 +- src/alire-index.ads | 27 ++- src/alire-properties-labeled.ads | 9 + src/alire-properties.adb | 16 ++ src/alire-properties.ads | 6 + src/alire-releases.adb | 62 ++++-- src/alire-releases.ads | 19 +- src/alire-root_project.adb | 7 +- src/alire-root_project.ads | 4 +- 18 files changed, 250 insertions(+), 350 deletions(-) delete mode 100644 index/alire-index-dak.ads delete mode 100644 index/alire-index-example_dependencies.ads delete mode 100644 index/alire-index-pragmarc.ads delete mode 100644 index/alire-index-rxada.ads create mode 100644 src/alire-conditional-vectors.adb create mode 100644 src/alire-conditional-vectors.ads create mode 100644 src/alire-conditions.ads create mode 100644 src/alire-properties.adb diff --git a/index/alire-index-alire.ads b/index/alire-index-alire.ads index 1f56e926..b0df4a37 100644 --- a/index/alire-index-alire.ads +++ b/index/alire-index-alire.ads @@ -15,6 +15,29 @@ package Alire.Index.Alire is Git (Repo, "e2dee2e147ae9e4d666567b53b108cbe61bc06e8"), Depends_On => Within_Minor (Semantic_Versioning.V_0_1) and - Within_Major (Simple_Logging.V_1)); + Within_Major (Simple_Logging.V_1) + ); + + + Syntax_Example : constant Release := + Register ("alire_example", + V ("1.0.0"), + "Release with all index syntax features", + Origins.New_Filesystem ("/fake"), + Properties => + If_Platform + (System_Is (GNU_Linux), + Comment ("Long life the penguin")) and + If_Platform + (not Compiler_Is_At_Least (GNAT_Unknown), + Comment ("Never saw that compiler") and Comment ("But I would like to")) and + If_Platform + (Distribution_Is (Ubuntu_Artful), + When_True => Comment ("Living on the edge"), + When_False => Comment ("I am a rock")) and + Comment ("Tell me about your mother"), + Available_When => -- Impossible mix + (System_Is (Windows) and System_Is (GNU_Linux)) or + (Compiler_Is_At_Least (GNAT_Unknown) and not Compiler_Is_At_Least (GNAT_Unknown))); end Alire.Index.Alire; diff --git a/index/alire-index-dak.ads b/index/alire-index-dak.ads deleted file mode 100644 index 17b4cbb2..00000000 --- a/index/alire-index-dak.ads +++ /dev/null @@ -1,232 +0,0 @@ -with Alire.Index.LibGNUTLS; - -package Alire.Index.DAK is - - -- Simple Components by Dmitry A. Kazakov - -- This library is a good challenge since it has many subprojects - -- It prompted the introduction of the GPR_File property - - -- Since most project names are common words, I've taken the liberty to prefix them with dak_ - -- but the original sources are unchanged. - - Base : constant Project_Name := "dak_"; - Repo : constant URL := "https://github.com/alire-project/dak_simple_components.git"; - - DAK_Author : constant String := "Dmitry A. Kazakov"; - DAK_Website : constant String := "http://www.dmitry-kazakov.de/ada/components.htm"; - - Desc_Pre : constant String := "Simple Components "; - Desc_Post : constant String := " by Dmitry A. Kazakov"; - - Strings_Edit_V_4_27 : constant Release := - Register (Base & "strings_edit", - V ("4.27"), - Desc_Pre & "(strings)" & Desc_Post, - Git (Repo, "44ac8e0c817558b8641f746ce225b3d2fa90b7a1"), - Properties => - - GPR_File ("strings_edit.gpr") and - GPR_File ("test_strings_edit" / "strings_edit-test.gpr") and - - GPR_Scenario ("Legacy", "Ada95" or "Ada2005" or "Ada2012") and - GPR_Scenario ("Development", "Debug" or "Release") and - - Executable ("test_base64") and - Executable ("test_strings_edit") and - Executable ("test_string_streams") and - - License (GMGPL_2_0) and - Author (DAK_Author) and - Website (DAK_Website) - ); - - Tables_V_4_27 : constant Release := - Register (Base & "tables", - V ("4.27"), - Desc_Pre & "(tables)" & Desc_Post, - Git (Repo, "19205e4981d72242daf72da7d59c5faf2b4c91fd"), - Properties => - - GPR_File ("tables.gpr") and - GPR_File ("test_tables" / "tables-test.gpr") and - - GPR_Scenario ("Legacy", "Ada95" or "Ada2005" or "Ada2012") and - GPR_Scenario ("Development", "Debug" or "Release") and - - Executable ("test_tables") and - - License (GMGPL_2_0) and - Author (DAK_Author) and - Website (DAK_Website) - ); - - Components_V_4_27 : constant Release := - Register (Base & "components", - V ("4.27"), - Desc_Pre & "(base components)" & Desc_Post, - Git (Repo, "542f02c9be86693f759fcb784a8462bc4b25f1f2"), - Depends_On => - Within_Major (Strings_Edit_V_4_27) and - Within_Major (Tables_V_4_27), - - Properties => - GPR_File ("components.gpr") and - GPR_File ("test_components" / "components-tests.gpr") and - - GPR_Scenario ("Atomic_Access", "Pragma-atomic" or "GCC-built-ins" or "GCC-long-offsets") and - GPR_Scenario ("Tasking", "Multiple" or "Single") and - GPR_Scenario ("Traced_objects", "Off" or "On") and - - Executable ("test_approximations") and - Executable ("test_association") and - Executable ("test_blackboard") and - Executable ("test_blackboard_performance") and - Executable ("test_blocking_files") and - Executable ("test_block_streams") and - Executable ("test_b_trees") and - Executable ("test_cubic_spline") and - Executable ("test_dining_philosophers") and - Executable ("test_fifo") and - Executable ("test_generic_indefinite_sets") and - Executable ("test_generic_maps") and - Executable ("test_generic_sets") and - Executable ("test_graphs") and - Executable ("test_handles") and - Executable ("test_ieee_754") and - Executable ("test_linked_lists") and - Executable ("test_linked_lists_scheduler_test") and - Executable ("test_parser_stream_io") and - Executable ("test_persistent_memory_pool") and - Executable ("test_persistent_storage") and - Executable ("test_sequencer") and - Executable ("test_single_file_persistence") and - Executable ("test_stack") and - Executable ("test_storage_streams") and - Executable ("test_string_streams") and - Executable ("test_synchronization_events") and - Executable ("test_transactional_blocking_files") and - Executable ("test_utf8_tables") and - - License (GMGPL_2_0) and - Author (DAK_Author) and - Website (DAK_Website) and - Comment ("Tasking=Single seems to be broken at persistent-single_file-text_io.adb") - ); - - Components_NTP_V_4_27 : constant Release := - Register (Base & "components_ntp", - V ("4.27"), - Desc_Pre & "(ntp)" & Desc_Post, - Git (Repo, "34fb305d6ef360cde5e272b51409097a5de72017"), - Depends_On => - Within_Major (Components_V_4_27), - - Properties => - GPR_File ("components-ntp.gpr") and - GPR_File ("test_components" / "components-ntp-test_ntp.gpr") and - - Executable ("test_ntp") and - - License (GMGPL_2_0) and - Author (DAK_Author) and - Website (DAK_Website) - ); - - Components_Sqlite_V_4_27 : constant Release := - Register (Base & "components_sqlite", - V ("4.27"), - Desc_Pre & "(sqlite)" & Desc_Post, - Git (Repo, "6fda0f3f7494815c87b329f7411b9a49ff97b9ba"), - Depends_On => - Within_Major (Components_V_4_27), - - Properties => - GPR_File ("components-sqlite.gpr") and - GPR_File ("test_components" / "components-sqlite-benchmark_tests.gpr") and - GPR_File ("test_components" / "components-sqlite-sqlite_persistence_tests.gpr") and - - Executable ("test_sqlite_benchmark") and - Executable ("test_sqlite_persistence") and - - License (GMGPL_2_0) and - Author (DAK_Author) and - Website (DAK_Website) - ); - - Components_Connections_V_4_27 : constant Release := - Register (Base & "components_connections", - V ("4.27"), - Desc_Pre & "(clients/servers)" & Desc_Post, - Git (Repo, "008935d5a89396cc0c39afb39f04bf6a89a92058"), - Depends_On => - Within_Major (Components_V_4_27) and - Within_Major (Components_Sqlite_V_4_27), - - Properties => - -- Main projects - GPR_File ("components-connections_server.gpr") and - GPR_File ("components-connections_server-elv_max_cube.gpr") and - GPR_File ("components-connections_server-http_server.gpr") and - GPR_File ("components-connections_server-http_server-sqlite_browser.gpr") and - GPR_File ("components-connections_server-modbus.gpr") and - GPR_File ("components-connections_server-mqtt.gpr") and - GPR_File ("components-connections_server-smtp.gpr") and - -- Test projects - GPR_File ("test_components" / "components-connections_server-elv_max_cube-test_elv_max_cube_client.gpr") and - GPR_File ("test_components" / "components-connections_server-http_server-test_http_server.gpr") and - GPR_File ("test_components" / "components-connections_server-modbus-test_modbus_client.gpr") and - GPR_File ("test_components" / "components-connections_server-mqtt-test_mqtt.gpr") and - GPR_File ("test_components" / "components-connections_server-test_data_server.gpr") and - GPR_File ("test_components" / "components-connections_server-test_echo_client_async.gpr") and - GPR_File ("test_components" / "components-connections_server-test_echo_client.gpr") and - GPR_File ("test_components" / "components-connections_server-test_echo_server.gpr") and - GPR_File ("test_components" / "components-connections_server-test_websockets_mqtt.gpr") and - GPR_File ("test_components" / "components-test_sqlite_browser.gpr") and - - Executable ("test_data_server") and - Executable ("test_echo_client") and - Executable ("test_echo_client_async") and - Executable ("test_echo_server") and - Executable ("test_elv_max_cube_client") and - Executable ("test_http_client") and - Executable ("test_http_continuous_server") and - Executable ("test_http_server") and - Executable ("test_http_sqlite_browser") and - Executable ("test_infinity_server") and - Executable ("test_modbus_client") and - Executable ("test_mqtt_client") and - Executable ("test_mqtt_server") and - Executable ("test_mqtt_webserver") and - Executable ("test_websocket_duplex_server") and - Executable ("test_websocket_server") and - - License (GMGPL_2_0) and - Author (DAK_Author) and - Website (DAK_Website) - ); - - Components_Connections_Secure_V_4_27 : constant Release := - Register (Base & "components_connections_secure", - V ("4.27"), - Desc_Pre & "(client/servers over TLS)" & Desc_Post, - Git (Repo, "ca72cf4150ae14ba6d40c3d2dd92c7846cb4cb5d"), - Depends_On => - Within_Major (Components_Connections_V_4_27) and - Within_Major (LibGNUTLS.V_3_5_8), - - Properties => - GPR_File ("components-connections_server-secure.gpr") and - GPR_File ("components-gnutls.gpr") and - GPR_File ("test_components" / "components-connections_server-http_server-test_https_server.gpr") and - GPR_File ("test_components" / "components-connections_server-smtp-test_smtp.gpr") and - - Executable ("test_https_client") and - Executable ("test_https_server") and - Executable ("test_smtp_client") and - - License (GMGPL_2_0) and - Author (DAK_Author) and - Website (DAK_Website) - ); - -end Alire.Index.DAK; diff --git a/index/alire-index-example_dependencies.ads b/index/alire-index-example_dependencies.ads deleted file mode 100644 index 21bea481..00000000 --- a/index/alire-index-example_dependencies.ads +++ /dev/null @@ -1,14 +0,0 @@ -with Alire.Origins; - -package Alire.Index.Example_Dependencies is - - V_1_0_0 : constant Release := - Register ("alr_example_dependencies", - V ("1.0.0"), - "Release with assorted advanced dependency conditions", - Origins.New_Filesystem ("/fake"), - Available_When => -- Impossible mix - (System_Is (Windows) and System_Is (GNU_Linux)) or - (Compiler_Is_At_Least (GNAT_Unknown) and not Compiler_Is_At_Least (GNAT_Unknown))); - -end Alire.Index.Example_Dependencies; diff --git a/index/alire-index-pragmarc.ads b/index/alire-index-pragmarc.ads deleted file mode 100644 index e10fbfb6..00000000 --- a/index/alire-index-pragmarc.ads +++ /dev/null @@ -1,40 +0,0 @@ -package Alire.Index.PragmARC is - - Name : constant Project_Name := "pragmarc"; - Repo : constant URL := "https://github.com/alire-project/PragmARC.git"; - - Desc : constant Project_Description := - "PragmAda Reusable Components (PragmARCs), "; - - Auth : constant String := "Jeffrey R. Carter"; - - Web1 : constant String := "https://github.com/jrcarter/PragmARC"; - Web2 : constant String := "https://pragmada.x10hosting.com/"; - - V_2017 : constant Release := -- Experimental '07 version - Register (Name, - V ("2017.2007.0"), - Desc & "ISO/IEC 8652:2007 version", - Git (Repo, "db6c1730fe825f8303c60b48f82db08bd408588d"), - Properties => - Executable ("compile_all") and - License (GMGPL_2_0) and - Author (Auth) and - Website (Web1) and - Website (Web2) - ); - - V_2011 : constant Release := -- Pure Ada95 version - Register (Name, - V ("2011.1995.0"), - Desc & "Ada 95 version", - Git (Repo, "34b0e12b5f9aea63408c94cc48ba7a16687c8d76"), - Properties => - Executable ("compile_all") and - License (GMGPL_2_0) and - Author (Auth) and - Website (Web1) and - Website (Web2) - ); - -end Alire.Index.PragmARC; diff --git a/index/alire-index-rxada.ads b/index/alire-index-rxada.ads deleted file mode 100644 index 9395681f..00000000 --- a/index/alire-index-rxada.ads +++ /dev/null @@ -1,24 +0,0 @@ -package Alire.Index.RxAda is - - Name : constant Project_Name := "rxada"; - Repo : constant URL := "https://bitbucket.org/amosteo/rxada"; - - Desc : constant Project_Description := "RxAda port of the Rx framework"; - - V_0_1_0 : constant Release := - Register (Name, - V ("0.1.0"), - Desc, - Hg (Repo, "361d4e2ab20a7dcca007e31bf7094d57b13fee6b"), - Properties => - - Executable ("rx-examples-basic") and - Executable ("rx-examples-minimal") and - Executable ("rx-examples-tests") and - Executable ("rx-examples-threading") and - - License (LGPL_3_0) and - Maintainer ("alejandro@mosteo.com") and - Website (Repo)); - -end Alire.Index.RxAda; diff --git a/src/alire-conditional-vectors.adb b/src/alire-conditional-vectors.adb new file mode 100644 index 00000000..25a85082 --- /dev/null +++ b/src/alire-conditional-vectors.adb @@ -0,0 +1,42 @@ +package body Alire.Conditional.Vectors is + + ---------------- + -- All_Values -- + ---------------- + + function All_Values (V : Vector) return Values is + begin + return Result : Values do + for Cond of V loop + Result := Result & Cond.Then_Value & Cond.Else_Value; + end loop; + end return; + end All_Values; + + -------------- + -- Evaluate -- + -------------- + + function Evaluate (V : Vector; On : Properties.Vector) return Values is + begin + return Result : Values do + for Cond of V loop + Result := Result & Cond.Evaluate (On); + end loop; + end return; + end Evaluate; + + -------------- + -- Evaluate -- + -------------- + + function Evaluate (V : Vector; On : Properties.Vector) return Vector is + begin + return Result : Vector do + for Cond of V loop + Result.Append (Conditional_Value'(New_Inconditional (Values'(Cond.Evaluate (On))))); + end loop; + end return; + end Evaluate; + +end Alire.Conditional.Vectors; diff --git a/src/alire-conditional-vectors.ads b/src/alire-conditional-vectors.ads new file mode 100644 index 00000000..5e8d0b09 --- /dev/null +++ b/src/alire-conditional-vectors.ads @@ -0,0 +1,30 @@ +with Ada.Containers.Indefinite_Vectors; + +generic +package Alire.Conditional.Vectors with Preelaborate is + + package Condition_Vectors is new Ada.Containers.Indefinite_Vectors (Positive, Conditional_Value); + + type Vector is new Condition_Vectors.Vector with null record; + + function All_Values (V : Vector) return Values; + + function Evaluate (V : Vector; On : Properties.Vector) return Values; + -- Return the values that pass evaluation + + function Evaluate (V : Vector; On : Properties.Vector) return Vector; + -- Take the values that pass evaluation and make a vector of inconditionals + + function New_Conditional (If_X : Requisites.Tree; + Then_X : Values; + Else_X : Values) return Vector is + (To_Vector (New_Conditional (If_X, Then_X, Else_X), 1)); + + function New_Inconditional (V : Values) return Vector is (To_Vector (New_Inconditional (V), 1)); + + function "+" (V : Conditional_Value) return Vector is (To_Vector (V, 1)); + function "and" (L, R : Vector) return Vector is (L & R); + + Empty_Vector : constant Vector := (Condition_Vectors.Empty_Vector with null record); + +end Alire.Conditional.Vectors; diff --git a/src/alire-conditional.ads b/src/alire-conditional.ads index ae219dfa..dd69f2de 100644 --- a/src/alire-conditional.ads +++ b/src/alire-conditional.ads @@ -3,7 +3,9 @@ with Alire.Requisites; generic type Values is private; -package Alire.Conditional is + with function "&" (L, R : Values) return Values with Unreferenced; -- used in child vectors + -- FIXME: we'll have to keep an eye on the overhead of this (append to be considered) +package Alire.Conditional with Preelaborate is type Conditional_Value (<>) is tagged private; @@ -11,8 +13,18 @@ package Alire.Conditional is Then_X : Values; Else_X : Values) return Conditional_Value; + function New_Inconditional (V : Values) return Conditional_Value; + function Evaluate (This : Conditional_Value; Against : Properties.Vector) return Values; + function Condition (This : Conditional_Value) return Requisites.Tree; + + function Is_Inconditional (This : Conditional_Value) return Boolean; + + function True_Value (This : Conditional_Value) return Values; + + function False_Value (This : Conditional_Value) return Values; + private type Conditional_Value is tagged record @@ -33,4 +45,17 @@ private Then_Value => Then_X, Else_Value => Else_X); + function New_Inconditional (V : Values) return Conditional_Value is + (Condition => Requisites.No_Requisites, + Then_Value => V, + Else_Value => <>); + + function Condition (This : Conditional_Value) return Requisites.Tree is (This.Condition); + + function Is_Inconditional (This : Conditional_Value) return Boolean is (This.Condition.Is_Empty); + + function True_Value (This : Conditional_Value) return Values is (This.Then_Value); + + function False_Value (This : Conditional_Value) return Values is (This.Else_Value); + end Alire.Conditional; diff --git a/src/alire-conditions.ads b/src/alire-conditions.ads new file mode 100644 index 00000000..fc8206b1 --- /dev/null +++ b/src/alire-conditions.ads @@ -0,0 +1,12 @@ +with Alire.Conditional; +with Alire.Conditional.Vectors; +with Alire.Properties; +with Alire.Requisites; + +package Alire.Conditions with Preelaborate is + + package For_Properties is new Conditional (Properties.Vector, + Properties."and"); + package Properties is new For_Properties.Vectors; -- Conditional properties declared therein + +end Alire.Conditions; diff --git a/src/alire-index.adb b/src/alire-index.adb index 6fb923c3..a7f6abf2 100644 --- a/src/alire-index.adb +++ b/src/alire-index.adb @@ -42,8 +42,7 @@ package body Alire.Index is Description : Project_Description; Origin : Origins.Origin; Depends_On : Dependencies := No_Dependencies; - Properties : Alire.Properties.Vector := No_Properties; - Requisites : Alire.Requisites.Tree := No_Requisites; + Properties : Release_Properties := No_Properties; Available_When : Alire.Requisites.Tree := No_Requisites) return Release is begin @@ -54,7 +53,6 @@ package body Alire.Index is Origin, Depends_On, Properties => Properties, - Requisites => Requisites, Available => Available_When) do if Releases.Contains (Rel) then diff --git a/src/alire-index.ads b/src/alire-index.ads index 86605060..f260438b 100644 --- a/src/alire-index.ads +++ b/src/alire-index.ads @@ -2,6 +2,7 @@ private with Alire_Early_Elaboration; pragma Unreferenced (Alire_Early_Elaborati with Ada.Directories; +with Alire.Conditions; with Alire.Containers; with Alire.Dependencies.Vectors; with Alire.GPR; @@ -22,11 +23,13 @@ with Semantic_Versioning; package Alire.Index is Releases : Containers.Release_Set; + + subtype Release_Properties is Conditions.Properties.Vector; subtype Dependencies is Alire.Dependencies.Vectors.Vector; No_Dependencies : constant Dependencies := Alire.Dependencies.Vectors.No_Dependencies; - No_Properties : constant Properties.Vector := Properties.No_Properties; + No_Properties : constant Release_Properties := Conditions.Properties.Empty_Vector; No_Requisites : constant Requisites.Tree := Requisites.Trees.Empty_Tree; subtype Release is Alire.Releases.Release; @@ -38,8 +41,7 @@ package Alire.Index is Origin : Origins.Origin; -- Optional Depends_On : Dependencies := No_Dependencies; - Properties : Alire.Properties.Vector := No_Properties; - Requisites : Alire.Requisites.Tree := No_Requisites; + Properties : Release_Properties := No_Properties; Available_When : Alire.Requisites.Tree := No_Requisites) return Release; -- Properties are of the Release -- Requisites are properties that dependencies have to fulfill, not used yet. @@ -113,13 +115,20 @@ package Alire.Index is use all type Platforms.Distributions; use all type Platforms.Operating_Systems; use all type Properties.Property'Class; + use all type Release_Properties; use all type Requisites.Requisite'Class; use all type Requisites.Tree; -- These "use all" are useful for alire-index-* packages, but not for project_alr metadata files + -- Function for introducing conditional properties + function If_Platform (Condition : Requisites.Tree; + When_True : Properties.Vector; + When_False : Properties.Vector := Properties.No_Properties) return Release_Properties; + -- "Typed" attributes (named pairs of label-value) function Author is new Properties.Labeled.Generic_New_Label (Properties.Labeled.Author); function Comment is new Properties.Labeled.Generic_New_Label (Properties.Labeled.Comment); + function Comment is new Properties.Labeled.Inconditional_New_Label (Properties.Labeled.Comment); function Executable is new Properties.Labeled.Generic_New_Label (Properties.Labeled.Executable); function GPR_File is new Properties.Labeled.Generic_New_Label (Properties.Labeled.GPR_File); function GPR_Free_Scenario (Name : String) return Properties.Vector; @@ -129,8 +138,6 @@ package Alire.Index is function License (L : Licensing.Licenses) return Properties.Vector is (+Properties.Licenses.Values.New_Property (L)); - - Default_Properties : constant Properties.Vector := No_Properties; function "and" (Dep1, Dep2 : Dependencies) return Dependencies renames Alire.Dependencies.Vectors."and"; function "and" (P1, P2 : Properties.Vector) return Properties.Vector renames Alire.Properties."and"; @@ -164,8 +171,7 @@ package Alire.Index is function Set_Root_Project (Project : Alire.Project_Name; Version : Semantic_Versioning.Version; - Depends_On : Alire.Index.Dependencies := Alire.Index.No_Dependencies; - Properties : Alire.Properties.Vector := No_Properties) + Depends_On : Alire.Index.Dependencies := Alire.Index.No_Dependencies) return Release renames Root_Project.Set; -- This function must be called in the working project alire file. -- Otherwise alr does not know what's the current project, and its version and dependencies @@ -242,6 +248,11 @@ private (+Properties.Scenarios.New_Variable (GPR.Free_Variable (Name))); function GPR_Scenario (Name : String; Values : GPR.Value_Vector) return Properties.Vector is - (+Properties.Scenarios.New_Variable (GPR.Enum_Variable (Name, Values))); + (+Properties.Scenarios.New_Variable (GPR.Enum_Variable (Name, Values))); + + function If_Platform (Condition : Requisites.Tree; + When_True : Properties.Vector; + When_False : Properties.Vector := Properties.No_Properties) return Release_Properties is + (Conditions.Properties.New_Conditional (Condition, When_True, When_False)); end Alire.Index; diff --git a/src/alire-properties-labeled.ads b/src/alire-properties-labeled.ads index 03923752..2d623d0e 100644 --- a/src/alire-properties-labeled.ads +++ b/src/alire-properties-labeled.ads @@ -1,3 +1,5 @@ +with Alire.Conditions; + private with Alire.Utils; package Alire.Properties.Labeled with Preelaborate is @@ -27,6 +29,10 @@ package Alire.Properties.Labeled with Preelaborate is function Generic_New_Label (Value : String) return Properties.Vector; -- Returns a vector so its directly usable during indexing + generic + Name : Labels; + function Inconditional_New_Label (Value : String) return Conditions.Properties.Vector; + private type Label (Length : Natural) is new Properties.Property with record @@ -44,6 +50,9 @@ private function Generic_New_Label (Value : String) return Properties.Vector is (To_Vector (New_Label (Name, Value), 1)); + function Inconditional_New_Label (Value : String) return Conditions.Properties.Vector is + (Conditions.Properties.New_Inconditional (+New_Label (Name, Value))); + overriding function Image (L : Label) return String is (Utils.To_Mixed_Case (L.Name'Img) & ": " & L.Value); end Alire.Properties.Labeled; diff --git a/src/alire-properties.adb b/src/alire-properties.adb new file mode 100644 index 00000000..383da304 --- /dev/null +++ b/src/alire-properties.adb @@ -0,0 +1,16 @@ +with GNAT.IO; + +package body Alire.Properties is + + ----------- + -- Print -- + ----------- + + procedure Print (V : Vector; Prefix : String := "") is + begin + for Prop of V loop + GNAT.IO.Put_Line (Prefix & Prop.Image); + end loop; + end Print; + +end Alire.Properties; diff --git a/src/alire-properties.ads b/src/alire-properties.ads index e6afea6a..d107823b 100644 --- a/src/alire-properties.ads +++ b/src/alire-properties.ads @@ -20,6 +20,10 @@ package Alire.Properties with Preelaborate is No_Properties : constant Vector; + procedure Print (V : Vector; Prefix : String := ""); + + function Empty_Properties return Vector; + -- function "and" (L, R : Property'Class) return Vector; -- function "and" (L : Vector; R : Property'Class) return Vector; function "and" (L, R : Vector) return Vector; @@ -57,6 +61,8 @@ private No_Properties : constant Vector := (Vectors.Empty_Vector with null record); + function Empty_Properties return Vector is (No_Properties); + function "and" (L, R : Vector) return Vector is (L & R); function "+" (P : Property'Class) return Vector is (To_Vector (P, 1)); diff --git a/src/alire-releases.adb b/src/alire-releases.adb index d7d9e6b8..1a061bb7 100644 --- a/src/alire-releases.adb +++ b/src/alire-releases.adb @@ -32,7 +32,7 @@ package body Alire.Releases is function Executables (R : Release) return Utils.String_Vector is begin - return Exes : Utils.String_Vector := Values (R.Props, Executable) do + return Exes : Utils.String_Vector := Values (R.Properties.All_Values, Executable) do if OS_Lib.Exe_Suffix /= "" then for I in Exes.Iterate loop Exes (I) := Exes (I) & OS_Lib.Exe_Suffix; @@ -47,13 +47,37 @@ package body Alire.Releases is function GPR_Files (R : Release) return Utils.String_Vector is begin - return Files : Utils.String_Vector := Values (R.Props, GPR_File) do + return Files : Utils.String_Vector := Values (R.Properties.All_Values, GPR_File) do if Files.Is_Empty then Files.Append (R.Project & ".gpr"); end if; end return; end GPR_Files; + -------------------------------- + -- Print_Conditional_Property -- + -------------------------------- + + procedure Print_Conditional_Property (Cond : Conditions.For_Properties.Conditional_Value) is + use GNAT.IO; + begin + if Cond.Is_Inconditional then + Cond.True_Value.Print (Prefix => " "); + else + if Cond.True_Value.Is_Empty then + Put_Line (" when not (" & Cond.Condition.Image & "):"); + Cond.False_Value.Print (Prefix => " "); + else + Put_Line (" when " & Cond.Condition.Image & ":"); + Cond.True_Value.Print (Prefix => " "); + if not Cond.False_Value.Is_Empty then + Put_Line (" else:"); + Cond.False_Value.Print (Prefix => " "); + end if; + end if; + end if; + end Print_Conditional_Property; + ----------- -- Print -- ----------- @@ -72,17 +96,11 @@ package body Alire.Releases is Put_Line ("Available when: " & R.Available.Image); end if; - -- REQUISITES - if not R.Reqs.Is_Empty then - Put ("Requisites: "); - R.Reqs.Print_Skeleton; - end if; - -- PROPERTIES - if not R.Props.Is_Empty then + if not R.Properties.Is_Empty then Put_Line ("Properties:"); - for Prop of R.Props loop - Put_Line (" " & Prop.Image); + for Cond of R.Properties loop + Print_Conditional_Property (Cond); end loop; end if; @@ -104,7 +122,7 @@ package body Alire.Releases is Search : constant String := To_Lower_Case (Str); begin - for P of R.Props loop + for P of R.Properties.All_Values loop declare Text : constant String := To_Lower_Case @@ -121,4 +139,24 @@ package body Alire.Releases is return False; end Property_Contains; + -------------- + -- Whenever -- + -------------- + + function Whenever (R : Release; P : Properties.Vector) return Release is + begin + return Solid : constant Release (R.Name_Len, R.Descr_Len) := + (R.Name_Len, R.Descr_Len, + R.Name, + R.Description, + R.Version, + R.Origin, + R.Depends_On, + R.Properties.Evaluate (P), + R.Available) + do + null; + end return; + end Whenever; + end Alire.Releases; diff --git a/src/alire-releases.ads b/src/alire-releases.ads index 188673d2..3657ac0e 100644 --- a/src/alire-releases.ads +++ b/src/alire-releases.ads @@ -1,3 +1,4 @@ +with Alire.Conditions; with Alire.Dependencies.Vectors; with Alire.Milestones; with Alire.Origins; @@ -21,11 +22,13 @@ package Alire.Releases with Preelaborate is Version : Semantic_Versioning.Version; Origin : Origins.Origin; Depends_On : Dependencies; - Properties : Alire.Properties.Vector; - Requisites : Alire.Requisites.Tree; + Properties : Conditions.Properties.Vector; Available : Alire.Requisites.Tree) return Release; function "<" (L, R : Release) return Boolean; + + function Whenever (R : Release; P : Properties.Vector) return Release; + -- Materialize conditions in a Release once the system/whatever properties are known function Project (R : Release) return Project_Name; function Description (R : Release) return Project_Description; @@ -68,18 +71,19 @@ private Version : Semantic_Versioning.Version; Origin : Origins.Origin; Depends_On : Dependencies; - Props : Properties.Vector; - Reqs : Requisites.Tree; + Properties : Conditions.Properties.Vector; +-- Reqs : Requisites.Tree; Available : Requisites.Tree; end record; + use Conditions.Properties; + function New_Release (Name : Project_Name; Description : Project_Description; Version : Semantic_Versioning.Version; Origin : Origins.Origin; Depends_On : Dependencies; - Properties : Alire.Properties.Vector; - Requisites : Alire.Requisites.Tree; + Properties : Conditions.Properties.Vector; Available : Alire.Requisites.Tree) return Release is (Name'Length, Description'Length, Name, @@ -87,8 +91,7 @@ private Version, Origin, Depends_On, - Properties and Describe (Description), - Requisites, + +Conditions.For_Properties.New_Inconditional (Describe (Description)) and Properties, Available); use Semantic_Versioning; diff --git a/src/alire-root_project.adb b/src/alire-root_project.adb index 3d65d605..2f20c3e8 100644 --- a/src/alire-root_project.adb +++ b/src/alire-root_project.adb @@ -1,6 +1,7 @@ with Ada.Directories; +with Alire.Conditions; with Alire.Containers; with Alire.Index; with Alire.Origins; @@ -32,8 +33,7 @@ package body Alire.Root_Project is function Set (Project : Alire.Project_Name; Version : Semantic_Versioning.Version; - Depends_On : Alire.Dependencies.Vectors.Vector := Alire.Dependencies.Vectors.No_Dependencies; - Properties : Alire.Properties.Vector := Alire.Properties.No_Properties) + Depends_On : Alire.Dependencies.Vectors.Vector := Alire.Dependencies.Vectors.No_Dependencies) return Releases.Release is use Origins; @@ -46,8 +46,7 @@ package body Alire.Root_Project is Version, New_Filesystem (Ada.Directories.Current_Directory), Depends_On, - Properties => Properties, - Requisites => Requisites.No_Requisites, + Properties => Conditions.Properties.Empty_Vector, Available => Requisites.No_Requisites); begin if Index.Exists (Project, Version) then diff --git a/src/alire-root_project.ads b/src/alire-root_project.ads index 7e1d6233..fd8d8191 100644 --- a/src/alire-root_project.ads +++ b/src/alire-root_project.ads @@ -1,5 +1,4 @@ with Alire.Dependencies.Vectors; -with Alire.Properties; with Alire.Releases; with Semantic_Versioning; @@ -12,8 +11,7 @@ package Alire.Root_Project is function Set (Project : Alire.Project_Name; Version : Semantic_Versioning.Version; - Depends_On : Alire.Dependencies.Vectors.Vector := Alire.Dependencies.Vectors.No_Dependencies; - Properties : Alire.Properties.Vector := Alire.Properties.No_Properties) + Depends_On : Alire.Dependencies.Vectors.Vector := Alire.Dependencies.Vectors.No_Dependencies) return Releases.Release; -- This function must be called in the working project alire file. -- Otherwise alr does not know what's the current project, and its version and dependencies