Skip to content

Execute process replace#161

Merged
poshul merged 13 commits intomasterfrom
execute_process_replace
Dec 3, 2025
Merged

Execute process replace#161
poshul merged 13 commits intomasterfrom
execute_process_replace

Conversation

@poshul
Copy link
Copy Markdown
Contributor

@poshul poshul commented Dec 3, 2025

Replace the outdated exec_program with execute_process

Summary by CodeRabbit

  • Chores
    • Exposed per-language build flags and a general extra-arguments option for clearer compile-time control.
    • Unified execution for configure/build/patch/copy/extract to capture stdout/stderr, exit status, and restore environment; improved status and error messages.
    • Normalized archive-extraction arguments for more reliable unpacking.
    • Strengthened contrib project configuration with stricter toolchain and C++ standard checks and adjusted build timeouts.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 3, 2025

Walkthrough

Replaces many exec_program calls with execute_process to capture stdout/stderr and result codes; introduces per-language COINOR flags and COINOR_EXTRA_ARGS in the COIN‑OR build flow; runs configure/make install via execute_process with env preservation/restoration and expanded logging/error reporting. (50 words)

Changes

Cohort / File(s) Summary
COIN-OR build configuration
libraries.cmake/coinor.cmake
Adds COINOR_CXXFLAGS, COINOR_CFLAGS, COINOR_FFLAGS, COINOR_EXTRA_ARGS; prints and sets per-language env before configure; uses execute_process for configure and make install, captures COINOR_CONFIGURE_OUT/ERR and COINOR_MAKE_OUT/ERR, restores original env vars, and updates logging/error handling.
Macro execution & logging refactor
macros.cmake
Replaces exec_program with execute_process in extraction/patch/copy/build macros (OPENMS_SMARTEXTRACT, OPENMS_BUILDLIB, OPENMS_PATCH, OPENMS_COPYDIR and tar/tgz flows); introduces RESULT_VARIABLE + _OUT/_ERR variables, logs stderr alongside stdout, and changes failure checks to use result variables with updated fatal messages.
Unquoted ZIP_ARGS across libraries
libraries.cmake/arrow.cmake, libraries.cmake/boost.cmake, libraries.cmake/bzip2.cmake, libraries.cmake/eigen.cmake, libraries.cmake/glpk.cmake, libraries.cmake/hdf5.cmake, libraries.cmake/kissfft.cmake, libraries.cmake/libsvm.cmake, libraries.cmake/openmp.cmake, libraries.cmake/xercesc.cmake, libraries.cmake/zlib.cmake
Removed surrounding quotes from ZIP_ARGS assignments in MSVC and non‑MSVC branches (e.g., "x -y -osrc"x -y -osrc, "xzf"xzf), changing how extraction arguments are tokenized; glpk.cmake also removes -j ${NUMBER_OF_JOBS} from some make/install invocations.
Top-level project and policy changes
CMakeLists.txt
Reintroduces PROJECT("OpenMS_CONTRIB"), sets CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true, enforces CMAKE_CXX_STANDARD 20 and CMAKE_CXX_STANDARD_REQUIRED, and adds toolchain/version checks on UNIX compilers.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~30–60 minutes

  • Areas to focus on:
    • libraries.cmake/coinor.cmake: correctness of execute_process COMMAND/ENV construction, handling of captured OUT/ERR variables, and safe restoration/unsetting of original CXXFLAGS/CFLAGS/FFLAGS.
    • macros.cmake: ensure argument tokenization matches previous behavior when moving from exec_program to execute_process, consistent use of RESULT_VARIABLE vs ERROR_VARIABLE, and that *_ERR logging is meaningful/escaped.
    • ZIP_ARGS changes: verify callers accept list-form args on both MSVC and Unix; confirm no change in extraction semantics.
    • CMakeLists.txt: check project re-declaration and strict C++ standard/toolchain checks for unintended CI or platform breakage.

Possibly related PRs

Poem

I’m a rabbit in the build-tree glen, 🐇
I hop through flags and capture when,
Outputs and errors now held tight,
Configure hums, make finishes right,
Logs glow — no surprises at ten! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main objective of the pull request: replacing the outdated exec_program with execute_process across multiple files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch execute_process_replace

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e54dffd and 6bd4c98.

📒 Files selected for processing (1)
  • libraries.cmake/coinor.cmake (2 hunks)
🔇 Additional comments (2)
libraries.cmake/coinor.cmake (2)

134-143: Per-language COINOR_ flag split looks good*

The separation into COINOR_CXXFLAGS, COINOR_CFLAGS, COINOR_FFLAGS, and COINOR_EXTRA_ARGS is clear and makes the platform-specific configuration easier to reason about. No issues from a CMake/build perspective here.


206-218: make install execute_process wiring and logging look solid

The switch to execute_process for ${CMAKE_MAKE_PROGRAM} install with COINOR_MAKE_OUT/COINOR_MAKE_ERR capture, plus appending both streams to ${LOGFILE}, is a clear improvement over exec_program. The status/error messaging on failure also looks appropriate.

Also applies to: 221-221

Comment thread libraries.cmake/coinor.cmake
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
libraries.cmake/coinor.cmake (2)

168-201: Use the more robust RESULT_VARIABLE check pattern for execute_process

execute_process can set RESULT_VARIABLE either to an integer exit code or to a non-numeric error string (e.g. for timeouts or spawn failures).(cmake.org)
To handle both cases reliably, CMake docs and common usage recommend the idiom if(STATUS AND NOT STATUS EQUAL 0) rather than only if(NOT STATUS EQUAL 0) when checking RESULT_VARIABLE.(stackoverflow.com)

Here that would slightly improve robustness for both the configure and make steps:

-    if( NOT COINOR_CONFIGURE_SUCCESS EQUAL 0)
+    if(COINOR_CONFIGURE_SUCCESS AND NOT COINOR_CONFIGURE_SUCCESS EQUAL 0)
       message( STATUS "Configure COIN-OR library .. failed")
       message( STATUS ${COINOR_CONFIGURE_ERR})
       message( FATAL_ERROR ${COINOR_CONFIGURE_OUT})
     else()
       message( STATUS "Configure COIN-OR library .. done")
     endif()

     ## make install
     message( STATUS "Building and installing COIN-OR library (make install).. ")
@@
-    if( NOT COINOR_MAKE_SUCCESS EQUAL 0)
+    if(COINOR_MAKE_SUCCESS AND NOT COINOR_MAKE_SUCCESS EQUAL 0)
       message( STATUS "Building and installing COIN-OR library (make install) .. failed")
       message( STATUS ${COINOR_MAKE_ERR})
       message( FATAL_ERROR ${COINOR_MAKE_OUT})
     else()
       message( STATUS "Building and installing COIN-OR library (make install) .. done")
     endif()

This keeps behavior unchanged for normal non-zero exit codes, but is safer if CMake ever returns a descriptive error string in COINOR_*_SUCCESS.

If you want to double-check how RESULT_VARIABLE behaves in your exact CMake version, you can run a tiny CMake script that calls execute_process with a bad command and prints the captured status, then confirm the above pattern behaves as expected.

Also applies to: 210-224, 242-245


170-179: Env save/restore fixes earlier leak; optionally track “defined vs empty” explicitly

Saving CXXFLAGS/CFLAGS/FFLAGS into _ORIG_* and restoring them after the configure + make steps cleanly addresses the earlier concern about leaking these flags into later execute_process calls, and logging both COINOR_CONFIGURE_OUT and COINOR_CONFIGURE_ERR to ${LOGFILE} completes the diagnostics story.(cmake.org)

One minor edge case: using STREQUAL "" to decide whether to unset(ENV{...}) cannot distinguish between an env var that was truly undefined and one that was defined but empty. If you ever care about that distinction, you could track “had this env var” separately:

-    set(_ORIG_CXXFLAGS "$ENV{CXXFLAGS}")
-    set(_ORIG_CFLAGS "$ENV{CFLAGS}")
-    set(_ORIG_FFLAGS "$ENV{FFLAGS}")
+    if(DEFINED ENV{CXXFLAGS})
+      set(_ORIG_CXXFLAGS "$ENV{CXXFLAGS}")
+      set(_HAD_CXXFLAGS TRUE)
+    else()
+      set(_ORIG_CXXFLAGS "")
+      set(_HAD_CXXFLAGS FALSE)
+    endif()
+    if(DEFINED ENV{CFLAGS})
+      set(_ORIG_CFLAGS "$ENV{CFLAGS}")
+      set(_HAD_CFLAGS TRUE)
+    else()
+      set(_ORIG_CFLAGS "")
+      set(_HAD_CFLAGS FALSE)
+    endif()
+    if(DEFINED ENV{FFLAGS})
+      set(_ORIG_FFLAGS "$ENV{FFLAGS}")
+      set(_HAD_FFLAGS TRUE)
+    else()
+      set(_ORIG_FFLAGS "")
+      set(_HAD_FFLAGS FALSE)
+    endif()
@@
-    if(_ORIG_CXXFLAGS STREQUAL "")
-      unset(ENV{CXXFLAGS})
-    else()
-      set(ENV{CXXFLAGS} "${_ORIG_CXXFLAGS}")
-    endif()
-    if(_ORIG_CFLAGS STREQUAL "")
-      unset(ENV{CFLAGS})
-    else()
-      set(ENV{CFLAGS} "${_ORIG_CFLAGS}")
-    endif()
-    if(_ORIG_FFLAGS STREQUAL "")
-      unset(ENV{FFLAGS})
-    else()
-      set(ENV{FFLAGS} "${_ORIG_FFLAGS}")
-    endif()
+    if(_HAD_CXXFLAGS)
+      set(ENV{CXXFLAGS} "${_ORIG_CXXFLAGS}")
+    else()
+      unset(ENV{CXXFLAGS})
+    endif()
+    if(_HAD_CFLAGS)
+      set(ENV{CFLAGS} "${_ORIG_CFLAGS}")
+    else()
+      unset(ENV{CFLAGS})
+    endif()
+    if(_HAD_FFLAGS)
+      set(ENV{FFLAGS} "${_ORIG_FFLAGS}")
+    else()
+      unset(ENV{FFLAGS})
+    endif()

If you don’t have cases where empty-but-defined flags matter, the current implementation is perfectly acceptable and already a clear improvement over the previous behavior.

If you’re unsure whether any of your CI or local environments rely on CXXFLAGS/CFLAGS/FFLAGS being explicitly set to an empty string, it’s worth spot-checking by printing those env vars before invoking CMake in one representative build.

Also applies to: 225-240

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1cebe6 and 0cbbb5e.

📒 Files selected for processing (1)
  • libraries.cmake/coinor.cmake (2 hunks)
🔇 Additional comments (1)
libraries.cmake/coinor.cmake (1)

132-143: *Per-language COINOR_FLAGS / COINOR_EXTRA_ARGS split is coherent

The Darwin vs non-Darwin split for COINOR_CXXFLAGS, COINOR_CFLAGS, COINOR_FFLAGS, and COINOR_EXTRA_ARGS is consistent and lines up with how you feed COINOR_CXXFLAGS into the configure environment below. I don’t see issues with this refactor in isolation.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
CMakeLists.txt (2)

145-159: Add compiler version checks for Windows/MSVC to complete C++20 enforcement.

C++20 standard is enforced globally (line 141–142), but compiler version checks are only applied on UNIX (line 145). Windows/MSVC builds lack a minimum version guard, risking silent failures on older toolchains that cannot support C++20.

Add a complementary MSVC version check to ensure Visual Studio 2019 (toolset 14.2) or later, which is the minimum for reasonable C++20 support.

 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
   if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0.0")
     message(FATAL_ERROR "g++: OpenMS-contrib requires version 10.0.0 or later to build but found ${CMAKE_CXX_COMPILER_VERSION}")
   endif()  
 endif()
+elseif (MSVC)
+  if(MSVC_VERSION VERSION_LESS "1920")
+    message(FATAL_ERROR "MSVC: OpenMS-contrib requires Visual Studio 2019 (toolset 14.2, MSVC_VERSION ≥ 1920) or later for C++20 support but found ${MSVC_VERSION}")
+  endif()
+endif()

90-91: Replace remaining exec_program calls in libraries.cmake/glpk.cmake with execute_process.

The codebase still contains 5 active exec_program calls in glpk.cmake (lines 22, 37, 73, 98, 115), contradicting the migration goal noted at CMakeLists.txt:90–91. These must be replaced with execute_process to complete the deprecation migration. The NOTE comment indicates past concerns about Windows argument handling with execute_process—verify functionality on Windows before merging.

🧹 Nitpick comments (1)
CMakeLists.txt (1)

136-142: Remove the deprecated CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS flag.

CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS is a CMake 2.x–era backward-compatibility setting no longer needed in CMake 3.10+ (your minimum required version per line 134). It has no effect and should be removed to keep the build system clean.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f89cfa and bbe4c8e.

📒 Files selected for processing (2)
  • CMakeLists.txt (1 hunks)
  • libraries.cmake/eigen.cmake (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build (ubuntu-latest)
🔇 Additional comments (4)
libraries.cmake/eigen.cmake (4)

11-14: LGTM!

Unquoting ZIP_ARGS values creates proper CMake lists, which is the correct approach when these arguments will be expanded as separate command-line arguments in OPENMS_SMARTEXTRACT.


24-26: LGTM!

Good addition of diagnostic messages. These will be helpful for troubleshooting build configuration issues.


38-48: LGTM!

Good enhancements:

  • TIMEOUT 300 prevents indefinite hangs during configuration.
  • Capturing the exit code in RESULT_VARIABLE and displaying stdout/stderr on failure significantly improves debugging.

65-75: LGTM!

Consistent with the configuration step enhancements. The 5-minute timeout is appropriate for installing Eigen headers.

@poshul poshul merged commit be8c14f into master Dec 3, 2025
6 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant