Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit e4f88b5

Browse files
authored
Render GraphViz graphs using library instead of spawning processes (#240)
* Render GraphViz graphs using library instead of spawning processes Update GraphViz dependency * Add Brewfile Use brew bundle in CI
1 parent 35b7a82 commit e4f88b5

File tree

10 files changed

+119
-13
lines changed

10 files changed

+119
-13
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
${{ runner.os }}-spm-xcode-${{ matrix.xcode }}-
3030
- name: Install System Dependencies
3131
run: |
32-
brew install graphviz
32+
brew bundle
3333
- name: Build and Test
3434
run: |
3535
swift test -c release
@@ -58,7 +58,7 @@ jobs:
5858
${{ runner.os }}-spm-xcode-${{ matrix.xcode }}-
5959
- name: Install System Dependencies
6060
run: |
61-
brew install graphviz
61+
brew bundle
6262
- name: Build and Test
6363
run: |
6464
swift test -c release
@@ -89,7 +89,7 @@ jobs:
8989
- name: Install System Dependencies
9090
run: |
9191
apt-get update
92-
apt-get install -y libxml2-dev graphviz
92+
apt-get install -y libxml2-dev graphviz-dev
9393
- name: Build and Test
9494
run: swift test -c release --enable-test-discovery
9595

Brewfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
brew 'graphviz'

Brewfile.lock.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"entries": {
3+
"brew": {
4+
"graphviz": {
5+
"version": "2.47.0",
6+
"bottle": {
7+
"rebuild": 0,
8+
"cellar": "/usr/local/Cellar",
9+
"prefix": "/usr/local",
10+
"root_url": "https://homebrew.bintray.com/bottles",
11+
"files": {
12+
"arm64_big_sur": {
13+
"url": "https://homebrew.bintray.com/bottles/graphviz-2.47.0.arm64_big_sur.bottle.tar.gz",
14+
"sha256": "e4263e38be3d51648bffba45b0572dafd16254ce27fc3d1b13c555dff1110d5a"
15+
},
16+
"big_sur": {
17+
"url": "https://homebrew.bintray.com/bottles/graphviz-2.47.0.big_sur.bottle.tar.gz",
18+
"sha256": "7972126b79753efa1f0c3519d6a063079cb1ff02c69759864a865e4ae6b4f193"
19+
},
20+
"catalina": {
21+
"url": "https://homebrew.bintray.com/bottles/graphviz-2.47.0.catalina.bottle.tar.gz",
22+
"sha256": "e5d3b7b652e5cf828c0a2afc2fadb31090f3d7f10389766857404b4359b695e3"
23+
},
24+
"mojave": {
25+
"url": "https://homebrew.bintray.com/bottles/graphviz-2.47.0.mojave.bottle.tar.gz",
26+
"sha256": "d045a9a68315b4e3fa61c7a0a813da345be8197892d070162d909f4985ff3bd7"
27+
}
28+
}
29+
}
30+
},
31+
"sqlite": {
32+
"version": "3.35.3",
33+
"bottle": {
34+
"rebuild": 0,
35+
"cellar": ":any",
36+
"prefix": "/usr/local",
37+
"root_url": "https://homebrew.bintray.com/bottles",
38+
"files": {
39+
"arm64_big_sur": {
40+
"url": "https://homebrew.bintray.com/bottles/sqlite-3.35.3.arm64_big_sur.bottle.tar.gz",
41+
"sha256": "dc73e344c364d891047ab1b4fa54c25196b5fb61ac646d3ac3c731311d81e9a4"
42+
},
43+
"big_sur": {
44+
"url": "https://homebrew.bintray.com/bottles/sqlite-3.35.3.big_sur.bottle.tar.gz",
45+
"sha256": "6f491b7ef85515ede5f193db760117c39f4d4f2dadb482c2f48410b2ea00d1eb"
46+
},
47+
"catalina": {
48+
"url": "https://homebrew.bintray.com/bottles/sqlite-3.35.3.catalina.bottle.tar.gz",
49+
"sha256": "615597e87a1804124b019e35609539878eaf17e52f58ef03ce2ed1cd9536b299"
50+
},
51+
"mojave": {
52+
"url": "https://homebrew.bintray.com/bottles/sqlite-3.35.3.mojave.bottle.tar.gz",
53+
"sha256": "996aa3f07c2a41ef497bed0c00fbff1272d89e3a282ac8661e7ad5533f09d533"
54+
}
55+
}
56+
}
57+
}
58+
}
59+
},
60+
"system": {
61+
"macos": {
62+
"catalina": {
63+
"HOMEBREW_VERSION": "3.0.10-23-g5e0b08d",
64+
"HOMEBREW_PREFIX": "/usr/local",
65+
"Homebrew/homebrew-core": "98313dbb946cca3ddc973624b80f39fd1b481c81",
66+
"CLT": "12.4.0.0.1.1610135815",
67+
"Xcode": "12.4",
68+
"macOS": "10.15.7"
69+
}
70+
}
71+
}
72+
}

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import PackageDescription
66
let package = Package(
77
name: "swift-doc",
88
platforms: [
9-
.macOS(.v10_13)
9+
.macOS(.v10_15)
1010
],
1111
products: [
1212
.executable(name: "swift-doc", targets: ["swift-doc"]),
@@ -17,7 +17,7 @@ let package = Package(
1717
.package(url: "https://github.com/SwiftDocOrg/SwiftSemantics.git", .upToNextMinor(from: "0.1.0")),
1818
.package(url: "https://github.com/SwiftDocOrg/CommonMark.git", .upToNextMinor(from: "0.4.0")),
1919
.package(url: "https://github.com/SwiftDocOrg/SwiftMarkup.git", .upToNextMinor(from: "0.2.1")),
20-
.package(url: "https://github.com/SwiftDocOrg/GraphViz.git", .upToNextMinor(from: "0.1.2")),
20+
.package(url: "https://github.com/SwiftDocOrg/GraphViz.git", .upToNextMinor(from: "0.3.0")),
2121
.package(url: "https://github.com/NSHipster/HypertextLiteral.git", .upToNextMinor(from: "0.0.2")),
2222
.package(url: "https://github.com/SwiftDocOrg/Markup.git", .upToNextMinor(from: "0.0.3")),
2323
.package(url: "https://github.com/NSHipster/SwiftSyntaxHighlighter.git", .revision("1.1.3")),

[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let package = Package(
1414
.package(url: "https://github.com/SwiftDocOrg/SwiftSemantics.git", .upToNextMinor(from: "0.1.0")),
1515
.package(url: "https://github.com/SwiftDocOrg/CommonMark.git", .upToNextMinor(from: "0.4.0")),
1616
.package(url: "https://github.com/SwiftDocOrg/SwiftMarkup.git", .upToNextMinor(from: "0.2.1")),
17-
.package(url: "https://github.com/SwiftDocOrg/GraphViz.git", .upToNextMinor(from: "0.1.2")),
17+
.package(url: "https://github.com/SwiftDocOrg/GraphViz.git", .upToNextMinor(from: "0.3.0")),
1818
.package(url: "https://github.com/NSHipster/HypertextLiteral.git", .upToNextMinor(from: "0.0.2")),
1919
.package(url: "https://github.com/SwiftDocOrg/Markup.git", .upToNextMinor(from: "0.0.3")),
2020
.package(url: "https://github.com/NSHipster/SwiftSyntaxHighlighter.git", .revision("1.0.2")),

Sources/swift-doc/Extensions/SwiftDoc+Extensions.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import SwiftDoc
22
import SwiftSemantics
33
import GraphViz
4-
import DOT
54
import struct Foundation.URL
65

76
extension Symbol {

Sources/swift-doc/Helpers/Await.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Foundation
2+
3+
func _await<T>(_ body: (@escaping (Result<T, Error>) -> Void) -> Void) throws -> T {
4+
return try _await(body).get()
5+
}
6+
7+
func _await<T>(_ body: (@escaping (T) -> Void) -> Void) -> T {
8+
let condition = NSCondition()
9+
var value: T?
10+
11+
body { output in
12+
condition.lock {
13+
value = output
14+
condition.signal()
15+
}
16+
}
17+
18+
condition.lock {
19+
while value == nil {
20+
condition.wait()
21+
}
22+
}
23+
24+
return value!
25+
}
26+
27+
fileprivate extension NSCondition {
28+
func lock<T>(_ body: () throws -> T) rethrows -> T {
29+
lock()
30+
defer { unlock() }
31+
32+
return try body()
33+
}
34+
}

Sources/swift-doc/Subcommands/Diagram.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import Foundation
33
import SwiftDoc
44
import SwiftSemantics
55
import GraphViz
6-
import DOT
7-
86

97
extension SwiftDoc {
108
struct Diagram: ParsableCommand {

Sources/swift-doc/Supporting Types/Components/Relationships.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import SwiftSemantics
55
import Foundation
66
import HypertextLiteral
77
import GraphViz
8-
import DOT
8+
9+
fileprivate typealias SVG = HypertextLiteral.HTML
910

1011
extension StringBuilder {
1112
// MARK: buildIf
@@ -51,7 +52,8 @@ struct Relationships: Component {
5152
let algorithm: LayoutAlgorithm = graph.nodes.count > 3 ? .neato : .dot
5253

5354
do {
54-
return try HypertextLiteral.HTML(String(data: graph.render(using: algorithm, to: .svg), encoding: .utf8) ?? "")
55+
let data = try _await { graph.render(using: algorithm, to: .svg, completion: $0) }
56+
return SVG(String(data: data, encoding: .utf8) ?? "")
5557
} catch {
5658
logger.warning("Failed to generate relationship graph for \(symbol.id). Please ensure that GraphViz binaries are accessible from your PATH. (\(error))")
5759
return nil

0 commit comments

Comments
 (0)