Skip to content

Revert "revert" to test toolchain change #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 10, 2021
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
/.build
/Packages
/*.xcodeproj
.swiftpm
Package.resolved
18 changes: 14 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.2
// swift-tools-version:5.3
/*
This source file is part of the Swift.org open source project

Expand All @@ -12,6 +12,8 @@
import PackageDescription
import class Foundation.ProcessInfo

let cmarkPackageName = ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil ? "swift-cmark" : "swift-cmark-gfm"

let package = Package(
name: "swift-markdown",
products: [
Expand All @@ -25,13 +27,21 @@ let package = Package(
targets: [
.target(
name: "Markdown",
dependencies: ["cmark-gfm", "cmark-gfm-extensions", "CAtomic"]),
dependencies: [
"CAtomic",
.product(name: "cmark-gfm", package: cmarkPackageName),
.product(name: "cmark-gfm-extensions", package: cmarkPackageName),
]),
.target(
name: "markdown-tool",
dependencies: ["Markdown", .product(name: "ArgumentParser", package: "swift-argument-parser")]),
dependencies: [
"Markdown",
.product(name: "ArgumentParser", package: "swift-argument-parser")
]),
.testTarget(
name: "MarkdownTests",
dependencies: ["Markdown"]),
dependencies: ["Markdown"],
resources: [.process("Visitors/Everything.md")]),
.target(name: "CAtomic"),
]
)
Expand Down
66 changes: 66 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// swift-tools-version:5.5
// In order to support users running on the latest Xcodes, please ensure that
// [email protected] is kept in sync with this file.
/*
This source file is part of the Swift.org open source project

Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import PackageDescription
import class Foundation.ProcessInfo

let cmarkPackageName = ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil ? "swift-cmark" : "swift-cmark-gfm"

let package = Package(
name: "swift-markdown",
products: [
.library(
name: "Markdown",
targets: ["Markdown"]),
.executable(
name: "markdown-tool",
targets: ["markdown-tool"]),
],
targets: [
.target(
name: "Markdown",
dependencies: [
"CAtomic",
.product(name: "cmark-gfm", package: cmarkPackageName),
.product(name: "cmark-gfm-extensions", package: cmarkPackageName),
]),
.executableTarget(
name: "markdown-tool",
dependencies: [
"Markdown",
.product(name: "ArgumentParser", package: "swift-argument-parser")
]),
.testTarget(
name: "MarkdownTests",
dependencies: ["Markdown"],
resources: [.process("Visitors/Everything.md")]),
.target(name: "CAtomic"),
]
)

// If the `SWIFTCI_USE_LOCAL_DEPS` environment variable is set,
// we're building in the Swift.org CI system alongside other projects in the Swift toolchain and
// we can depend on local versions of our dependencies instead of fetching them remotely.
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
// Building standalone, so fetch all dependencies remotely.
package.dependencies += [
.package(url: "https://github.com/apple/swift-cmark.git", .branch("gfm")),
.package(url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(from: "0.4.4")),
]
} else {
// Building in the Swift.org CI system, so rely on local versions of dependencies.
package.dependencies += [
.package(path: "../swift-cmark-gfm"),
.package(path: "../swift-argument-parser"),
]
}
9 changes: 7 additions & 2 deletions Sources/markdown-tool/Commands/FormatCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,16 @@ extension MarkdownCommand {
/// Search for the an executable with a given base name.
func findExecutable(named name: String) throws -> String? {
let which = Process()
which.launchPath = "/usr/bin/which"
which.arguments = [name]
let standardOutput = Pipe()
which.standardOutput = standardOutput
which.launch()
if #available(macOS 10.13, *) {
which.executableURL = URL(fileURLWithPath: "/usr/bin/which")
try which.run()
} else {
which.launchPath = "/usr/bin/which"
which.launch()
}
which.waitUntilExit()

guard which.terminationStatus == 0,
Expand Down
9 changes: 7 additions & 2 deletions Sources/markdown-tool/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,20 @@ struct MarkdownCommand: ParsableCommand {
])

static func parseFile(at path: String, options: ParseOptions) throws -> (source: String, parsed: Document) {
let data = try Data(contentsOf: URL( fileURLWithPath: path))
let data = try Data(contentsOf: URL(fileURLWithPath: path))
guard let inputString = String(data: data, encoding: .utf8) else {
throw Error.couldntDecodeInputAsUTF8
}
return (inputString, Document(parsing: inputString, options: options))
}

static func parseStandardInput(options: ParseOptions) throws -> (source: String, parsed: Document) {
let stdinData = FileHandle.standardInput.readDataToEndOfFile()
let stdinData: Data
if #available(macOS 10.15.4, *) {
stdinData = try FileHandle.standardInput.readToEnd() ?? Data()
} else {
stdinData = FileHandle.standardInput.readDataToEndOfFile()
}
guard let stdinString = String(data: stdinData, encoding: .utf8) else {
throw Error.couldntDecodeInputAsUTF8
}
Expand Down
8 changes: 6 additions & 2 deletions Tests/MarkdownTests/Visitors/Everything.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
> BlockQuote

```swift
func foo() { let x = 1 }
func foo() {
let x = 1
}
```

// Is this real code? Or just fantasy?

This is an <topic://autolink>.

---

<a href="foo.png">
An HTML Block.
An HTML Block.
</a>

This is some <p>inline html</p>.
Expand Down
40 changes: 1 addition & 39 deletions Tests/MarkdownTests/Visitors/MarkupRewriterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,7 @@ import XCTest
@testable import Markdown

/// A `Document` that has every kind of element in it at least once.
let everythingDocument = Document(parsing: """
# Header

*Emphasized* **strong** `inline code` [link](foo) ![image](foo).

- this
- is
- a
- list

1. eggs
1. milk

> BlockQuote

```swift
func foo() {
let x = 1
}
```

// Is this real code? Or just fantasy?

This is an <topic://autolink>.

---

<a href="foo.png">
An HTML Block.
</a>

This is some <p>inline html</p>.

line
break

soft
break
""")
let everythingDocument = Document(parsing: try! String(contentsOf: Bundle.module.url(forResource: "Everything", withExtension: "md")!))


class MarkupRewriterTests: XCTestCase {
Expand Down
16 changes: 9 additions & 7 deletions Tests/MarkdownTests/Visitors/MarkupTreeDumperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import XCTest
final class MarkupTreeDumperTests: XCTestCase {
func testDumpEverything() {
let expectedDump = """
Document @1:1-37:6 Root #\(everythingDocument.raw.metadata.id.rootId) #0
Document @1:1-39:90 Root #\(everythingDocument.raw.metadata.id.rootId) #0
├─ Heading @1:1-1:9 #1 level: 1
│ └─ Text @1:3-1:9 #2 "Header"
├─ Paragraph @3:1-3:65 #3
Expand Down Expand Up @@ -52,8 +52,8 @@ final class MarkupTreeDumperTests: XCTestCase {
│ └─ ListItem @11:1-12:1 #35
│ └─ Paragraph @11:4-11:8 #36
│ └─ Text @11:4-11:8 #37 "milk"
├─ BlockQuote @13:1-13:14 #38
│ └─ Paragraph @13:3-13:14 #39
├─ BlockQuote @13:1-13:13 #38
│ └─ Paragraph @13:3-13:13 #39
│ └─ Text @13:3-13:13 #40 "BlockQuote"
├─ CodeBlock @15:1-19:4 #41 language: swift
│ func foo() {
Expand Down Expand Up @@ -81,10 +81,12 @@ final class MarkupTreeDumperTests: XCTestCase {
│ ├─ Text @33:1-33:7 #57 "line"
│ ├─ LineBreak #58
│ └─ Text @34:1-34:6 #59 "break"
└─ Paragraph @36:1-37:6 #60
├─ Text @36:1-36:5 #61 "soft"
├─ SoftBreak #62
└─ Text @37:1-37:6 #63 "break"
├─ Paragraph @36:1-37:6 #60
│ ├─ Text @36:1-36:5 #61 "soft"
│ ├─ SoftBreak #62
│ └─ Text @37:1-37:6 #63 "break"
└─ HTMLBlock @39:1-39:90 #64
<!-- Copyright (c) 2021 Apple Inc and the Swift Project authors. All Rights Reserved. -->
"""
print(everythingDocument.debugDescription(options: [.printEverything]))
XCTAssertEqual(expectedDump, everythingDocument.debugDescription(options: [.printEverything]))
Expand Down
2 changes: 1 addition & 1 deletion bin/check-source
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ for language in swift-or-c bash md-or-tutorial html docker; do
reader=head
case "$language" in
swift-or-c)
exceptions=( -name Package.swift)
exceptions=( -name 'Package*.swift')
matching_files=( -name '*.swift' -o -name '*.c' -o -name '*.h' )
cat > "$tmp" <<"EOF"
/*
Expand Down