Enforced platform paths

This commit is contained in:
Alejandro R. Mosteo
2018-03-05 20:59:53 +01:00
parent 6b1629d0a4
commit 0b32fdfc20
8 changed files with 148 additions and 54 deletions
+23
View File
@@ -1,3 +1,6 @@
with Ada.Directories;
with Ada.Strings.Maps;
package body Alire.Index is
use all type Version;
@@ -68,4 +71,24 @@ package body Alire.Index is
end return;
end Register;
---------------
-- To_Native --
---------------
Dir_Seps : constant Ada.Strings.Maps.Character_Set := Ada.Strings.Maps.To_Set ("/\");
function To_Native (Path : Platform_Independent_Path) return String is
use Ada.Strings.Maps;
begin
for I in Path'Range loop
if Is_In (Path (I), Dir_Seps) then
return Ada.Directories.Compose
(Path (Path'First .. I - 1),
To_Native (Path (I + 1 .. Path'Last)));
end if;
end loop;
return Path;
end To_Native;
end Alire.Index;
+16 -12
View File
@@ -1,7 +1,5 @@
private with Alire_Early_Elaboration; pragma Unreferenced (Alire_Early_Elaboration);
with Ada.Directories;
with Alire.Conditional;
with Alire.Containers;
with Alire.Dependencies.Vectors;
@@ -48,6 +46,13 @@ package Alire.Index is
-- Requisites are properties that dependencies have to fulfill, not used yet.
-- Available_On are properties the platform has to fulfill.
subtype Platform_Independent_Path is String with Dynamic_Predicate =>
(for all C of Platform_Independent_Path => C /= '\');
-- This type is used to ensure that folder separators are externally always '/',
-- and internally properly converted to the platform one
function To_Native (Path : Platform_Independent_Path) return String;
---------------------
-- BASIC QUERIES --
---------------------
@@ -179,8 +184,8 @@ package Alire.Index is
function Author is new PL.Cond_New_Label (Properties.Labeled.Author);
function Comment is new PL.Cond_New_Label (Properties.Labeled.Comment);
function Executable is new PL.Cond_New_Label (Properties.Labeled.Executable);
function GPR_Extra_Config is new PL.Cond_New_Label (Properties.Labeled.GPR_Extra_Config);
function GPR_File is new PL.Cond_New_Label (Properties.Labeled.GPR_File);
function GPR_Extra_Config is new PL.Cond_New_Label (Properties.Labeled.GPR_Extra_Config);
function GPR_File (File : Platform_Independent_Path) return Release_Properties;
function Maintainer is new PL.Cond_New_Label (Properties.Labeled.Maintainer);
function Website is new PL.Cond_New_Label (Properties.Labeled.Website);
@@ -227,14 +232,6 @@ package Alire.Index is
function Word_Size_Is (V : Platforms.Word_Sizes) return Requisites.Tree
renames Requisites.Platform.Word_Size_Is;
-- function Version_Is (V : Platforms.Versions) return
-- Other useful functions
function "/" (L, R : String) return String is (Ada.Directories.Compose (L, R));
-- Path composition.
-- FIXME: hardcoded path separators shouldn't reach the index, not sure how to force-prevent this...
----------------------
-- Set_Root_Project --
@@ -247,5 +244,12 @@ package Alire.Index is
-- 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
-- The returned Release is the same; this is just a trick to be able to use it in an spec file.
private
function GPR_File_Unsafe is new PL.Cond_New_Label (Properties.Labeled.GPR_File);
function GPR_File (File : Platform_Independent_Path) return Release_Properties
renames GPR_File_Unsafe;
end Alire.Index;
+15 -15
View File
@@ -16,13 +16,13 @@ package Alire.Releases with Preelaborate is
type Release (<>) is tagged private;
function New_Release (Name : Project_Name;
Description : Project_Description;
Version : Semantic_Versioning.Version;
Origin : Origins.Origin;
function New_Release (Name : Project_Name;
Description : Project_Description;
Version : Semantic_Versioning.Version;
Origin : Origins.Origin;
Dependencies : Conditional.Dependencies;
Properties : Conditional.Properties;
Available : Alire.Requisites.Tree) return Release;
Properties : Conditional.Properties;
Available : Alire.Requisites.Tree) return Release;
function "<" (L, R : Release) return Boolean;
@@ -56,9 +56,9 @@ package Alire.Releases with Preelaborate is
-- Explicitly declared ones, or if default one if none declared
-- Under some conditions (usually current platform)
function Image (R : Release) return Path_String;
function Image (R : Release) return Folder_String;
-- Unique string built as name_version_id
function Unique_Folder (R : Release) return Path_String renames Image;
function Unique_Folder (R : Release) return Folder_String renames Image;
function Labeled_Properties (R : Release; P : Properties.Vector; Label : Properties.Labeled.Labels)
return Utils.String_Vector;
@@ -113,13 +113,13 @@ private
use all type Conditional.Properties;
function New_Release (Name : Project_Name;
Description : Project_Description;
Version : Semantic_Versioning.Version;
Origin : Origins.Origin;
function New_Release (Name : Project_Name;
Description : Project_Description;
Version : Semantic_Versioning.Version;
Origin : Origins.Origin;
Dependencies : Conditional.Dependencies;
Properties : Conditional.Properties;
Available : Alire.Requisites.Tree) return Release is
Properties : Conditional.Properties;
Available : Alire.Requisites.Tree) return Release is
(Name'Length, Description'Length,
Name,
Description,
@@ -157,7 +157,7 @@ private
(R.Name & OS_Lib.Exe_Suffix);
use all type Origins.Kinds;
function Image (R : Release) return Path_String is
function Image (R : Release) return Folder_String is
(R.Name & "_" &
Image (R.Version) & "_" &
(case R.Origin.Kind is
+4 -3
View File
@@ -22,9 +22,10 @@ package Alire with Preelaborate is
subtype Project_Description is String with Dynamic_Predicate =>
Project_Description'Length <= Max_Description_Length;
subtype Path_String is String with Dynamic_Predicate =>
Path_String'Length > 0 and then
(for all C of Path_String => C in 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' | '.');
subtype Folder_String is String with Dynamic_Predicate =>
Folder_String'Length > 0 and then
(for all C of Folder_String => C in 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' | '.');
-- Used for cross-platform folder names
---------------
-- LOGGING --