Skip to content
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

Move swift-parser-cli to its own package #2063

Merged
merged 4 commits into from
Oct 15, 2023
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
21 changes: 0 additions & 21 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,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 @@ -330,14 +320,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
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
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