Skip to content

fix: suppress xlings subprocess noise on Windows during bootstrap#56

Closed
Sunrisepeak wants to merge 7 commits into
mainfrom
fix/windows-bootstrap-noise
Closed

fix: suppress xlings subprocess noise on Windows during bootstrap#56
Sunrisepeak wants to merge 7 commits into
mainfrom
fix/windows-bootstrap-noise

Conversation

@Sunrisepeak
Copy link
Copy Markdown
Member

Summary

  • Fix ensure_init() missing output redirect on Windows — xlings self init internal messages no longer leak to terminal
  • Fix install_with_progress() fallback missing stderr redirect on Windows — NDJSON interface stderr suppressed

Problem

Windows first-run printed excessive xlings internal output (debug messages, extraction logs) while Linux/macOS were clean and silent. This was because two subprocess calls were missing platform-appropriate output redirection on Windows.

Test plan

  • Verify Windows first-run only shows mcpp status messages + progress bars
  • Verify Linux/macOS first-run behavior unchanged
  • CI passes on all three platforms

New module mcpp.toolchain.msvc with three discovery strategies:
1. vswhere.exe (Microsoft's official VS locator) — most reliable
2. Environment variables (VSINSTALLDIR, VS*COMNTOOLS)
3. Well-known paths (VS 2017-2025, all editions + BuildTools)

Replaces the hardcoded VS2022 path in clang.cppm with
msvc::find_std_module_source(). Fixes "no std module source"
error on machines with non-standard VS installations.

Also provides find_cl() for future MSVC toolchain support.
Create a unified platform abstraction layer that consolidates all
platform-specific code into dedicated modules under src/platform/:

- common.cppm:   compile-time constants, platform detection, naming
- process.cppm:  unified subprocess execution (auto-closes stdin on
                 POSIX — fixes macOS first-run hang where xcrun/xcode-
                 select would block waiting for user input)
- fs.cppm:       self_exe_path(), which(), RAII FileLock
- shell.cppm:    platform-aware shell argument quoting
- env.cppm:      environment variable operations
- macos.cppm:    Xcode CLT detection, xcrun SDK discovery
- linux.cppm:    LD_LIBRARY_PATH construction, runtime lib dirs
- windows.cppm:  PATH manipulation
- platform.cppm: facade that re-exports all sub-modules

Migrated consumers:
- config.cppm:         use platform::fs::self_exe_path(), which()
- xlings.cppm:         use platform::shell, process, env (all raw
                       popen/system calls removed)
- probe.cppm:          use platform::fs::which(), macos::sdk_path(),
                       linux_::build_ld_library_path_prefix()
- bmi_cache.cppm:      use platform::fs::FileLock (RAII)
- ninja_backend.cppm:  use platform::fs::self_exe_path()
- clang.cppm:          use platform::exe_suffix for tool paths
- cli.cppm:            use platform::name constant

Deleted:
- src/platform.cppm:  replaced by src/platform/common.cppm
- src/process.cppm:   absorbed by src/platform/process.cppm + shell.cppm

Net result: ~550 lines of scattered #ifdef blocks removed, all
subprocess calls now go through platform::process which auto-redirects
stdin from /dev/null on POSIX.
The previous commit removed <cstdio> during cleanup but stderr is still
used in ensure_init(), ensure_patchelf(), and ensure_ninja() warning
messages.
P0: Remove all #define popen/_popen macros from 6 files — migrate
    every raw popen/pclose/std::system call to platform::process APIs.
    Files: cli, ninja_backend, msvc, stdmod, pack, publisher, p1689.
    Add run_passthrough() and extract_exit_code() to platform::process.

P1: Replace all manual shell quoting #ifdefs in cli.cppm with
    platform::shell::quote(). Covers git clone, ninja -C, cmd_run,
    cmd_test (5 locations).

P2: Create platform/terminal.cppm — absorbs is_tty() and
    terminal_cols() from ui.cppm. Eliminates #ifdef __unix__ blocks.

P3: Move kXpkgPlatform constant to platform::common::xpkg_platform.
    resolver.cppm now uses it without #if defined blocks.

P4: Add link strategy constants (supports_full_static, supports_rpath,
    needs_explicit_libcxx) to platform::common. flags.cppm now uses
    if constexpr instead of #if defined blocks.

P5: Replace #if defined(_WIN32) in xlings.cppm build_command_prefix,
    install_with_progress, ensure_init with if constexpr.

P6: Eliminate all #if defined blocks in ninja_backend.cppm rule
    generation. Introduce constexpr $toolenv prefix variable, use
    if constexpr for platform-specific rules (cp_bmi, scan_deps).

Net: ~440 lines of #ifdef removed, 315 lines of clean constexpr/
platform API code added. Zero raw popen calls remain outside
src/platform/.
Two places in the first-run bootstrap path were missing output
redirection on Windows, causing xlings internal messages to leak
to the terminal:

1. ensure_init(): `xlings self init` ran without any output redirect
   on Windows (Linux/macOS already had >/dev/null 2>&1). Now appends
   platform::shell::silent_redirect (">/dev/null 2>&1" on Windows).

2. install_with_progress() fallback: the NDJSON interface command
   had no stderr redirect on Windows (Linux/macOS had 2>/dev/null).
   Now appends platform::null_redirect ("2>nul" on Windows).

After this fix, the first-run experience is consistent across all
three platforms — only mcpp's own status messages and progress bars
are shown; xlings internal output is fully suppressed.
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