Skip to content

Commit bdca1a4

Browse files
committed
Move swift-parser-cli to its own package
1 parent 7a643a7 commit bdca1a4

File tree

18 files changed

+119
-24
lines changed

18 files changed

+119
-24
lines changed

Package.swift

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,6 @@ let package = Package(
292292
dependencies: ["_SwiftSyntaxTestSupport", "SwiftRefactor"]
293293
),
294294

295-
// MARK: - Executable targets
296-
297-
.executableTarget(
298-
name: "swift-parser-cli",
299-
dependencies: [
300-
"_InstructionCounter", "SwiftBasicFormat", "SwiftDiagnostics", "SwiftOperators", "SwiftParser", "SwiftParserDiagnostics", "SwiftSyntax",
301-
.product(name: "ArgumentParser", package: "swift-argument-parser"),
302-
]
303-
),
304-
305295
// MARK: - Deprecated targets
306296

307297
// MARK: PerformanceTest
@@ -330,14 +320,3 @@ package.targets.append(
330320
}
331321
)
332322
)
333-
334-
if useLocalDependencies {
335-
package.dependencies += [
336-
.package(path: "../swift-argument-parser")
337-
]
338-
} else {
339-
// Building standalone.
340-
package.dependencies += [
341-
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2")
342-
]
343-
}

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 PackageDescription
4+
import Foundation
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

0 commit comments

Comments
 (0)