-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New shared builds mechanism (mockup) (#1419)
* New shared builds mechanism (mockup) * Self-review * Fixes for Windows
- Loading branch information
Showing
39 changed files
with
623 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
with AAA.Strings; | ||
|
||
with Alire.Config.Edit; | ||
with Alire.Directories; | ||
with Alire.OS_Lib.Subprocess; | ||
with Alire.Paths.Vault; | ||
with Alire.Platforms.Current; | ||
with Alire.Properties.Actions.Executor; | ||
with Alire.Utils.Tools; | ||
|
||
package body Alire.Builds is | ||
|
||
use Directories.Operators; -- "/" | ||
|
||
---------------------------- | ||
-- Sandboxed_Dependencies -- | ||
---------------------------- | ||
|
||
function Sandboxed_Dependencies return Boolean | ||
is (not Config.DB.Get (Config.Keys.Dependencies_Shared, | ||
Config.Defaults.Dependencies_Shared)); | ||
|
||
------------------- | ||
-- To_Msys2_Path -- | ||
------------------- | ||
-- Convert C:\blah\blah into /c/blah/blah. This is needed because otherwise | ||
-- rsync confuses drive letters with remote hostnames. This might be useful | ||
-- in our troubles with tar? | ||
function To_Msys2_Path (Path : Absolute_Path) return String | ||
is | ||
begin | ||
if not Platforms.Current.On_Windows then | ||
return Path; | ||
end if; | ||
|
||
declare | ||
use AAA.Strings; | ||
New_Path : String (1 .. Path'Length) := Path; | ||
begin | ||
-- Replace ':' with '/' | ||
New_Path (2) := '/'; | ||
|
||
-- Replace '\' with '/' | ||
return "/" & Replace (New_Path, "\", "/"); | ||
end; | ||
end To_Msys2_Path; | ||
|
||
---------- | ||
-- Sync -- | ||
---------- | ||
|
||
procedure Sync (Release : Releases.Release; | ||
Was_There : out Boolean) | ||
is | ||
Src : constant Absolute_Path := Paths.Vault.Path | ||
/ Release.Deployment_Folder; | ||
Dst : constant Absolute_Path := Builds.Path (Release); | ||
Completed : Directories.Completion := Directories.New_Completion (Dst); | ||
|
||
use AAA.Strings; | ||
begin | ||
Was_There := False; | ||
|
||
if Completed.Is_Complete then | ||
Trace.Detail ("Skipping build syncing to existing " & Dst); | ||
Was_There := True; | ||
return; | ||
end if; | ||
|
||
Directories.Create_Tree (Dst); | ||
-- Ensure the sync destination dir exists | ||
|
||
Utils.Tools.Check_Tool (Utils.Tools.Rsync); | ||
|
||
declare | ||
Busy : constant Simple_Logging.Ongoing := | ||
Simple_Logging.Activity | ||
("Syncing " & Release.Milestone.TTY_Image) | ||
with Unreferenced; | ||
begin | ||
OS_Lib.Subprocess.Checked_Spawn | ||
(Command => "rsync", | ||
Arguments => | ||
To_Vector ("--del") | ||
& "-aChH" | ||
-- Archive, no CVS folders, keep hard links, human units | ||
& (if Log_Level > Detail then To_Vector ("-P") else Empty_Vector) | ||
& (if Log_Level < Info then To_Vector ("-q") else Empty_Vector) | ||
-- Trailing '/' to access contents directly in the following paths | ||
& To_Msys2_Path (Src / "") | ||
& To_Msys2_Path (Dst / "") | ||
); | ||
-- TODO: this may take some time, and rsync doesn't have a way | ||
-- to show oneliner progress, so at some point we may want to use | ||
-- something like GNAT.Expect for our spawns, and spin on newlines | ||
-- for example. | ||
end; | ||
|
||
declare | ||
use Directories; | ||
Work_Dir : Guard (Enter (Dst)) with Unreferenced; | ||
begin | ||
Alire.Properties.Actions.Executor.Execute_Actions | ||
(Release => Release, | ||
Env => Platforms.Current.Properties, | ||
Moment => Properties.Actions.Post_Fetch); | ||
exception | ||
when E : others => | ||
Log_Exception (E); | ||
Trace.Warning ("A post-fetch action failed, " & | ||
"re-run with -vv -d for details"); | ||
end; | ||
|
||
Completed.Mark (Complete => True); | ||
end Sync; | ||
|
||
---------- | ||
-- Path -- | ||
---------- | ||
|
||
function Path return Absolute_Path | ||
is (Config.Edit.Cache_Path | ||
/ Paths.Build_Folder_Inside_Working_Folder); | ||
|
||
---------- | ||
-- Path -- | ||
---------- | ||
|
||
function Path (Release : Releases.Release) return Absolute_Path | ||
is (Builds.Path | ||
/ (Release.Deployment_Folder | ||
& "_deadbeef")); | ||
-- TODO: implement actual hashing of environment for a release | ||
|
||
end Alire.Builds; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
with Alire.Releases; | ||
|
||
package Alire.Builds is | ||
|
||
-- Stuff for shared builds: build hashes, syncing from the vault, etc. | ||
|
||
-- The new "shared builds" mechanism aims to provide safe sharing of | ||
-- builds, which should result in decreased recompilations (as most | ||
-- configs should be compiled only once, unless some actions are touching | ||
-- something) and decreased disk use (as multiple workspaces will reuse the | ||
-- same builds). | ||
|
||
-- This relies on having a separate source folder for each build | ||
-- configuration (a 'build folder'). This build folder is uniquely | ||
-- identified by a hash derived from the configuration variables, | ||
-- environment variables, GPR externals, and build profile that affect a | ||
-- release, according to manifests in scope. | ||
|
||
-- The build folder is created on-demand, under the name of | ||
-- <crate_version_commithash_buildhash>, syncing it from a "read-only" | ||
-- location, the 'vault', where all releases are fetched initially. | ||
|
||
-- To be able to quickly identify available toolchains without maintaining | ||
-- a "state" file, these are now separately stored, whereas in the past | ||
-- they were stored together with all binary releases. Since now we'll have | ||
-- many more shared releases in the vault, finding toolchains could take | ||
-- much more time, hence the separate storage. | ||
|
||
function Sandboxed_Dependencies return Boolean; | ||
-- Queries config to see if dependencies should be sandboxed in workspace | ||
|
||
procedure Sync (Release : Releases.Release; | ||
Was_There : out Boolean) | ||
with Pre => Release.Origin.Requires_Build; | ||
|
||
function Path return Absolute_Path; | ||
-- Location of shared builds | ||
|
||
function Path (Release : Releases.Release) return Absolute_Path; | ||
-- Computes the complete path in which the release is going to be built | ||
|
||
end Alire.Builds; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.