Skip to content

Commit

Permalink
Test environment hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Aug 27, 2023
1 parent e3a9149 commit fa092a3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/alire/alire-builds-hashes.adb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ package body Alire.Builds.Hashes is
begin
for Var of Rel.Environment (Root.Environment) loop
-- If the crate modifies the var, it must be in the loaded env
Add ("environment", Var.Key, Env (Var.Key));
Add ("environment", Var.Name, Env (Var.Name));
end loop;
end Add_Environment;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ version = "1.0.0"
maintainers = ["[email protected]"]
maintainers-logins = ["mylogin"]

# Externals and environment used to track build hash generation immutability

[gpr-externals]
foo = ""

[gpr-set-externals]
bar = "foo"

[environment]
BAZ.set = "foo"

[origin]
url = "file:../../../crates/libhello_1.0.0.tgz"
hashes = ["sha512:99fa3a55540d0655c87605b54af732f76a8a363015f183b06e98aa91e54c0e69397872718c5c16f436dd6de0fba506dc50c66d34a0e5c61fb63cb01fa22f35ac"]
28 changes: 16 additions & 12 deletions testsuite/tests/build/hashes/hashing-inputs/test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""
Test that the inputs to the hashing properly reflect the build profile
Test that the inputs to the hashing properly reflect the build profile and
other inputs.
"""

import shutil
from drivers.alr import alr_with, init_local_crate, run_alr
from drivers.alr import alr_with, external_compiler_version, init_local_crate, run_alr
from drivers.builds import find_hash, hash_input
from drivers.asserts import assert_match
from drivers.asserts import assert_eq, assert_match
from drivers import builds

run_alr("config", "--set", "--global", "dependencies.shared", "true")
Expand All @@ -29,15 +30,18 @@
# Check that the hashes are different
assert hash1 != hash2, "Hashes should be different"

# Chech that the hash inputs contains GPR externals
# either set or observed by the crate:

assert_match(
".*external:TEST_FREEFORM_UNSET=default.*" # a declared unset external
".*external:TEST_GPR_EXTERNAL=gpr_ext_B.*" # a declared & set enum external
".*external:TEST_UNDECLARED=used_by_another_crate.*",
# set without prev declaration
# Chech that the hash inputs contains exactly what we expect it to contain.
# This includes environment variables, GPR externals set or observed, build
# profile, compiler version.

assert_eq(
'environment:TEST_ENV=myenv\n' # plain env var set
'external:TEST_FREEFORM_UNSET=default\n' # declared unset GPR external
'external:TEST_GPR_EXTERNAL=gpr_ext_B\n' # declared set GPR external
'external:TEST_UNDECLARED=used_by_another_crate\n' # modified GPR external
'profile:libhello=VALIDATION\n' # build profile
f'version:gnat_external={external_compiler_version()}\n',
# compiler version
hash_input("libhello"))


print("SUCCESS")
7 changes: 5 additions & 2 deletions testsuite/tests/dockerized/misc/default-cache/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@
f"Vault not found at the expected location: f{contents(base)}"

# Shared builds
# We hardcode this hash so we detect unwilling changes to our hashing scheme
hash = "7b5ad18029d4984b4076f4910c699700e7a325ab0c3dc786ccf89c3c6035212f"

# We hardcode this hash so we detect unwilling changes to our hashing scheme.
# Every time this hash changes we must know the reason (changes in the hashing
# procedures)
hash = "1a29f0454348e767e78ac6912c7409b374b7bf650e81396c8a8750797ae073eb"
assert \
os.path.isdir(f"{base}/builds/crate_real_1.0.0_filesystem_{hash}"), \
f"Shared build not found at the expected location: f{contents(base)}"
Expand Down

0 comments on commit fa092a3

Please sign in to comment.