From b63982a444afabc353b6fb8cf11fb7dc1c1d9672 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Wed, 29 Nov 2023 15:48:02 -0800 Subject: [PATCH] Add a bash script to simplify calling `swift-syntax-dev-utils` Calling `swift-syntax-dev-utils` has always been a little bit cumbersome. Add a `swift-syntax-dev-utils` script that expands to `swift run --package-path SwiftSyntaxDevUtils/` to make it simpler. rdar://118137372 Fixes #2341 --- CONTRIBUTING.md | 4 ++-- .../Sources/swift-syntax-dev-utils/commands/Format.swift | 6 +++--- swift-syntax-dev-utils | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100755 swift-syntax-dev-utils diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fb91ef5b86b..08ac35e2c27 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,7 +23,7 @@ swift-syntax is formatted using [swift-format](http://github.com/apple/swift-for To format your changes run the formatter using the following command ```bash -swift run --package-path SwiftSyntaxDevUtils/ swift-syntax-dev-utils format +./swift-syntax-dev-utils format ``` It will build a local copy of swift-format from the `main` branch and format the repository. Since it is building a release version of `swift-format`, the first run will take few minutes. Subsequent runs take less than 2 seconds. @@ -36,7 +36,7 @@ Generated source code is not formatted to make it easier to spot changes when re > #!/usr/bin/env bash > set -e > SOURCE_DIR=$(realpath "$(dirname $0)/../..") -> swift run --package-path "$SOURCE_DIR/SwiftSyntaxDevUtils" swift-syntax-dev-utils format --lint +> swift "$SOURCE_DIR/swift-syntax-dev-utils" format --lint > ``` > 2. Mark the file as executable: `chmod a+x swift-syntax/.git/hooks/pre-commit` > 3. If you have global git hooks installed, be sure to call them at the end of the script with `path/to/global/hooks/pre-commit "$@"` diff --git a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Format.swift b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Format.swift index 9d114a4521b..a598045b782 100644 --- a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Format.swift +++ b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Format.swift @@ -82,15 +82,15 @@ struct FormatExecutor { Run the following command to format swift-syntax - swift run --package-path SwiftSyntaxDevUtils/ swift-syntax-dev-utils format + ./swift-syntax-dev-utils format If the issue persists, try updating swift-format by running - swift run --package-path SwiftSyntaxDevUtils/ swift-syntax-dev-utils format --update + ./swift-syntax-dev-utils format --update Should that still fail, fix any remaining issues manually and verify they match the swift-format style using - swift run --package-path SwiftSyntaxDevUtils/ swift-syntax-dev-utils format --lint + ./swift-syntax-dev-utils format --lint """ } } diff --git a/swift-syntax-dev-utils b/swift-syntax-dev-utils new file mode 100755 index 00000000000..0bc2050d284 --- /dev/null +++ b/swift-syntax-dev-utils @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +swift run --package-path "$(dirname $0)/SwiftSyntaxDevUtils" swift-syntax-dev-utils "$@"