Skip to content

Commit 26658f1

Browse files
authored
Allow a client to select the release/version for SwiftFormat (#42)
Upgraded rules_spm to 0.7.0. Upgraded bazel-starlib to 0.3.0. Removed obsolete src update code. Allow a client to select a specific version of SwiftFormat.
1 parent 85d8c70 commit 26658f1

File tree

12 files changed

+121
-89
lines changed

12 files changed

+121
-89
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ This repository contains Bazel rules and macros that will format Swift source fi
66
[nicklockwood/SwiftFormat](https://github.com/nicklockwood/SwiftFormat), test that the formatted
77
files exist in the workspace directory, and copy the formatted files to the workspace directory.
88

9+
## Table of Contents
10+
11+
* [Quickstart](#quickstart)
12+
* [1\. Configure your workspace to use rules\_swiftformat](#1-configure-your-workspace-to-use-rules_swiftformat)
13+
* [2\. Update the BUILD\.bazel at the root of your workspace](#2-update-the-buildbazel-at-the-root-of-your-workspace)
14+
* [3\. Add swiftformat\_pkg to every Bazel package with Swift source files](#3-add-swiftformat_pkg-to-every-bazel-package-with-swift-source-files)
15+
* [4\. Format, Update, and Test](#4-format-update-and-test)
16+
* [Specifying the Version of SwiftFormat](#specifying-the-version-of-swiftformat)
17+
* [Learn More](#learn-more)
18+
919
<a id="#quickstart"></a>
1020
## Quickstart
1121

@@ -131,6 +141,23 @@ $ bazel run //:update_all
131141
$ bazel test //...
132142
```
133143

144+
## Specifying the Version of SwiftFormat
145+
146+
By default, `rules_swiftformat` will load the [latest release of
147+
SwiftFormat](https://github.com/nicklockwood/SwiftFormat/releases). This works well for most cases.
148+
However, if you would like to specify the SwiftFormat release, you can do so by passing the version
149+
to the [`swiftformat_load_package`](/doc/repository_rules_overview.md#swiftformat_load_package) function in your `WORKSPACE`.
150+
151+
```python
152+
load("@cgrindel_rules_swiftformat//swiftformat:load_package.bzl", "swiftformat_load_package")
153+
154+
swiftformat_load_package(version = "0.49.1")
155+
```
156+
157+
One reason you may want to do so is to ensure that everyone working on your project is using the
158+
same version of SwiftFormat. Without the version specification, Bazel will cache whichever version
159+
was the latest when the project was run for the first time after the cache was cleared.
160+
134161
## Learn More
135162

136163
- [How It Works](/doc/how_it_works.md)

doc/BUILD.bazel

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ load(
99

1010
# MARK: - Documentation Providers
1111

12-
_PROVIDERS_DOC_PROVIDER = doc_providers.create(
13-
name = "providers_overview",
14-
stardoc_input = "//swiftformat:swiftformat.bzl",
15-
symbols = [
16-
"SwiftFormatInfo",
17-
],
18-
deps = ["//swiftformat"],
19-
)
20-
2112
_RULES_AND_MACROS_DOC_PROVIDER = doc_providers.create(
2213
name = "rules_and_macros_overview",
2314
stardoc_input = "//swiftformat:swiftformat.bzl",
@@ -31,6 +22,15 @@ _RULES_AND_MACROS_DOC_PROVIDER = doc_providers.create(
3122
deps = ["//swiftformat"],
3223
)
3324

25+
_REPOSITORY_RULES_DOC_PROVIDER = doc_providers.create(
26+
name = "repository_rules_overview",
27+
stardoc_input = "//swiftformat:load_package.bzl",
28+
symbols = [
29+
"swiftformat_load_package",
30+
],
31+
deps = ["//swiftformat:load_package"],
32+
)
33+
3434
_API_SRCS = [
3535
"src_utils",
3636
]
@@ -47,7 +47,7 @@ _API_DOC_PROVIDERS = [
4747

4848
_ALL_DOC_PROVIDERS = [
4949
_RULES_AND_MACROS_DOC_PROVIDER,
50-
_PROVIDERS_DOC_PROVIDER,
50+
_REPOSITORY_RULES_DOC_PROVIDER,
5151
doc_providers.create(
5252
name = "api",
5353
is_stardoc = False,
@@ -59,25 +59,25 @@ _ALL_DOC_PROVIDERS = [
5959
# MARK: - Headers
6060

6161
write_header(
62-
name = _PROVIDERS_DOC_PROVIDER.header_label,
62+
name = _RULES_AND_MACROS_DOC_PROVIDER.header_label,
6363
header_content = [
64-
"# Providers",
64+
"# Rules and Macros",
6565
"",
66-
"The providers described below are used by [the rules](/doc/rules_and_macros_overview.md) to",
67-
"pass along information about the source files and the formatted files.",
66+
"The rules and macros described below are used to format, test and ",
67+
"copy Swift source files.",
6868
],
69-
symbols = _PROVIDERS_DOC_PROVIDER.symbols,
69+
symbols = _RULES_AND_MACROS_DOC_PROVIDER.symbols,
7070
)
7171

7272
write_header(
73-
name = _RULES_AND_MACROS_DOC_PROVIDER.header_label,
73+
name = _REPOSITORY_RULES_DOC_PROVIDER.header_label,
7474
header_content = [
75-
"# Rules and Macros",
75+
"# Repository Rules and Macros",
7676
"",
77-
"The rules and macros described below are used to format, test and ",
78-
"copy Swift source files.",
77+
"The rules and macros described below are used to configure and download ",
78+
"dependencies for rules_swiftformat.",
7979
],
80-
symbols = _RULES_AND_MACROS_DOC_PROVIDER.symbols,
80+
symbols = _REPOSITORY_RULES_DOC_PROVIDER.symbols,
8181
)
8282

8383
# Write the API headers

doc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
## Reference Documentation
1414

1515
- [Rules and Macros](/doc/rules_and_macros_overview.md)
16-
- [Providers](/doc/providers_overview.md)
16+
- [Repository Rules and Macros](/doc/repository_rules_overview.md)
1717
- [APIs](/doc/api.md)

doc/providers_overview.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

doc/repository_rules_overview.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!-- Generated with Stardoc, Do Not Edit! -->
2+
# Repository Rules and Macros
3+
4+
The rules and macros described below are used to configure and download
5+
dependencies for rules_swiftformat.
6+
7+
On this page:
8+
9+
* [swiftformat_load_package](#swiftformat_load_package)
10+
11+
12+
<a id="#swiftformat_load_package"></a>
13+
14+
## swiftformat_load_package
15+
16+
<pre>
17+
swiftformat_load_package(<a href="#swiftformat_load_package-version">version</a>)
18+
</pre>
19+
20+
Loads SwiftFormat using Swift Package Manager via `rules_spm`.
21+
22+
If a version is not specified, Swift Package Manager will be configured to load the latest release.
23+
24+
25+
**PARAMETERS**
26+
27+
28+
| Name | Description | Default Value |
29+
| :------------- | :------------- | :------------- |
30+
| <a id="swiftformat_load_package-version"></a>version | Optional. A valid semver <code>string</code> for SwiftFormat. | <code>None</code> |
31+
32+

examples/simple/WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ swift_rules_extra_dependencies()
3939

4040
load("@cgrindel_rules_swiftformat//swiftformat:load_package.bzl", "swiftformat_load_package")
4141

42-
swiftformat_load_package()
42+
swiftformat_load_package(version = "0.49.1")

swiftformat/BUILD.bazel

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ bzlformat_pkg(
99
update_visibility = ["//:__subpackages__"],
1010
)
1111

12+
bzl_library(
13+
name = "bazel_tools_repo_utils",
14+
srcs = ["@bazel_tools//tools/build_defs/repo:utils.bzl"],
15+
)
16+
1217
bzl_library(
1318
name = "deps",
1419
srcs = ["deps.bzl"],
@@ -17,13 +22,16 @@ bzl_library(
1722
bzl_library(
1823
name = "load_package",
1924
srcs = ["load_package.bzl"],
25+
deps = [
26+
":bazel_tools_repo_utils",
27+
"@cgrindel_rules_spm//spm:defs",
28+
],
2029
)
2130

2231
bzl_library(
2332
name = "swiftformat",
2433
srcs = ["swiftformat.bzl"],
2534
deps = [
26-
"//swiftformat/internal:providers",
2735
"//swiftformat/internal:src_utils",
2836
"//swiftformat/internal:swiftformat_binary",
2937
"//swiftformat/internal:swiftformat_format",

swiftformat/deps.bzl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@ def swiftformat_rules_dependencies():
1313
sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
1414
)
1515

16-
maybe(
17-
http_archive,
16+
http_archive(
1817
name = "cgrindel_bazel_starlib",
19-
sha256 = "238c05abf31447b93bd15b616c7413c4c719ee7b5e81c1489ca20f02ce628489",
20-
strip_prefix = "bazel-starlib-0.2.0",
18+
sha256 = "5b36e7f11bf0c1d52480f1b022430611b402b5424979f280f13c52550de76584",
19+
strip_prefix = "bazel-starlib-0.3.0",
2120
urls = [
22-
"http://github.com/cgrindel/bazel-starlib/archive/v0.2.0.tar.gz",
21+
"http://github.com/cgrindel/bazel-starlib/archive/v0.3.0.tar.gz",
2322
],
2423
)
2524

2625
maybe(
2726
http_archive,
2827
name = "cgrindel_rules_spm",
29-
sha256 = "fab28a41793744f3944ad2606cdd9c0f8e2f4861dd29fb1d61aa4263c7a1400a",
30-
strip_prefix = "rules_spm-0.6.0",
31-
urls = ["https://github.com/cgrindel/rules_spm/archive/v0.6.0.tar.gz"],
28+
sha256 = "cbe5d5dccdc8d5aa300e1538c4214f44a1266895d9817e8279a9335bcbee2f1e",
29+
strip_prefix = "rules_spm-0.7.0",
30+
urls = [
31+
"http://github.com/cgrindel/rules_spm/archive/v0.7.0.tar.gz",
32+
],
3233
)
3334

3435
maybe(

swiftformat/internal/BUILD.bazel

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ bzlformat_pkg(
99
update_visibility = ["//:__subpackages__"],
1010
)
1111

12-
bzl_library(
13-
name = "providers",
14-
srcs = ["providers.bzl"],
15-
)
16-
1712
bzl_library(
1813
name = "src_utils",
1914
srcs = ["src_utils.bzl"],
@@ -23,7 +18,6 @@ bzl_library(
2318
name = "swiftformat_format",
2419
srcs = ["swiftformat_format.bzl"],
2520
deps = [
26-
":providers",
2721
"@bazel_skylib//lib:paths",
2822
"@cgrindel_bazel_starlib//updatesrc:defs",
2923
],

swiftformat/internal/providers.bzl

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)