-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
swiftformat_exclude
to the rules_swift
helpers and bug fixe…
…s. (#19) Added swiftformat_exclude to swiftformat_library, swiftformat_binary, and swiftformat_test. This allows a Swift file to be included for the build, but not formatted. This is useful for Swift source files that cause SwiftFormat to hang or take a long time to process. Added missing logic for handling if srcs was not specified for swiftformat_library, swiftformat_binary, or swiftformat_test. Added exclude_files example which demonstrates the use of the swiftformat_exclude attribute. Fixed typo in rules_swift_helpers example. Fixed issue where the name for the formatting targets was not unique.
- Loading branch information
Showing
25 changed files
with
242 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# For information on the rules, see | ||
# https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md | ||
|
||
--swiftversion 5.4 | ||
|
||
--allman false | ||
--indent 2 | ||
--semicolons never | ||
--stripunusedargs always | ||
--maxwidth 100 | ||
--wraparguments before-first | ||
--wrapparameters before-first | ||
--wrapcollections before-first | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
load( | ||
"@cgrindel_rules_swiftformat//swiftformat:swiftformat.bzl", | ||
"swiftformat_update_all", | ||
) | ||
|
||
# MARK: - SwiftFormat Targets | ||
|
||
# We only need to export this file if there are any other packages that need to | ||
# reference the config file. | ||
exports_files([".swiftformat"]) | ||
|
||
# Defines a target that will copy all of the formatted Swift source files to | ||
# the workspace directory. | ||
swiftformat_update_all( | ||
name = "update_all", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Example Demonstrating `rules_swift` Convenience Macros | ||
|
||
This example demonstrates the use of | ||
[`swiftformat_library`](/doc/rules_and_macros_overview.md#swiftformat_library), | ||
[`swiftformat_binary`](/doc/rules_and_macros_overview.md#swiftformat_binary), and | ||
[`swiftformat_test`](/doc/rules_and_macros_overview.md#swiftformat_test) | ||
to define `rules_swift` targets along with `rules_swiftformat` targets. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
load( | ||
"@cgrindel_rules_swiftformat//swiftformat:swiftformat.bzl", | ||
"swiftformat_binary", | ||
) | ||
|
||
# Defines a swift_binary and swiftformat_pkg. | ||
swiftformat_binary( | ||
name = "simple", | ||
swiftformat_exclude = ["PoorlyFormatted.swift"], | ||
visibility = ["//:__subpackages__"], | ||
deps = [ | ||
"//Sources/Foo", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// This file is purposely poorly formatted. It is excluded from formatting in | ||
// the BUILD.bazel file. | ||
struct PoorlyFormatted { | ||
var name = "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Foo | ||
|
||
var msg = Message() | ||
msg.value = "Hello World!" | ||
|
||
var pfmt = PoorlyFormatted() | ||
pfmt.name = "Larry" | ||
|
||
Swift.print(msg.value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
load( | ||
"@cgrindel_rules_swiftformat//swiftformat:swiftformat.bzl", | ||
"swiftformat_library", | ||
) | ||
|
||
swiftformat_library( | ||
name = "Foo", | ||
module_name = "Foo", | ||
swiftformat_exclude = ["PoorlyFormatted.swift"], | ||
visibility = ["//:__subpackages__"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
public struct Message { | ||
public var value: String | ||
var pfmt: PoorlyFormatted | ||
|
||
public init(value: String = "") { | ||
self.value = value | ||
pfmt = PoorlyFormatted() | ||
pfmt.name = value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// This file is purposely poorly formatted. It is excluded from formatting in | ||
// the BUILD.bazel file. | ||
struct PoorlyFormatted { | ||
var name = "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sh_test( | ||
name = "simple_test", | ||
srcs = ["simple_test.sh"], | ||
data = ["//Sources/App:simple"], | ||
deps = ["@bazel_tools//tools/bash/runfiles"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
|
||
# --- begin runfiles.bash initialization v2 --- | ||
# Copy-pasted from the Bazel Bash runfiles library v2. | ||
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash | ||
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ | ||
source "$0.runfiles/$f" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e | ||
# --- end runfiles.bash initialization v2 --- | ||
|
||
err_msg() { | ||
local msg="$1" | ||
echo >&2 "${msg}" | ||
exit 1 | ||
} | ||
|
||
workspace="${TEST_WORKSPACE}" | ||
binary="$(rlocation "${workspace}/Sources/App/simple")" | ||
|
||
expected="Hello World" | ||
"${binary}" | grep "${expected}" || err_msg "Failed to find expected output. ${expected}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load( | ||
"@cgrindel_rules_swiftformat//swiftformat:swiftformat.bzl", | ||
"swiftformat_test", | ||
) | ||
|
||
swiftformat_test( | ||
name = "FooTests", | ||
swiftformat_exclude = ["PoorlyFormattedTests.swift"], | ||
deps = [ | ||
"//Sources/Foo", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@testable import Foo | ||
import XCTest | ||
|
||
class MessageTests: XCTestCase { | ||
func test_init() throws { | ||
let value = "hello" | ||
let msg = Message(value: value) | ||
XCTAssertEqual(msg.value, value) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
examples/exclude_files/Tests/FooTests/PoorlyFormattedTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@testable import Foo | ||
import XCTest | ||
|
||
// Purposely poorly formatted. | ||
class PoorlyFormattedTests: XCTestCase { | ||
func test_init() throws { | ||
let value = "hello" | ||
var pfmt = PoorlyFormatted() | ||
pfmt.name = value | ||
XCTAssertEqual(pfmt.name, value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
workspace(name = "exclude_files_example") | ||
|
||
local_repository( | ||
name = "cgrindel_rules_swiftformat", | ||
path = "../..", | ||
) | ||
|
||
load("@cgrindel_rules_swiftformat//swiftformat:deps.bzl", "swiftformat_rules_dependencies") | ||
|
||
swiftformat_rules_dependencies() | ||
|
||
load( | ||
"@cgrindel_rules_spm//spm:deps.bzl", | ||
"spm_rules_dependencies", | ||
) | ||
|
||
spm_rules_dependencies() | ||
|
||
load( | ||
"@build_bazel_rules_swift//swift:repositories.bzl", | ||
"swift_rules_dependencies", | ||
) | ||
|
||
swift_rules_dependencies() | ||
|
||
load( | ||
"@build_bazel_rules_swift//swift:extras.bzl", | ||
"swift_rules_extra_dependencies", | ||
) | ||
|
||
swift_rules_extra_dependencies() | ||
|
||
load("@cgrindel_rules_swiftformat//swiftformat:load_package.bzl", "swiftformat_load_package") | ||
|
||
swiftformat_load_package() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Example Demonstrating `rules_swift` Convenience Macros | ||
# Example Demonstrating Exclusion of Select Files from Formatting | ||
|
||
This example demonstrates the use of | ||
[`swiftformat_library`](/doc/rules_and_macros_overview.md#swiftformat_library), | ||
[`swiftformat_binary`](/doc/rules_and_macros_overview.md#swiftformat_binary), and | ||
[`swiftformat_test`](/doc/rules_and_macros_overview.md#swiftformat_test) | ||
to define `rules_swift` targets along with `rules_swiftformat` targets. | ||
using `swiftformat_exclude` to skip the formatting of select files. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.