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

[ICON] add variant extra-configure-args #896

Merged
merged 9 commits into from
Jan 4, 2024
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
49 changes: 49 additions & 0 deletions repos/c2sm/packages/icon/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ def check_variant_fcgroup(fcgroup):
return False


def check_variant_extra_config_args(extra_config_arg):
pattern = re.compile(r'--(enable|disable)-\S+')
if pattern.match(extra_config_arg) or extra_config_arg == 'none':
return True
else:
tty.warn(
f'The value "{extra_config_arg}" for the extra_config_args variant must follow the format "--enable-arg" or "--disable-arg"'
)
return False


class Icon(AutotoolsPackage, CudaPackage):
"""Icosahedral Nonhydrostatic Weather and Climate Model."""

Expand Down Expand Up @@ -146,6 +157,15 @@ class Icon(AutotoolsPackage, CudaPackage):
default=False,
description='Enable ICON Testbed infrastructure')

variant(
'extra-config-args',
default='none',
multi=True,
values=check_variant_extra_config_args,
description=
'Inject any configure argument not yet available as variant\nUse this feature cautiously, as injecting non-variant configure arguments may potentially disrupt the build process'
)

# Optimization Features:
variant('loop-exchange', default=True, description='Enable loop exchange')
variant('vectorized-lrtm',
Expand Down Expand Up @@ -618,6 +638,18 @@ def configure_args(self):
self.spec['py-gridtools-cpp:data'].headers.directories[0])
config_vars['GT4PYNVCFLAGS'] = config_vars['NVCFLAGS']

# add configure arguments not yet available as variant
extra_config_args = self.spec.variants['extra-config-args'].value
if extra_config_args != ('none', ):
for x in extra_config_args:
# prevent configure-args already available as variant
# to be set through variant extra_config_args
self.validate_extra_config_args(x)
config_args.append(x)
tty.warn(
'You use variant extra-config-args. Injecting non-variant configure arguments may potentially disrupt the build process!'
)

# Finalize the LIBS variable (we always put the real collected
# libraries to the front):
config_vars['LIBS'].insert(0, libs.link_flags)
Expand Down Expand Up @@ -656,6 +688,23 @@ def fcgroup_to_config_var(self):
var[f'ICON_{name}_FCFLAGS'] = [flag]
return var

def strip_variant_prefix(self, variant_string):
prefixes = ["--enable-", "--disable-"]

for prefix in prefixes:
if variant_string.startswith(prefix):
return variant_string[len(prefix):]

raise ValueError

def validate_extra_config_args(self, arg):
variant_from_arg = self.strip_variant_prefix(arg)
if variant_from_arg in self.spec.variants:
raise error.SpecError(
f'The value "{arg}" for the extra_config_args variant conflicts '
f'with the existing variant {variant_from_arg}. Set this variant instead.'
)

@run_after('configure')
def adjust_rttov_macro(self):
if '+rttov' in self.spec:
Expand Down
3 changes: 3 additions & 0 deletions test/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ def test_icon(self):
spack_spec('icon')
spack_spec('icon serialization=create claw=std')
spack_spec('icon fcgroup=DACE.externals/dace_icon.-O1')
spack_spec(
'icon extra-config-args=--disable-new_feature,--enable-old_config_arg'
)

def test_icon_ham(self):
spack_spec('icon-ham')
Expand Down