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

Only calculate the mapping of version suffixes if they are actually used #3326

Merged
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
37 changes: 33 additions & 4 deletions easybuild/framework/easyconfig/tweak.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,11 @@ def map_common_versionsuffixes(software_name, original_toolchain, toolchain_mapp
if original_suffix in versionsuffix_mappings:
if mapped_suffix != versionsuffix_mappings[original_suffix]:
raise EasyBuildError("No unique versionsuffix mapping for %s in %s toolchain "
"hierarchy to %s toolchain hierarchy", original_suffix,
original_toolchain, toolchain_mapping[original_toolchain['name']])
"hierarchy to %s toolchain hierarchy (mapped suffix was %s but "
"versionsuffix mappings were %s)",
original_suffix, original_toolchain,
toolchain_mapping[original_toolchain['name']], mapped_suffix,
versionsuffix_mappings)
else:
versionsuffix_mappings[original_suffix] = mapped_suffix

Expand Down Expand Up @@ -953,8 +956,9 @@ def map_easyconfig_to_target_tc_hierarchy(ec_spec, toolchain_mapping, targetdir=
parsed_ec = process_easyconfig(ec_spec, validate=False)[0]['ec']

versonsuffix_mapping = {}

if update_dep_versions:
# We only need to map versionsuffixes if we are updating dependency versions and if there are
# versionsuffixes being used in dependencies
if update_dep_versions and list_deps_versionsuffixes(ec_spec):
# We may need to update the versionsuffix if it is like, for example, `-Python-2.7.8`
versonsuffix_mapping = map_common_versionsuffixes('Python', parsed_ec['toolchain'], toolchain_mapping)

Expand Down Expand Up @@ -1061,6 +1065,31 @@ def map_easyconfig_to_target_tc_hierarchy(ec_spec, toolchain_mapping, targetdir=
return tweaked_spec


def list_deps_versionsuffixes(ec_spec):
"""
Take an easyconfig spec, parse it, extracts the list of version suffixes used in its dependencies

:param ec_spec: location of original easyconfig file

:return: The list of versionsuffixes used by the dependencies of this recipe
"""
# Fully parse the original easyconfig
parsed_ec = process_easyconfig(ec_spec, validate=False)[0]['ec']

versionsuffix_list = []
for key in DEPENDENCY_PARAMETERS:
val = parsed_ec[key]

if key in parsed_ec.iterate_options:
val = flatten(val)

for dep in val:
if dep['versionsuffix']:
versionsuffix_list += [dep['versionsuffix']]

return list(set(versionsuffix_list))


def find_potential_version_mappings(dep, toolchain_mapping, versionsuffix_mapping=None, highest_versions_only=True):
"""
Find potential version mapping for a dependency in a new hierarchy
Expand Down
19 changes: 19 additions & 0 deletions test/framework/tweak.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from easybuild.framework.easyconfig.tweak import get_matching_easyconfig_candidates, map_toolchain_hierarchies
from easybuild.framework.easyconfig.tweak import find_potential_version_mappings
from easybuild.framework.easyconfig.tweak import map_easyconfig_to_target_tc_hierarchy
from easybuild.framework.easyconfig.tweak import list_deps_versionsuffixes
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.config import module_classes
from easybuild.tools.filetools import change_dir, write_file
Expand Down Expand Up @@ -482,6 +483,24 @@ def test_map_easyconfig_to_target_tc_hierarchy(self):
hit_extension += 1
self.assertEqual(hit_extension, 1, "Should only have updated one extension")

def test_list_deps_versionsuffixes(self):
"""Test listing of dependencies' version suffixes"""
test_easyconfigs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')
build_options = {
'robot_path': [test_easyconfigs],
'silent': True,
'valid_module_classes': module_classes(),
}
init_config(build_options=build_options)
get_toolchain_hierarchy.clear()

ec_spec = os.path.join(test_easyconfigs, 'g', 'golf', 'golf-2018a.eb')
self.assertEqual(list_deps_versionsuffixes(ec_spec), ['-serial'])
ec_spec = os.path.join(test_easyconfigs, 't', 'toy', 'toy-0.0-deps.eb')
self.assertEqual(list_deps_versionsuffixes(ec_spec), [])
ec_spec = os.path.join(test_easyconfigs, 'g', 'gzip', 'gzip-1.4-GCC-4.6.3.eb')
self.assertEqual(list_deps_versionsuffixes(ec_spec), ['-deps'])

def suite():
""" return all the tests in this file """
return TestLoaderFiltered().loadTestsFromTestCase(TweakTest, sys.argv[1:])
Expand Down