Skip to content

Commit 1c628c1

Browse files
committed
Only calculate the mapping of version suffixes if they are actually used
1 parent e9e8532 commit 1c628c1

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

easybuild/framework/easyconfig/tweak.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,9 @@ def map_easyconfig_to_target_tc_hierarchy(ec_spec, toolchain_mapping, targetdir=
951951
parsed_ec = process_easyconfig(ec_spec, validate=False)[0]['ec']
952952

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

@@ -1059,6 +1060,34 @@ def map_easyconfig_to_target_tc_hierarchy(ec_spec, toolchain_mapping, targetdir=
10591060
return tweaked_spec
10601061

10611062

1063+
def list_deps_versionsuffixes(ec_spec):
1064+
"""
1065+
Take an easyconfig spec, parse it, extracts the list of version suffixes used in its dependencies
1066+
1067+
:param ec_spec: location of original easyconfig file
1068+
1069+
:return: The list of versionsuffixes used by the dependencies of this recipe
1070+
"""
1071+
# Fully parse the original easyconfig
1072+
parsed_ec = process_easyconfig(ec_spec, validate=False)[0]['ec']
1073+
1074+
versionsuffix_list = []
1075+
for key in DEPENDENCY_PARAMETERS:
1076+
# loop over a *copy* of dependency dicts (with resolved templates);
1077+
1078+
# to update the original dep dict, we need to get a reference with templating disabled...
1079+
val = parsed_ec[key]
1080+
1081+
if key in parsed_ec.iterate_options:
1082+
val = flatten(val)
1083+
1084+
for dep in val:
1085+
if dep['versionsuffix']:
1086+
versionsuffix_list += [dep['versionsuffix']]
1087+
1088+
return list(set(versionsuffix_list))
1089+
1090+
10621091
def find_potential_version_mappings(dep, toolchain_mapping, versionsuffix_mapping=None, highest_versions_only=True):
10631092
"""
10641093
Find potential version mapping for a dependency in a new hierarchy

test/framework/tweak.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from easybuild.framework.easyconfig.tweak import get_matching_easyconfig_candidates, map_toolchain_hierarchies
4141
from easybuild.framework.easyconfig.tweak import find_potential_version_mappings
4242
from easybuild.framework.easyconfig.tweak import map_easyconfig_to_target_tc_hierarchy
43+
from easybuild.framework.easyconfig.tweak import list_deps_versionsuffixes
4344
from easybuild.tools.build_log import EasyBuildError
4445
from easybuild.tools.config import module_classes
4546
from easybuild.tools.filetools import change_dir, write_file
@@ -483,6 +484,24 @@ def test_map_easyconfig_to_target_tc_hierarchy(self):
483484
hit_extension += 1
484485
self.assertEqual(hit_extension, 1, "Should only have updated one extension")
485486

487+
def test_list_deps_versionsuffixes(self):
488+
"""Test listing of dependencies' version suffixes"""
489+
test_easyconfigs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')
490+
build_options = {
491+
'robot_path': [test_easyconfigs],
492+
'silent': True,
493+
'valid_module_classes': module_classes(),
494+
}
495+
init_config(build_options=build_options)
496+
get_toolchain_hierarchy.clear()
497+
498+
ec_spec = os.path.join(test_easyconfigs, 'g', 'golf', 'golf-2018a.eb')
499+
self.assertEqual(list_deps_versionsuffixes(ec_spec), ['-serial'])
500+
ec_spec = os.path.join(test_easyconfigs, 't', 'toy', 'toy-0.0-deps.eb')
501+
self.assertEqual(list_deps_versionsuffixes(ec_spec), [])
502+
ec_spec = os.path.join(test_easyconfigs, 'g', 'gzip', 'gzip-1.4-GCC-4.6.3.eb')
503+
self.assertEqual(list_deps_versionsuffixes(ec_spec), ['-deps'])
504+
486505
def suite():
487506
""" return all the tests in this file """
488507
return TestLoaderFiltered().loadTestsFromTestCase(TweakTest, sys.argv[1:])

0 commit comments

Comments
 (0)