Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/_docset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ toc:
- folder: make
children:
- file: index.md
- file: graph.md
- file: wrappers.md
- file: mise.md
- file: makefile.md
Expand Down
76 changes: 76 additions & 0 deletions docs/make/graph.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Drawing the plan

`--graph` draws what a run would do, and runs nothing. It plans the run exactly as the target would: it binds the
target's arguments, applies `-s`, and evaluates each `OnlyWhen` condition. A target the run would skip shows as skipped,
with the reason.

```bash
./build.cs release --graph
```

```text
release Test, then pack
├─ requires
│ ├─ pristine-check
│ └─ test
│ └─ build
│ └─ clean
└─ composes
├─ pkg generate
└─ pkg validate

Runs: pristine-check → clean → build → test → pkg generate → pkg validate
```

`Runs:` lists the targets whose bodies run, in order. A target that two others depend on runs once; the tree draws it
the first time and marks later references `(above)`.

## Skipped targets

With `-s`, the named target's gates show as skipped and their own dependencies drop out of the plan:

```bash
./build.cs release -s --graph
```

```text
release Test, then pack
├─ requires
│ ├─ pristine-check skipped: -s
│ └─ test skipped: -s
└─ composes
├─ pkg generate
└─ pkg validate

Runs: pkg generate → pkg validate
```

A target whose condition is false shows `skipped: its condition is false`. Its dependencies still run, as they do in a
real run. `--graph` evaluates the condition when it draws the plan; a real run evaluates it again just before the
target would start.

## Dependencies with values

A dependency that names a value runs with that value, and the plan shows it after the route:

```text
ci
└─ composes
├─ test (filter: Unit)
└─ test (filter: Integration)
```

Two references with equal values are one target in the plan, and run once. Two references with different values run
once each. Only the target named on the command line binds the command line's arguments.

## Formats

| Command | Prints |
|---|---|
| `--graph` or `--graph tree` | The tree and the `Runs:` line |
| `--graph mermaid` | A Mermaid flowchart, with one edge per ordering and skipped targets dashed |
| `--graph json` | The plan as JSON: `roots`, then `targets` in run order with their stages and what each waits for |

`--graph=mermaid` works too. `--graph` without a target draws every target that nothing else depends on.

A target's `--help` lists the same order under `Runs:` when the target has dependencies.
3 changes: 3 additions & 0 deletions docs/make/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
./build.cs --help
./build.cs test --filter Unit
./build.cs release -s # skip the gates, run only the composed targets
./build.cs release --graph # draw the plan and run nothing
```

[**Drawing the plan**](graph.md) - `--graph` draws what a run would do, skipped targets included, and runs nothing.

[**Wrappers**](wrappers.md) - Generate one task per target for [mise](mise.md), [make](makefile.md) and
[just](just.md), and let mise hooks keep them up to date.

Expand Down
14 changes: 10 additions & 4 deletions src/Nullean.Make.Fs/MakeApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ type MakeApp<'TCase when 'TCase : comparison and 'TCase : not null>
let mutable singleTarget = false
let mutable showHelp = false
let mutable showVersion = false
let mutable graph : GraphFormat option = None
let mutable i = 0
while i < argv.Length do
let arg = argv.[i]
if arg = "-h" || arg = "--help" then showHelp <- true; i <- i + 1
let graphFormat = GraphOption.TryRead(argv, &i)
if graphFormat.HasValue then graph <- Some graphFormat.Value
elif arg = "-h" || arg = "--help" then showHelp <- true; i <- i + 1
elif arg = "--version" then showVersion <- true; i <- i + 1
elif arg = "-s" || arg = "--single-target" then singleTarget <- true; i <- i + 1
else
Expand Down Expand Up @@ -72,7 +75,7 @@ type MakeApp<'TCase when 'TCase : comparison and 'TCase : not null>
opt.Set argv.[i]
i <- i + 1
| None -> remaining.Add(arg); i <- i + 1
remaining.ToArray(), singleTarget, showHelp, showVersion
remaining.ToArray(), singleTarget, showHelp, showVersion, graph

let resolveRoute (remaining: string[]) (byRoute: Collections.Generic.Dictionary<string, TargetNode>) =
let routeTokens = Collections.Generic.List<string>()
Expand Down Expand Up @@ -161,7 +164,7 @@ type MakeApp<'TCase when 'TCase : comparison and 'TCase : not null>
| Error (code, msg) ->
eprintfn "%s" msg
return code
| Ok (remaining, singleTarget, showHelp, showVersion) ->
| Ok (remaining, singleTarget, showHelp, showVersion, graphFormat) ->

if showVersion then
printfn "%s" (entryVersion ())
Expand Down Expand Up @@ -196,6 +199,8 @@ type MakeApp<'TCase when 'TCase : comparison and 'TCase : not null>
| Some t ->
eprintfn "Unknown target '%s'." t
return 2
| None when graphFormat.IsSome ->
return DepGraphExecutor.DrawWholeGraph(graph, graphFormat.Value)
| None ->
MakeHelpPrinter.PrintRoot(graph, appName)
return 0
Expand All @@ -214,6 +219,7 @@ type MakeApp<'TCase when 'TCase : comparison and 'TCase : not null>
ParsedArgs(
Target = node,
TargetArgs = targetArgs,
SingleTarget = singleTarget)
SingleTarget = singleTarget,
Graph = Option.toNullable graphFormat)
return! DepGraphExecutor.ExecuteAsync(node, parsed, graph)
}
13 changes: 13 additions & 0 deletions src/Nullean.Make.Fs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,19 @@ let token = app.Option<string option>("--token", desc = "API token", defaultVa

Read them in target blocks through `.Value`. Help shows each option's type, such as `--config <string>`, and `--token <string?>` for an option type. Both `--token abc` and `--token=abc` work. A value that does not parse, or a missing value, exits `2` before any target runs. Enum options bind by name, ignoring case.

## Drawing the plan

`--graph` draws what a run would do and runs nothing. It binds the target's arguments, applies `-s` and evaluates
conditions, so a skipped target shows as skipped:

```
build release -s --graph
build release --graph mermaid # or json
```

A target's `--help` lists the order its dependencies run in under `Runs:`. See
[Drawing the plan](https://argh.nullean.net/make/graph).

## mise, make and just

`__wrappers sync` writes a mise task include, a Makefile include and a justfile import with one task per target, so
Expand Down
30 changes: 28 additions & 2 deletions src/Nullean.Make/Execution/DepGraphExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,50 @@ namespace Nullean.Make.Execution;

internal static class DepGraphExecutor
{
/// <summary>Binds the named target's arguments, plans the run and executes it.</summary>
/// <summary>
/// Binds the named target's arguments, plans the run and executes it. With <c>--graph</c>, draws the plan instead
/// and runs nothing.
/// </summary>
public static async Task<int> ExecuteAsync(TargetNode root, ParsedArgs parsed, BuildGraph graph)
{
var source = graph.Source ?? throw new InvalidOperationException("The graph has no target source.");
RunPlan plan;
try
{
var value = source.BindArguments(root, parsed.TargetArgs);
plan = RunPlan.Build([new DepRef(root, value)], source, new PlanOptions(parsed.SingleTarget));
plan = RunPlan.Build([new DepRef(root, value)], source, new PlanOptions(parsed.SingleTarget, EvaluateConditions: parsed.Graph is not null));
}
catch (MakeException ex)
{
Console.Error.WriteLine(ex.Message);
return ex.ExitCode;
}

if (parsed.Graph is { } format)
{
PlanRenderer.Write(plan, format, Console.Out);
return 0;
}
return await ExecuteAsync(plan, parsed);
}

/// <summary><c>--graph</c> without a target: draws every target nothing else depends on.</summary>
public static int DrawWholeGraph(BuildGraph graph, GraphFormat format)
{
var source = graph.Source ?? throw new InvalidOperationException("The graph has no target source.");
try
{
var plan = PlanRenderer.WholeGraph(graph, source, new PlanOptions(SingleTarget: false, EvaluateConditions: true));
PlanRenderer.Write(plan, format, Console.Out);
return 0;
}
catch (MakeException ex)
{
Console.Error.WriteLine(ex.Message);
return ex.ExitCode;
}
}

public static async Task<int> ExecuteAsync(RunPlan plan, ParsedArgs parsed)
{
var context = new MakeContext(parsed.GlobalValues, parsed.SingleTarget) { TargetArgs = parsed.TargetArgs };
Expand Down
Loading
Loading