From 25b2c29513a62987e490428e4a3fcf2274fba029 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 7 Mar 2022 12:00:49 +0100 Subject: [PATCH] Remove pins from manifest during `alr publish` (#947) * Remove pins from deployed sources and final manifest * Bump toml_slicer pin in manifest * Test for pin removal during `alr publish` --- alire.toml | 2 +- deps/toml_slicer | 2 +- src/alire/alire-publish.adb | 25 ++++++++- src/alire/alire-roots.adb | 5 +- testsuite/drivers/alr.py | 7 ++- .../pin-removal/my_index/index/index.toml | 1 + testsuite/tests/publish/pin-removal/test.py | 52 +++++++++++++++++++ testsuite/tests/publish/pin-removal/test.yaml | 4 ++ 8 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 testsuite/tests/publish/pin-removal/my_index/index/index.toml create mode 100644 testsuite/tests/publish/pin-removal/test.py create mode 100644 testsuite/tests/publish/pin-removal/test.yaml diff --git a/alire.toml b/alire.toml index b14f00f7..44bb14d8 100644 --- a/alire.toml +++ b/alire.toml @@ -52,5 +52,5 @@ optional = { url = "https://github.com/mosteo/optional.git", commit = "0c7d20c0c semantic_versioning = { url = "https://github.com/alire-project/semantic_versioning.git", commit = "fe4e72e40786589a66d53662639f894fcdb3419c" } simple_logging = { url = "https://github.com/alire-project/simple_logging.git", commit = "02a7de7568af6af7cedd1048901fae8e9477b1d9" } stopwatch = { url = "https://github.com/mosteo/stopwatch.git", commit = "86e7302d29f360f98f568b6015755229949b2194" } -toml_slicer = { url = "https://github.com/mosteo/toml_slicer.git", commit = "1c0286bd724c6f257a36fc89412fcefd4f555228" } +toml_slicer = { url = "https://github.com/mosteo/toml_slicer.git", commit = "8b9dff0f450394b07ea71f0eb9b39d9c20e21f9c" } uri_ada = { url = "https://github.com/mosteo/uri-ada.git", commit = "b61eba59099b3ab39e59e228fe4529927f9e849e" } diff --git a/deps/toml_slicer b/deps/toml_slicer index 1c0286bd..8b9dff0f 160000 --- a/deps/toml_slicer +++ b/deps/toml_slicer @@ -1 +1 @@ -Subproject commit 1c0286bd724c6f257a36fc89412fcefd4f555228 +Subproject commit 8b9dff0f450394b07ea71f0eb9b39d9c20e21f9c diff --git a/src/alire/alire-publish.adb b/src/alire/alire-publish.adb index d5d484d0..c96ff427 100644 --- a/src/alire/alire-publish.adb +++ b/src/alire/alire-publish.adb @@ -23,19 +23,22 @@ with Alire.TOML_Adapters; with Alire.TOML_Index; with Alire.TOML_Keys; with Alire.TOML_Load; +with Alire.User_Pins.Maps; with Alire.Utils.TTY; with Alire.Utils.User_Input.Query_Config; with Alire.VCSs.Git; with Alire.VFS; +with CLIC.User_Input; + with GNATCOLL.OS.Constants; with Semantic_Versioning; -with CLIC.User_Input; - with TOML.File_IO; +with TOML_Slicer; + package body Alire.Publish is package Semver renames Semantic_Versioning; @@ -195,6 +198,15 @@ package body Alire.Publish is Ada.Text_IO.New_Line; Release.Print; + -- Warn if the release contains pins + + if not Release.Pins.Is_Empty then + Ada.Text_IO.New_Line; + Trace.Warning ("The release manifest " + & TTY.Warn ("contains pins that will be removed") + & " in the published version."); + end if; + -- Detect missing recommended fields for Key in Properties.From_TOML.Recommended'Range loop @@ -390,6 +402,15 @@ package body Alire.Publish is Context.Tmp_Deploy_Dir.Filename / Roots.Crate_File_Name); end if; + -- Remove pins at this point, as this manifest will be the basis for the + -- published one; also this way the build test will not rely on pins. + + TOML_Slicer.Remove_Array + (File_Name => Packaged_Manifest (Context), + Array_Name => TOML_Keys.Pins, + Backup => True, + Backup_Dir => Deploy_Path (Context)); + end Deploy_Sources; ----------------------------- diff --git a/src/alire/alire-roots.adb b/src/alire/alire-roots.adb index 77fdadc8..c4b04ca4 100644 --- a/src/alire/alire-roots.adb +++ b/src/alire/alire-roots.adb @@ -1188,7 +1188,10 @@ package body Alire.Roots is Allowed : Containers.Crate_Name_Sets.Set := Alire.Containers.Crate_Name_Sets.Empty_Set) is - Old : constant Solutions.Solution := This.Solution; + Old : constant Solutions.Solution := + (if This.Has_Lockfile + then This.Solution + else Solutions.Empty_Valid_Solution); begin -- Ensure requested crates are in solution first. diff --git a/testsuite/drivers/alr.py b/testsuite/drivers/alr.py index ac210098..70404301 100644 --- a/testsuite/drivers/alr.py +++ b/testsuite/drivers/alr.py @@ -467,14 +467,17 @@ def alr_submit(manifest, index_path): def alr_publish(name, version="0.0.0", submit=True, - index_path=os.path.join("..", "my_index")): + index_path=os.path.join("..", "my_index"), + quiet=True): """ Run `alr publish` at the current location and optionally move the produced manifest to its intended location in a local index. """ - run_alr("publish", force=True) + p = run_alr("publish", force=True, quiet=quiet) # Force due to missing optional crate info by `alr init` if submit: alr_submit(os.path.join("alire", "releases", f"{name}-{version}.toml"), index_path) + + return p diff --git a/testsuite/tests/publish/pin-removal/my_index/index/index.toml b/testsuite/tests/publish/pin-removal/my_index/index/index.toml new file mode 100644 index 00000000..bad265e4 --- /dev/null +++ b/testsuite/tests/publish/pin-removal/my_index/index/index.toml @@ -0,0 +1 @@ +version = "1.1" diff --git a/testsuite/tests/publish/pin-removal/test.py b/testsuite/tests/publish/pin-removal/test.py new file mode 100644 index 00000000..d4807347 --- /dev/null +++ b/testsuite/tests/publish/pin-removal/test.py @@ -0,0 +1,52 @@ +""" +Publish a crate that contains pins, and verify pins are removed in the process +""" + +import os +import shutil + +from drivers.alr import run_alr, init_local_crate, alr_pin, alr_publish, \ + alr_manifest +from drivers.helpers import content_of, init_git_repo +from drivers.asserts import assert_eq, assert_match +from subprocess import run + +crate = "pinner" + +# We create a repository with the nested crate that will act as the upstream +# remote repository: +start_dir = os.getcwd() +init_local_crate(crate) + +# And add the pin directly in the remote +alr_pin("unobtanium", path="/") + +# We can now create the upstream repo +os.chdir("..") +commit = init_git_repo(crate) +os.rename(crate, f"{crate}.upstream") + +# We clone the project to obtain our local copy +assert run(["git", "clone", f"{crate}.upstream", crate]).returncode == 0 + +# We enter the clone +os.chdir(crate) + +# Verify the pin is there +assert_match(".*\[\[pins\]\].*", content_of(alr_manifest())) + +# We publish with the pin in the manifest +p = alr_publish(crate, "0.0.0", + index_path=os.path.join(start_dir, "my_index"), + submit=False, + quiet=False) + +# Verify warning during publishing +assert_match(".*contains pins that will be removed.*", p.out) + +# Verify no pins in the generated file +assert "[[pins]]" not in \ + content_of(os.path.join("alire", "releases", f"{crate}-0.0.0.toml")), \ + "Unexpected contents in published file" + +print('SUCCESS') diff --git a/testsuite/tests/publish/pin-removal/test.yaml b/testsuite/tests/publish/pin-removal/test.yaml new file mode 100644 index 00000000..0a859639 --- /dev/null +++ b/testsuite/tests/publish/pin-removal/test.yaml @@ -0,0 +1,4 @@ +driver: python-script +indexes: + my_index: + in_fixtures: false -- 2.39.5