Skip to content

Commit cd01b65

Browse files
committed
handle extra_dirs passed as string and throw error for non-iterables
1 parent 80e5825 commit cd01b65

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

easybuild/tools/toolchain/toolchain.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,9 +1086,19 @@ def _add_dependency_cpp_headers(self, dep_root, extra_dirs=None):
10861086
Append prepocessor paths for given dependency root directory
10871087
"""
10881088
header_dirs = ["include"]
1089-
if isinstance(extra_dirs, (tuple, list)):
1089+
1090+
if extra_dirs is None:
1091+
extra_dirs = ()
1092+
elif extra_dirs and isinstance(extra_dirs, (str,)):
1093+
extra_dirs = [extra_dirs]
1094+
1095+
try:
10901096
header_dirs.extend(extra_dirs)
1091-
header_dirs = nub(header_dirs) # remove duplicates
1097+
except TypeError as err:
1098+
err_msg = f"_add_dependency_cpp_headers: given extra_dirs is not iterable: {extra_dirs}"
1099+
raise EasyBuildError(err_msg) from err
1100+
else:
1101+
header_dirs = nub(header_dirs) # remove duplicates
10921102

10931103
# mode of operation is defined by search-path-cpp-headers option
10941104
# toolchain option has precedence over build option
@@ -1116,14 +1126,27 @@ def _add_dependency_linker_paths(self, dep_root, extra_dirs=None):
11161126
Append linker paths for given dependency root directory
11171127
"""
11181128
lib_dirs = ["lib64", "lib"]
1119-
if isinstance(extra_dirs, (tuple, list)):
1129+
1130+
if extra_dirs is None:
1131+
extra_dirs = ()
1132+
elif extra_dirs and isinstance(extra_dirs, (str,)):
1133+
extra_dirs = [extra_dirs]
1134+
1135+
try:
11201136
lib_dirs.extend(extra_dirs)
1121-
lib_dirs = nub(lib_dirs) # remove duplicates
1137+
except TypeError as err:
1138+
err_msg = f"_add_dependency_linker_paths: given extra_dirs is not iterable: {extra_dirs}"
1139+
raise EasyBuildError(err_msg) from err
1140+
else:
1141+
lib_dirs = nub(lib_dirs) # remove duplicates
11221142

11231143
env_var = "LDFLAGS"
11241144
self.log.debug("Adding lib paths to toolchain variable '%s': %s", env_var, dep_root)
11251145
self.variables.append_subdirs(env_var, dep_root, subdirs=lib_dirs)
11261146

1147+
def _unique_ordered_list_append(self, base, extra_dirs):
1148+
"""Append list of dirs to another list of dirs keeping order and without duplicates"""
1149+
11271150
def _setenv_variables(self, donotset=None, verbose=True):
11281151
"""Actually set the environment variables"""
11291152

0 commit comments

Comments
 (0)