Skip to content

Commit

Permalink
Upgraded bazel-starlib to 0.6.0 and addressed a number of lint issues. (
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrindel authored Feb 26, 2022
1 parent 9ff33a2 commit 0e2b09c
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 52 deletions.
16 changes: 5 additions & 11 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,22 @@ swift_rules_extra_dependencies()

# MARK: - Buildifier

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")

go_rules_dependencies()
buildifier_prebuilt_deps()

go_register_toolchains(version = "1.17.2")
load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

gazelle_dependencies()

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()
buildifier_prebuilt_register_toolchains()

# MARK: - Integration Testing

load("@cgrindel_rules_bazel_integration_test//bazel_integration_test:deps.bzl", "bazel_integration_test_rules_dependencies")

bazel_integration_test_rules_dependencies()

load("//:bazel_versions.bzl", "SUPPORTED_BAZEL_VERSIONS")
load("@cgrindel_rules_bazel_integration_test//bazel_integration_test:defs.bzl", "bazel_binaries")
load("//:bazel_versions.bzl", "SUPPORTED_BAZEL_VERSIONS")

bazel_binaries(versions = SUPPORTED_BAZEL_VERSIONS)

Expand Down
2 changes: 2 additions & 0 deletions bazel_versions.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Tested/Supported Bazel Versions"""

CURRENT_BAZEL_VERSION = "5.0.0"

OTHER_BAZEL_VERSIONS = [
Expand Down
2 changes: 1 addition & 1 deletion doc/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg")
load(
"@cgrindel_bazel_starlib//bazeldoc:defs.bzl",
"doc_for_provs",
"write_file_list",
"write_header",
doc_providers = "providers",
)
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg")

# MARK: - Documentation Providers

Expand Down
4 changes: 0 additions & 4 deletions doc/rules_and_macros_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ NOTE: Any labels detected in the `srcs` will be ignored.
| <a id="swiftformat_pkg-srcs"></a>srcs | Optional. The Swift source files that should be formatted. | <code>None</code> |
| <a id="swiftformat_pkg-config"></a>config | Optional. The swiftformat YAML configuration file. | <code>None</code> |

**RETURNS**

None.


<a id="#swiftformat_test"></a>

Expand Down
18 changes: 10 additions & 8 deletions swiftformat/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
"""Public API for rules_swiftformat."""

load(
"//swiftformat/internal:swiftformat_pkg.bzl",
_swiftformat_pkg = "swiftformat_pkg",
"//swiftformat/internal:src_utils.bzl",
_src_utils = "src_utils",
)
load(
"//swiftformat/internal:swiftformat_binary.bzl",
_swiftformat_binary = "swiftformat_binary",
)
load(
"//swiftformat/internal:swiftformat_format.bzl",
Expand All @@ -11,17 +17,13 @@ load(
_swiftformat_library = "swiftformat_library",
)
load(
"//swiftformat/internal:swiftformat_binary.bzl",
_swiftformat_binary = "swiftformat_binary",
"//swiftformat/internal:swiftformat_pkg.bzl",
_swiftformat_pkg = "swiftformat_pkg",
)
load(
"//swiftformat/internal:swiftformat_test.bzl",
_swiftformat_test = "swiftformat_test",
)
load(
"//swiftformat/internal:src_utils.bzl",
_src_utils = "src_utils",
)

# Macros
swiftformat_pkg = _swiftformat_pkg
Expand Down
8 changes: 5 additions & 3 deletions swiftformat/deps.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Dependencies for rules_swiftformat."""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

Expand All @@ -16,10 +18,10 @@ def swiftformat_rules_dependencies():
maybe(
http_archive,
name = "cgrindel_bazel_starlib",
sha256 = "9e054e423bb7674e02052e52725b41288369dd94efff963479f76fe269b5177f",
strip_prefix = "bazel-starlib-0.3.1",
sha256 = "8ac3e45dc237121283d70506497ec39feb5092af9a57bfe34f7abf4a6bd2ebaa",
strip_prefix = "bazel-starlib-0.6.0",
urls = [
"http://github.com/cgrindel/bazel-starlib/archive/v0.3.1.tar.gz",
"http://github.com/cgrindel/bazel-starlib/archive/v0.6.0.tar.gz",
],
)

Expand Down
2 changes: 2 additions & 0 deletions swiftformat/internal/src_utils.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Definition for src_utils module."""

def _is_label(src):
"""Determines whether the provided string is a label.
Expand Down
2 changes: 2 additions & 0 deletions swiftformat/internal/swiftformat_binary.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Definition for swiftformat_binary macro."""

load("@build_bazel_rules_swift//swift:swift.bzl", "swift_binary")
load(":swiftformat_pkg.bzl", "swiftformat_pkg")

Expand Down
24 changes: 11 additions & 13 deletions swiftformat/internal/swiftformat_format.bzl
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
load("@bazel_skylib//lib:paths.bzl", "paths")
"""A build rule that formats Swift source files. """

load(
"@cgrindel_bazel_starlib//updatesrc:defs.bzl",
"UpdateSrcsInfo",
"update_srcs",
)

"""A build rule that formats Swift source files.
"""

def _swiftformat_format_impl(ctx):
updsrcs = []
for src in ctx.files.srcs:
Expand Down Expand Up @@ -48,6 +46,15 @@ def _swiftformat_format_impl(ctx):
swiftformat_format = rule(
implementation = _swiftformat_format_impl,
attrs = {
"config": attr.label(
allow_single_file = True,
doc = "A swiftformat config file.",
default = "@//:.swiftformat",
),
"output_suffix": attr.string(
default = "_formatted",
doc = "The suffix to add to the output filename.",
),
"srcs": attr.label_list(
allow_files = True,
mandatory = True,
Expand All @@ -59,15 +66,6 @@ The Swift version to be used by `swiftformat`. You probably want to add this \
to your config file instead of adding it here.\
""",
),
"config": attr.label(
allow_single_file = True,
doc = "A swiftformat config file.",
default = "@//:.swiftformat",
),
"output_suffix": attr.string(
default = "_formatted",
doc = "The suffix to add to the output filename.",
),
"_swiftformat": attr.label(
default = "@swiftformat_repos//SwiftFormat:swiftformat",
executable = True,
Expand Down
2 changes: 2 additions & 0 deletions swiftformat/internal/swiftformat_library.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Definition for swiftformat_library macro."""

load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
load(":swiftformat_pkg.bzl", "swiftformat_pkg")

Expand Down
16 changes: 7 additions & 9 deletions swiftformat/internal/swiftformat_pkg.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
load(":src_utils.bzl", "src_utils")
load(":swiftformat_format.bzl", "swiftformat_format")
"""\
A macro which defines targets that format Swift source files, test that \
they are formatted and copies them to the workspace directory.\
"""

load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("@cgrindel_bazel_starlib//updatesrc:defs.bzl", "updatesrc_update")

"""A macro which defines targets that format Swift source files, test that
they are formatted and copies them to the workspace directory.
"""
load(":src_utils.bzl", "src_utils")
load(":swiftformat_format.bzl", "swiftformat_format")

def swiftformat_pkg(name, srcs = None, config = None):
"""Defines targets that will format, test and update the specified Swift sources.
Expand All @@ -16,9 +17,6 @@ def swiftformat_pkg(name, srcs = None, config = None):
name: The base name for the targets that will be defined.
srcs: Optional. The Swift source files that should be formatted.
config: Optional. The swiftformat YAML configuration file.
Returns:
None.
"""
if srcs == None:
srcs = native.glob(["*.swift"])
Expand Down
2 changes: 2 additions & 0 deletions swiftformat/internal/swiftformat_test.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Definition for swiftformat_test macro."""

load("@build_bazel_rules_swift//swift:swift.bzl", "swift_test")
load(":swiftformat_pkg.bzl", "swiftformat_pkg")

Expand Down
4 changes: 3 additions & 1 deletion swiftformat/load_package.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Definition for swiftformat_load_package function."""

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@cgrindel_rules_spm//spm:defs.bzl", "spm_pkg", "spm_repositories")

Expand All @@ -11,8 +13,8 @@ def swiftformat_load_package(version = None):
version: Optional. A valid semver `string` for SwiftFormat.
"""
spm_pkg_args = {
"url": "https://github.com/nicklockwood/SwiftFormat.git",
"products": ["swiftformat"],
"url": "https://github.com/nicklockwood/SwiftFormat.git",
}
if version == None:
# Load the latest 0.x.x version of SwiftFormat.
Expand Down
2 changes: 2 additions & 0 deletions swiftformat/swiftformat.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Deprecated. Public API for rules_swiftformat."""

# NOTE: This file is deprecated and will be removed in a future release. Please use
# //swiftformat:defs.bzl intead.

Expand Down
2 changes: 1 addition & 1 deletion tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load(":src_utils_tests.bzl", "src_utils_test_suite")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg")
load(":src_utils_tests.bzl", "src_utils_test_suite")

bzlformat_pkg(name = "bzlformat")

Expand Down
4 changes: 3 additions & 1 deletion tests/src_utils_tests.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests for src_utils module."""

load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
load("//swiftformat/internal:src_utils.bzl", "src_utils")
load("//swiftformat:defs.bzl", "src_utils")

def _is_label_test(ctx):
env = unittest.begin(ctx)
Expand Down

0 comments on commit 0e2b09c

Please sign in to comment.