Skip to content

Commit

Permalink
Correctly set {relative_root} for alias_mods
Browse files Browse the repository at this point in the history
Previously it was using the alias directory not the alias_mods directory
  • Loading branch information
MHendricks committed Apr 11, 2023
1 parent ad75d3a commit 4bcb015
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
9 changes: 5 additions & 4 deletions hab/parsers/flat_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ def extract_global_keys(operation, merged_env, global_env):
def aliases(self):
"""List of the names and commands that need created to launch desired
applications."""
if "aliases" in self.frozen_data:
return self.frozen_data.get("aliases", {}).get(utils.Platform.name(), {})

return self.frozen_data.get("aliases", {}).get(utils.Platform.name(), {})

@property
Expand Down Expand Up @@ -236,7 +233,11 @@ def versions(self):

# If this version defines any alias_mods, store them for later
if version.alias_mods:
for name, mod in version.alias_mods.items():
# Format the alias environment at this point so any path
# based variables like {relative_root} are resolved against
# the version's directory not the alias being modified
mods = version.format_environment_value(version.alias_mods)
for name, mod in mods.items():
self._alias_mods.setdefault(name, []).append(mod)

return self.frozen_data["versions"]
3 changes: 3 additions & 0 deletions hab/parsers/hab_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ def format_environment_value(self, value, ext=None, platform=None):
k: self.format_environment_value(v, ext=ext, platform=platform)
for k, v in value.items()
}
elif isinstance(value, bool):
# Just return boolean values, no need to format
return value

# Expand and format any variables like "relative_root" using the current
# platform for paths.
Expand Down
6 changes: 4 additions & 2 deletions tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,10 @@ def test_alias_mods_as_dict(resolver):
env = alias["environment"]

# Check alias_mod is prepended to alias defined env var
assert env['ALIASED_LOCAL'][0].endswith("modified")
assert env['ALIASED_LOCAL'][1].endswith('test')
# Also check that the alias_mods {relative_root} path is resolved to the directory
assert env['ALIASED_LOCAL'][0].endswith("distros/aliased_mod/1.0/modified")
# Check that the alias {relative_root} path is resolved to it's directory
assert env['ALIASED_LOCAL'][1].endswith('distros/aliased/2.0/test')
# Env var can be set by alias_mod without any other hab management
assert env['ALIASED_MOD_LOCAL_A'] == ['Local Mod A']

Expand Down

0 comments on commit 4bcb015

Please sign in to comment.