From 2a1496728a473e7a47167526a86f402e3f71a0f7 Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Wed, 7 Mar 2018 00:40:33 +0100 Subject: [PATCH] GPR_External vs GPR_Scenario --- index/alire-index-alire.ads | 2 +- index/alire-index-dak.ads | 8 ++++---- index/alire-index-libadacrypt.ads | 4 ++-- index/alire-index-openglada.ads | 2 +- index/alire-index-sdlada.ads | 5 +++-- src/alire-gpr.adb | 13 ++++++++----- src/alire-gpr.ads | 28 ++++++++++++++++++++++++++-- src/alire-index.ads | 8 +++++--- src/alire-properties-labeled.ads | 13 ++++++------- src/alire-properties-scenarios.ads | 24 +++++++++++++++++------- src/alire-releases.adb | 7 +++++++ src/alire-releases.ads | 7 +++++-- 12 files changed, 85 insertions(+), 36 deletions(-) diff --git a/index/alire-index-alire.ads b/index/alire-index-alire.ads index a9d7a7bc..dbf2a774 100644 --- a/index/alire-index-alire.ads +++ b/index/alire-index-alire.ads @@ -42,7 +42,7 @@ package Alire.Index.Alire is Otherwise => Within_Major ("alire", V ("0.5")))), Alr_Properties => -- These are only interesting to alr, not users - GPR_Config ("-XProfile=False"), + GPR_External ("Profile", "False"), -- Sample extra params for build Properties => diff --git a/index/alire-index-dak.ads b/index/alire-index-dak.ads index 9de46f89..2454e8a1 100644 --- a/index/alire-index-dak.ads +++ b/index/alire-index-dak.ads @@ -252,16 +252,16 @@ package Alire.Index.DAK is Alr_Properties => On_Condition (System_Is (GNU_Linux), - GPR_Config ("-Xodbc=unixODBC")) and + GPR_External ("odbc", "unixODBC")) and On_Condition (System_Is (Windows), - GPR_Config ("-Xodbc=ODBC32")) and + GPR_External ("odbc", "ODBC32")) and On_Condition (Word_Size_Is (Bits_32), - GPR_Config ("-Xarch=i686")) and + GPR_External ("arch", "i686")) and On_Condition (Word_Size_Is (Bits_64), - GPR_Config ("-Xarch=x86_64")) + GPR_External ("arch", "x86_64")) ); end Alire.Index.DAK; diff --git a/index/alire-index-libadacrypt.ads b/index/alire-index-libadacrypt.ads index da94e70f..a87ecfcc 100644 --- a/index/alire-index-libadacrypt.ads +++ b/index/alire-index-libadacrypt.ads @@ -37,10 +37,10 @@ package Alire.Index.Libadacrypt is Alr_Properties => On_Condition (System_Is (GNU_Linux), - GPR_Config ("-Xsystem=unix")) and + GPR_External ("system", "unix")) and On_Condition (System_Is (Windows), - GPR_Config ("-Xsystem=windows")) + GPR_External ("system", "windows")) ); end Alire.Index.Libadacrypt; diff --git a/index/alire-index-openglada.ads b/index/alire-index-openglada.ads index f531c372..1d8cb2bd 100644 --- a/index/alire-index-openglada.ads +++ b/index/alire-index-openglada.ads @@ -44,7 +44,7 @@ package Alire.Index.OpenGLAda is Alr_Properties => On_Condition - (System_Is (GNU_Linux), GPR_Config ("-XWindowing_System=x11")), + (System_Is (GNU_Linux), GPR_External ("Windowing_System", "x11")), Available_When => System_Is (GNU_Linux) diff --git a/index/alire-index-sdlada.ads b/index/alire-index-sdlada.ads index 0a364f51..32811576 100644 --- a/index/alire-index-sdlada.ads +++ b/index/alire-index-sdlada.ads @@ -51,10 +51,11 @@ package Alire.Index.SDLAda is Executable ("test") and Executable ("version") and - GPR_Config ("-XSDL_MODE=release") and + GPR_External ("SDL_MODE", "release") and + On_Condition (System_Is (GNU_Linux), - GPR_Config ("-XSDL_PLATFORM=linux")), + GPR_External ("SDL_PLATFORM", "linux")), Available_When => System_Is (GNU_Linux) diff --git a/src/alire-gpr.adb b/src/alire-gpr.adb index f10f047b..97edaa85 100644 --- a/src/alire-gpr.adb +++ b/src/alire-gpr.adb @@ -19,11 +19,14 @@ package body Alire.GPR is end Listify; begin - if V.Kind = Free_String then - return V.Name & " = "; - else - return V.Name & " = " & Listify (V.Values); - end if; + case V.Kind is + when Free_String => + return V.Name & " = "; + when Enumeration => + return V.Name & " = " & Listify (V.Values); + when External => + return V.Name & " = " & V.Value.First_Element; + end case; end Image; ------------------ diff --git a/src/alire-gpr.ads b/src/alire-gpr.ads index 9c89c528..6ee65485 100644 --- a/src/alire-gpr.ads +++ b/src/alire-gpr.ads @@ -2,12 +2,17 @@ with Alire.Utils; package Alire.GPR with Preelaborate is - type Variable_Kinds is (Enumeration, Free_String); + type Variable_Kinds is (Enumeration, Free_String, External); + -- Enumeration: Name + all possible values + -- Free_String: Name without value + -- External : Name=Value type Variable (<>) is tagged private; function Kind (V : Variable) return Variable_Kinds; + function Name (V : Variable) return String; + function Image (V : Variable) return String; function Free_Variable (Name : String) return Variable; @@ -18,14 +23,23 @@ package Alire.GPR with Preelaborate is function Enum_Variable (Name : String; Values : Value_Vector'Class) return Variable; + -- Used to represent a Typed enum with its possible values: Name = Value1 | Value2 ... + + function External_Value (Name : String; + Value : String) return Variable; + -- Used to represent a pair Name=Value function Values (V : Variable) return Value_Vector'Class with Pre => V.Kind = Enumeration; + function External_value (V : Variable) return String + with Pre => V.Kind = External; + function "or" (L, R : Value) return Value_Vector; function "or" (L : Value_Vector; R : Value) return Value_Vector; -- A collection of Var=Arg conform a scenario: + -- These are used to store -X command-line arguments type Scenario is tagged private; @@ -45,6 +59,8 @@ private case Kind is when Enumeration => Values : Value_Vector; + when External => + Value : Value_Vector; -- Only one element when Free_String => null; end case; @@ -52,14 +68,22 @@ private function Kind (V : Variable) return Variable_Kinds is (V.Kind); + function Name (V : Variable) return String is (V.Name); + function Free_Variable (Name : String) return Variable is (Free_String, Name'Length, Name); function Enum_Variable (Name : String; Values : Value_Vector'Class) return Variable is - (Enumeration, Name'Length, Name, Value_Vector (Values)); + (Enumeration, Name'Length, Name, Value_Vector (Values)); + + function External_Value (Name : String; + Value : String) return Variable is + (External, Name'Length, Name, To_Vector (Value, 1)); function Values (V : Variable) return Value_Vector'Class is (V.Values); + function External_Value (V : Variable) return String is (V.Value.First_Element); + function "or" (L, R : Value) return Value_Vector is (L & R); function "or" (L : Value_Vector; R : Value) return Value_Vector is (L & R); diff --git a/src/alire-index.ads b/src/alire-index.ads index 6ead26ae..7b8baba4 100644 --- a/src/alire-index.ads +++ b/src/alire-index.ads @@ -211,10 +211,10 @@ package Alire.Index is renames Conditional.For_Properties.New_Value; -- Non-label attributes require a custom builder function - function GPR_Free_Scenario (Name : String) return Properties.Vector is (+Properties.Scenarios.New_Variable (GPR.Free_Variable (Name))); + function GPR_Free_Scenario (Name : String) return Properties.Vector is (+Properties.Scenarios.New_Property (GPR.Free_Variable (Name))); function GPR_Free_Scenario (Name : String) return Conditional.Properties is (U (GPR_Free_Scenario (Name))); - function GPR_Scenario (Name : String; Values : GPR.Value_Vector) return Properties.Vector is (+Properties.Scenarios.New_Variable (GPR.Enum_Variable (Name, Values))); + function GPR_Scenario (Name : String; Values : GPR.Value_Vector) return Properties.Vector is (+Properties.Scenarios.New_Property (GPR.Enum_Variable (Name, Values))); function GPR_Scenario (Name : String; Values : GPR.Value_Vector) return Conditional.Properties is (U (GPR_Scenario (Name, Values))); function License (L : Licensing.Licenses) return Properties.Vector is (+Properties.Licenses.Values.New_Property (L)); @@ -228,7 +228,9 @@ package Alire.Index is ------------------------ -- Those instruct alr on how to build, but are not the main concern of the project user - function GPR_Config is new PL.Cond_New_Label (Properties.Labeled.GPR_Config); + function GPR_External (Name : String; Value : String) return Conditional.Properties is + (U (+Properties.Scenarios.New_Property (GPR.External_Value (Name, Value)))); + function GPR_File (File : Platform_Independent_Path) return Release_Properties; function GPR_Path (Path : Platform_Independent_Path) return Release_Properties; diff --git a/src/alire-properties-labeled.ads b/src/alire-properties-labeled.ads index 9c499d3a..b85bb765 100644 --- a/src/alire-properties-labeled.ads +++ b/src/alire-properties-labeled.ads @@ -12,15 +12,14 @@ package Alire.Properties.Labeled with Preelaborate is Description, -- One-liner description, so it is searched too Executable, -- A resulting executable built by the project Maintainer, -- Info about the maintainer of the alr-packaged project - Project_File,-- GPR files that the user can use. No path. This is purely informative - Website, + Project_File,-- GPR files that the user can use. No path. Search paths given with GPR_Path + Website, -- A website other than the repository -- internal labels - GPR_Config, -- Extra config to pass to gprbuild for building the project with alr - GPR_File, -- Alternative naming of the project file (or more than one) - -- Those are used when testing the build, and must include full relative path - GPR_Path -- Extra path to add to the environment to look for projects - ); -- A website other than the repository + GPR_File, -- Alternative naming of the project file (or aditional ones) + -- Those are used when testing the build, and must include full relative path + GPR_Path -- Extra path to add to the environment to look for projects + ); type Label (<>) is new Properties.Property with private; diff --git a/src/alire-properties-scenarios.ads b/src/alire-properties-scenarios.ads index 9b1a2a8c..a62108f2 100644 --- a/src/alire-properties-scenarios.ads +++ b/src/alire-properties-scenarios.ads @@ -4,24 +4,34 @@ private with Ada.Containers.Indefinite_Holders; package Alire.Properties.Scenarios with Preelaborate is - type Variable is new Property with private; + type Property is new Properties.Property with private; - function New_Variable (V : GPR.Variable) return Variable; + function New_Property (V : GPR.Variable) return Property; - overriding function Image (V : Variable) return String; + overriding function Image (V : Property) return String; + + function Value (V : Property) return Gpr.Variable; private package Holders is new Ada.Containers.Indefinite_Holders (Gpr.Variable, GPR."="); - type Variable is new Property with record + type Property is new Properties.Property with record Var : Holders.Holder; end record; - function New_Variable (V : GPR.Variable) return Variable is + function New_Property (V : GPR.Variable) return Property is (Var => Holders.To_Holder (V)); - overriding function Image (V : Variable) return String is - ("GPR Scenario: " & V.Var.Constant_Reference.Image); + overriding function Image (V : Property) return String is + ((case V.Var.Element.Kind is + when GPR.External => "GPR External: ", + when others => "GPR Scenario: ") & V.Var.Element.Image); + +-- overriding function Image (V : Property) return String is +-- ("GPR Scenario: " & V.Var.Constant_Reference.Image); + + function Value (V : Property) return Gpr.Variable is + (V.Var.Element); end Alire.Properties.Scenarios; diff --git a/src/alire-releases.adb b/src/alire-releases.adb index ba724dad..3a336494 100644 --- a/src/alire-releases.adb +++ b/src/alire-releases.adb @@ -9,6 +9,13 @@ package body Alire.Releases is use all type Properties.Labeled.Labels; + ---------------------------- + -- On_Platform_Properties -- + ---------------------------- + + function On_Platform_Properties (R : Release; P : Properties.Vector) return Properties.Vector is + (R.Properties.Evaluate (P)); + ------------ -- Values -- ------------ diff --git a/src/alire-releases.ads b/src/alire-releases.ads index 87971c2b..369ffad2 100644 --- a/src/alire-releases.ads +++ b/src/alire-releases.ads @@ -60,6 +60,9 @@ package Alire.Releases with Preelaborate is -- Unique string built as name_version_id function Unique_Folder (R : Release) return Folder_String renames Image; + function On_Platform_Properties (R : Release; P : Properties.Vector) return Properties.Vector; + -- Return properties that apply to R under platform properties P + function Labeled_Properties (R : Release; P : Properties.Vector; Label : Properties.Labeled.Labels) return Utils.String_Vector; -- Get all values for a given property for a given platform properties @@ -98,8 +101,8 @@ private function Unavailable return Conditional.Dependencies is (On ("alire_unavailable", Semantic_Versioning.Any)); - use Properties; - function Describe is new Properties.Labeled.Cond_New_Label (Properties.Labeled.Description); + use Alire.Properties; + function Describe is new Alire.Properties.Labeled.Cond_New_Label (Alire.Properties.Labeled.Description); type Release (Name_Len, Descr_Len : Natural) is tagged record Name : Project_Name (1 .. Name_Len);