Skip to content

Commit e695b37

Browse files
authored
Merge pull request #2063 from StevenWong12/move_swift_parser_cli
2 parents 27db137 + 657f2e1 commit e695b37

File tree

20 files changed

+127
-26
lines changed

20 files changed

+127
-26
lines changed

Package.swift

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,6 @@ let package = Package(
297297
dependencies: ["_SwiftSyntaxTestSupport", "SwiftRefactor"]
298298
),
299299

300-
// MARK: - Executable targets
301-
302-
.executableTarget(
303-
name: "swift-parser-cli",
304-
dependencies: [
305-
"_InstructionCounter", "SwiftBasicFormat", "SwiftDiagnostics", "SwiftOperators", "SwiftParser", "SwiftParserDiagnostics", "SwiftSyntax",
306-
.product(name: "ArgumentParser", package: "swift-argument-parser"),
307-
]
308-
),
309-
310300
// MARK: - Deprecated targets
311301

312302
// MARK: PerformanceTest
@@ -335,14 +325,3 @@ package.targets.append(
335325
}
336326
)
337327
)
338-
339-
if useLocalDependencies {
340-
package.dependencies += [
341-
.package(path: "../swift-argument-parser")
342-
]
343-
} else {
344-
// Building standalone.
345-
package.dependencies += [
346-
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2")
347-
]
348-
}

Sources/SwiftBasicFormat/SwiftBasicFormat.docc/FilingBugReports.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Guide to provide steps for filing actionable bug reports for `BasicFormat` failu
66

77
Reducing a failure requires the `swift-parser-cli` utility that you can build by checking out `swift-syntax` and running
88
```
9-
swift build --product swift-parser-cli
9+
swift build --package-path SwiftParserCLI
1010
```
11-
or building the `swift-parser-cli` target in Xcode.
11+
or openning `SwiftParserCLI` package and building the `swift-parser-cli` target in Xcode.
1212

1313
1. After you have built `swift-parse-cli`, you can format a single source file using BasicFormat by running the following command. If you are only experiencing the issue while formatting a single node, e.g. while creating an `AccessorDeclSyntax` inside a macro, you can additionally pass the type of the node as `--node-type AccessorDeclSyntax`
1414
```

Sources/SwiftParser/SwiftParser.docc/FilingBugReports.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Guide to provide steps for filing actionable bug reports for parser failures.
44

5-
Reducing a test case requires the `swift-parser-cli` utility that you can build by checking out `swift-syntax` and running `swift build --product swift-parser-cli` or building the `swift-parser-cli` target in Xcode.
5+
Reducing a test case requires the `swift-parser-cli` utility that you can build by checking out `swift-syntax` and running `swift build --package-path SwiftParserCLI` or openning the `SwiftParserCLI` package and building the `swift-parser-cli` target in Xcode.
66

77
## Round-Trip Failure or Parser Crash
88

SwiftParserCLI/Package.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// swift-tools-version:5.7
2+
3+
import Foundation
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "SwiftParserCLI",
8+
platforms: [
9+
.macOS(.v10_15)
10+
],
11+
products: [
12+
.executable(name: "swift-parser-cli", targets: ["swift-parser-cli"])
13+
],
14+
dependencies: [
15+
.package(path: "..")
16+
],
17+
targets: [
18+
.target(
19+
name: "InstructionCounter"
20+
),
21+
22+
.executableTarget(
23+
name: "swift-parser-cli",
24+
dependencies: [
25+
"InstructionCounter",
26+
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
27+
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
28+
.product(name: "SwiftOperators", package: "swift-syntax"),
29+
.product(name: "SwiftParser", package: "swift-syntax"),
30+
.product(name: "SwiftParserDiagnostics", package: "swift-syntax"),
31+
.product(name: "SwiftSyntax", package: "swift-syntax"),
32+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
33+
]
34+
),
35+
]
36+
)
37+
38+
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
39+
// Building standalone.
40+
package.dependencies += [
41+
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2")
42+
]
43+
} else {
44+
package.dependencies += [
45+
.package(path: "../../swift-argument-parser")
46+
]
47+
}

SwiftParserCLI/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SwiftParserCLI
2+
3+
This directory contains the source files of the `swift-parser-cli` program.
4+
5+
You can build `swift-parser-cli` by checking out `swift-syntax` and running
6+
```
7+
swift build --package-path SwiftParserCLI
8+
```
9+
or entering this directory and running
10+
```
11+
swift build
12+
```
13+
14+
You can also open the `SwiftParserCLI` package and building the `swift-parser-cli` target in Xcode.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include <stdint.h>
14+
15+
/// On macOS returns the number of instructions the process has executed since
16+
/// it was launched, on all other platforms returns 0.
17+
uint64_t getInstructionsExecuted();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#if __APPLE__
14+
#include <TargetConditionals.h>
15+
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
16+
#define TARGET_IS_MACOS 1
17+
#endif
18+
#endif
19+
20+
#include "InstructionsExecuted.h"
21+
22+
#ifdef TARGET_IS_MACOS
23+
#include <libproc.h>
24+
#include <sys/resource.h>
25+
#include <unistd.h>
26+
27+
uint64_t getInstructionsExecuted() {
28+
struct rusage_info_v4 ru;
29+
if (proc_pid_rusage(getpid(), RUSAGE_INFO_V4, (rusage_info_t *)&ru) == 0) {
30+
return ru.ri_instructions;
31+
}
32+
return 0;
33+
}
34+
#else
35+
uint64_t getInstructionsExecuted() {
36+
return 0;
37+
}
38+
#endif

Sources/swift-parser-cli/Commands/PerformanceTest.swift renamed to SwiftParserCLI/Sources/swift-parser-cli/Commands/PerformanceTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
import ArgumentParser
1414
import Foundation
15+
import InstructionCounter
1516
import SwiftParser
1617
import SwiftSyntax
17-
import _InstructionCounter
1818

1919
struct PerformanceTest: ParsableCommand {
2020
static var configuration = CommandConfiguration(

Sources/swift-parser-cli/swift-parser-cli.swift renamed to SwiftParserCLI/Sources/swift-parser-cli/swift-parser-cli.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
import ArgumentParser
1414
import Foundation
15+
import InstructionCounter
1516
import SwiftDiagnostics
1617
import SwiftOperators
1718
import SwiftParser
1819
import SwiftParserDiagnostics
1920
import SwiftSyntax
20-
import _InstructionCounter
2121

2222
#if os(Windows)
2323
import WinSDK

SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Build.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct Build: ParsableCommand, BuildCommand {
2626
func run() throws {
2727
try buildTarget(packageDir: Paths.packageDir, targetName: "SwiftSyntax-all")
2828
try buildTarget(packageDir: Paths.examplesDir, targetName: "Examples-all")
29+
try buildTarget(packageDir: Paths.swiftParserCliDir, targetName: "swift-parser-cli")
2930
try buildEditorExtension()
3031
}
3132

SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/Paths.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ enum Paths {
3232
.appendingPathComponent("Examples")
3333
}
3434

35+
static var swiftParserCliDir: URL {
36+
packageDir
37+
.appendingPathComponent("SwiftParserCLI")
38+
}
39+
3540
static var codeGenerationDir: URL {
3641
packageDir
3742
.appendingPathComponent("CodeGeneration")

0 commit comments

Comments
 (0)