From 119e690458d3a8ec3cbb3b07cff934e2849d2300 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Thu, 30 May 2024 13:14:29 +0200 Subject: [PATCH] Fix monorepo bug wrt location of generated manifest (#1684) * Fix monorepo bug wrt location of generated manifest 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. * Use macOS 12 to avoid linking problems * Self-review --- src/alire/alire-releases.adb | 31 ++++++----- .../my_index/index/index.toml | 1 + .../tests/monorepo/manifest-in-place/test.py | 54 +++++++++++++++++++ .../monorepo/manifest-in-place/test.yaml | 5 ++ 4 files changed, 78 insertions(+), 13 deletions(-) create mode 100644 testsuite/tests/monorepo/manifest-in-place/my_index/index/index.toml create mode 100644 testsuite/tests/monorepo/manifest-in-place/test.py create mode 100644 testsuite/tests/monorepo/manifest-in-place/test.yaml diff --git a/src/alire/alire-releases.adb b/src/alire/alire-releases.adb index 1858480f..f616c4e0 100644 --- a/src/alire/alire-releases.adb +++ b/src/alire/alire-releases.adb @@ -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 @@ -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 @@ -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. @@ -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 @@ -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; diff --git a/testsuite/tests/monorepo/manifest-in-place/my_index/index/index.toml b/testsuite/tests/monorepo/manifest-in-place/my_index/index/index.toml new file mode 100644 index 00000000..bad265e4 --- /dev/null +++ b/testsuite/tests/monorepo/manifest-in-place/my_index/index/index.toml @@ -0,0 +1 @@ +version = "1.1" diff --git a/testsuite/tests/monorepo/manifest-in-place/test.py b/testsuite/tests/monorepo/manifest-in-place/test.py new file mode 100644 index 00000000..b6c2e129 --- /dev/null +++ b/testsuite/tests/monorepo/manifest-in-place/test.py @@ -0,0 +1,54 @@ +""" +Verify that the index manifest is copied in the proper place instead of the one +possibly packed by upstream, like it 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 (in the nested +# crate), and the only backup is too there. + +os.chdir(glob("monoproject_*")[0]) + +assert not os.path.isfile(alr_manifest()), \ + "Unexpected manifest at the root of the repository" + +assert_contents(".", + ['./crate1/alire.toml', + './crate1/alire/alire.toml.upstream'], + regex=".*alire.*toml") + +print('SUCCESS') diff --git a/testsuite/tests/monorepo/manifest-in-place/test.yaml b/testsuite/tests/monorepo/manifest-in-place/test.yaml new file mode 100644 index 00000000..d6aa8a36 --- /dev/null +++ b/testsuite/tests/monorepo/manifest-in-place/test.yaml @@ -0,0 +1,5 @@ +driver: python-script +indexes: + my_index: + in_fixtures: false + compiler_only_index: {} -- 2.39.5