Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix redeploying of toolchains #1533

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
run: ./bin/alr --non-interactive help get

- name: install tar from msys2 (Git tar in Actions VM does not seem to work)
run: C:\Users\runneradmin\.cache\alire\msys64\usr\bin\pacman --noconfirm -S tar
run: C:\Users\runneradmin\AppData\Local\alire\msys64\usr\bin\pacman --noconfirm -S tar

- name: Install Python 3.x (required for the testsuite)
uses: actions/setup-python@v2
Expand All @@ -57,17 +57,17 @@ jobs:
run: gprinstall -p -P alr_env --prefix=${{ runner.temp }}/alr_install

- name: Install qt-installer-framework in msys2
run: C:\Users\runneradmin\.cache\alire\msys64\usr\bin\pacman --noconfirm -S mingw64/mingw-w64-x86_64-qt-installer-framework
run: C:\Users\runneradmin\AppData\Local\alire\msys64\usr\bin\pacman --noconfirm -S mingw64/mingw-w64-x86_64-qt-installer-framework

- name: Add msys2 /mingw64/bin to the path (for qt-installer-framework)
run: echo 'C:\Users\runneradmin\.cache\alire\msys64\mingw64\bin' >> $GITHUB_PATH
run: echo 'C:\Users\runneradmin\AppData\Local\alire\msys64\mingw64\bin' >> $GITHUB_PATH
shell: bash

- name: Install zip in msys2
run: C:\Users\runneradmin\.cache\alire\msys64\usr\bin\pacman --noconfirm -S zip
run: C:\Users\runneradmin\AppData\Local\alire\msys64\usr\bin\pacman --noconfirm -S zip

- name: Add msys2 /usr/bin to the path (for zip)
run: echo 'C:\Users\runneradmin\.cache\alire\msys64\usr\bin' >> $GITHUB_PATH
run: echo 'C:\Users\runneradmin\AppData\Local\alire\msys64\usr\bin' >> $GITHUB_PATH
shell: bash

- name: Run installer build script
Expand Down
12 changes: 12 additions & 0 deletions src/alire/alire-builds-hashes.adb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ package body Alire.Builds.Hashes is
Add ("profile",
Rel.Name.As_String,
Root.Configuration.Build_Profile (Rel.Name)'Image);
exception
when others =>
Trace.Error
("While hashing: missing build profile for "
& Rel.Milestone.TTY_Image);
raise;
end Add_Profile;

------------------
Expand All @@ -123,6 +129,12 @@ package body Alire.Builds.Hashes is
Add ("switches",
Rel.Name.As_String,
Switches.To_Vector.Flatten (","));
exception
when others =>
Trace.Error
("While hashing: missing switches for "
& Rel.Milestone.TTY_Image);
raise;
end Add_Switches;

-------------------
Expand Down
6 changes: 5 additions & 1 deletion src/alire/alire-directories.adb
Original file line number Diff line number Diff line change
Expand Up @@ -1153,10 +1153,14 @@ package body Alire.Directories is
-- Touch --
-----------

procedure Touch (File : File_Path) is
procedure Touch (File : File_Path; Create_Tree : Boolean := False) is
use GNAT.OS_Lib;
Success : Boolean := False;
begin
if Create_Tree then
Directories.Create_Tree (Parent (File));
end if;

if Is_Regular_File (File) then
Set_File_Last_Modify_Time_Stamp (File, Current_Time);
elsif Ada.Directories.Exists (File) then
Expand Down
4 changes: 2 additions & 2 deletions src/alire/alire-directories.ads
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ package Alire.Directories is
-- the top-level only contains "doinstall", "README" and so on that
-- are unusable and would be confusing in a binary prefix.

procedure Touch (File : File_Path)
with Pre => Is_Directory (Parent (File));
procedure Touch (File : File_Path; Create_Tree : Boolean := False)
with Pre => Create_Tree or else Is_Directory (Parent (File));
-- If the file exists, update last edition time; otherwise create it.
-- If File denotes anything else than a regular file, raise.

Expand Down
1 change: 0 additions & 1 deletion src/alire/alire-toolchains-solutions.adb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ package body Alire.Toolchains.Solutions is

-- It must be redeployed
Put_Warning ("Tool " & Mil.TTY_Image & " is missing, redeploying...");

Toolchains.Deploy (Index.Find (Mil.Crate, Mil.Version));
end Redeploy_If_Needed;

Expand Down
35 changes: 22 additions & 13 deletions src/alire/alire-toolchains.adb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ package body Alire.Toolchains is

use Directories.Operators;

procedure Invalidate_Available_Cache;

--------------
-- Any_Tool --
--------------
-- crate=* dependency builder
function Any_Tool (Crate : Crate_Name) return Dependencies.Dependency
is (Dependencies.New_Dependency
(Crate, Semantic_Versioning.Extended.Any));
(Crate, Semantic_Versioning.Extended.Any));

----------------------
-- Dirty_Cache_Flag --
----------------------

function Dirty_Cache_Flag return Absolute_Path is (Path / "must_reload");

---------------
-- Assistant --
Expand Down Expand Up @@ -382,8 +386,6 @@ package body Alire.Toolchains is
Install (Release);
end loop;

Invalidate_Available_Cache;

end Assistant;

----------------------
Expand Down Expand Up @@ -412,8 +414,6 @@ package body Alire.Toolchains is
(Level,
Key => Tool_Key (Release.Name, For_Is_External),
Value => not Release.Origin.Is_Index_Provided);

Invalidate_Available_Cache;
end Set_As_Default;

-----------------------------
Expand Down Expand Up @@ -487,11 +487,9 @@ package body Alire.Toolchains is
end if;
end;
end if;

Invalidate_Available_Cache;
end Unconfigure;

Available_Cached : Releases.Containers.Release_Set;
Available_Cached : Releases.Containers.Release_Set;

--------------------------------
-- Invalidate_Available_Cache --
Expand Down Expand Up @@ -545,9 +543,12 @@ package body Alire.Toolchains is

begin
-- Early exit with cached available toolchains. Looking for toolchains
-- on disk is expensive. We invalidate the cache on toolchain changes.
-- on disk is expensive. We rely on folder modification time to
-- re-detect available toolchains.

if not Available_Cached.Is_Empty then
if not Available_Cached.Is_Empty and then
not Ada.Directories.Exists (Dirty_Cache_Flag)
then
return Available_Cached;
end if;

Expand All @@ -573,15 +574,19 @@ package body Alire.Toolchains is
end loop;
end loop;

-- Update cache and remove dirty flag

Available_Cached := Result;
Directories.Force_Delete (Dirty_Cache_Flag);

return Result;
end Available;

----------
-- Path --
----------

function Path return String
function Path return Absolute_Path
is (Config.Edit.Cache_Path / "toolchains");

------------
Expand Down Expand Up @@ -620,6 +625,10 @@ package body Alire.Toolchains is
& Release.Milestone.TTY_Image);
end if;

-- Notify that releases must be reloaded

Directories.Touch (Dirty_Cache_Flag, Create_Tree => True);

Put_Info (Release.Milestone.TTY_Image & " installed successfully.");
end Deploy;

Expand Down
2 changes: 1 addition & 1 deletion src/alire/alire-toolchains.ads
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ package Alire.Toolchains is
-- Retrieve the release corresponding to Target, if it exists. Will raise
-- Constraint_Error if not among Available.

function Path return Any_Path;
function Path return Absolute_Path;
-- Returns the base folder in which all toolchain releases live, defaults
-- to <cache>/toolchains

Expand Down
Binary file not shown.
Binary file added testsuite/fixtures/crates/gprbuild_mock_1.0.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ licenses = "GPL-3.0-only OR MIT"
maintainers = ["[email protected]"]
maintainers-logins = ["mylogin"]

[origin]
url = "file:."
# Conditional origin so it's considered a binary crate
[origin."case(os)"."..."]
url = "file:../../../crates/gnat_native_mock_1.0.zip"
hashes = ["sha256:db87865b59d7d733e4104b3c0f29c8bf590d5ff0b3ea2d61bded4e47beabf1a3"]
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ licenses = "GPL-3.0-only OR MIT"
maintainers = ["[email protected]"]
maintainers-logins = ["mylogin"]

[origin]
url = "file:."
# Conditional origin so it's considered a binary crate
[origin."case(os)"."..."]
url = "file:../../../crates/gprbuild_mock_1.0.zip"
hashes = ["sha256:e3d52b4a441a56ab1c0175ee8ea407864b72879cf73184a9f7d68eef53a87451"]
25 changes: 25 additions & 0 deletions testsuite/tests/toolchain/missing-tool-redeploy/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Verify that redeploying a missing tool works as intended.
As we cache the detected toolchains, if we fail to reload them on changes, we
could end trying to use a toolchain that is no longer available.
"""

import os
from shutil import rmtree
from drivers.alr import init_local_crate, run_alr
from drivers.asserts import assert_match

# We can trigger a buggy situation by configuring a toolchain, removing
# manually the tool (as if we had moved the cache), and running `alr printenv`.

run_alr("toolchain", "--select", "gprbuild", "gnat_native")
init_local_crate()

# Remove the tool manually through the filesystem
rmtree(os.path.join(os.environ["ALR_CONFIG"], "cache"))

# This should not fail. A message should warn of redeployments happening.
p = run_alr("printenv", quiet=False)
assert_match(".*Tool .* is missing, redeploying", p.out)

print("SUCCESS")
4 changes: 4 additions & 0 deletions testsuite/tests/toolchain/missing-tool-redeploy/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: python-script
build_mode: both
indexes:
gnat_toolchain_index: {}
Loading