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
16 changes: 8 additions & 8 deletions src/Terrabuild/Core/Build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ let run (options: ConfigOptions.Options) (cache: Cache.ICache) (api: Contracts.I
let cacheEntryId = GraphDef.buildCacheKey node

let projectDirectory =
match node.Project with
match node.ProjectDir with
| FS.Directory projectDirectory -> projectDirectory
| FS.File projectFile -> projectFile |> FS.parentDirectory |> Option.get
| _ -> "."
Expand Down Expand Up @@ -200,7 +200,7 @@ let run (options: ConfigOptions.Options) (cache: Cache.ICache) (api: Contracts.I
let successful = lastStatusCode = 0
let endedAt = DateTime.UtcNow
let summary =
{ Cache.TargetSummary.Project = node.Project
{ Cache.TargetSummary.Project = node.ProjectDir
Cache.TargetSummary.Target = node.Target
Cache.TargetSummary.Operations = [ stepLogs |> List.ofSeq ]
Cache.TargetSummary.Outputs = outputs
Expand All @@ -213,9 +213,9 @@ let run (options: ConfigOptions.Options) (cache: Cache.ICache) (api: Contracts.I
notification.NodeUploading node

// create an archive with new files
Log.Debug("{NodeId}: Building '{Project}/{Target}' with {Hash}", node.Id, node.Project, node.Target, node.TargetHash)
Log.Debug("{NodeId}: Building '{Project}/{Target}' with {Hash}", node.Id, node.ProjectDir, node.Target, node.TargetHash)
let files = cacheEntry.Complete summary
api |> Option.iter (fun api -> api.AddArtifact node.Project node.Target node.ProjectHash node.TargetHash files successful)
api |> Option.iter (fun api -> api.AddArtifact node.ProjectDir node.Target node.ProjectHash node.TargetHash files successful)

match lastStatusCode with
| 0 -> TaskStatus.Success endedAt
Expand All @@ -237,7 +237,7 @@ let run (options: ConfigOptions.Options) (cache: Cache.ICache) (api: Contracts.I
notification.NodeDownloading node
match cache.TryGetSummary allowRemoteCache cacheEntryId with
| Some summary ->
Log.Debug("{NodeId} restoring '{Project}/{Target}' from {Hash}", node.Id, node.Project, node.Target, node.TargetHash)
Log.Debug("{NodeId} restoring '{Project}/{Target}' from {Hash}", node.Id, node.ProjectDir, node.Target, node.TargetHash)
match summary.Outputs with
| Some outputs ->
let files = IO.enumerateFiles outputs
Expand All @@ -253,7 +253,7 @@ let run (options: ConfigOptions.Options) (cache: Cache.ICache) (api: Contracts.I
let restorable = Restorable(callback, dependencies)
restorables.TryAdd(node.Id, restorable) |> ignore
else
Log.Debug("{NodeId} skipping restore '{Project}/{Target}' from {Hash}", node.Id, node.Project, node.Target, node.TargetHash)
Log.Debug("{NodeId} skipping restore '{Project}/{Target}' from {Hash}", node.Id, node.ProjectDir, node.Target, node.TargetHash)
if summary.IsSuccessful then TaskStatus.Success summary.EndedAt
else TaskStatus.Failure (summary.EndedAt, $"Restored node {node.Id} with a build in failure state")
| _ ->
Expand Down Expand Up @@ -353,7 +353,7 @@ let run (options: ConfigOptions.Options) (cache: Cache.ICache) (api: Contracts.I
| true, (request, status) ->
{ NodeInfo.Request = request
NodeInfo.Status = status
NodeInfo.Project = node.Project
NodeInfo.Project = node.ProjectDir
NodeInfo.Target = node.Target
NodeInfo.ProjectHash = node.ProjectHash
NodeInfo.TargetHash = node.TargetHash } |> Some
Expand Down Expand Up @@ -401,7 +401,7 @@ let loadSummary (options: ConfigOptions.Options) (cache: Cache.ICache) (graph: G

{ NodeInfo.Request = TaskRequest.Restore
NodeInfo.Status = status
NodeInfo.Project = node.Project
NodeInfo.Project = node.ProjectDir
NodeInfo.Target = node.Target
NodeInfo.ProjectHash = node.ProjectHash
NodeInfo.TargetHash = node.TargetHash } |> Some
Expand Down
5 changes: 3 additions & 2 deletions src/Terrabuild/Core/Builder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ let build (options: ConfigOptions.Options) (configuration: Configuration.Workspa

let node =
{ Node.Id = nodeId
Node.Label = $"{targetName} {projectConfig.Name}"
Node.Label = $"{targetName} {projectConfig.Directory}"

Node.Project = projectConfig.Name
Node.ProjectId = projectConfig.Id
Node.ProjectDir = projectConfig.Directory
Node.Target = targetName
Node.ConfigurationTarget = target
Node.Operations = ops
Expand Down
6 changes: 3 additions & 3 deletions src/Terrabuild/Core/Configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Target = {
[<RequireQualifiedAccess>]
type Project = {
Id: string option
Name: string
Directory: string
Hash: string
Dependencies: string set
Files: string set
Expand Down Expand Up @@ -569,7 +569,7 @@ let private finalizeProject projectDir evaluationContext (projectDef: LoadedProj
let projectDependencies = projectDependencies.Keys |> Seq.map String.toLower |> Set.ofSeq

{ Project.Id = projectDef.Id
Project.Name = projectDir
Project.Directory = projectDir
Project.Hash = projectHash
Project.Dependencies = projectDependencies
Project.Files = files
Expand Down Expand Up @@ -660,7 +660,7 @@ let read (options: ConfigOptions.Options) =
// build task & code & notify
let dependsOnProjects =
awaitedProjectSignals
|> Seq.map (fun projectDependency -> projectDependency.Value.Name, projectDependency.Value)
|> Seq.map (fun projectDependency -> projectDependency.Value.Directory, projectDependency.Value)
|> Map.ofSeq

let project = finalizeProject projectDir evaluationContext loadedProject dependsOnProjects
Expand Down
3 changes: 2 additions & 1 deletion src/Terrabuild/Core/GraphDef.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ type Node = {
Id: string
Label: string

Project: string
ProjectId: string option
ProjectDir: string
Target: string
ConfigurationTarget: Configuration.Target

Expand Down
24 changes: 23 additions & 1 deletion src/Terrabuild/Core/Mermaid.fs
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
module Mermaid
open GraphDef
open System



type GetStatus = Node -> string

type GetOrigin = Node -> Build.TaskRequest option


let scaleToPastel (value: int) : int =
// Map from [0, 255] to [160, 240]
160 + (value * (240 - 160) / 255)

let pastelColorFromHash (md5hash: string) : string =
if md5hash.Length < 6 then
invalidArg "md5hash" "MD5 hash string must be at least 6 characters long"

let r = Convert.ToInt32(md5hash.Substring(0, 2), 16) |> scaleToPastel
let g = Convert.ToInt32(md5hash.Substring(2, 2), 16) |> scaleToPastel
let b = Convert.ToInt32(md5hash.Substring(4, 2), 16) |> scaleToPastel

$"#{r:X2}{g:X2}{b:X2}"

let render (getStatus: GetStatus option) (getOrigin: GetOrigin option) (graph: Graph) =
let mermaid = [
"flowchart TD"
Expand All @@ -20,7 +36,11 @@ let render (getStatus: GetStatus option) (getOrigin: GetOrigin option) (graph: G
|> Option.map (fun getNodeStatus -> getNodeStatus node)
|> Option.defaultValue ""

$"{node.Id}(\"<b>{node.Target}</b> {status}\n{node.Project}\")"
let nodeTitle =
match node.ProjectId with
| None -> node.Target
| Some projectId -> $"{node.Target} {projectId}"
$"{node.Id}(\"<b>{nodeTitle}</b> {status}\n{node.ProjectDir}\")"

for (KeyValue(_, node)) in graph.Nodes do
for dependency in node.Dependencies do
Expand All @@ -35,6 +55,8 @@ let render (getStatus: GetStatus option) (getOrigin: GetOrigin option) (graph: G
| Some Build.TaskRequest.Build -> $"class {node.Id} build"
| Some Build.TaskRequest.Restore -> $"class {node.Id} restore"
| _ -> $"class {node.Id} ignore"
let color = node.ProjectDir |> Hash.md5 |> pastelColorFromHash
$"style {node.Id} fill:{color}"
]

mermaid
Expand Down
2 changes: 1 addition & 1 deletion src/Terrabuild/Core/Notification.fs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type BuildNotification() =
return! messageLoop ()

| PrinterProtocol.NodeCompleted (node, status, success) ->
let label = $"{node.Label} {node.Project}"
let label = $"{node.Label} {node.ProjectDir}"
renderer.Complete node.TargetHash label success (status = Build.TaskRequest.Restore)
scheduleUpdate ()
return! messageLoop ()
Expand Down
14 changes: 7 additions & 7 deletions tests/cluster-layers/results/terrabuild-debug.build-graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"a:build": {
"id": "a:build",
"label": "build A",
"project": "A",
"projectDir": "A",
"target": "build",
"configurationTarget": {
"hash": "34215119A4D68DB3B1137C90704FFA326799B219AE86B2DE93A123F6FEDCF68B",
Expand Down Expand Up @@ -84,7 +84,7 @@
"b:build": {
"id": "b:build",
"label": "build B",
"project": "B",
"projectDir": "B",
"target": "build",
"configurationTarget": {
"hash": "34215119A4D68DB3B1137C90704FFA326799B219AE86B2DE93A123F6FEDCF68B",
Expand Down Expand Up @@ -165,7 +165,7 @@
"c:build": {
"id": "c:build",
"label": "build C",
"project": "C",
"projectDir": "C",
"target": "build",
"configurationTarget": {
"hash": "E970FB6D3CCDCEE5AB6C4BAAB40D38439BDA75E6635D1B81F9A9DF7AFA6286C4",
Expand Down Expand Up @@ -246,7 +246,7 @@
"d:build": {
"id": "d:build",
"label": "build D",
"project": "D",
"projectDir": "D",
"target": "build",
"configurationTarget": {
"hash": "F9B0B5708DFC227889BB22353D3EC4D1C1A57C07439470229E286568F031D11A",
Expand Down Expand Up @@ -307,7 +307,7 @@
"e:build": {
"id": "e:build",
"label": "build E",
"project": "E",
"projectDir": "E",
"target": "build",
"configurationTarget": {
"hash": "F9B0B5708DFC227889BB22353D3EC4D1C1A57C07439470229E286568F031D11A",
Expand Down Expand Up @@ -368,7 +368,7 @@
"f:build": {
"id": "f:build",
"label": "build F",
"project": "F",
"projectDir": "F",
"target": "build",
"configurationTarget": {
"hash": "8F9422FFE2A136EC80F0C31D42C172CA05826D7DAFBB18BBCE27B1719A82AE1E",
Expand Down Expand Up @@ -427,7 +427,7 @@
"g:build": {
"id": "g:build",
"label": "build G",
"project": "G",
"projectDir": "G",
"target": "build",
"configurationTarget": {
"hash": "8F9422FFE2A136EC80F0C31D42C172CA05826D7DAFBB18BBCE27B1719A82AE1E",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@ F")
g:build("<b>build</b>
G")
class a:build ignore
style a:build fill:#C7DDBE
class b:build ignore
style b:build fill:#D1BDE3
c:build --> a:build
c:build --> b:build
class c:build ignore
style c:build fill:#A4BEED
d:build --> c:build
class d:build ignore
style d:build fill:#EDAAE8
e:build --> c:build
class e:build ignore
style e:build fill:#B2B3D2
f:build --> d:build
f:build --> e:build
class f:build ignore
style f:build fill:#C8A1A7
g:build --> c:build
class g:build ignore
class g:build ignore
style g:build fill:#E5E0AC
14 changes: 7 additions & 7 deletions tests/cluster-layers/results/terrabuild-debug.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"projects": {
"a": {
"name": "A",
"directory": "A",
"hash": "CE24C7D4BBCA45AE8BB4AACDA925C35DD828536AFAF55FB15271EB0F1FA52EAA",
"dependencies": [],
"files": [
Expand Down Expand Up @@ -72,7 +72,7 @@
"labels": []
},
"b": {
"name": "B",
"directory": "B",
"hash": "C54887690548A58E1E6220C83D97E3239943F79A4C51A0DFC7087DE52F57577A",
"dependencies": [],
"files": [
Expand Down Expand Up @@ -129,7 +129,7 @@
"labels": []
},
"c": {
"name": "C",
"directory": "C",
"hash": "76C8F07B90D3785DD412BAF3BBCBD4B054084FA4B952DFE658A8073B15BA19C1",
"dependencies": [
"a",
Expand Down Expand Up @@ -184,7 +184,7 @@
"labels": []
},
"d": {
"name": "D",
"directory": "D",
"hash": "81597327F78177AB91ED77989DF8373BF7138BDE82CB6D59BA1C5BD9994BE255",
"dependencies": [
"c"
Expand Down Expand Up @@ -227,7 +227,7 @@
"labels": []
},
"e": {
"name": "E",
"directory": "E",
"hash": "D9ADE2A1821B9D2BBBB534435F6FF3CA40296AD7BFEED2094FD0460B9DCCB98C",
"dependencies": [
"c"
Expand Down Expand Up @@ -270,7 +270,7 @@
"labels": []
},
"f": {
"name": "F",
"directory": "F",
"hash": "84D7C7DEABFE38F3471D9D74526A46F2344BA0C7A641CFDA3C43E16DC10DCB3D",
"dependencies": [
"d",
Expand Down Expand Up @@ -309,7 +309,7 @@
"labels": []
},
"g": {
"name": "G",
"directory": "G",
"hash": "03ABE717383A7C29E355225594E80D4C9F531BE8F0C5DBAA9C3F7E43C8847761",
"dependencies": [
"c"
Expand Down
6 changes: 3 additions & 3 deletions tests/multirefs/results/terrabuild-debug.build-graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"a:build": {
"id": "a:build",
"label": "build A",
"project": "A",
"projectDir": "A",
"target": "build",
"configurationTarget": {
"hash": "8B56DAA76BB451252D58A9AFF5D2E5A77D0568D8681204549E53A422C9FBDBF0",
Expand Down Expand Up @@ -54,7 +54,7 @@
"b:build": {
"id": "b:build",
"label": "build B",
"project": "B",
"projectDir": "B",
"target": "build",
"configurationTarget": {
"hash": "8B56DAA76BB451252D58A9AFF5D2E5A77D0568D8681204549E53A422C9FBDBF0",
Expand Down Expand Up @@ -104,7 +104,7 @@
"c:build": {
"id": "c:build",
"label": "build C",
"project": "C",
"projectDir": "C",
"target": "build",
"configurationTarget": {
"hash": "8B56DAA76BB451252D58A9AFF5D2E5A77D0568D8681204549E53A422C9FBDBF0",
Expand Down
5 changes: 4 additions & 1 deletion tests/multirefs/results/terrabuild-debug.build-graph.mermaid
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ C")
a:build --> b:build
a:build --> c:build
class a:build ignore
style a:build fill:#C7DDBE
b:build --> c:build
class b:build ignore
class c:build ignore
style b:build fill:#D1BDE3
class c:build ignore
style c:build fill:#A4BEED
6 changes: 3 additions & 3 deletions tests/multirefs/results/terrabuild-debug.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"projects": {
"a": {
"name": "A",
"directory": "A",
"hash": "A7A0CD9E85C9D7AA20838EBF01C91953701319318395EC276A797D66F9AB084D",
"dependencies": [
"b",
Expand Down Expand Up @@ -59,7 +59,7 @@
"labels": []
},
"b": {
"name": "B",
"directory": "B",
"hash": "93C4F757BAF84BE922E6F30EBA5A726573E0028C76082652B062DD5EE775EB39",
"dependencies": [
"c"
Expand Down Expand Up @@ -96,7 +96,7 @@
"labels": []
},
"c": {
"name": "C",
"directory": "C",
"hash": "D2FFA5DCF08258EA5851EDC06944F88D7C19865C3DF17E09693D7F640B4514FC",
"dependencies": [],
"files": [],
Expand Down
Loading