Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
Move all 3 providers into their own files
Browse files Browse the repository at this point in the history
  • Loading branch information
David Johnston committed Sep 2, 2020
1 parent 84ef82e commit c31851c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 27 deletions.
24 changes: 24 additions & 0 deletions markdown/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
exports_files(
# NOTE(dwtj): We export all `bzl` files in this package so that the website
# can wrap these files in `bzl_library` targets and pass them to `stardoc`.
# We don't want to declare `bzl_library` targets and `stardoc` targets in
# this package, because then all users of these rules would also depend
# upon the `bazel-skylib` and `stardoc` external repositories (and thus
# need to configure their Bazel workspace to include these dependencies).
glob([
"**/*.bzl",
]),
# TODO(dwtj): These files are probably only needed for the website. Can we
# make visibility narrower even though the website is in an external
# repository?
visibility = ["//visibility:public"],
)

filegroup(
name = "all_bzl_files_in_project",
srcs = glob(["**/*.bzl"]),
# TODO(dwtj): These files are probably only needed for the website. Can we
# make visibility narrower even though the website is in an external
# repository?
visibility = ["//visibility:public"]
)
16 changes: 5 additions & 11 deletions markdown/private/aspects/markdownlint_aspect/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ This aspect adds a lint as an action to `markdown` targets. The lint is
performed by the lint tool provided by the selected `markdown_lint_toolchain`.
'''

load("@dwtj_rules_markdown//markdown:private/rules/markdown_library/defs.bzl", "MarkdownInfo")

MarkdownLintAspectInfo = provider(
fields = {
# Will be `None` if the target can't be or shouldn't be linted.
'output_file': 'The lint report file produced by `markdownlint`.',
}
)
load("@dwtj_rules_markdown//markdown:private/providers/MarkdownInfo.bzl", "MarkdownInfo")
load("@dwtj_rules_markdown//markdown:private/providers/MarkdownlintAspectInfo.bzl", "MarkdownlintAspectInfo")

def _target_provides_markdown_info(target):
return MarkdownInfo in target
Expand All @@ -25,7 +19,7 @@ def _output_file_name_of(target):
def _markdownlint_aspect_impl(target, aspect_ctx):
# Skip a target if it doesn't provide `MarkdownInfo`:
if not _target_provides_markdown_info(target):
return [MarkdownLintAspectInfo()]
return [MarkdownlintAspectInfo()]

# Extract information from the toolchain:
toolchain = aspect_ctx.toolchains['@dwtj_rules_markdown//markdown/toolchains/markdownlint:toolchain_type']
Expand Down Expand Up @@ -76,11 +70,11 @@ def _markdownlint_aspect_impl(target, aspect_ctx):

return [
OutputGroupInfo(default = [output_file]),
MarkdownLintAspectInfo(output_file = output_file),
MarkdownlintAspectInfo(output_file = output_file),
]

markdownlint_aspect = aspect(
implementation = _markdownlint_aspect_impl,
provides = [MarkdownLintAspectInfo],
provides = [MarkdownlintAspectInfo],
toolchains = ['@dwtj_rules_markdown//markdown/toolchains/markdownlint:toolchain_type'],
)
10 changes: 10 additions & 0 deletions markdown/private/providers/MarkdownInfo.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'''Defines the `MarkdownInfo` provider.
'''

MarkdownInfo = provider(
fields = [
'direct_source_files',
'transitive_source_files',
'markdownlint_config_file',
],
)
9 changes: 9 additions & 0 deletions markdown/private/providers/MarkdownlintAspectInfo.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'''Defines the `MarkdownlintAspectInfo` provider.
'''

MarkdownlintAspectInfo = provider(
fields = {
# Will be `None` if the target can't be or shouldn't be linted.
'output_file': 'The lint report file produced by `markdownlint`.',
}
)
10 changes: 10 additions & 0 deletions markdown/private/providers/MarkdownlintToolchainInfo.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'''Defines the `MarkdownlintToolchainInfo` provider.
'''

MarkdownlintToolchainInfo = provider(
fields = [
"node_executable",
"markdownlint_executable",
"config_file",
],
)
9 changes: 1 addition & 8 deletions markdown/private/rules/markdown_library/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@ load(
'SUPPORTED_MARKDOWN_FILE_EXTENSIONS',
'SUPPORTED_MARKDOWNLINT_CONFIG_FILE_EXTENSIONS',
)

MarkdownInfo = provider(
fields = [
'direct_source_files',
'transitive_source_files',
'markdownlint_config_file',
],
)
load("//markdown:private/providers/MarkdownInfo.bzl", "MarkdownInfo")

def _build_transitive_source_files_depset(srcs, deps):
return depset(
Expand Down
9 changes: 1 addition & 8 deletions markdown/private/rules/markdownlint_toolchain/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ Markdown lint toolchain instances are created by writing
'''

load('//markdown:private/common/constants.bzl', 'SUPPORTED_MARKDOWNLINT_CONFIG_FILE_EXTENSIONS')

MarkdownlintToolchainInfo = provider(
fields = [
"node_executable",
"markdownlint_executable",
"config_file",
],
)
load("//markdown:private/providers/MarkdownlintToolchainInfo.bzl", "MarkdownlintToolchainInfo")

def _markdownlint_toolchain_impl(ctx):
toolchain_info = platform_common.ToolchainInfo(
Expand Down

0 comments on commit c31851c

Please sign in to comment.