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

Migrate to Generator models #104

Closed
wants to merge 12 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ jobs:
- name: Install System Dependencies
run: |
apt-get update
apt-get install -y libxml2-dev graphviz
apt-get install -y libxml2-dev libsqlite3-dev graphviz
- name: Build and Test
run: swift test -c release --enable-test-discovery
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM swift:5.2 as builder
WORKDIR /swiftdoc
COPY . .
RUN apt-get -qq update && apt-get install -y libxml2-dev && rm -r /var/lib/apt/lists/*
RUN apt-get -qq update && apt-get install -y libxml2-dev libsqlite3-dev && rm -r /var/lib/apt/lists/*
RUN mkdir -p /build/lib && cp -R /usr/lib/swift/linux/*.so* /build/lib
RUN make install prefix=/build

FROM ubuntu:18.04
RUN apt-get -qq update && apt-get install -y graphviz libatomic1 libxml2-dev libcurl4-openssl-dev && rm -r /var/lib/apt/lists/*
RUN apt-get -qq update && apt-get install -y graphviz libatomic1 libxml2-dev libsqlite3-dev libcurl4-openssl-dev && rm -r /var/lib/apt/lists/*
COPY --from=builder /build/bin/swift-doc /usr/bin
COPY --from=builder /build/lib/* /usr/lib/
ENTRYPOINT ["swift-doc"]
Expand Down
34 changes: 26 additions & 8 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let package = Package(
.package(url: "https://github.com/NSHipster/HypertextLiteral.git", .upToNextMinor(from: "0.0.2")),
.package(url: "https://github.com/SwiftDocOrg/Markup.git", .upToNextMinor(from: "0.0.3")),
.package(url: "https://github.com/NSHipster/SwiftSyntaxHighlighter.git", .revision("1.1.1")),
.package(url: "https://github.com/stephencelis/SQLite.swift.git", .revision("0.12.2")),
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.0.6")),
.package(url: "https://github.com/apple/swift-log.git", .upToNextMinor(from: "1.2.0")),
.package(name: "LoggingGitHubActions", url: "https://github.com/NSHipster/swift-log-github-actions.git", .upToNextMinor(from: "0.0.1")),
Expand All @@ -41,6 +42,7 @@ let package = Package(
.product(name: "Markup", package: "Markup"),
.product(name: "GraphViz", package: "GraphViz"),
.product(name: "SwiftSyntaxHighlighter", package: "SwiftSyntaxHighlighter"),
.product(name: "SQLite", package: "SQLite"),
.product(name: "Logging", package: "swift-log"),
.product(name: "LoggingGitHubActions", package: "LoggingGitHubActions")
]
Expand Down
42 changes: 21 additions & 21 deletions Sources/SwiftDoc/Helpers.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import Foundation

public func route(for symbol: Symbol) -> String {
return route(for: symbol.id)
}

public func route(for name: CustomStringConvertible) -> String {
return name.description.replacingOccurrences(of: ".", with: "_")
}

public func path(for symbol: Symbol, with baseURL: String) -> String {
return path(for: route(for: symbol), with: baseURL)
}

public func path(for identifier: CustomStringConvertible, with baseURL: String) -> String {
let url = URL(string: baseURL)?.appendingPathComponent("\(identifier)") ?? URL(string: "\(identifier)")
guard let string = url?.absoluteString else {
fatalError("Unable to construct path for \(identifier) with baseURL \(baseURL)")
}

return string
}
//
//public func route(for symbol: Symbol) -> String {
// return route(for: symbol.id)
//}
//
//public func route(for name: CustomStringConvertible) -> String {
// return name.description.replacingOccurrences(of: ".", with: "_")
//}
//
//public func path(for symbol: Symbol, with baseURL: String) -> String {
// return path(for: route(for: symbol), with: baseURL)
//}
//
//public func path(for identifier: CustomStringConvertible, with baseURL: String) -> String {
// let url = URL(string: baseURL)?.appendingPathComponent("\(identifier)") ?? URL(string: "\(identifier)")
// guard let string = url?.absoluteString else {
// fatalError("Unable to construct path for \(identifier) with baseURL \(baseURL)")
// }
//
// return string
//}
85 changes: 85 additions & 0 deletions Sources/SwiftDoc/Identifier.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,51 @@
import SwiftSemantics

public struct Identifier: Hashable {
public let pathComponents: [String]
public let name: String
public let checksum: String

public init(symbol: Symbol) {
self.pathComponents = symbol.context.compactMap {
($0 as? Symbol)?.name ?? ($0 as? Extension)?.extendedType
}

self.name = {
switch symbol.api {
case let function as Function where function.isOperator:
var components = symbol.api.nonAccessModifiers.map { $0.name }
if components.isEmpty {
components.append("infix")
}

components.append(function.identifier)
return components.joined(separator: " ")
case let `operator` as Operator:
var components = symbol.api.nonAccessModifiers.map { $0.name }
if components.isEmpty {
components.append("infix")
}

components.append(`operator`.name)
return components.joined(separator: " ")
default:
return symbol.api.name
}
}()

var hasher = SipHasher()
var declaration = "\(symbol.api)"
print(declaration)
withUnsafeBytes(of: &declaration) { hasher.append($0) }
let hashValue = hasher.finalize()

self.checksum = String(UInt(bitPattern: hashValue), radix: 32, uppercase: false)
print(checksum)
}

public var escaped: String {
description.escaped
}

public func matches(_ string: String) -> Bool {
(pathComponents + CollectionOfOne(name)).reversed().starts(with: string.split(separator: ".").map { String($0) }.reversed())
Expand All @@ -14,3 +59,43 @@ extension Identifier: CustomStringConvertible {
(pathComponents + CollectionOfOne(name)).joined(separator: ".")
}
}

// MARK: -

fileprivate let replacements: [Character: String] = [
"-": "minus",
".": "dot",
"!": "bang",
"?": "quest",
"*": "star",
"/": "slash",
"&": "amp",
"%": "percent",
"^": "caret",
"+": "plus",
"<": "lt",
"=": "equals",
">": "gt",
"|": "bar",
"~": "tilde"
]

fileprivate extension String {
var escaped: String {
zip(indices, self).reduce(into: "") { (result, element) in
let (cursor, character) = element
if let replacement = replacements[character] {
result.append(contentsOf: replacement)
if cursor != index(before: endIndex) {
result.append("-")
}
} else if character == " " {
result.append("-")
} else if !character.isPunctuation,
!character.isWhitespace
{
result.append(character)
}
}
}
}
2 changes: 1 addition & 1 deletion Sources/SwiftDoc/Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public final class Module {
let fileManager = FileManager.default
for path in paths {
let directory = URL(fileURLWithPath: path)
guard let directoryEnumerator = fileManager.enumerator(at: directory, includingPropertiesForKeys: nil) else { continue }
guard let directoryEnumerator = fileManager.enumerator(at: directory, includingPropertiesForKeys: nil, options: [.skipsHiddenFiles]) else { continue }
for case let url as URL in directoryEnumerator {
var isDirectory: ObjCBool = false
guard url.pathExtension == "swift",
Expand Down
Loading