build-graph 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/context/getting-started.md +65 -0
- data/context/index.yaml +18 -0
- data/context/visualization.md +79 -0
- data/lib/build/graph/task.rb +17 -0
- data/lib/build/graph/version.rb +1 -1
- data/lib/build/graph/visualization.rb +55 -0
- data/lib/build/graph/walker.rb +0 -3
- data/lib/build/graph.rb +1 -0
- data/readme.md +22 -0
- data/releases.md +4 -0
- data.tar.gz.sig +0 -0
- metadata +7 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 732e8eb3e448d4b4d2e29b99cfa776dd3fee02bcac14bf93c87112e907bca776
|
|
4
|
+
data.tar.gz: 030b9b4aa3f3aadddd4f29569c8ff43151ec10d5a921bc7dd58300cc9808b78b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6cd9d0b4486e3617da1496598baf89a16508fac212ad0c92023948098eab6e1d53ad7fc0c75e9de3f5b0bba5b8f5acebab9cd833d2fb72a6d9220df6babb6183
|
|
7
|
+
data.tar.gz: b71e886594c0b7aba83db98e4c7da0d5ed97d4f3341006edaa723246a531631457d224ec2a46b5caa25326f938c19861058bb6c28f6b06e1eee207f51a591d7d
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
This guide explains how to use `build-graph` to build a dependency graph for file-based build systems.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add the gem to your project:
|
|
8
|
+
|
|
9
|
+
~~~ bash
|
|
10
|
+
$ bundle add build-graph
|
|
11
|
+
~~~
|
|
12
|
+
|
|
13
|
+
Or install it directly:
|
|
14
|
+
|
|
15
|
+
~~~ bash
|
|
16
|
+
$ gem install build-graph
|
|
17
|
+
~~~
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
A build graph is an abstract set of `[input, process, output]` nodes. A node executes its process within the context of a `Task` which represents a specific set of inputs and outputs and is managed within a `Walker` that walks over graph nodes, regenerating tasks where required. If inputs or outputs change (i.e. become dirty), the old task is nullified.
|
|
22
|
+
|
|
23
|
+
A `Walker` is used to traverse the build graph once. As it walks over the graph it builds a set of `Edge` relationships between nodes and only traverses relationships which are complete (`Walker#wait_on_paths`). Parent nodes also wait until all their children are complete (`Walker#wait_on_nodes`). It also keeps track of failures (`Walker#failed?`) and fails all dependencies of a node.
|
|
24
|
+
|
|
25
|
+
A `Task` is instantiated once per node when traversing the graph. The task represents a specific process being applied to the graph, e.g. build, clean, etc. It is responsible for actually performing any real actions and providing the methods to do so. A `Task` contains all details about the specific graph state at that point in time, e.g. `Task#children` and updating the node state in `Task#exit`. Statistics on the build graph are also captured through `Task` and `Walker`, e.g. number of nodes visited, etc.
|
|
26
|
+
|
|
27
|
+
### Inputs and Outputs
|
|
28
|
+
|
|
29
|
+
Inputs to a node should be all on-disk state and any additional parameters which cause its behaviour to produce different results.
|
|
30
|
+
|
|
31
|
+
Outputs from a node should be all files that are generated directly by the processes within the node and sometimes its children.
|
|
32
|
+
|
|
33
|
+
### Dirty Propagation
|
|
34
|
+
|
|
35
|
+
A `Node` has a set of `#inputs` and `#outputs` but these are abstract. For example, `#outputs` could be `:inherit` which means that the node symbolically has all the outputs of all its direct children. A `Task`, at the time of execution, captures its inputs and outputs and these may be monitored for changes in real time.
|
|
36
|
+
|
|
37
|
+
File changes are currently detected using `File::mtime` as this is generally a good trade off between efficiency and accuracy.
|
|
38
|
+
|
|
39
|
+
When a task is marked as dirty, it also marks all its outputs as being dirty, which in turn could mark other tasks as dirty. This is the mechanism by which dirtiness propagates through the graph. The walker should only have to traverse the graph once to build it completely. If multiple updates are required (i.e. building one part of the graph implicitly dirties another part of the graph), the specification of the graph is incomplete and this may lead to problems within the build graph.
|
|
40
|
+
|
|
41
|
+
### Example Graph
|
|
42
|
+
|
|
43
|
+
~~~ ruby
|
|
44
|
+
target("Library/UnitTest", [] => :inherit) do
|
|
45
|
+
library([UnitTest.cpp] => "UnitTest.a") do
|
|
46
|
+
compile([UnitTest.cpp] => "UnitTest.o")
|
|
47
|
+
link([UnitTest.o] => "libUnitTest.a")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
copy headers: ["UnitTest.hpp"]
|
|
51
|
+
|
|
52
|
+
# Outputs become libUnitTest.a and UnitTest.hpp
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
target("Executable/UnitTest", [] => :inherit) do
|
|
56
|
+
depends("Library/UnitTest")
|
|
57
|
+
|
|
58
|
+
executable("main.cpp" => "UnitTest") do
|
|
59
|
+
compile("main.cpp" => "main.o")
|
|
60
|
+
link(["main.o", "libUnitTest.a"] => "UnitTest")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Outputs become UnitTest
|
|
64
|
+
end
|
|
65
|
+
~~~
|
data/context/index.yaml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Automatically generated context index for Utopia::Project guides.
|
|
2
|
+
# Do not edit then files in this directory directly, instead edit the guides and then run `bake utopia:project:agent:context:update`.
|
|
3
|
+
---
|
|
4
|
+
description: Build::Graph is a framework for build systems, with specific functionality
|
|
5
|
+
for dealing with file based processes.
|
|
6
|
+
metadata:
|
|
7
|
+
documentation_uri: https://ioquatix.github.io/build-graph
|
|
8
|
+
funding_uri: https://github.com/sponsors/ioquatix
|
|
9
|
+
source_code_uri: https://github.com/ioquatix/build-graph.git
|
|
10
|
+
files:
|
|
11
|
+
- path: getting-started.md
|
|
12
|
+
title: Getting Started
|
|
13
|
+
description: This guide explains how to use `build-graph` to build a dependency
|
|
14
|
+
graph for file-based build systems.
|
|
15
|
+
- path: visualization.md
|
|
16
|
+
title: Visualization
|
|
17
|
+
description: This guide explains how to use <code class="language-ruby">Build::Graph::Visualization</code>
|
|
18
|
+
to generate Mermaid flowchart diagrams from a build graph.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Visualization
|
|
2
|
+
|
|
3
|
+
This guide explains how to use {ruby Build::Graph::Visualization} to generate Mermaid flowchart diagrams from a build graph.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
When debugging or documenting a build graph, it is useful to see the relationships between inputs and outputs visually. `Build::Graph::Visualization` produces a [Mermaid](https://mermaid.js.org) `flowchart LR` diagram from a completed {ruby Build::Graph::Walker}, showing each file as a node and each build step as a directed edge.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
After running a walker, pass it to {ruby Build::Graph::Visualization#generate}:
|
|
12
|
+
|
|
13
|
+
~~~ ruby
|
|
14
|
+
require "build/graph/visualization"
|
|
15
|
+
|
|
16
|
+
walker = Build::Graph::Walker.new do |walker, node|
|
|
17
|
+
task = Build::Graph::Task.new(walker, node)
|
|
18
|
+
task.visit do
|
|
19
|
+
# perform the actual build step here
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
walker.update(root_node)
|
|
24
|
+
|
|
25
|
+
visualization = Build::Graph::Visualization.new
|
|
26
|
+
diagram = visualization.generate(walker)
|
|
27
|
+
|
|
28
|
+
puts diagram
|
|
29
|
+
~~~
|
|
30
|
+
|
|
31
|
+
The output is a Mermaid diagram string that can be embedded in documentation, printed to the terminal, or written to a file:
|
|
32
|
+
|
|
33
|
+
~~~
|
|
34
|
+
flowchart LR
|
|
35
|
+
_src_main_c[main.c]
|
|
36
|
+
_obj_main_o[main.o]
|
|
37
|
+
_src_main_c --> _obj_main_o
|
|
38
|
+
_obj_main_o[main.o]
|
|
39
|
+
_bin_program[program]
|
|
40
|
+
_obj_main_o --> _bin_program
|
|
41
|
+
~~~
|
|
42
|
+
|
|
43
|
+
## Traversal Without Building
|
|
44
|
+
|
|
45
|
+
To generate a diagram without actually executing any build steps (e.g. for documentation or dry-run inspection), use {ruby Build::Graph::Task#traverse} instead of `visit` in the walker block:
|
|
46
|
+
|
|
47
|
+
~~~ ruby
|
|
48
|
+
walker = Build::Graph::Walker.new do |walker, node|
|
|
49
|
+
task = Build::Graph::Task.new(walker, node)
|
|
50
|
+
task.traverse
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
walker.update(root_node)
|
|
54
|
+
|
|
55
|
+
diagram = Build::Graph::Visualization.new.generate(walker)
|
|
56
|
+
~~~
|
|
57
|
+
|
|
58
|
+
Unlike `visit`, `traverse` skips input validation and does not require any files to exist on disk. It registers all node outputs with the walker so that dependent nodes can still be resolved correctly.
|
|
59
|
+
|
|
60
|
+
However, `traverse` only follows **declared** edges — the inputs and outputs as written in the build definition. Some build systems discover additional dependencies at build time (for example, a C compiler producing a `.d` file that lists every header it included). Those discovered edges will not appear in the diagram.
|
|
61
|
+
|
|
62
|
+
## Complete Graph Visualization
|
|
63
|
+
|
|
64
|
+
To get a complete and accurate picture of the graph, including any dependencies discovered during execution, use {ruby Build::Graph::Task#visit} with an empty block instead of `traverse`:
|
|
65
|
+
|
|
66
|
+
~~~ ruby
|
|
67
|
+
walker = Build::Graph::Walker.new do |walker, node|
|
|
68
|
+
task = Build::Graph::Task.new(walker, node)
|
|
69
|
+
task.visit do
|
|
70
|
+
# perform the actual build step here, e.g. compile, link, etc.
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
walker.update(root_node)
|
|
75
|
+
|
|
76
|
+
diagram = Build::Graph::Visualization.new.generate(walker)
|
|
77
|
+
~~~
|
|
78
|
+
|
|
79
|
+
This executes the build steps and captures the full set of inputs and outputs — including any that are only known after running the task — giving a diagram that accurately reflects what was built and why.
|
data/lib/build/graph/task.rb
CHANGED
|
@@ -66,6 +66,23 @@ module Build
|
|
|
66
66
|
# A list of any inputs whose relevant tasks failed:
|
|
67
67
|
attr :inputs_failed
|
|
68
68
|
|
|
69
|
+
# Traverse the graph without performing any real work. Unlike {visit}, this does not
|
|
70
|
+
# wait for inputs to be generated, making it suitable for graph analysis tasks such
|
|
71
|
+
# as visualization where actual files do not need to exist.
|
|
72
|
+
def traverse
|
|
73
|
+
update_inputs_and_outputs
|
|
74
|
+
|
|
75
|
+
@walker.enter(self)
|
|
76
|
+
|
|
77
|
+
update_outputs!
|
|
78
|
+
|
|
79
|
+
@state = :complete
|
|
80
|
+
|
|
81
|
+
@walker.exit(self)
|
|
82
|
+
|
|
83
|
+
return self
|
|
84
|
+
end
|
|
85
|
+
|
|
69
86
|
# Derived task can override this function to provide appropriate behaviour.
|
|
70
87
|
def visit
|
|
71
88
|
update_inputs_and_outputs
|
data/lib/build/graph/version.rb
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Released under the MIT License.
|
|
4
|
+
# Copyright, 2026, by Samuel Williams.
|
|
5
|
+
|
|
6
|
+
module Build
|
|
7
|
+
module Graph
|
|
8
|
+
# Generates Mermaid flowchart visualizations of build graphs.
|
|
9
|
+
class Visualization
|
|
10
|
+
# Convert a path to a valid Mermaid node ID.
|
|
11
|
+
# @parameter path [String] The path to sanitize.
|
|
12
|
+
# @returns [String] A sanitized identifier safe for use in Mermaid diagrams.
|
|
13
|
+
def sanitize_id(path)
|
|
14
|
+
path.to_s.gsub(/[^a-zA-Z0-9_]/, "_")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Generate a Mermaid flowchart diagram for a completed walker.
|
|
18
|
+
# @parameter walker [Walker] The completed walker containing tasks.
|
|
19
|
+
# @returns [String] A Mermaid flowchart diagram in text format.
|
|
20
|
+
def generate(walker)
|
|
21
|
+
lines = ["flowchart LR"]
|
|
22
|
+
|
|
23
|
+
walker.tasks.each do |node, task|
|
|
24
|
+
next unless task.inputs && task.outputs
|
|
25
|
+
next if task.outputs.equal?(:inherit)
|
|
26
|
+
|
|
27
|
+
input_ids = task.inputs.to_a.map{|path| sanitize_id(path)}
|
|
28
|
+
output_ids = task.outputs.to_a.map{|path| sanitize_id(path)}
|
|
29
|
+
|
|
30
|
+
task.inputs.each do |path|
|
|
31
|
+
lines << " #{sanitize_id(path)}[#{path.basename}]"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
task.outputs.each do |path|
|
|
35
|
+
lines << " #{sanitize_id(path)}[#{path.basename}]"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
label = node.respond_to?(:title) ? node.title.to_s : nil
|
|
39
|
+
|
|
40
|
+
input_ids.each do |input_id|
|
|
41
|
+
output_ids.each do |output_id|
|
|
42
|
+
if label && !label.empty?
|
|
43
|
+
lines << " #{input_id} -->|#{label}| #{output_id}"
|
|
44
|
+
else
|
|
45
|
+
lines << " #{input_id} --> #{output_id}"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
return lines.join("\n")
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
data/lib/build/graph/walker.rb
CHANGED
|
@@ -160,7 +160,6 @@ module Build
|
|
|
160
160
|
# Register a task as active and record its declared output paths.
|
|
161
161
|
# @parameter task [Task] the task that is beginning execution.
|
|
162
162
|
def enter(task)
|
|
163
|
-
|
|
164
163
|
@tasks[task.node] = task
|
|
165
164
|
|
|
166
165
|
# In order to wait on outputs, they must be known before entering the task. This might seem odd, but unless we know outputs are being generated, waiting for them to complete is impossible - unless this was somehow specified ahead of time. The implications of this logic is that all tasks must be sequential in terms of output -> input chaning. This is by design and is not a problem in practice.
|
|
@@ -183,7 +182,6 @@ module Build
|
|
|
183
182
|
# Mark a task as finished, resolve its output paths and notify any waiting tasks.
|
|
184
183
|
# @parameter task [Task] the task that has finished execution.
|
|
185
184
|
def exit(task)
|
|
186
|
-
|
|
187
185
|
# Fail outputs if the node failed:
|
|
188
186
|
if task.failed?
|
|
189
187
|
@failed_tasks << task
|
|
@@ -216,7 +214,6 @@ module Build
|
|
|
216
214
|
# Remove a node and its associated task from the walker, e.g. after it has been invalidated.
|
|
217
215
|
# @parameter node [Node] the node to remove.
|
|
218
216
|
def delete(node)
|
|
219
|
-
|
|
220
217
|
if task = @tasks.delete(node)
|
|
221
218
|
@monitor.delete(task)
|
|
222
219
|
end
|
data/lib/build/graph.rb
CHANGED
data/readme.md
CHANGED
|
@@ -10,10 +10,16 @@ Please see the [project documentation](https://ioquatix.github.io/build-graph) f
|
|
|
10
10
|
|
|
11
11
|
- [Getting Started](https://ioquatix.github.io/build-graphguides/getting-started/index) - This guide explains how to use `build-graph` to build a dependency graph for file-based build systems.
|
|
12
12
|
|
|
13
|
+
- [Visualization](https://ioquatix.github.io/build-graphguides/visualization/index) - This guide explains how to use <code class="language-ruby">Build::Graph::Visualization</code> to generate Mermaid flowchart diagrams from a build graph.
|
|
14
|
+
|
|
13
15
|
## Releases
|
|
14
16
|
|
|
15
17
|
Please see the [project releases](https://ioquatix.github.io/build-graphreleases/index) for all releases.
|
|
16
18
|
|
|
19
|
+
### v2.3.0
|
|
20
|
+
|
|
21
|
+
- Add `Build::Graph::Visualization` for generating Mermaid diagrams of the build graph.
|
|
22
|
+
|
|
17
23
|
### v2.2.0
|
|
18
24
|
|
|
19
25
|
- Remove `logger` interface.
|
|
@@ -28,6 +34,22 @@ We welcome contributions to this project.
|
|
|
28
34
|
4. Push to the branch (`git push origin my-new-feature`).
|
|
29
35
|
5. Create new Pull Request.
|
|
30
36
|
|
|
37
|
+
### Running Tests
|
|
38
|
+
|
|
39
|
+
To run the test suite:
|
|
40
|
+
|
|
41
|
+
``` shell
|
|
42
|
+
bundle exec sus
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Making Releases
|
|
46
|
+
|
|
47
|
+
To make a new release:
|
|
48
|
+
|
|
49
|
+
``` shell
|
|
50
|
+
bundle exec bake gem:release:patch # or minor or major
|
|
51
|
+
```
|
|
52
|
+
|
|
31
53
|
### Developer Certificate of Origin
|
|
32
54
|
|
|
33
55
|
In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
|
data/releases.md
CHANGED
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: build-graph
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Williams
|
|
@@ -84,11 +84,15 @@ executables: []
|
|
|
84
84
|
extensions: []
|
|
85
85
|
extra_rdoc_files: []
|
|
86
86
|
files:
|
|
87
|
+
- context/getting-started.md
|
|
88
|
+
- context/index.yaml
|
|
89
|
+
- context/visualization.md
|
|
87
90
|
- lib/build/graph.rb
|
|
88
91
|
- lib/build/graph/edge.rb
|
|
89
92
|
- lib/build/graph/node.rb
|
|
90
93
|
- lib/build/graph/task.rb
|
|
91
94
|
- lib/build/graph/version.rb
|
|
95
|
+
- lib/build/graph/visualization.rb
|
|
92
96
|
- lib/build/graph/walker.rb
|
|
93
97
|
- license.md
|
|
94
98
|
- readme.md
|
|
@@ -106,14 +110,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
106
110
|
requirements:
|
|
107
111
|
- - ">="
|
|
108
112
|
- !ruby/object:Gem::Version
|
|
109
|
-
version: '3.
|
|
113
|
+
version: '3.3'
|
|
110
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
115
|
requirements:
|
|
112
116
|
- - ">="
|
|
113
117
|
- !ruby/object:Gem::Version
|
|
114
118
|
version: '0'
|
|
115
119
|
requirements: []
|
|
116
|
-
rubygems_version: 4.0.
|
|
120
|
+
rubygems_version: 4.0.6
|
|
117
121
|
specification_version: 4
|
|
118
122
|
summary: Build::Graph is a framework for build systems, with specific functionality
|
|
119
123
|
for dealing with file based processes.
|
metadata.gz.sig
CHANGED
|
Binary file
|