3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-07-14 19:15:41 +00:00

cmake: prevent install_tactic.deps from triggering spurious rebuilds on reconfigure (#10102)

`z3_add_install_tactic_rule` unconditionally called `file(WRITE)` during
CMake configure, updating `install_tactic.deps`'s mtime on every
reconfiguration — even when the content was identical. Since
`install_tactic.cpp` lists `install_tactic.deps` as a dependency, any
CMake reconfigure (e.g. touching `src/api/ml/CMakeLists.txt`) caused a
full rebuild of the tactic installation target.

## Change

- **`cmake/z3_add_component.cmake` — `z3_add_install_tactic_rule`**:
Replace unconditional `file(WRITE)` with a read-and-compare guard; the
deps file is only rewritten when its content actually changes.

```cmake
# Before
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/install_tactic.deps" ${_tactic_header_files})

# After
set(_install_tactic_deps_file "${CMAKE_CURRENT_BINARY_DIR}/install_tactic.deps")
if (EXISTS "${_install_tactic_deps_file}")
  file(READ "${_install_tactic_deps_file}" _install_tactic_deps_old)
else()
  set(_install_tactic_deps_old "")
endif()
if (NOT _install_tactic_deps_old STREQUAL "${_tactic_header_files}")
  file(WRITE "${_install_tactic_deps_file}" "${_tactic_header_files}")
endif()
```

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
Copilot 2026-07-12 20:07:41 -07:00 committed by GitHub
parent 0b8335e776
commit 136a653ade
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -273,7 +273,19 @@ macro(z3_add_install_tactic_rule)
unset(_component_tactic_header_files)
string(REPLACE ";" "\n" _tactic_header_files "${_tactic_header_files}")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/install_tactic.deps" ${_tactic_header_files})
# Only write the deps file if content has changed to avoid unnecessary rebuilds
# (file(WRITE) always updates the timestamp even if content is unchanged)
set(_install_tactic_deps_file "${CMAKE_CURRENT_BINARY_DIR}/install_tactic.deps")
if (EXISTS "${_install_tactic_deps_file}")
file(READ "${_install_tactic_deps_file}" _install_tactic_deps_old)
else()
set(_install_tactic_deps_old "")
endif()
if (NOT _install_tactic_deps_old STREQUAL "${_tactic_header_files}")
file(WRITE "${_install_tactic_deps_file}" "${_tactic_header_files}")
endif()
unset(_install_tactic_deps_old)
unset(_install_tactic_deps_file)
add_custom_command(OUTPUT "install_tactic.cpp"
COMMAND "${Python3_EXECUTABLE}"
"${PROJECT_SOURCE_DIR}/scripts/mk_install_tactic_cpp.py"