Skip to content

Commit 9b5a43f

Browse files
committed
Update the documentation
1 parent d04af42 commit 9b5a43f

File tree

2 files changed

+60
-19
lines changed

2 files changed

+60
-19
lines changed

docs/developers_guide/spack.md

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ To enable Spack-based environments for a new machine, you will need to:
1414
supported compiler and MPI library combination.
1515
2. Add system-provided (external) packages, saving time and preventing build
1616
failures if Spack attempts to build them from source.
17-
3. Optionally, provide shell script templates for module/environment setup if
18-
needed.
17+
3. Prefer automatic shell script generation. Shell snippets used to be
18+
maintained as templates in `mache.spack.templates`, but are now derived
19+
primarily from the E3SM CIME machine configuration
20+
(`mache/cime_machine_config/config_machines.xml`). Only add a minimal
21+
template override when strictly necessary (see below).
1922

2023
## YAML Template Files
2124

@@ -82,21 +85,46 @@ all:
8285
8386
```
8487

85-
## Shell Script Templates
88+
## Automatic shell script generation (preferred)
8689

87-
If the machine requires special module loads or environment variables not handled by Spack, add corresponding shell script templates:
90+
When downstream packages call
91+
{py:func}`mache.spack.get_spack_script`, the module loads and
92+
environment-variable setup are constructed as follows:
8893

89-
- `<machine>.sh` and/or `<machine>_<compiler>_<mpilib>.sh` for bash
90-
- `<machine>.csh` and/or `<machine>_<compiler>_<mpilib>.csh` for csh/tcsh
94+
1. Optional: activate Spack and the requested environment.
95+
2. Auto-generate a shell snippet from the E3SM CIME machine configuration
96+
stored in `mache/cime_machine_config/config_machines.xml`, filtered for the
97+
requested `(machine, compiler, mpilib)` and rendered for the target shell
98+
(`sh` or `csh`).
99+
3. Append any Jinja2 template override found in
100+
`mache/spack/templates/` named either `<machine>.<sh|csh>` or
101+
`<machine>_<compiler>_<mpilib>.<sh|csh>`.
91102

92-
These scripts are also Jinja2 templates and can use the same conditional logic as the YAML files.
103+
This pipeline greatly reduces maintenance and prevents drift between Mache and
104+
E3SM’s authoritative machine configuration. In most cases, you do not need to
105+
author or maintain shell script templates in Mache.
106+
107+
### When to add a template override
108+
109+
Only provide a small override in `mache/spack/templates/` if you need to:
110+
111+
- Apply an adjustment that’s not appropriate for the shared E3SM CIME config
112+
(machine-local quirk, temporary workaround, etc.).
113+
- Add conditional behavior toggled by
114+
`include_e3sm_lapack` or `include_e3sm_hdf5_netcdf` (both exposed as Jinja
115+
booleans in templates) that cannot be expressed in the CIME config.
116+
117+
Templates are Jinja2 files and can use the same conditional logic as YAML
118+
templates.
93119

94120
## Testing
95121

96-
After adding or modifying YAML and shell script templates:
122+
After adding or modifying YAML templates (or an exceptional shell override):
97123

98-
1. Use the `make_spack_env` or `get_spack_script` functions in `mache.spack` to generate and test the environment.
99-
2. Confirm that all modules load and all external packages are correctly detected by Spack.
124+
1. Use `make_spack_env` or `get_spack_script` in `mache.spack` to generate and
125+
test the environment and load scripts.
126+
2. Confirm that the generated shell snippet includes the expected module loads
127+
from the CIME machine config and that Spack detects all external packages.
100128
3. Build and run a simple test application to verify the environment.
101129

102130
## Further Reading

docs/users_guide/spack/build.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ from mache.spack import get_spack_script
9494
```
9595

9696
**Purpose:**
97-
Generates a shell script snippet to activate a Spack environment and load any required modules or environment variables.
97+
Generates a shell script snippet to activate a Spack environment and load the
98+
required modules or environment variables.
9899

99100
**Typical usage in downstream packages:**
100101

@@ -118,13 +119,19 @@ spack_script = get_spack_script(
118119
)
119120
```
120121

121-
**Returns:**
122-
A string containing shell commands to:
122+
**How the script is composed:**
123+
124+
The returned snippet is assembled in three steps:
123125

124-
- Load required modules (if any).
125-
- Source the Spack setup script.
126-
- Activate the specified Spack environment.
127-
- Set any additional environment variables.
126+
1. Optionally source Spack and activate the requested environment.
127+
2. Auto-generate module loads and environment exports from the E3SM CIME
128+
machine configuration (`mache/cime_machine_config/config_machines.xml`) for
129+
the given `(machine, compiler, mpi)` and target shell (`sh` or `csh`).
130+
3. Append any Mache template override present in `mache/spack/templates/` named
131+
`<machine>.<sh|csh>` or `<machine>_<compiler>_<mpi>.<sh|csh>`.
132+
133+
This design keeps Mache aligned with E3SM’s authoritative machine
134+
configuration and minimizes maintenance.
128135

129136
**Usage in activation scripts:**
130137

@@ -142,7 +149,8 @@ from mache.spack import get_modules_env_vars_and_mpi_compilers
142149
```
143150

144151
**Purpose:**
145-
Returns the MPI compiler wrappers and a shell snippet to load modules and set environment variables for a given machine, compiler, and MPI library.
152+
Returns the MPI compiler wrappers and a shell snippet to load modules and set
153+
environment variables for a given machine, compiler, and MPI library.
146154

147155
**Typical usage in downstream packages:**
148156

@@ -169,13 +177,18 @@ mpicc, mpicxx, mpifc, mod_env_commands = get_modules_env_vars_and_mpi_compilers(
169177
- `mpifc`: Name of the MPI Fortran compiler wrapper (e.g., `mpif90` or `ftn`).
170178
- `mod_env_commands`: Shell commands to load modules and set environment variables.
171179

172-
**Usage in build scripts:**
180+
**Notes and usage in build scripts:**
173181

174182
```bash
175183
{{ mod_env_commands }}
176184
# Now safe to use $mpicc, $mpicxx, $mpifc for building MPI-dependent software
177185
```
178186

187+
- This helper produces a minimal snippet based on Mache’s template overrides
188+
(when present). It does not auto-generate content from
189+
`config_machines.xml`. If you need the full environment setup used by
190+
downstream activation scripts, prefer `get_spack_script`.
191+
179192
---
180193

181194
## Example: How Downstream Packages Use These Functions

0 commit comments

Comments
 (0)