Skip to content

Run a command's parallel stages side by side - #134

Merged
Mpdreamz merged 11 commits into
mainfrom
make/parallel
Nov 12, 2026
Merged

Mpdreamz merged 11 commits into
mainfrom
make/parallel

Conversation

@Mpdreamz

@Mpdreamz Mpdreamz commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

A command can declare a stage whose targets run side by side: .Parallel(...) in C#, concurrently [...] in F#. -j caps how many run at once, and -k keeps going after a failure.

Prompt summary: Neither the C# nor the F# Make DSL can declare that some targets run in parallel. The ask is to expose that in the DSL and run it.

Why

DepGraphExecutor ran the plan in a foreach. A release that packs NuGet packages, builds docs and builds an image waited for each in turn.

What

Parallel stages

C# union: app.Command().Requires(new Test()).Parallel(new PackNuget(), new Docs()).Composes(new Publish()). Class: .Parallel(PackNuget, Docs) on a command builder. F#: concurrently [...] in a command { } block, because F# reserves parallel and warns on every use. Stages run in declared order, requires before composes. Lists keep running in order: a list item's dependencies wait for the item before it.

The scheduler

An instance starts once everything it waits for has finished, earliest in the plan first, up to -j / --jobs at once (default: one per processor). A plan without a parallel stage runs one target at a time, as before. The first failure cancels the targets still running and starts no more; -k / --keep-going lets those that do not depend on it finish. Async bodies can take the token: app.Target(async ct => ...), or MakeContext.Current.CancellationToken.

Output

While targets run side by side, Console.Out and Console.Error are replaced by a writer that prefixes each line with the target's name. Shell.Exec streams its process through it and stops the process on cancellation. --output grouped writes each target's lines together when it finishes, as a collapsible group on GitHub Actions. A summary lists each target's time against the wall-clock time.

Switches the build already declares

A global option the build declares itself keeps its name: a build with its own -k keeps it, and --keep-going is left for the switch.

The public builder interfaces gain members (Parallel, Requires, an Executes overload). Only the library implements them; the API diff reports 0 breaking changes.

Verify

dotnet test --project tests/Nullean.Make.Tests -c Release --treenode-filter "/*/*/*Parallel*/*"
dotnet test --project tests/Nullean.Make.Tests -c Release --treenode-filter "/*/*/OrderTests/*"

Stack: 3 of 6, on top of #133; next: #135

🤖 Generated with Claude Code

Mpdreamz and others added 4 commits November 12, 2026 08:25
A dependency such as `Test { Filter = Some "Unit" }` or `new Test("Unit")` ran with the case's defaults in the
union and F# surfaces, and with the named target's own arguments in the class and F# surfaces. Each surface now
hands the planner a target source, and a run is planned as instances: a target and a value. Equal values run
once, different values once each, and only the named target binds the command line. The union app's --version
prints the entry assembly's informational version instead of 0.0.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`--graph` plans the run as the target would, with its arguments bound, `-s` applied and conditions evaluated,
then draws it and runs nothing. Skipped targets show with the reason. It draws a tree with the run order below
it, a Mermaid flowchart or JSON. A target's help lists the order its dependencies run in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A command declares a stage whose targets run at once: `.Parallel(...)` in C#, `concurrently [...]` in F#,
where `parallel` is reserved. The run starts each target once everything it waits for has finished, up to
`-j` targets at a time. The first failure cancels the targets still running; `-k` lets the ones that do not
depend on it finish. While targets run side by side their output carries their names, or `--output grouped`
writes each target's lines together. Lists keep running in order, so a build without a parallel stage runs as
before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mpdreamz and others added 6 commits November 12, 2026 11:51
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	src/Nullean.Make/Execution/DepGraphExecutor.cs
#	src/Nullean.Make/Execution/RunPlan.cs
#	src/Nullean.Make/MakeAppOfT.cs
#	tests/Nullean.Make.Fs.Tests/Nullean.Make.Fs.Tests.fsproj
@Mpdreamz
Mpdreamz changed the base branch from make/run-graph to main November 12, 2026 11:23
Mpdreamz added a commit that referenced this pull request Nov 12, 2026
`--graph` draws what a run would do and runs nothing: a tree with the
run order below it, a Mermaid flowchart, or JSON. A target's `--help`
lists the order its dependencies run in.

**Prompt summary:** A Make script should be able to show its run graph
in the terminal with a command that is built in, and help should show it
too. The drawing has to evaluate what a run would skip and show those
targets as skipped.

## Why

There was no way to see what `release -s` would run without running it.
Help listed a target's direct dependencies only, not the order the whole
plan runs in.

## What

#### `--graph`
`build release --graph` plans the run exactly as `build release` would:
it binds the target's arguments, applies `-s`, and evaluates each
`OnlyWhen` condition. The tree marks a gate `-s` skips as `skipped: -s`
and a false condition as `skipped: its condition is false`, then prints
`Runs: a → b → c`. A target two others depend on is drawn once and
marked `(above)` after that. Without a target, `--graph` draws every
target nothing else depends on.

#### Mermaid and JSON
`--graph mermaid` prints a flowchart with one edge per ordering
(transitive edges removed) and skipped targets dashed. `--graph json`
prints `roots`, then `targets` in run order with their stages and what
each waits for.

#### Help
A target's or command's `--help` prints `Runs:` with the order of a bare
invocation, and the global options list `--graph`.

## Verify

```bash
dotnet run build.cs -- release --graph
dotnet run build.cs -- release -s --graph
dotnet run build.cs -- release --graph mermaid
```

**Stack:** 2 of 6, on top of
[#132](#132); next:
[#134](#134)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/_docset.yml
#	docs/make/index.md
#	src/Nullean.Make.Fs/MakeApp.fs
#	src/Nullean.Make/Execution/DepGraphExecutor.cs
#	src/Nullean.Make/Help/MakeHelpPrinter.cs
#	src/Nullean.Make/MakeAppOfT.cs
#	src/Nullean.Make/Parsing/ArgvParser.cs
#	tests/Nullean.Make.Fs.Tests/Nullean.Make.Fs.Tests.fsproj
@Mpdreamz
Mpdreamz merged commit 35671ae into main Nov 12, 2026
13 checks passed
@Mpdreamz
Mpdreamz deleted the make/parallel branch November 12, 2026 11:39
Mpdreamz added a commit that referenced this pull request Nov 12, 2026
Every target surface can now skip a body on a condition, run after a
target without depending on it, clean up at the end of a run, and say
which environment variables and tools it needs.

**Prompt summary:** Beyond parallel stages, the Make DSLs should get the
other make- and graph-like features that are missing.

## Why

`OnlyWhen` existed only on the class surface. There was no way to order
two targets without one depending on the other, no cleanup that runs
after a failure, and a missing `NUGET_API_KEY` failed the run at
`publish`, after everything else had run.

## What

#### Conditions
`.OnlyWhen(() => ...)` on the union builder and `|> onlyWhen (fun () ->
...)` in F#, as the class surface already had. The body is skipped; the
dependencies still run.

#### `After`
`.After(new Lint())` / `|> after [Lint]` orders a target after another
one when both are in the run, without adding it. A reference with its
default value matches the other target with any value. An `After` that
contradicts an order the plan already has is a cycle, and the run exits
`1` naming the targets.

#### `Cleanup`
`.Cleanup(new StopDb())` / `|> cleanup [StopDb]` runs targets at the end
of the run once this one started, newest first, each once, even after a
failure. A cleanup runs its body only. The run keeps the failure's exit
code.

#### `NeedsEnv` and `NeedsTool`
Checked for every target the run would start before the first one
starts. The run lists everything missing and exits `1`. `--graph` lists
it under `Missing:`.

#### `describe` for F# scripts
`|> describe "..."` sets a description in the script, for an `.fsx`
without an XML doc file. This addresses
#128 with a pipe function rather
than the forms the issue proposes, so the PR does not close it.

## Verify

```bash
dotnet test --project tests/Nullean.Make.Tests -c Release --treenode-filter "/*/*/*ModifierTests/*"
dotnet test --project tests/Nullean.Make.Fs.Tests -c Release --treenode-filter "/*/*/*ModifierTests*/*"
```

**Stack:** 4 of 6, on top of
[#134](#134); next:
[#136](#136)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature A new capability (minor bump)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant