From 9df60506fac71227176b5f86c96222af87df25af Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 4 Sep 2023 14:14:12 +0200 Subject: [PATCH] Generate crate config on demand for shared dependencies (#1435) We needn't to generate it more than once, when the unique build folder is created. --- src/alire/alire-builds.adb | 3 + src/alire/alire-crate_configuration.adb | 139 +++++++++++++----------- src/alire/alire-crate_configuration.ads | 6 + src/alire/alire-roots.adb | 10 +- 4 files changed, 91 insertions(+), 67 deletions(-) diff --git a/src/alire/alire-builds.adb b/src/alire/alire-builds.adb index 9ccbc34c..2863e1f2 100644 --- a/src/alire/alire-builds.adb +++ b/src/alire/alire-builds.adb @@ -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; diff --git a/src/alire/alire-crate_configuration.adb b/src/alire/alire-crate_configuration.adb index f7c5edf9..4e5a4847 100644 --- a/src/alire/alire-crate_configuration.adb +++ b/src/alire/alire-crate_configuration.adb @@ -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; @@ -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 @@ -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; ------------------------- diff --git a/src/alire/alire-crate_configuration.ads b/src/alire/alire-crate_configuration.ads index 292e4d76..452141f9 100644 --- a/src/alire/alire-crate_configuration.ads +++ b/src/alire/alire-crate_configuration.ads @@ -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; @@ -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). diff --git a/src/alire/alire-roots.adb b/src/alire/alire-roots.adb index 03c8bc99..0869985e 100644 --- a/src/alire/alire-roots.adb +++ b/src/alire/alire-roots.adb @@ -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 @@ -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; ----------------------------- -- 2.39.5