Skip to content

Commit

Permalink
Generate crate config on demand for shared dependencies (#1435)
Browse files Browse the repository at this point in the history
We needn't to generate it more than once, when the unique build folder is
created.
  • Loading branch information
mosteo authored Sep 4, 2023
1 parent baaca73 commit 9df6050
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 67 deletions.
3 changes: 3 additions & 0 deletions src/alire/alire-builds.adb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ package body Alire.Builds is
"Could not sync build dir from " & Src & " to " & Dst);
end;

-- At this point we can generate the final crate configuration
Root.Configuration.Generate_Config_Files (Root, Release);

declare
use Directories;
Work_Dir : Guard (Enter (Dst)) with Unreferenced;
Expand Down
139 changes: 78 additions & 61 deletions src/alire/alire-crate_configuration.adb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ with AAA.Strings; use AAA.Strings;
with Alire.Containers;
with Alire_Early_Elaboration;
with Alire.Solutions;
with Alire.Releases;
with Alire.Roots;
with Alire.Origins;
with Alire.Warnings;
Expand Down Expand Up @@ -379,10 +378,41 @@ package body Alire.Crate_Configuration is
procedure Generate_Config_Files (This : Global_Config;
Root : in out Alire.Roots.Root)
is
Solution : constant Solutions.Solution := Root.Solution;
begin
if not Solution.Is_Complete then
Warnings.Warn_Once ("Generating possibly incomplete configuration"
& " because of missing dependencies");
end if;

Trace.Detail ("Generating crate config files");

This.Save_Last_Build_Profiles;

for Crate of Root.Nonabstract_Crates loop
declare
Rel : constant Releases.Release := Root.Release (Crate);
begin
This.Generate_Config_Files (Root, Rel);
end;
end loop;
end Generate_Config_Files;

---------------------------
-- Generate_Config_Files --
---------------------------

procedure Generate_Config_Files (This : Global_Config;
Root : in out Alire.Roots.Root;
Rel : Releases.Release)
is

use Alire.Directories;
use Alire.Origins;

Solution : constant Solutions.Solution := Root.Solution;
----------------------
-- Get_Config_Entry --
----------------------

function Get_Config_Entry (Rel : Releases.Release) return Config_Entry is
begin
Expand All @@ -400,72 +430,59 @@ package body Alire.Crate_Configuration is
end;
end Get_Config_Entry;
begin
-- We don't create config files for external releases, since they
-- are not sources built by Alire.
if Rel.Origin.Requires_Build then

if not Solution.Is_Complete then
Warnings.Warn_Once ("Generating possibly incomplete configuration"
& " because of missing dependencies");
end if;
-- Check completeness before generating anything

Trace.Detail ("Generating crate config files");
if not This.Is_Config_Complete (Rel.Name_Str) then
Warnings.Warn_Once
("Skipping generation of incomplete configuration files "
& "for crate " & Utils.TTY.Name (Rel.Name_Str));
else
declare
Ent : constant Config_Entry := Get_Config_Entry (Rel);

This.Save_Last_Build_Profiles;
Conf_Dir : constant Absolute_Path :=
Root.Release_Base (Rel.Name, Roots.For_Build)
/ Ent.Output_Dir;

for Crate of Root.Nonabstract_Crates loop
declare
Rel : constant Releases.Release := Root.Release (Crate);
begin
-- We don't create config files for external releases, since they
-- are not sources built by Alire.
if Rel.Origin.Kind /= Alire.Origins.External then
Version_Str : constant String := Rel.Version.Image;
begin
if not Ent.Disabled then
Ada.Directories.Create_Path (Conf_Dir);

if Ent.Generate_Ada then
This.Generate_Ada_Config
(Rel.Name,
Conf_Dir / (+Rel.Name & "_config.ads"),
Version_Str);
end if;

-- Check completeness before generating anything
if Ent.Generate_GPR then
This.Generate_GPR_Config
(Rel.Name,
Conf_Dir / (+Rel.Name & "_config.gpr"),
(if Ent.Auto_GPR_With
then Root.Direct_Withs (Rel)
else AAA.Strings.Empty_Set),
Version_Str);
end if;

if not This.Is_Config_Complete (Rel.Name_Str) then
Warnings.Warn_Once
("Skipping generation of incomplete configuration files "
& "for crate " & Utils.TTY.Name (Rel.Name_Str));
else
declare
Ent : constant Config_Entry := Get_Config_Entry (Rel);

Conf_Dir : constant Absolute_Path :=
Root.Release_Base (Rel.Name, Roots.For_Build)
/ Ent.Output_Dir;

Version_Str : constant String := Rel.Version.Image;
begin
if not Ent.Disabled then
Ada.Directories.Create_Path (Conf_Dir);

if Ent.Generate_Ada then
This.Generate_Ada_Config
(Rel.Name,
Conf_Dir / (+Rel.Name & "_config.ads"),
Version_Str);
end if;

if Ent.Generate_GPR then
This.Generate_GPR_Config
(Rel.Name,
Conf_Dir / (+Rel.Name & "_config.gpr"),
(if Ent.Auto_GPR_With
then Root.Direct_Withs (Rel)
else AAA.Strings.Empty_Set),
Version_Str);
end if;

if Ent.Generate_C then
This.Generate_C_Config
(Rel.Name,
Conf_Dir / (+Rel.Name & "_config.h"),
Version_Str);
end if;
end if;
end;
if Ent.Generate_C then
This.Generate_C_Config
(Rel.Name,
Conf_Dir / (+Rel.Name & "_config.h"),
Version_Str);
end if;
end if;
end if;
end;
end loop;
end;
end if;
else
Trace.Debug ("Not generating config files for non-buildable release: "
& Rel.Milestone.TTY_Image);
end if;
end Generate_Config_Files;

-------------------------
Expand Down
6 changes: 6 additions & 0 deletions src/alire/alire-crate_configuration.ads
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ with TOML;

with Alire.Utils.Switches;
with Alire.Properties.Configurations;
with Alire.Releases;
limited with Alire.Roots;

private with Ada.Strings.Unbounded;
Expand Down Expand Up @@ -56,6 +57,11 @@ package Alire.Crate_Configuration is
procedure Generate_Config_Files (This : Global_Config;
Root : in out Alire.Roots.Root);

procedure Generate_Config_Files (This : Global_Config;
Root : in out Alire.Roots.Root;
Rel : Releases.Release);
-- Generate config files only for the given release

procedure Save_Last_Build_Profiles (This : Global_Config);
-- Record in local user configuration the last profiles used in crate
-- configuration (the ones currently in the given configuration).
Expand Down
10 changes: 4 additions & 6 deletions src/alire/alire-roots.adb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ package body Alire.Roots is
This.Deploy_Dependencies;
This.Sync_Builds;
-- Changes in configuration may require new build dirs
This.Configuration.Generate_Config_Files (This, Release (This));
-- Generate the config for the root crate.
-- TODO: generate only when changed (same optimization as for
-- sandboxed dependencies).
end if;

if Export_Build_Env or else not Builds.Sandboxed_Dependencies then
Expand Down Expand Up @@ -868,12 +872,6 @@ package body Alire.Roots is

-- Visit dependencies in safe order
This.Traverse (Doing => Sync_Release'Access);

-- Update/Create configuration files
This.Generate_Configuration;
-- TODO: this should be made more granular to only generate
-- configurations of newly synced build sources, since with the
-- new shared builds system configs do not change once created.
end Sync_Builds;

-----------------------------
Expand Down

0 comments on commit 9df6050

Please sign in to comment.