Skip to content

Read Make conditionals as Conditions: each branch, and each variable's value, in the builds it holds in - #360

Merged
lefticus merged 3 commits into
cpp-best-practices:mainfrom
leftibot:make-conditions
Nov 23, 2026
Merged

lefticus merged 3 commits into
cpp-best-practices:mainfrom
leftibot:make-conditions

Conversation

@leftibot

Copy link
Copy Markdown
Collaborator

Part of #300 (step 5: Make's conditional branches give conditional values, as CMake's and Meson's do)

What changes

Make read a conditional it could not decide by reading every branch, one after the other. A variable set in two branches kept only the last value, and every recipe line counted on every runner.

Now each makefile line is read in the builds it holds in, a Condition, the same model CMake and Meson use:

  • Platform tests hold on their platforms:
    • ifeq ($(OS),Windows_NT), and ifeq ($(OS),);
    • what $(shell uname -s) prints (Linux, Darwin, or MINGW/MSYS/CYGWIN for Windows), directly or through UNAME_S := $(shell uname -s).
  • Tests only the environment could decide (ifdef DEBUG, ifeq ($(CC),clang)) hold behind that requirement. Both branches may still run, as before: nothing is narrowed by a guess.
  • Variables take each value in the builds its branch holds in, for =, ?= and += alike. With ifeq ($(OS),Windows_NT) RM = del /q else RM = rm -f endif, $(RM) out is del /q out on Windows and rm -f out elsewhere.
  • CI jobs follow only the recipe lines that may hold on their runner's OS (expansion.Only). On a runner of unknown OS they follow every line.

Meson's Choices, assigned and combined move to facts.conditions, so Make uses the same helpers.

Fixed along the way

  • Indented lines: a makefile line indented with spaces (neovim's CMAKE := cmake inside a conditional) was read as a directive, so the variable was never set. neovim's CMAKE, MKDIR and TOUCH were unknown in every recipe; they now resolve.
  • A variable that refers to itself (argo-cd's BUILD_DATE := $(if $(BUILD_DATE),$(BUILD_DATE),…)) was substituted ten times, doubling each time, into a 375 kB argument. The reference inside its own value now stays as written. Computed names (erlang.mk's $(gen_verbose_$(V))) still expand.
  • Unknown recipes: a recipe line whose program is unknown is reported once, not once per combination of its arguments' values.

Corpus: 4 of 235 projects differ

  • neovim: the 14 unknown $(CMAKE)/$(MKDIR)/$(TOUCH) recipes, including the runaway texts, are gone. This is the indentation fix.
  • opam: $(DUNE_PROFILE_ARG) is now --profile=release, from an indented assignment. DUNE stays unknown, as before.
  • uutils/coreutils: its make build jobs now list Release as well as debug. The cause is PROFILE?=release under ifneq (,$(filter install, $(MAKECMDGOALS))): $(filter …) isn't evaluated, so that branch is held as possible. Evaluating $(filter) with the command's goals would settle it.
  • argo-cd: Go statement coverage is now credited to the whole project, including ui. make test-e2e-local builds with -cover behind "the environment sets COVERAGE_ENABLED=true", where before the last branch read (no flag) won. That step doesn't set it, so this is an over-report.

Open question

No question reads a command's condition yet. A command behind a requirement counts as running, as a GitHub step behind if: already does. That is what makes argo-cd's answer an over-report. Weighing conditions in the questions would apply to every provider, so I've left it for a separate change.

Verified:

  • All local gates pass.
  • The new tests failed first, each for the expected reason.
  • The corpus differences are only the four above.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt

leftibot and others added 3 commits November 23, 2026 13:42
`Choices`, `assigned` and `combined` (a variable's values set in branches, each in the builds it takes it in) were
written for Meson's values, but nothing in them is Meson's. They move to `facts.conditions`, generic over the value,
so that Make's evaluator can keep its variables the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
Makefiles indent what a conditional holds (neovim's `  CMAKE := cmake` under `ifeq ($(UNIX_LIKE),FALSE)`). Only a
tab starts a recipe line; make reads any other line as if it were not indented. The parser matched assignments,
includes and rules from the line's first column, so an indented one was read as a directive and never set: neovim's
CMAKE was unknown in every recipe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
…lds in

Make read a conditional it could not decide by reading every branch, one after another. A variable set in two
branches kept only the last value, and every recipe line ran on every runner: a Linux job "ran" the Windows branch's
`build.bat`, and `$(RM)` was `rm -f` on Windows too.

The evaluator now reads each line in the builds it holds in, a `Condition`, as Meson's and CMake's do:
- A conditional's test is a `Condition`. A test the makefile and the command line decide takes its branch, as before.
  One on the platform (`$(OS)` is Windows_NT, or empty; what `$(shell uname -s)` prints, also through
  `UNAME_S := $(shell uname -s)`) holds on those platforms. Anything else the environment could decide (`ifdef DEBUG`,
  `ifeq ($(CC),clang)`) holds behind that requirement, so both branches may still run.
- A variable holds each value in the builds its assignment was read in (`=`, `?=`, `+=` alike), and a recipe line
  expands to each text its variables give it, in the builds it takes it in. Prerequisites carry their builds too.
- A recipe line that holds in only some builds is an `expansion.Only`. A CI job follows it only where it may hold on
  the job's runner; on a runner of unknown OS, everywhere. An unknown recipe in a branch that cannot hold there is
  not reported, and one whose program is unknown is reported once, whatever values its arguments take.

Expansion is now recursive, which fixes how a variable that refers to itself was read: argo-cd's
`BUILD_DATE := $(if $(BUILD_DATE),$(BUILD_DATE),…)` was substituted ten times over, doubling each time, into a
375 kB argument. A reference inside its own variable's value now stays as written (make rejects a variable that
refers to itself). A reference whose name is computed (erlang.mk's `$(gen_verbose_$(V))`) is still expanded once its
name is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.71%. Comparing base (116970c) to head (3004954).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #360      +/-   ##
==========================================
+ Coverage   99.68%   99.71%   +0.02%     
==========================================
  Files         311      311              
  Lines       19734    19840     +106     
  Branches     2303     2319      +16     
==========================================
+ Hits        19672    19783     +111     
+ Misses         62       57       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lefticus
lefticus merged commit d2c42cd into cpp-best-practices:main Nov 23, 2026
26 checks passed
@lefticus
lefticus deleted the make-conditions branch November 23, 2026 23:22
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.

2 participants