ESMCI / ESMCI/cime

Refactor Slice 3B: Move build logic into `CIME/core/build/`

Open
#4,999 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
174
Forks
225
Avg merge
1d 16h
Merged PRs (30d)
14

Description

Part of #4950. Slice 3B of 5. Estimated 5 weeks. Depends on #4998.

## Goal

Move build logic from `build.py` (1350 lines) into focused modules under
`CIME/core/build/`. Keep `CIME/build_scripts/` as the stable external wrapper.

## Tasks

### Extract into `CIME/core/build/`
- [ ] Build planning logic.
- [ ] Build execution / orchestration.
- [ ] `build.py` becomes a thin re-export layer.

### Move from `utils.py`
- [ ] `analyze_build_log`, `run_bld_cmd_ensure_logging`,
`copy_local_macros_to_dir` → `core/build/`.
- [ ] `safe_copy`, `safe_recursive_copy`, `symlink_force`, `copy_globs`,
`copy_over_file`, `copyifnewer` → `CIME/core/fileops.py` (build is heavy
consumer, pulled here).

### Consolidation — free functions taking `case`
- [ ] `case_build()`, `clean()`, `_clean_impl()`, `post_build()` (`build.py`)
currently access `case._gitinterface` (private!), call `case.get_value`,
`case.set_value`, `case.flush()`. Make them `Case` methods that delegate
to `core/build/`.
- [ ] `get_standard_cmake_args()`, `get_standard_makefile_args()`,
`uses_kokkos()` (`build.py`) extract ~15 values from Case.
Consolidate as Case methods or a `BuildConfig` data class.
- [ ] `generate_makefile_macro()` (`build.py`) calls `case.get_value()` —
same pattern.

### Deduplicate copy functions
- [ ] Four overlapping copy functions in `utils.py` (`safe_copy`,
`copy_over_file`, `copyifnewer`, `copy_globs`) → coherent
`CIME/core/fileops.py` API.

### Sharedlibs (resolves #4837)
- [ ] Sharedlibs list currently hard-coded; expose as configurable.

### Imports & re-exports
- [ ] Update internal CIME imports to `core/build/`.
- [ ] Keep re-exports in `build.py` and `utils.py`.
- [ ] `CIME/build_scripts/` unchanged — stable external interface.

## Definition of done

- [ ] All build tests pass.
- [ ] `CIME/build_scripts/` compatibility maintained.
- [ ] External models (E3SM, CESM, NorESM) build unchanged.
- [ ] No private-attribute access (`case._gitinterface` etc.) from outside Case.
- [ ] One coherent fileops API; no four-copy-function-zoo.
- [ ] Resolves #4837.

## Related

- Resolves #4837 (sharedlibs hard-coding)
- Depends on #4998 (config loading must be stable first)
- Blocks #5000 (Case build delegation comes from this slice)

Contributor guide

Open the contributing guide

Research direction

Start by reading build.py, utils.py, CIME/core/fileops.py, CIME/build_scripts/, and the dependent issue #4998; run the existing build tests before changing structure. Trace the listed Case access patterns and current copy functions, then verify that build tests pass, build_scripts and external model builds remain compatible, private Case attributes are isolated, and sharedlibs is configurable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system, tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.