Skip to content

Commit

Permalink
Fix monorepo bug wrt location of generated manifest
Browse files Browse the repository at this point in the history
When deploying crates, to avoid confusion, we replace the packaged manifest (if
any) with the one from the index, which is the one used anyway. For monorepos,
the replacement was placed at the repo root instead of at the crate location.
  • Loading branch information
mosteo committed May 23, 2024
1 parent a016de2 commit 3645eec
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/alire/alire-releases.adb
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,24 @@ package body Alire.Releases is
Mark_Completion : Boolean := True)
is
use Alire.Directories;
Folder : constant Any_Path := Parent_Folder / This.Deployment_Folder;
Completed : Flags.Flag := Flags.Complete_Copy (Folder);
Repo_Folder : constant Any_Path :=
Parent_Folder / This.Deployment_Folder;
Rel_Folder : constant Any_Path :=
Parent_Folder / This.Base_Folder;
Completed : Flags.Flag := Flags.Complete_Copy (Repo_Folder);

------------------------------
-- Backup_Upstream_Manifest --
------------------------------

procedure Backup_Upstream_Manifest is
Working_Dir : Guard (Enter (Folder)) with Unreferenced;
Working_Dir : Guard (Enter (Rel_Folder)) with Unreferenced;
begin
Ada.Directories.Create_Path (Paths.Working_Folder_Inside_Root);

if GNAT.OS_Lib.Is_Regular_File (Paths.Crate_File_Name) then
Trace.Debug ("Backing up bundled manifest file as *.upstream");
Trace.Debug ("Backing up bundled manifest file at "
& Adirs.Current_Directory & " as *.upstream");
declare
Upstream_File : constant String :=
Paths.Working_Folder_Inside_Root
Expand Down Expand Up @@ -295,16 +299,17 @@ package body Alire.Releases is
begin
Trace.Debug ("Generating manifest file for "
& This.Milestone.TTY_Image & " with"
& This.Dependencies.Leaf_Count'Img & " dependencies");
& This.Dependencies.Leaf_Count'Img & " dependencies "
& " at " & (Rel_Folder / Paths.Crate_File_Name));

This.Whenever (Env).To_File (Folder / Paths.Crate_File_Name,
This.Whenever (Env).To_File (Rel_Folder / Paths.Crate_File_Name,
Kind);
end Create_Authoritative_Manifest;

begin

Trace.Debug ("Deploying " & This.Milestone.TTY_Image
& " into " & TTY.URL (Folder));
& " into " & TTY.URL (Repo_Folder));

-- Deploy if the target dir is not already there. We only skip for
-- releases that require a folder to be deployed; system releases
Expand All @@ -331,14 +336,14 @@ package body Alire.Releases is
else
Was_There := False;
Put_Info ("Deploying " & This.Milestone.TTY_Image & "...");
Alire.Origins.Deployers.Deploy (This, Folder).Assert;
Alire.Origins.Deployers.Deploy (This, Repo_Folder).Assert;
end if;

-- For deployers that do nothing, we ensure the folder exists so all
-- dependencies leave a trace in the cache/dependencies folder, and
-- a place from where to run their actions by default.

Ada.Directories.Create_Path (Folder);
Ada.Directories.Create_Path (Repo_Folder);

-- Backup a potentially packaged manifest, so our authoritative
-- manifest from the index is always used.
Expand All @@ -349,8 +354,8 @@ package body Alire.Releases is

if Create_Manifest then
Create_Authoritative_Manifest (if Include_Origin
then Manifest.Index
else Manifest.Local);
then Manifest.Index
else Manifest.Local);
end if;

if Mark_Completion then
Expand All @@ -363,10 +368,10 @@ package body Alire.Releases is
-- during an action).
Log_Exception (E);

if Ada.Directories.Exists (Folder) then
if Ada.Directories.Exists (Repo_Folder) then
Trace.Debug ("Cleaning up failed release deployment of "
& This.Milestone.TTY_Image);
Directories.Force_Delete (Folder);
Directories.Force_Delete (Repo_Folder);
end if;

raise;
Expand Down
3 changes: 3 additions & 0 deletions src/alire/alire-roots.adb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
with AAA.Debug;

with Ada.Directories;
with Ada.Unchecked_Deallocation;

Expand Down Expand Up @@ -1058,6 +1060,7 @@ package body Alire.Roots is
Trace.Debug
("Crate found at pin location " & Pin.Relative_Path);
if Target.Value.Name /= Crate then
Trace.Error (AAA.Debug.Stack_Trace);
Raise_Checked_Error
("Mismatched crates for pin linking to "
& TTY.URL (Pin.Path) & ": expected " &
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "1.1"
54 changes: 54 additions & 0 deletions testsuite/tests/monorepo/manifest-in-place/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
Verify that the index manifest is copied in the proper place instead of the one
possible packed by upstream, like is done for regular crates.
"""

from glob import glob
import os
from subprocess import run

from drivers.alr import alr_manifest, alr_publish, init_local_crate, run_alr
from drivers.asserts import assert_contents
from drivers.helpers import init_git_repo

# We create a repository with a nested crate that will act as the upstream
# remote repository:

start_dir = os.getcwd()
os.mkdir("monoproject.upstream")
os.chdir("monoproject.upstream")
init_local_crate("crate1", enter=False)
os.chdir(start_dir)
commit1 = init_git_repo("monoproject.upstream")

# We clone the project to obtain our local copy

assert run(["git", "clone",
"monoproject.upstream", "monoproject"]).returncode == 0

# We enter the crate nested inside and publish.

os.chdir("monoproject")
os.chdir("crate1")
alr_publish("crate1", "0.1.0-dev",
index_path=os.path.join(start_dir, "my_index"))

# Verify that we can `alr get` the nested crate

os.chdir(start_dir)
run_alr("get", "crate1")

# Enter and verify the only manifest is at the expected location, and the only
# backup is too.

os.chdir(glob("monoproject_*")[0])

assert not os.path.isfile(alr_manifest()), \
"Unexpected manifest in the root of the repository"

assert_contents(".",
['./crate1/alire.toml',
'./crate1/alire/alire.toml.upstream'],
".*alire.*toml")

print('SUCCESS')
5 changes: 5 additions & 0 deletions testsuite/tests/monorepo/manifest-in-place/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: python-script
indexes:
my_index:
in_fixtures: false
compiler_only_index: {}

0 comments on commit 3645eec

Please sign in to comment.