From 6e4e9599a475ea44fcf215b3622b208834998197 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Thu, 21 Oct 2021 12:03:38 -0600 Subject: [PATCH] Added `swiftformat_exclude` to the `rules_swift` helpers and bug fixes. (#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. --- .github/workflows/bazel.yml | 6 ++++ doc/rules_and_macros_overview.md | 12 +++---- examples/README.md | 2 ++ examples/exclude_files/.swiftformat | 14 ++++++++ examples/exclude_files/BUILD.bazel | 16 +++++++++ examples/exclude_files/README.md | 7 ++++ .../exclude_files/Sources/App/BUILD.bazel | 14 ++++++++ .../Sources/App/PoorlyFormatted.swift | 5 +++ examples/exclude_files/Sources/App/main.swift | 9 +++++ .../exclude_files/Sources/Foo/BUILD.bazel | 11 ++++++ .../exclude_files/Sources/Foo/Message.swift | 10 ++++++ .../Sources/Foo/PoorlyFormatted.swift | 5 +++ .../exclude_files/Tests/AppTests/BUILD.bazel | 6 ++++ .../Tests/AppTests/simple_test.sh | 24 +++++++++++++ .../exclude_files/Tests/FooTests/BUILD.bazel | 12 +++++++ .../Tests/FooTests/MessageTests.swift | 10 ++++++ .../Tests/FooTests/PoorlyFormattedTests.swift | 12 +++++++ examples/exclude_files/WORKSPACE | 35 +++++++++++++++++++ examples/rules_swift_helpers/README.md | 4 +-- .../Tests/FooTests/MessageTests.swift | 2 +- swiftformat/internal/swiftformat_binary.bzl | 10 ++++-- swiftformat/internal/swiftformat_library.bzl | 10 ++++-- swiftformat/internal/swiftformat_pkg.bzl | 13 +++++-- swiftformat/internal/swiftformat_test.bzl | 10 ++++-- swiftformat/internal/swiftformat_update.bzl | 4 ++- 25 files changed, 242 insertions(+), 21 deletions(-) create mode 100644 examples/exclude_files/.swiftformat create mode 100644 examples/exclude_files/BUILD.bazel create mode 100644 examples/exclude_files/README.md create mode 100644 examples/exclude_files/Sources/App/BUILD.bazel create mode 100644 examples/exclude_files/Sources/App/PoorlyFormatted.swift create mode 100644 examples/exclude_files/Sources/App/main.swift create mode 100644 examples/exclude_files/Sources/Foo/BUILD.bazel create mode 100644 examples/exclude_files/Sources/Foo/Message.swift create mode 100644 examples/exclude_files/Sources/Foo/PoorlyFormatted.swift create mode 100644 examples/exclude_files/Tests/AppTests/BUILD.bazel create mode 100755 examples/exclude_files/Tests/AppTests/simple_test.sh create mode 100644 examples/exclude_files/Tests/FooTests/BUILD.bazel create mode 100644 examples/exclude_files/Tests/FooTests/MessageTests.swift create mode 100644 examples/exclude_files/Tests/FooTests/PoorlyFormattedTests.swift create mode 100644 examples/exclude_files/WORKSPACE diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml index cac67fe..82bd271 100644 --- a/.github/workflows/bazel.yml +++ b/.github/workflows/bazel.yml @@ -59,3 +59,9 @@ jobs: run: | cd examples/rules_swift_helpers bazelisk test //... + + - name: Test File Exclusion Example + shell: bash + run: | + cd examples/exclude_files + bazelisk test //... diff --git a/doc/rules_and_macros_overview.md b/doc/rules_and_macros_overview.md index aa8930d..1293684 100755 --- a/doc/rules_and_macros_overview.md +++ b/doc/rules_and_macros_overview.md @@ -61,7 +61,7 @@ Copies the formatted Swift sources to the workspace directory. ## swiftformat_binary
-swiftformat_binary(name, swiftformat_config, swiftformat_name, srcs, kwargs)
+swiftformat_binary(name, swiftformat_config, swiftformat_exclude, srcs, kwargs)
 
Defines a `swift_binary` along with a `swiftformat_pkg`. @@ -73,7 +73,7 @@ Defines a `swift_binary` along with a `swiftformat_pkg`. | :------------- | :------------- | :------------- | | name | The name for the swift_binary as a string. | none | | swiftformat_config | A label for the SwiftFormat config file. | None | -| swiftformat_name | Optional. The name for the swiftformat_pkg. | "swiftformat" | +| swiftformat_exclude | A list of files or glob patterns that should be ignored for formatting. | [] | | srcs | The Swift sources that should be used by the swift_binary and the swiftformat_pkg. | None | | kwargs | The attributes for swift_binary. | none | @@ -83,7 +83,7 @@ Defines a `swift_binary` along with a `swiftformat_pkg`. ## swiftformat_library
-swiftformat_library(name, swiftformat_config, swiftformat_name, srcs, kwargs)
+swiftformat_library(name, swiftformat_config, swiftformat_exclude, srcs, kwargs)
 
Defines a `swift_library` along with a `swiftformat_pkg`. @@ -95,7 +95,7 @@ Defines a `swift_library` along with a `swiftformat_pkg`. | :------------- | :------------- | :------------- | | name | The name for the swift_library as a string. | none | | swiftformat_config | A label for the SwiftFormat config file. | None | -| swiftformat_name | Optional. The name for the swiftformat_pkg. | "swiftformat" | +| swiftformat_exclude | A list of files or glob patterns that should be ignored for formatting. | [] | | srcs | The Swift sources that should be used by the swift_library and the swiftformat_pkg. | None | | kwargs | The attributes for swift_library. | none | @@ -125,7 +125,7 @@ Defines targets that will format, test and update the specified Swift sources. ## swiftformat_test
-swiftformat_test(name, swiftformat_config, swiftformat_name, srcs, kwargs)
+swiftformat_test(name, swiftformat_config, swiftformat_exclude, srcs, kwargs)
 
Defines a `swift_test` along with a `swiftformat_pkg`. @@ -137,7 +137,7 @@ Defines a `swift_test` along with a `swiftformat_pkg`. | :------------- | :------------- | :------------- | | name | The name for the swift_test as a string. | none | | swiftformat_config | A label for the SwiftFormat config file. | None | -| swiftformat_name | Optional. The name for the swiftformat_pkg. | "swiftformat" | +| swiftformat_exclude | A list of files or glob patterns that should be ignored for formatting. | [] | | srcs | The Swift sources that should be used by the swift_test and the swiftformat_pkg. | None | | kwargs | The attributes for swift_test. | none | diff --git a/examples/README.md b/examples/README.md index 96d6fb8..fcac212 100644 --- a/examples/README.md +++ b/examples/README.md @@ -5,3 +5,5 @@ [`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). +- [Exclude Files](exclude_files/) - Demonstrates the use of of the `rules_swift` helpers using + `swiftformat_exclude` attribute. diff --git a/examples/exclude_files/.swiftformat b/examples/exclude_files/.swiftformat new file mode 100644 index 0000000..5e3e1e7 --- /dev/null +++ b/examples/exclude_files/.swiftformat @@ -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 + diff --git a/examples/exclude_files/BUILD.bazel b/examples/exclude_files/BUILD.bazel new file mode 100644 index 0000000..bd06b75 --- /dev/null +++ b/examples/exclude_files/BUILD.bazel @@ -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", +) diff --git a/examples/exclude_files/README.md b/examples/exclude_files/README.md new file mode 100644 index 0000000..1bf631e --- /dev/null +++ b/examples/exclude_files/README.md @@ -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. diff --git a/examples/exclude_files/Sources/App/BUILD.bazel b/examples/exclude_files/Sources/App/BUILD.bazel new file mode 100644 index 0000000..080d9f4 --- /dev/null +++ b/examples/exclude_files/Sources/App/BUILD.bazel @@ -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", + ], +) diff --git a/examples/exclude_files/Sources/App/PoorlyFormatted.swift b/examples/exclude_files/Sources/App/PoorlyFormatted.swift new file mode 100644 index 0000000..0b817f9 --- /dev/null +++ b/examples/exclude_files/Sources/App/PoorlyFormatted.swift @@ -0,0 +1,5 @@ + // This file is purposely poorly formatted. It is excluded from formatting in + // the BUILD.bazel file. + struct PoorlyFormatted { + var name = "" + } diff --git a/examples/exclude_files/Sources/App/main.swift b/examples/exclude_files/Sources/App/main.swift new file mode 100644 index 0000000..23fbe23 --- /dev/null +++ b/examples/exclude_files/Sources/App/main.swift @@ -0,0 +1,9 @@ +import Foo + +var msg = Message() +msg.value = "Hello World!" + +var pfmt = PoorlyFormatted() +pfmt.name = "Larry" + +Swift.print(msg.value) diff --git a/examples/exclude_files/Sources/Foo/BUILD.bazel b/examples/exclude_files/Sources/Foo/BUILD.bazel new file mode 100644 index 0000000..ff5bb27 --- /dev/null +++ b/examples/exclude_files/Sources/Foo/BUILD.bazel @@ -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__"], +) diff --git a/examples/exclude_files/Sources/Foo/Message.swift b/examples/exclude_files/Sources/Foo/Message.swift new file mode 100644 index 0000000..74142a6 --- /dev/null +++ b/examples/exclude_files/Sources/Foo/Message.swift @@ -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 + } +} diff --git a/examples/exclude_files/Sources/Foo/PoorlyFormatted.swift b/examples/exclude_files/Sources/Foo/PoorlyFormatted.swift new file mode 100644 index 0000000..0b817f9 --- /dev/null +++ b/examples/exclude_files/Sources/Foo/PoorlyFormatted.swift @@ -0,0 +1,5 @@ + // This file is purposely poorly formatted. It is excluded from formatting in + // the BUILD.bazel file. + struct PoorlyFormatted { + var name = "" + } diff --git a/examples/exclude_files/Tests/AppTests/BUILD.bazel b/examples/exclude_files/Tests/AppTests/BUILD.bazel new file mode 100644 index 0000000..157ab34 --- /dev/null +++ b/examples/exclude_files/Tests/AppTests/BUILD.bazel @@ -0,0 +1,6 @@ +sh_test( + name = "simple_test", + srcs = ["simple_test.sh"], + data = ["//Sources/App:simple"], + deps = ["@bazel_tools//tools/bash/runfiles"], +) diff --git a/examples/exclude_files/Tests/AppTests/simple_test.sh b/examples/exclude_files/Tests/AppTests/simple_test.sh new file mode 100755 index 0000000..341cbbc --- /dev/null +++ b/examples/exclude_files/Tests/AppTests/simple_test.sh @@ -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}" diff --git a/examples/exclude_files/Tests/FooTests/BUILD.bazel b/examples/exclude_files/Tests/FooTests/BUILD.bazel new file mode 100644 index 0000000..4ce9164 --- /dev/null +++ b/examples/exclude_files/Tests/FooTests/BUILD.bazel @@ -0,0 +1,12 @@ +load( + "@cgrindel_rules_swiftformat//swiftformat:swiftformat.bzl", + "swiftformat_test", +) + +swiftformat_test( + name = "FooTests", + swiftformat_exclude = ["PoorlyFormattedTests.swift"], + deps = [ + "//Sources/Foo", + ], +) diff --git a/examples/exclude_files/Tests/FooTests/MessageTests.swift b/examples/exclude_files/Tests/FooTests/MessageTests.swift new file mode 100644 index 0000000..7102e76 --- /dev/null +++ b/examples/exclude_files/Tests/FooTests/MessageTests.swift @@ -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) + } +} diff --git a/examples/exclude_files/Tests/FooTests/PoorlyFormattedTests.swift b/examples/exclude_files/Tests/FooTests/PoorlyFormattedTests.swift new file mode 100644 index 0000000..9c9582d --- /dev/null +++ b/examples/exclude_files/Tests/FooTests/PoorlyFormattedTests.swift @@ -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) + } + } diff --git a/examples/exclude_files/WORKSPACE b/examples/exclude_files/WORKSPACE new file mode 100644 index 0000000..5b37ab4 --- /dev/null +++ b/examples/exclude_files/WORKSPACE @@ -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() diff --git a/examples/rules_swift_helpers/README.md b/examples/rules_swift_helpers/README.md index 1bf631e..fc6e8fd 100644 --- a/examples/rules_swift_helpers/README.md +++ b/examples/rules_swift_helpers/README.md @@ -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. diff --git a/examples/rules_swift_helpers/Tests/FooTests/MessageTests.swift b/examples/rules_swift_helpers/Tests/FooTests/MessageTests.swift index 38597e4..7102e76 100644 --- a/examples/rules_swift_helpers/Tests/FooTests/MessageTests.swift +++ b/examples/rules_swift_helpers/Tests/FooTests/MessageTests.swift @@ -4,7 +4,7 @@ import XCTest class MessageTests: XCTestCase { func test_init() throws { let value = "hello" - let msg = Messsage(value = value) + let msg = Message(value: value) XCTAssertEqual(msg.value, value) } } diff --git a/swiftformat/internal/swiftformat_binary.bzl b/swiftformat/internal/swiftformat_binary.bzl index 9a8b329..0dc6382 100644 --- a/swiftformat/internal/swiftformat_binary.bzl +++ b/swiftformat/internal/swiftformat_binary.bzl @@ -4,7 +4,7 @@ load(":swiftformat_pkg.bzl", "swiftformat_pkg") def swiftformat_binary( name, swiftformat_config = None, - swiftformat_name = "swiftformat", + swiftformat_exclude = [], srcs = None, **kwargs): """Defines a `swift_binary` along with a `swiftformat_pkg`. @@ -12,13 +12,16 @@ def swiftformat_binary( Args: name: The name for the swift_binary as a `string`. swiftformat_config: A `label` for the SwiftFormat config file. - swiftformat_name: Optional. The name for the `swiftformat_pkg`. + swiftformat_exclude: A `list` of files or glob patterns that should + be ignored for formatting. srcs: The Swift sources that should be used by the `swift_binary` and the `swiftformat_pkg`. **kwargs: The attributes for `swift_binary`. Returns: None. """ + if srcs == None: + srcs = native.glob(["*.swift"]) # Define the swift binary swift_binary( @@ -28,8 +31,9 @@ def swiftformat_binary( ) # Define the swiftformat stuff + swiftformat_name = name + "_swiftformat" swiftformat_pkg( name = swiftformat_name, - srcs = srcs, + srcs = native.glob(srcs, exclude = swiftformat_exclude), config = swiftformat_config, ) diff --git a/swiftformat/internal/swiftformat_library.bzl b/swiftformat/internal/swiftformat_library.bzl index 597a276..c48f7c1 100644 --- a/swiftformat/internal/swiftformat_library.bzl +++ b/swiftformat/internal/swiftformat_library.bzl @@ -4,7 +4,7 @@ load(":swiftformat_pkg.bzl", "swiftformat_pkg") def swiftformat_library( name, swiftformat_config = None, - swiftformat_name = "swiftformat", + swiftformat_exclude = [], srcs = None, **kwargs): """Defines a `swift_library` along with a `swiftformat_pkg`. @@ -12,13 +12,16 @@ def swiftformat_library( Args: name: The name for the swift_library as a `string`. swiftformat_config: A `label` for the SwiftFormat config file. - swiftformat_name: Optional. The name for the `swiftformat_pkg`. + swiftformat_exclude: A `list` of files or glob patterns that should + be ignored for formatting. srcs: The Swift sources that should be used by the `swift_library` and the `swiftformat_pkg`. **kwargs: The attributes for `swift_library`. Returns: None. """ + if srcs == None: + srcs = native.glob(["*.swift"]) # Define the swift library swift_library( @@ -28,8 +31,9 @@ def swiftformat_library( ) # Define the swiftformat stuff + swiftformat_name = name + "_swiftformat" swiftformat_pkg( name = swiftformat_name, - srcs = srcs, + srcs = native.glob(srcs, exclude = swiftformat_exclude), config = swiftformat_config, ) diff --git a/swiftformat/internal/swiftformat_pkg.bzl b/swiftformat/internal/swiftformat_pkg.bzl index a3a2b38..01c517a 100644 --- a/swiftformat/internal/swiftformat_pkg.bzl +++ b/swiftformat/internal/swiftformat_pkg.bzl @@ -6,6 +6,12 @@ load("@bazel_skylib//rules:diff_test.bzl", "diff_test") they are formatted and copies them to the workspace directory. """ +def _is_label(src): + return src.find(":") > -1 + +def _is_path(src): + return not _is_label(src) + def swiftformat_pkg(name, srcs = None, config = None): """Defines targets that will format, test and update the specified Swift sources. @@ -20,9 +26,12 @@ def swiftformat_pkg(name, srcs = None, config = None): if srcs == None: srcs = native.glob(["*.swift"]) + # Only process paths; ignore labels + src_paths = [src for src in srcs if _is_path(src)] + format_names = [] - for src in srcs: - src_name = src.replace("/", "_") + for src in src_paths: + src_name = src.replace("/", "_").replace(":", "") format_name = name + "_fmt_" + src_name format_names.append(":" + format_name) diff --git a/swiftformat/internal/swiftformat_test.bzl b/swiftformat/internal/swiftformat_test.bzl index d8ba2b1..aa35a67 100644 --- a/swiftformat/internal/swiftformat_test.bzl +++ b/swiftformat/internal/swiftformat_test.bzl @@ -4,7 +4,7 @@ load(":swiftformat_pkg.bzl", "swiftformat_pkg") def swiftformat_test( name, swiftformat_config = None, - swiftformat_name = "swiftformat", + swiftformat_exclude = [], srcs = None, **kwargs): """Defines a `swift_test` along with a `swiftformat_pkg`. @@ -12,13 +12,16 @@ def swiftformat_test( Args: name: The name for the swift_test as a `string`. swiftformat_config: A `label` for the SwiftFormat config file. - swiftformat_name: Optional. The name for the `swiftformat_pkg`. + swiftformat_exclude: A `list` of files or glob patterns that should + be ignored for formatting. srcs: The Swift sources that should be used by the `swift_test` and the `swiftformat_pkg`. **kwargs: The attributes for `swift_test`. Returns: None. """ + if srcs == None: + srcs = native.glob(["*.swift"]) # Define the swift binary swift_test( @@ -28,8 +31,9 @@ def swiftformat_test( ) # Define the swiftformat stuff + swiftformat_name = name + "_swiftformat" swiftformat_pkg( name = swiftformat_name, - srcs = srcs, + srcs = native.glob(srcs, exclude = swiftformat_exclude), config = swiftformat_config, ) diff --git a/swiftformat/internal/swiftformat_update.bzl b/swiftformat/internal/swiftformat_update.bzl index 5aa2199..fa2f0f0 100644 --- a/swiftformat/internal/swiftformat_update.bzl +++ b/swiftformat/internal/swiftformat_update.bzl @@ -16,7 +16,9 @@ def _swiftformat_update_impl(ctx): files = [format_map[src] for src in format_map], ) - update = ctx.actions.declare_file("update_with_formatted.sh") + update = ctx.actions.declare_file( + ctx.label.name + "_update_with_formatted.sh", + ) ctx.actions.write( output = update, content = """