mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
Add support for bzlmod (#4704)
This commit is contained in:
@@ -0,0 +1 @@
|
||||
.build
|
||||
@@ -1,3 +1,5 @@
|
||||
common --enable_bzlmod
|
||||
|
||||
try-import %workspace%/ci.bazelrc
|
||||
try-import %workspace%/user.bazelrc
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
module(
|
||||
name = "swiftlint",
|
||||
version = "0.50.3",
|
||||
compatibility_level = 1,
|
||||
repo_name = "SwiftLint",
|
||||
)
|
||||
|
||||
bazel_dep(name = "platforms", version = "0.0.5")
|
||||
bazel_dep(name = "rules_apple", version = "2.0.0", repo_name = "build_bazel_rules_apple")
|
||||
bazel_dep(name = "rules_swift", version = "1.5.1", repo_name = "build_bazel_rules_swift")
|
||||
bazel_dep(name = "rules_xcodeproj", version = "0.12.2", repo_name = "com_github_buildbuddy_io_rules_xcodeproj")
|
||||
bazel_dep(name = "sourcekitten", version = "0.34.0", repo_name = "com_github_jpsim_sourcekitten")
|
||||
bazel_dep(name = "swift_argument_parser", version = "1.2.1", repo_name = "sourcekitten_com_github_apple_swift_argument_parser")
|
||||
bazel_dep(name = "yams", version = "5.0.3", repo_name = "sourcekitten_com_github_jpsim_yams")
|
||||
|
||||
swiftlint_repos = use_extension("//bazel:repos.bzl", "swiftlint_repos_bzlmod")
|
||||
use_repo(
|
||||
swiftlint_repos,
|
||||
"com_github_apple_swift_syntax",
|
||||
"com_github_johnsundell_collectionconcurrencykit",
|
||||
"com_github_krzyzanowskim_cryptoswift",
|
||||
"swiftlint_com_github_scottrhoyt_swifty_text_table",
|
||||
)
|
||||
|
||||
extra_rules = use_extension("//bazel:extensions.bzl", "extra_rules")
|
||||
use_repo(extra_rules, "swiftlint_extra_rules")
|
||||
@@ -166,6 +166,7 @@ endif
|
||||
$(eval NEW_VERSION := $(shell echo $(NEW_VERSION_AND_NAME) | sed 's/:.*//' ))
|
||||
@sed -i '' 's/## Main/## $(NEW_VERSION_AND_NAME)/g' CHANGELOG.md
|
||||
@sed 's/__VERSION__/$(NEW_VERSION)/g' tools/Version.swift.template > Source/SwiftLintFramework/Models/Version.swift
|
||||
@sed -e '3s/.*/ version = "$(NEW_VERSION)",/' -i '' MODULE.bazel
|
||||
make package
|
||||
make bazel_release
|
||||
make portable_zip
|
||||
|
||||
@@ -64,13 +64,19 @@ You can also build and install from source by cloning this project and running
|
||||
|
||||
### Using Bazel
|
||||
|
||||
Put this in your `WORKSPACE`:
|
||||
Put this in your `MODULE.bazel`:
|
||||
|
||||
```bzl
|
||||
bazel_dep(name = "swiftlint", version = "0.50.4", repo_name = "SwiftLint")
|
||||
```
|
||||
|
||||
Or put this in your `WORKSPACE`:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>WORKSPACE</summary>
|
||||
|
||||
```python
|
||||
```bzl
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
http_archive(
|
||||
|
||||
@@ -1,58 +1,5 @@
|
||||
workspace(name = "SwiftLint")
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
http_archive(
|
||||
name = "build_bazel_rules_apple",
|
||||
sha256 = "43737f28a578d8d8d7ab7df2fb80225a6b23b9af9655fcdc66ae38eb2abcf2ed",
|
||||
url = "https://github.com/bazelbuild/rules_apple/releases/download/2.0.0/rules_apple.2.0.0.tar.gz",
|
||||
)
|
||||
|
||||
load(
|
||||
"@build_bazel_rules_apple//apple:repositories.bzl",
|
||||
"apple_rules_dependencies",
|
||||
)
|
||||
|
||||
apple_rules_dependencies()
|
||||
|
||||
http_archive(
|
||||
name = "rules_swift",
|
||||
sha256 = "84e2cc1c9e3593ae2c0aa4c773bceeb63c2d04c02a74a6e30c1961684d235593",
|
||||
url = "https://github.com/bazelbuild/rules_swift/releases/download/1.5.1/rules_swift.1.5.1.tar.gz",
|
||||
)
|
||||
|
||||
load(
|
||||
"@rules_swift//swift:repositories.bzl",
|
||||
"swift_rules_dependencies",
|
||||
)
|
||||
|
||||
swift_rules_dependencies()
|
||||
|
||||
load(
|
||||
"@rules_swift//swift:extras.bzl",
|
||||
"swift_rules_extra_dependencies",
|
||||
)
|
||||
|
||||
swift_rules_extra_dependencies()
|
||||
|
||||
load("//bazel:repos.bzl", "swiftlint_repos")
|
||||
|
||||
swiftlint_repos()
|
||||
|
||||
load("//bazel:deps.bzl", "swiftlint_deps")
|
||||
|
||||
swiftlint_deps()
|
||||
|
||||
http_archive(
|
||||
name = "com_github_buildbuddy_io_rules_xcodeproj",
|
||||
sha256 = "9c86784491854f205b075e5c4d8a838612d433d9454a226d270ad1a17ad8d634",
|
||||
url = "https://github.com/buildbuddy-io/rules_xcodeproj/releases/download/0.12.2/release.tar.gz",
|
||||
)
|
||||
|
||||
load("@com_github_buildbuddy_io_rules_xcodeproj//xcodeproj:repositories.bzl", "xcodeproj_rules_dependencies")
|
||||
|
||||
xcodeproj_rules_dependencies()
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
|
||||
|
||||
git_repository(
|
||||
@@ -70,10 +17,6 @@ load(
|
||||
|
||||
rules_ruby_dependencies()
|
||||
|
||||
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
|
||||
|
||||
bazel_skylib_workspace()
|
||||
|
||||
rules_ruby_select_sdk(version = "host")
|
||||
|
||||
load(
|
||||
|
||||
+18
-7
@@ -1,18 +1,29 @@
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
load("@com_github_jpsim_sourcekitten//bazel:repos.bzl", "sourcekitten_repos")
|
||||
|
||||
def _default_extra_swift_sources_impl(ctx):
|
||||
def _extra_swift_sources_impl(ctx):
|
||||
ctx.file("WORKSPACE", "")
|
||||
ctx.file("empty.swift", "func extraRules() -> [Rule.Type] { [] }")
|
||||
label = ":empty"
|
||||
if ctx.attr.srcs:
|
||||
label = ctx.attr.srcs
|
||||
ctx.file("BUILD.bazel", """
|
||||
filegroup(
|
||||
name = "extra_rules",
|
||||
name = "empty",
|
||||
srcs = ["empty.swift"],
|
||||
visibility = ["//visibility:public"],
|
||||
)""")
|
||||
)
|
||||
|
||||
_default_extra_swift_sources = repository_rule(
|
||||
implementation = _default_extra_swift_sources_impl,
|
||||
alias(
|
||||
name = "extra_rules",
|
||||
actual = "{}",
|
||||
visibility = ["//visibility:public"],
|
||||
)""".format(label))
|
||||
|
||||
extra_swift_sources = repository_rule(
|
||||
implementation = _extra_swift_sources_impl,
|
||||
attrs = {
|
||||
"srcs": attr.label(allow_files = [".swift"]),
|
||||
},
|
||||
)
|
||||
|
||||
def swiftlint_deps():
|
||||
@@ -24,6 +35,6 @@ def swiftlint_deps():
|
||||
fail("error: this depends on rules_swift but that wasn't setup")
|
||||
|
||||
if not native.existing_rule("swiftlint_extra_rules"):
|
||||
_default_extra_swift_sources(name = "swiftlint_extra_rules")
|
||||
extra_swift_sources(name = "swiftlint_extra_rules")
|
||||
|
||||
sourcekitten_repos()
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
"""bzlmod module_extension for providing extra rule sources that should be loaded by swiftlint"""
|
||||
|
||||
load(":deps.bzl", "extra_swift_sources")
|
||||
|
||||
def _extra_rules(module_ctx):
|
||||
root_modules = [m for m in module_ctx.modules if m.is_root]
|
||||
if len(root_modules) > 1:
|
||||
fail("Expected at most one root module, found {}".format(", ".join([x.name for x in root_modules])))
|
||||
|
||||
if root_modules:
|
||||
root_module = root_modules[0]
|
||||
else:
|
||||
root_module = module_ctx.modules[0]
|
||||
|
||||
kwargs = {}
|
||||
if root_module.tags.setup:
|
||||
kwargs["srcs"] = root_module.tags.setup[0].srcs
|
||||
|
||||
extra_swift_sources(
|
||||
name = "swiftlint_extra_rules",
|
||||
**kwargs
|
||||
)
|
||||
|
||||
extra_rules = module_extension(
|
||||
implementation = _extra_rules,
|
||||
tag_classes = {
|
||||
"setup": tag_class(attrs = {
|
||||
"srcs": attr.label(allow_files = [".swift"]),
|
||||
}),
|
||||
},
|
||||
)
|
||||
+13
-7
@@ -1,13 +1,14 @@
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
def swiftlint_repos():
|
||||
def swiftlint_repos(bzlmod = False):
|
||||
"""Fetches SwiftLint repositories"""
|
||||
http_archive(
|
||||
name = "com_github_jpsim_sourcekitten",
|
||||
sha256 = "7a38debb93ef11504f6b6a776be598095591fae7e128263754d041c5ada8e856",
|
||||
strip_prefix = "SourceKitten-0.34.0",
|
||||
url = "https://github.com/jpsim/SourceKitten/archive/refs/tags/0.34.0.tar.gz",
|
||||
)
|
||||
if not bzlmod:
|
||||
http_archive(
|
||||
name = "com_github_jpsim_sourcekitten",
|
||||
sha256 = "7a38debb93ef11504f6b6a776be598095591fae7e128263754d041c5ada8e856",
|
||||
strip_prefix = "SourceKitten-0.34.0",
|
||||
url = "https://github.com/jpsim/SourceKitten/archive/refs/tags/0.34.0.tar.gz",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "swiftlint_com_github_scottrhoyt_swifty_text_table",
|
||||
@@ -41,3 +42,8 @@ def swiftlint_repos():
|
||||
strip_prefix = "CryptoSwift-ea07950124f7e44e88bd783bf29e6691a7866228",
|
||||
url = "https://github.com/krzyzanowskim/CryptoSwift/archive/ea07950124f7e44e88bd783bf29e6691a7866228.tar.gz",
|
||||
)
|
||||
|
||||
def _swiftlint_repos_bzlmod(_):
|
||||
swiftlint_repos(bzlmod = True)
|
||||
|
||||
swiftlint_repos_bzlmod = module_extension(implementation = _swiftlint_repos_bzlmod)
|
||||
|
||||
@@ -2,8 +2,12 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
readonly swiftlint="$RUNFILES_DIR/SwiftLint/swiftlint"
|
||||
readonly swiftpm_yaml="$RUNFILES_DIR/SwiftLint/swiftpm.yaml"
|
||||
readonly swiftlint="$RUNFILES_DIR/_main/swiftlint"
|
||||
if [[ ! -x "$swiftlint" ]]; then
|
||||
echo "SwiftLint not found at $swiftlint"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Change to workspace directory
|
||||
cd "$(dirname "$(readlink Package.swift)")"
|
||||
swift build --build-tests
|
||||
|
||||
Reference in New Issue
Block a user