Repository navigation
Read Make conditionals as Conditions: each branch, and each variable's value, in the builds it holds in - #360
Merged
Conversation
`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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:ifeq ($(OS),Windows_NT), andifeq ($(OS),);$(shell uname -s)prints (Linux, Darwin, or MINGW/MSYS/CYGWIN for Windows), directly or throughUNAME_S := $(shell uname -s).ifdef DEBUG,ifeq ($(CC),clang)) hold behind that requirement. Both branches may still run, as before: nothing is narrowed by a guess.=,?=and+=alike. Withifeq ($(OS),Windows_NT) RM = del /q else RM = rm -f endif,$(RM) outisdel /q outon Windows andrm -f outelsewhere.expansion.Only). On a runner of unknown OS they follow every line.Meson's
Choices,assignedandcombinedmove tofacts.conditions, so Make uses the same helpers.Fixed along the way
CMAKE := cmakeinside a conditional) was read as a directive, so the variable was never set. neovim'sCMAKE,MKDIRandTOUCHwere unknown in every recipe; they now resolve.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.Corpus: 4 of 235 projects differ
$(CMAKE)/$(MKDIR)/$(TOUCH)recipes, including the runaway texts, are gone. This is the indentation fix.$(DUNE_PROFILE_ARG)is now--profile=release, from an indented assignment.DUNEstays unknown, as before.make buildjobs now list Release as well as debug. The cause isPROFILE?=releaseunderifneq (,$(filter install, $(MAKECMDGOALS))):$(filter …)isn't evaluated, so that branch is held as possible. Evaluating$(filter)with the command's goals would settle it.ui.make test-e2e-localbuilds with-coverbehind "the environment setsCOVERAGE_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:
🤖 Generated with Claude Code
https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt