Skip to content

Commit

Permalink
Add drhook to the um package (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
penguian authored Sep 27, 2024
1 parent a2e7667 commit a490029
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions packages/um/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Um(Package):

# Bool variants have their default value set to True here.
_bool_variants = (
"DR_HOOK",
"eccodes",
"netcdf")
for var in _bool_variants:
Expand Down Expand Up @@ -118,21 +119,35 @@ class Um(Package):
depends_on("[email protected]", when="@13.3", type=("build", "link"))
depends_on("[email protected]", when="@13.4", type=("build", "link"))
depends_on("[email protected]:", when="@13.5:", type=("build", "link"))
depends_on("fiat@um", type=("build", "link", "run"),
when="+DR_HOOK")
depends_on("eccodes +fortran +netcdf", type=("build", "link", "run"),
when="+eccodes")
depends_on("[email protected]", type=("build", "link", "run"),
when="+netcdf")

phases = ["build", "install"]

# The dependency name and the ld_flags from
# The dependency name, include paths, and ld_flags from
# the FCM config for each library configured via FCM.
_lib_cfg = {
"DR_HOOK": {
"includes": [
join_path("include", "fiat"),
join_path("module", "fiat"),
join_path("module", "parkind_dp")],
"dep_name": "fiat",
"fcm_name": "drhook",
"fcm_ld_flags": "-lfiat -lparkind_dp"},
"eccodes": {
"includes": ["include"],
"dep_name": "eccodes",
"fcm_name": "eccodes",
"fcm_ld_flags": "-leccodes_f90 -leccodes"},
"netcdf": {
"includes": ["include"],
"dep_name": "netcdf-fortran",
"fcm_name": "netcdf",
"fcm_ld_flags": "-lnetcdff -lnetcdf"}}


Expand Down Expand Up @@ -188,16 +203,6 @@ def check_model_vs_spec(model, config_env, var, spec_value):

spec = self.spec

# Define CPATH for dependencies that need include files.
ideps = ["eccodes", "gcom", "netcdf-fortran"]
incs = [spec[d].prefix.include for d in ideps]
for ipath in incs:
env.prepend_path("CPATH", ipath)

# The gcom library does not contain shared objects and
# therefore must be statically linked.
env.prepend_path("LIBRARY_PATH", spec["gcom"].prefix.lib)

# Use rose-app.conf to set config options.
config = configparser.ConfigParser()
# Ensure that keys are case sensitive.
Expand All @@ -219,9 +224,6 @@ def check_model_vs_spec(model, config_env, var, spec_value):
check_model_vs_spec(model, config_env, key, spec_um_rev)
config_env[key] = spec_um_rev

# Set DR_HOOK="false" until this package is available.
config_env["DR_HOOK"] = "false"

# Override those environment variables where a bool variant is specified.
bool_to_str = lambda b: "true" if b else "false"
for var in self._bool_variants:
Expand Down Expand Up @@ -256,10 +258,26 @@ def check_model_vs_spec(model, config_env, var, spec_value):
check_model_vs_spec(model, config_env, var, spec_value)
config_env[var] = spec_value

# Define CPATH and FPATH for dependencies that need include files or modules.
for path in ["CPATH", "FPATH"]:
env.prepend_path(path, spec["gcom"].prefix.include)
for var in self._bool_variants:
if config_env[var] == "true":
prefix = spec[self._lib_cfg[var]["dep_name"]].prefix
for include in self._lib_cfg[var]["includes"]:
env.prepend_path(path, prefix.join(include))
tty.info(f"{path}={[p.value for p in env.group_by_name()[path]]}")

# The gcom library does not contain shared objects and
# therefore must be statically linked.
env.prepend_path("LIBRARY_PATH", spec["gcom"].prefix.lib)

# Get the linker arguments for some dependencies.
for fcm_libname in ["eccodes", "netcdf"]:
linker_args = self._get_linker_args(spec, fcm_libname)
config_env[f"ldflags_{fcm_libname}_on"] = linker_args
for var in self._bool_variants:
if config_env[var] == "true":
fcm_name = self._lib_cfg[var]["fcm_name"]
linker_args = self._get_linker_args(spec, var)
config_env[f"ldflags_{fcm_name}_on"] = linker_args

# Set environment variables based on config_env.
for key in config_env:
Expand Down

0 comments on commit a490029

Please sign in to comment.