Skip to content

Commit

Permalink
New ALR_TRACEBACK_ENABLED env. var. (#1450)
Browse files Browse the repository at this point in the history
* Add traceback enabling env var

* Test for new config var
  • Loading branch information
mosteo authored Sep 12, 2023
1 parent 000fe70 commit eb1e0b8
Show file tree
Hide file tree
Showing 14 changed files with 268 additions and 193 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@
[submodule "deps/diskflags"]
path = deps/diskflags
url = https://github.com/mosteo/diskflags
[submodule "deps/dirty_booleans"]
path = deps/dirty_booleans
url = https://github.com/mosteo/dirty_booleans
1 change: 1 addition & 0 deletions alire.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ with "alire_common";
with "ajunitgen";
with "ansiada";
with "clic";
with "dirty_booleans";
with "diskflags";
with "gnatcoll";
with "minirest";
Expand Down
2 changes: 2 additions & 0 deletions alire.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ada_toml = "~0.3"
ajunitgen = "^1.0.1"
ansiada = "^1.0"
clic = "~0.3"
dirty_booleans = "~0.1"
diskflags = "~0.1"
gnatcoll = "^21"
minirest = "~0.3"
Expand Down Expand Up @@ -49,6 +50,7 @@ windows = { ALIRE_OS = "windows" }
aaa = { url = "https://github.com/mosteo/aaa", commit = "ecc38772bd4a6b469b54c62363766ea1c0e9f912" }
ada_toml = { url = "https://github.com/mosteo/ada-toml", commit = "da4e59c382ceb0de6733d571ecbab7ea4919b33d" }
clic = { url = "https://github.com/alire-project/clic", commit = "6879b90876a1c918b4e112f59c6db0e25b713f52" }
dirty_booleans = { url = "https://github.com/mosteo/dirty_booleans", branch = "main" }
diskflags = { url = "https://github.com/mosteo/diskflags", branch = "main" }
gnatcoll = { url = "https://github.com/alire-project/gnatcoll-core.git", commit = "4e663b87a028252e7e074f054f8f453661397166" }
minirest = { url = "https://github.com/mosteo/minirest.git", commit = "9a9c660f9c6f27f5ef75417e7fac7061dff14d78" }
Expand Down
1 change: 1 addition & 0 deletions alr_env.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ aggregate project Alr_Env is
"deps/ajunitgen",
"deps/ansi",
"deps/clic",
"deps/dirty_booleans",
"deps/diskflags",
"deps/gnatcoll-slim",
"deps/minirest",
Expand Down
1 change: 1 addition & 0 deletions deps/dirty_booleans
Submodule dirty_booleans added at 05c40d
4 changes: 2 additions & 2 deletions src/alire/alire-builds-hashes.adb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
with Alire.Crate_Configuration.Hashes;
with Alire.Directories;
with Alire.Environment;
with Alire.Environment.Loading;
with Alire.GPR;
with Alire.Hashes.SHA256_Impl;
with Alire.Paths;
Expand Down Expand Up @@ -249,7 +249,7 @@ package body Alire.Builds.Hashes is
Trace.Debug ("build hashing root " & Root.Path);
This.Hashes.Clear;

Environment.Load (Context, Root, For_Hashing => True);
Environment.Loading.Load (Context, Root, For_Hashing => True);
Env := Context.Get_All;

Root.Configuration.Ensure_Complete;
Expand Down
173 changes: 173 additions & 0 deletions src/alire/alire-environment-loading.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
with Alire_Early_Elaboration;
with Alire.Environment.Formatting;
with Alire.GPR;
with Alire.Platforms.Current;
with Alire.Properties.Scenarios;
with Alire.Releases;
with Alire.Solutions;
with Alire.Toolchains.Solutions;
with Alire.Utils.TTY;

with GNAT.IO;

package body Alire.Environment.Loading is

----------
-- Load --
----------

Already_Warned : Boolean := False;

procedure Load (This : in out Context;
Root : in out Alire.Roots.Root;
For_Hashing : Boolean := False)
is
Solution : constant Solutions.Solution :=
Toolchains.Solutions.Add_Toolchain (Root.Solution);
Tool_Root : Roots.Editable.Root :=
Roots.Editable.New_Root (Root);
-- We use a copy of the base root to add the toolchain elements that
-- might be missing from its solution
begin
Tool_Root.Set (Solution);

-- Load platform environment
Alire.Platforms.Current.Load_Environment (This);

-- Warnings when setting up an incomplete environment

if not Solution.Is_Complete then
Trace.Debug ("Generating possibly incomplete environment"
& " because of missing dependencies");

-- Normally we would generate a warning, but since that will pollute
-- the output making it unusable, for once we write directly to
-- stderr (unless quiet is in effect):

if not Alire_Early_Elaboration.Switch_Q and then not Already_Warned
then
Already_Warned := True;

GNAT.IO.Put_Line
(GNAT.IO.Standard_Error,
TTY.Warn ("warn:")
& " Generating possibly incomplete environment"
& " because of missing dependencies");
end if;
end if;

-- Project paths for all releases in the solution, implicitly defined by
-- supplied project files.

if not For_Hashing then
declare
Sorted_Paths : constant AAA.Strings.Set :=
Tool_Root.Current.Project_Paths;
begin
if not Sorted_Paths.Is_Empty then
for Path of reverse Sorted_Paths loop
-- Reverse should not matter as our paths shouldn't overlap,
-- but at least is nicer for user inspection to respect
-- alphabetical order.

This.Prepend ("GPR_PROJECT_PATH", Path, "crates");
end loop;
end if;
end;
end if;

-- Custom definitions provided by each release

for Rel of Solution.Releases.Including (Root.Release) loop
Load (This => This,
Root => Tool_Root,
Crate => Rel.Name,
For_Hashing => For_Hashing);
end loop;

This.Set ("ALIRE", "True", "Alire");
end Load;

----------
-- Load --
----------

procedure Load (This : in out Context;
Root : in out Roots.Editable.Root;
Crate : Crate_Name;
For_Hashing : Boolean := False)
is
Env : constant Properties.Vector := Root.Current.Environment;
Rel : constant Releases.Release := Root.Current.Release (Crate);
Origin : constant String := Rel.Name_Str;

Release_Base : constant String
:= (if For_Hashing
then Rel.Base_Folder
else Root.Current.Release_Base (Rel.Name, Roots.For_Build));
-- Before we can known the Release_Base, we supplant it with its
-- simple name. This shouldn't be a problem for hashing, as this
-- is only used for $CRATE_ROOT paths, and the important parts
-- that might merit a hash change are the rest of the path.
begin
Trace.Debug ("Loading environment for crate "
& Alire.Utils.TTY.Name (Crate)
& " release: " & Rel.Milestone.TTY_Image);

-- Environment variables defined in the crate manifest
for Act of Rel.Environment (Env) loop
Trace.Debug ("Processing env entry: " & Act.Name
& " of type " & Act.Action'Image
& " with value " & Act.Value);
begin
declare
Value : constant String :=
Formatting.Format (Release_Base, Act.Value);
begin
case Act.Action is

when Properties.Environment.Set =>

This.Set (Act.Name, Value, Origin & " (env)");

when Properties.Environment.Append =>

This.Append (Act.Name, Value, Origin & " (env)");

when Properties.Environment.Prepend =>

This.Prepend (Act.Name, Value, Origin & " (env)");

end case;
end;
exception
when Formatting.Unknown_Formatting_Key =>
Raise_Checked_Error
("Unknown environment variable formatting key in var '" &
Act.Name & " of '" & Origin & "'");
end;
end loop;

-- Environment variables for GPR external scenario variables
for Property of Rel.On_Platform_Properties (Env) loop
if Property in Alire.Properties.Scenarios.Property'Class then
declare
use all type Alire.GPR.Variable_Kinds;
Variable : constant Alire.GPR.Variable
:= Alire.Properties.Scenarios.Property (Property).Value;
begin
if Variable.Kind = External then
This.Set (Variable.Name, Variable.External_Value,
Origin & " (gpr ext)");
end if;
end;
end if;
end loop;

-- Set the crate PREFIX location for access to resources
This.Set (AAA.Strings.To_Upper_Case (+Rel.Name) & "_ALIRE_PREFIX",
Release_Base,
"Crate prefix for resources location");
end Load;

end Alire.Environment.Loading;
24 changes: 24 additions & 0 deletions src/alire/alire-environment-loading.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
with Alire.Roots.Editable;

package Alire.Environment.Loading is

procedure Load (This : in out Context;
Root : in out Alire.Roots.Root;
For_Hashing : Boolean := False);
-- Load the environment variables of a releases found in the workspace
-- Solution (GPR_PROJECT_PATH and custom variables) in the context. If
-- For_Hashing, skip or mock actions that require the build hash which is
-- part of the build path. We use this to gather all configuration when
-- paths aren't yet known (as they depend on the hash that is computed
-- from the configuration which will become itself part of the path).

private

procedure Load (This : in out Context;
Root : in out Roots.Editable.Root;
Crate : Crate_Name;
For_Hashing : Boolean := False);
-- Load the environment variables of a release (GPR_PROJECT_PATH and custom
-- variables) in the context. See note in previous Load about For_Hashing.

end Alire.Environment.Loading;
Loading

0 comments on commit eb1e0b8

Please sign in to comment.