-
-
Notifications
You must be signed in to change notification settings - Fork 16
Emit build-graph.json for editor tooling #486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ChrisonSimtian
merged 5 commits into
Fallout-build:main
from
ChrisonSimtian:emit-build-graph-json
Jul 13, 2026
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d031915
Emit build-graph.json on build initialization for editor tooling
ChrisonSimtian 1958fae
Update SerializeBuildGraphAttribute.cs
ChrisonSimtian 4c99afd
Update SerializeBuildGraphAttribute.cs
ChrisonSimtian e8c6f35
Potential fix for pull request finding
ChrisonSimtian cb69ec3
Extract build-graph projection into testable BuildGraphUtility
ChrisonSimtian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
src/Fallout.Build/Execution/Extensions/SerializeBuildGraphAttribute.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
| using Fallout.Common.Execution; | ||
| using Fallout.Common.IO; | ||
| using Fallout.Common.Utilities; | ||
|
|
||
| namespace Fallout.Build.Execution.Extensions; | ||
|
|
||
| /// <summary> | ||
| /// Emits <c>build-graph.json</c> into the temporary directory on every build initialization, | ||
| /// giving editor tooling (the VS Code extension) a machine-readable projection of the target | ||
| /// graph: names, descriptions, the default/listed flags, the declaring type, and the four | ||
| /// relation kinds. Best-effort — a serialization failure never fails the build. | ||
| /// </summary> | ||
| internal class SerializeBuildGraphAttribute : BuildExtensionAttributeBase, IOnBuildInitialized | ||
| { | ||
| private const string GraphFileName = "build-graph.json"; | ||
|
|
||
| /// <summary>Schema version consumers gate on; bump only on a breaking shape change.</summary> | ||
| private const int SchemaVersion = 1; | ||
|
|
||
| private static readonly JsonSerializerOptions serializerOptions = | ||
| new() | ||
| { | ||
| PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | ||
| WriteIndented = true, | ||
| }; | ||
|
ChrisonSimtian marked this conversation as resolved.
Outdated
|
||
|
|
||
| private AbsolutePath GraphFile => Build.TemporaryDirectory / GraphFileName; | ||
|
|
||
| public void OnBuildInitialized( | ||
| IReadOnlyCollection<ExecutableTarget> executableTargets, | ||
| IReadOnlyCollection<ExecutableTarget> executionPlan) | ||
| { | ||
| try | ||
| { | ||
| var model = new BuildGraphModel( | ||
| SchemaVersion, | ||
| ResolveFalloutVersion(), | ||
| executableTargets | ||
| .OrderBy(x => x.Name, StringComparer.Ordinal) | ||
| .Select(ToModel) | ||
| .ToList()); | ||
|
|
||
| GraphFile.WriteJson(model, serializerOptions ); | ||
|
ChrisonSimtian marked this conversation as resolved.
Outdated
|
||
| } | ||
| catch (Exception exception) | ||
| { | ||
| // Emission is a convenience for editor tooling — never let it break a build. | ||
| Serilog.Log.Verbose(exception, "Failed to emit {GraphFileName}", GraphFileName); | ||
| } | ||
| } | ||
|
|
||
| private static TargetModel ToModel(ExecutableTarget target) | ||
| => new( | ||
| target.Name, | ||
| target.Description, | ||
| target.Member?.DeclaringType?.Name, | ||
| target.IsDefault, | ||
| target.Listed, | ||
| SortedNames(target.ExecutionDependencies), | ||
| SortedNames(target.OrderDependencies), | ||
| SortedNames(target.TriggerDependencies), | ||
| SortedNames(target.Triggers)); | ||
|
|
||
| // Sorted for deterministic output — the graph carries no execution order, so the display | ||
| // order is irrelevant to consumers and a stable ordering avoids spurious file churn. | ||
| private static IReadOnlyList<string> SortedNames(IEnumerable<ExecutableTarget> targets) | ||
| => targets.Select(x => x.Name).OrderBy(x => x, StringComparer.Ordinal).ToList(); | ||
|
|
||
| // Mirrors Fallout.Migrate: the informational version up to the build-metadata separator, | ||
| // so the pin aligns with the running tool. Null for local/dev builds without a `+` suffix. | ||
| private static string ResolveFalloutVersion() | ||
|
ChrisonSimtian marked this conversation as resolved.
Outdated
|
||
| { | ||
| var informational = typeof(SerializeBuildGraphAttribute).Assembly | ||
| .GetCustomAttribute<AssemblyInformationalVersionAttribute>() | ||
| ?.InformationalVersion; | ||
| if (string.IsNullOrEmpty(informational)) | ||
|
ChrisonSimtian marked this conversation as resolved.
Outdated
|
||
| return null; | ||
|
|
||
| var plusIndex = informational.IndexOf('+'); | ||
| return plusIndex == -1 ? informational : informational[..plusIndex]; | ||
|
ChrisonSimtian marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| private sealed record BuildGraphModel( | ||
| int Version, | ||
| string FalloutVersion, | ||
| IReadOnlyList<TargetModel> Targets); | ||
|
|
||
| private sealed record TargetModel( | ||
| string Name, | ||
| string Description, | ||
| string DeclaredIn, | ||
| bool Default, | ||
| bool Listed, | ||
| IReadOnlyList<string> DependsOn, | ||
| IReadOnlyList<string> After, | ||
| IReadOnlyList<string> TriggeredBy, | ||
| IReadOnlyList<string> Triggers); | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.