Skip to content

Commit

Permalink
refactor: use sh_binary to express an executable (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyawk authored Apr 12, 2024
1 parent 6ecd42f commit d70c479
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 34 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,16 @@ jobs:
echo "ERROR: Files are changed by formatters" >&2
exit 1
fi
all-tests-passable:
if: always()
needs:
- unit-test
- example
- style-check
runs-on: ubuntu-22.04
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
4 changes: 2 additions & 2 deletions build_script/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ package(
default_visibility = ["//lang:__subpackages__"],
)

filegroup(
sh_binary(
name = "conditionally_execute",
srcs = ["conditionally_execute.bash"],
)

filegroup(
sh_binary(
name = "check_emptiness",
srcs = ["check_emptiness.bash"],
)
50 changes: 21 additions & 29 deletions lang/cc/build_error.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ _EXTENSIONS_CPP = [
".c++",
]

def _get_executable_file(label):
"""Get executable file if the label is not None.
Args:
label(label or None): Executable label
Returns:
File: Executable file.
"""
if not label:
return None
return label.files_to_run.executable

def _is_c(src_file):
"""Whether the source file is for C.
Expand Down Expand Up @@ -156,7 +169,7 @@ def _try_compile(ctx):
ctx.actions.run(
outputs = [compile_output, compile_stdout, compile_stderr],
inputs = inputs,
executable = ctx.file._conditionally_execute,
executable = _get_executable_file(ctx.attr._conditionally_execute),
arguments = [args],
tools = cc_toolchain.all_files,
)
Expand Down Expand Up @@ -249,7 +262,7 @@ def _try_link(ctx, compile_output):
ctx.actions.run(
outputs = [link_output, link_stdout, link_stderr],
inputs = inputs,
executable = ctx.file._conditionally_execute,
executable = _get_executable_file(ctx.attr._conditionally_execute),
arguments = [args],
tools = cc_toolchain.all_files,
)
Expand Down Expand Up @@ -291,7 +304,7 @@ def _check_build_error(ctx, compile_output, link_output):
ctx.actions.run(
outputs = [marker_check_build_error],
inputs = [compile_output, link_output],
executable = ctx.file._check_emptiness,
executable = _get_executable_file(ctx.attr._check_emptiness),
arguments = [args],
)

Expand Down Expand Up @@ -369,15 +382,9 @@ _try_build = rule(
),
"_check_emptiness": attr.label(
default = Label("//build_script:check_emptiness"),
allow_single_file = True,
cfg = "exec",
executable = True,
),
"_conditionally_execute": attr.label(
default = Label("//build_script:conditionally_execute"),
allow_single_file = True,
cfg = "exec",
executable = True,
),
},
fragments = ["cpp"],
Expand Down Expand Up @@ -429,7 +436,7 @@ def _check_each_message(ctx, message_file, matcher, pattern):
ctx.actions.run(
outputs = [marker_file],
inputs = [message_file],
executable = ctx.file._conditionally_execute,
executable = _get_executable_file(ctx.attr._conditionally_execute),
arguments = [
"-m",
"Pattern '{pattern}' is not found in '{message_file}' with the matcher '{matcher}'".format(
Expand Down Expand Up @@ -463,25 +470,25 @@ def _check_messages_impl(ctx):
marker_compile_stderr = _check_each_message(
ctx,
cc_build_error_info.compile_stderr,
ctx.file.matcher_compile_stderr,
_get_executable_file(ctx.attr.matcher_compile_stderr),
ctx.attr.pattern_compile_stderr,
)
marker_compile_stdout = _check_each_message(
ctx,
cc_build_error_info.compile_stdout,
ctx.file.matcher_compile_stdout,
_get_executable_file(ctx.attr.matcher_compile_stdout),
ctx.attr.pattern_compile_stdout,
)
marker_link_stderr = _check_each_message(
ctx,
cc_build_error_info.link_stderr,
ctx.file.matcher_link_stderr,
_get_executable_file(ctx.attr.matcher_link_stderr),
ctx.attr.pattern_link_stderr,
)
marker_link_stdout = _check_each_message(
ctx,
cc_build_error_info.link_stdout,
ctx.file.matcher_link_stdout,
_get_executable_file(ctx.attr.matcher_link_stdout),
ctx.attr.pattern_link_stdout,
)
markers = [
Expand Down Expand Up @@ -514,30 +521,18 @@ _check_messages = rule(
),
"matcher_compile_stderr": attr.label(
doc = "Matcher executable for stderr while compiling",
allow_single_file = True,
cfg = "exec",
executable = True,
mandatory = False,
),
"matcher_compile_stdout": attr.label(
doc = "Matcher executable for stdout while compiling",
allow_single_file = True,
cfg = "exec",
executable = True,
mandatory = False,
),
"matcher_link_stderr": attr.label(
doc = "Matcher executable for stderr while linking",
allow_single_file = True,
cfg = "exec",
executable = True,
mandatory = False,
),
"matcher_link_stdout": attr.label(
doc = "Matcher executable for stdout while linking",
allow_single_file = True,
cfg = "exec",
executable = True,
mandatory = False,
),
"pattern_compile_stderr": attr.string(
Expand All @@ -558,9 +553,6 @@ _check_messages = rule(
),
"_conditionally_execute": attr.label(
default = Label("//build_script:conditionally_execute"),
allow_single_file = True,
cfg = "exec",
executable = True,
),
},
provides = [CcBuildErrorInfo, DefaultInfo],
Expand Down
6 changes: 3 additions & 3 deletions matcher/executable/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ package(
default_visibility = ["//visibility:public"],
)

filegroup(
sh_binary(
name = "contains_basic_regex",
srcs = ["contains_basic_regex.bash"],
)

filegroup(
sh_binary(
name = "contains_extended_regex",
srcs = ["contains_extended_regex.bash"],
)

filegroup(
sh_binary(
name = "has_substr",
srcs = ["has_substr.bash"],
)

0 comments on commit d70c479

Please sign in to comment.