Skip to content

Commit

Permalink
Merge pull request swiftlang#2063 from StevenWong12/move_swift_parser…
Browse files Browse the repository at this point in the history
…_cli
  • Loading branch information
ahoppen authored Oct 15, 2023
2 parents 27db137 + 657f2e1 commit e695b37
Show file tree
Hide file tree
Showing 20 changed files with 127 additions and 26 deletions.
21 changes: 0 additions & 21 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,6 @@ let package = Package(
dependencies: ["_SwiftSyntaxTestSupport", "SwiftRefactor"]
),

// MARK: - Executable targets

.executableTarget(
name: "swift-parser-cli",
dependencies: [
"_InstructionCounter", "SwiftBasicFormat", "SwiftDiagnostics", "SwiftOperators", "SwiftParser", "SwiftParserDiagnostics", "SwiftSyntax",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
),

// MARK: - Deprecated targets

// MARK: PerformanceTest
Expand Down Expand Up @@ -335,14 +325,3 @@ package.targets.append(
}
)
)

if useLocalDependencies {
package.dependencies += [
.package(path: "../swift-argument-parser")
]
} else {
// Building standalone.
package.dependencies += [
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2")
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Guide to provide steps for filing actionable bug reports for `BasicFormat` failu

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

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`
```
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/SwiftParser.docc/FilingBugReports.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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.
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.

## Round-Trip Failure or Parser Crash

Expand Down
47 changes: 47 additions & 0 deletions SwiftParserCLI/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// swift-tools-version:5.7

import Foundation
import PackageDescription

let package = Package(
name: "SwiftParserCLI",
platforms: [
.macOS(.v10_15)
],
products: [
.executable(name: "swift-parser-cli", targets: ["swift-parser-cli"])
],
dependencies: [
.package(path: "..")
],
targets: [
.target(
name: "InstructionCounter"
),

.executableTarget(
name: "swift-parser-cli",
dependencies: [
"InstructionCounter",
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
.product(name: "SwiftOperators", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftParserDiagnostics", package: "swift-syntax"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
),
]
)

if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
// Building standalone.
package.dependencies += [
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2")
]
} else {
package.dependencies += [
.package(path: "../../swift-argument-parser")
]
}
14 changes: 14 additions & 0 deletions SwiftParserCLI/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SwiftParserCLI

This directory contains the source files of the `swift-parser-cli` program.

You can build `swift-parser-cli` by checking out `swift-syntax` and running
```
swift build --package-path SwiftParserCLI
```
or entering this directory and running
```
swift build
```

You can also open the `SwiftParserCLI` package and building the `swift-parser-cli` target in Xcode.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 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 the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#include <stdint.h>

/// On macOS returns the number of instructions the process has executed since
/// it was launched, on all other platforms returns 0.
uint64_t getInstructionsExecuted();
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 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 the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#if __APPLE__
#include <TargetConditionals.h>
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
#define TARGET_IS_MACOS 1
#endif
#endif

#include "InstructionsExecuted.h"

#ifdef TARGET_IS_MACOS
#include <libproc.h>
#include <sys/resource.h>
#include <unistd.h>

uint64_t getInstructionsExecuted() {
struct rusage_info_v4 ru;
if (proc_pid_rusage(getpid(), RUSAGE_INFO_V4, (rusage_info_t *)&ru) == 0) {
return ru.ri_instructions;
}
return 0;
}
#else
uint64_t getInstructionsExecuted() {
return 0;
}
#endif
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

import ArgumentParser
import Foundation
import InstructionCounter
import SwiftParser
import SwiftSyntax
import _InstructionCounter

struct PerformanceTest: ParsableCommand {
static var configuration = CommandConfiguration(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

import ArgumentParser
import Foundation
import InstructionCounter
import SwiftDiagnostics
import SwiftOperators
import SwiftParser
import SwiftParserDiagnostics
import SwiftSyntax
import _InstructionCounter

#if os(Windows)
import WinSDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct Build: ParsableCommand, BuildCommand {
func run() throws {
try buildTarget(packageDir: Paths.packageDir, targetName: "SwiftSyntax-all")
try buildTarget(packageDir: Paths.examplesDir, targetName: "Examples-all")
try buildTarget(packageDir: Paths.swiftParserCliDir, targetName: "swift-parser-cli")
try buildEditorExtension()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ enum Paths {
.appendingPathComponent("Examples")
}

static var swiftParserCliDir: URL {
packageDir
.appendingPathComponent("SwiftParserCLI")
}

static var codeGenerationDir: URL {
packageDir
.appendingPathComponent("CodeGeneration")
Expand Down

0 comments on commit e695b37

Please sign in to comment.