Skip to content

Commit

Permalink
New alr printenv --last-build
Browse files Browse the repository at this point in the history
This may be useful when no direct editing of manifests is convenient, as
otherwise `printenv` will always use the manifest's configuration.
  • Loading branch information
mosteo committed Sep 28, 2023
1 parent 2753a7c commit c5f3756
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/alr/alr-commands-printenv.adb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
with Alire.Crate_Configuration;
with Alire.Environment;
with Alire.Platforms;

Expand Down Expand Up @@ -29,6 +30,11 @@ package body Alr.Commands.Printenv is

Cmd.Requires_Workspace;

if Cmd.Last_Build then
Cmd.Root.Set_Build_Profiles
(Alire.Crate_Configuration.Last_Build_Profiles);
end if;

declare
Context : constant Alire.Environment.Context :=
Cmd.Root.Build_Context;
Expand Down Expand Up @@ -89,6 +95,10 @@ package body Alr.Commands.Printenv is
Cmd.Cmd_Shell'Access,
"", "--wincmd",
"Use a Windows CMD shell format for the export");
Define_Switch (Config,
Cmd.Last_Build'Access,
"", "--last-build",
"Use last build profiles instead of manifest profiles");
end Setup_Switches;

end Alr.Commands.Printenv;
1 change: 1 addition & 0 deletions src/alr/alr-commands-printenv.ads
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ private
Unix_Shell : aliased Boolean := False;
Power_Shell : aliased Boolean := False;
Cmd_Shell : aliased Boolean := False;
Last_Build : aliased Boolean := False;
end record;
end Alr.Commands.Printenv;
9 changes: 8 additions & 1 deletion testsuite/drivers/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
from drivers.alr import alr_builds_dir, run_alr


def clear_builds_dir() -> None:
"""
Clear the shared build directory
"""
rmtree(path())


def enable_shared() -> None:
"""
Enable shared builds
Expand Down Expand Up @@ -88,4 +95,4 @@ def sync() -> None:
pass

def sync_builds() -> None:
sync()
sync()
34 changes: 34 additions & 0 deletions testsuite/tests/printenv/last-build/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Test that `alr printenv --last-build` works as expected.
"""

from drivers import builds
from drivers.alr import alr_with, init_local_crate, run_alr
from drivers.asserts import assert_match

builds.enable_shared()

init_local_crate()
alr_with("libhello")
run_alr("build")

# After a default build, we obtain the hash of the build in release mode
hash_release = builds.find_hash("libhello")

builds.clear_builds_dir()

# Now obtain the hash of the build in development mode
run_alr("build", "--profiles=*=development")
hash_devel = builds.find_hash("libhello")

assert hash_release != hash_devel, "Hashes should be different"

# Check default printenv behavior
p = run_alr("printenv")
assert_match(f".*LIBHELLO_ALIRE_PREFIX=[^\n]*{hash_release}", p.out)

# Check printenv --last-build behavior
p = run_alr("printenv", "--last-build")
assert_match(f".*LIBHELLO_ALIRE_PREFIX=[^\n]*{hash_devel}", p.out)

print("SUCCESS")
3 changes: 3 additions & 0 deletions testsuite/tests/printenv/last-build/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
driver: python-script
indexes:
build_hash_index: {}

0 comments on commit c5f3756

Please sign in to comment.