Skip to content

fix: fpm run: improve error message#1303

Open
perazz wants to merge 2 commits into
fortran-lang:mainfrom
perazz:fix-compiler-not-found-message
Open

fix: fpm run: improve error message#1303
perazz wants to merge 2 commits into
fortran-lang:mainfrom
perazz:fix-compiler-not-found-message

Conversation

@perazz

@perazz perazz commented Jun 16, 2026

Copy link
Copy Markdown
Member

… line"

When a compiler, wrapper, or archiver executable is missing, a build failed
with the misleading runtime message "Invalid command line" (libgfortran's text
for a shell exit 126/127), which looks like a bad compiler flag rather than a
missing program.

`run` now detects a failed launch on both Unix (cmdstat/=0) and Windows
(cmdstat==0 but cmd.exe exit 9009), and when the invoked program cannot be
found on PATH reports:

    Could not execute '<name>': program not found on PATH.
      Check that it is installed and on your PATH, or set it explicitly with
      --compiler / FPM_FC (use FPM_CC / FPM_AR for the C compiler / archiver).

Detection is by name via the existing cross-platform which()/exists(), using
fpm's own shell lexer (fortran-shlex) to extract the program token, so quoted
paths and compiler wrappers (mpifort, caf, ...) resolve correctly. The check
runs only after a command has already failed, so the success path is unaffected.

Adds command_program/command_not_found helpers and unit tests pinning the
program extraction against the real command shapes fpm emits.
@perazz perazz force-pushed the fix-compiler-not-found-message branch from e37512d to 9fd005b Compare June 16, 2026 10:15
@perazz perazz changed the title fix(run): clear "program not found" error instead of "Invalid command line" fix: fpm run: improve error message Jun 16, 2026
The Windows lexer (ms_split) reports success=.false. when a command contains
redirection metacharacters (">", "2>&1"), even though it still tokenizes the
command correctly. command_program only used the tokens when success was true,
so it returned an empty program name for commands with inline redirects (e.g.
the "<cc> --version > out 2>&1" and "mpifort -show > out 2>&1" probes), which
broke the standard-command test on Windows.

Rely on the first token instead of the success flag: a redirection operator
never starts a command, so the first token is reliably the program. This also
makes the missing-program message work for the inline-redirect probe commands
on Windows.
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