From bf8a21dbab9e52bed8ec3b4ca3fab033876cee92 Mon Sep 17 00:00:00 2001 From: corymhall <43035978+corymhall@users.noreply.github.com> Date: Sat, 4 Feb 2023 06:40:51 +0000 Subject: [PATCH] chore: revert "chore(pipelines): write a GraphViz file with the pipeline structure (#23908)" This reverts commit ec73c390b2f8cf21b5d826240e1892efe4225da3. --- .../lib/codepipeline/codepipeline.ts | 7 +- .../pipelines/lib/helpers-internal/graph.ts | 95 ++----------------- 2 files changed, 8 insertions(+), 94 deletions(-) diff --git a/packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline.ts b/packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline.ts index ef94a85989f73..5fae734d240df 100644 --- a/packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline.ts +++ b/packages/@aws-cdk/pipelines/lib/codepipeline/codepipeline.ts @@ -1,11 +1,10 @@ -import * as fs from 'fs'; import * as path from 'path'; import * as cb from '@aws-cdk/aws-codebuild'; import * as cp from '@aws-cdk/aws-codepipeline'; import * as cpa from '@aws-cdk/aws-codepipeline-actions'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as iam from '@aws-cdk/aws-iam'; -import { Aws, CfnCapabilities, Duration, PhysicalName, Stack, Names } from '@aws-cdk/core'; +import { Aws, CfnCapabilities, Duration, PhysicalName, Stack } from '@aws-cdk/core'; import * as cxapi from '@aws-cdk/cx-api'; import { Construct } from 'constructs'; import { AssetType, FileSet, IFileSetProducer, ManualApprovalStep, ShellStep, StackAsset, StackDeployment, Step } from '../blueprint'; @@ -424,10 +423,6 @@ export class CodePipeline extends PipelineBase { this._cloudAssemblyFileSet = graphFromBp.cloudAssemblyFileSet; this.pipelineStagesAndActionsFromGraph(graphFromBp); - - // Write a dotfile for the pipeline layout - const dotFile = `${Names.uniqueId(this)}.dot`; - fs.writeFileSync(path.join(this.myCxAsmRoot, dotFile), graphFromBp.graph.renderDot().replace(/input\.dot/, dotFile), { encoding: 'utf-8' }); } private get myCxAsmRoot(): string { diff --git a/packages/@aws-cdk/pipelines/lib/helpers-internal/graph.ts b/packages/@aws-cdk/pipelines/lib/helpers-internal/graph.ts index 5f9c2af63df17..7ff5208a410ae 100644 --- a/packages/@aws-cdk/pipelines/lib/helpers-internal/graph.ts +++ b/packages/@aws-cdk/pipelines/lib/helpers-internal/graph.ts @@ -291,21 +291,13 @@ export class Graph extends GraphNode { return topoSort(new Set(projectedDependencies.keys()), projectedDependencies); } - public render() { - const lines = new Array(); - recurse(this, '', true); - return lines.join('\n'); - - function recurse(x: GraphNode, indent: string, last: boolean) { - const bullet = last ? '└─' : '├─'; - const follow = last ? ' ' : '│ '; - lines.push(`${indent} ${bullet} ${x}${depString(x)}`); - if (x instanceof Graph) { - let i = 0; - const sortedNodes = Array.prototype.concat.call([], ...x.sortedChildren()); - for (const child of sortedNodes) { - recurse(child, `${indent} ${follow} `, i++ == x.nodes.size - 1); - } + public consoleLog(indent: number = 0) { + process.stdout.write(' '.repeat(indent) + this + depString(this) + '\n'); + for (const node of this.nodes) { + if (node instanceof Graph) { + node.consoleLog(indent + 2); + } else { + process.stdout.write(' '.repeat(indent + 2) + node + depString(node) + '\n'); } } @@ -317,79 +309,6 @@ export class Graph extends GraphNode { } } - public renderDot() { - const lines = new Array(); - - lines.push('digraph G {'); - lines.push(' # Arrows represent an "unlocks" relationship (opposite of dependency). So chosen'); - lines.push(' # because the layout looks more natural that way.'); - lines.push(' # To represent subgraph dependencies, subgraphs are represented by BEGIN/END nodes.'); - lines.push(' # To render: `dot -Tsvg input.dot > graph.svg`, open in a browser.'); - lines.push(' node [shape="box"];'); - for (const child of this.nodes) { - recurse(child); - } - lines.push('}'); - - return lines.join('\n'); - - function recurse(node: GraphNode) { - let dependencySource; - - if (node instanceof Graph) { - lines.push(`${graphBegin(node)} [shape="cds", style="filled", fillcolor="#b7deff"];`); - lines.push(`${graphEnd(node)} [shape="cds", style="filled", fillcolor="#b7deff"];`); - dependencySource = graphBegin(node); - } else { - dependencySource = nodeLabel(node); - lines.push(`${nodeLabel(node)};`); - } - - for (const dep of node.dependencies) { - const dst = dep instanceof Graph ? graphEnd(dep) : nodeLabel(dep); - lines.push(`${dst} -> ${dependencySource};`); - } - - if (node instanceof Graph && node.nodes.size > 0) { - for (const child of node.nodes) { - recurse(child); - } - - // Add dependency arrows between the "subgraph begin" and the first rank of - // the children, and the last rank of the children and "subgraph end" nodes. - const sortedChildren = node.sortedChildren(); - for (const first of sortedChildren[0]) { - const src = first instanceof Graph ? graphBegin(first) : nodeLabel(first); - lines.push(`${graphBegin(node)} -> ${src};`); - } - for (const last of sortedChildren[sortedChildren.length - 1]) { - const dst = last instanceof Graph ? graphEnd(last) : nodeLabel(last); - lines.push(`${dst} -> ${graphEnd(node)};`); - } - } - } - - function id(node: GraphNode) { - return node.rootPath().slice(1).map(n => n.id).join('.'); - } - - function nodeLabel(node: GraphNode) { - return `"${id(node)}"`; - } - - function graphBegin(node: Graph) { - return `"BEGIN ${id(node)}"`; - } - - function graphEnd(node: Graph) { - return `"END ${id(node)}"`; - } - } - - public consoleLog(_indent: number = 0) { - process.stdout.write(this.render() + '\n'); - } - /** * Return the union of all dependencies of the descendants of this graph */