Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: mac portability #3

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
load("@rules_go//go:def.bzl", "go_binary", "go_library")
load("//release:release.bzl", "local_plugin")
Expand Down Expand Up @@ -42,6 +43,13 @@ go_binary(
visibility = ["//visibility:public"],
)

# TODO: add a Go unit test of the plugin logic.
# For now we just test that it builds.
build_test(
name = "test",
targets = [":lint-plugin"],
)

# Build this target to copy the plugin to bazel-bin/plugin and checksum it.
# Referenced by the .aspect/cli/config.yaml in the `From:` line.
local_plugin(
Expand Down
4 changes: 2 additions & 2 deletions example/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ fi
bazel build --aspects //:lint.bzl%eslint,//:lint.bzl%buf --output_groups=report $@

# Show the results.
# `-mtime -0.25`: only look at files modified in the last 15min, to avoid showing stale results of old bazel runs.
# `-mtime -1`: only look at files modified in the last day, to mitigate showing stale results of old bazel runs.
# `-size +1c`: don't show files containing zero bytes
for report in $(find $(bazel info bazel-bin) -mtime -0.25 -size +1c -type f -name "*-report.txt"); do
for report in $(find $(bazel info bazel-bin) -mtime -1 -size +1c -type f -name "*-report.txt"); do
echo "From ${report}:"
cat "${report}"
echo
Expand Down
6 changes: 4 additions & 2 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (plugin *LintPlugin) CustomCommands() ([]*aspectplugin.Command, error) {
}

func (plugin *LintPlugin) findLintResultFiles(streams ioutils.Streams, bazelStartupArgs []string) ([]string, error) {
// TODO: use bazel query
// TODO: use the Build Event Stream to learn of report files as actions write them

var infoOutBuf bytes.Buffer
infoStreams := ioutils.Streams{
Expand All @@ -140,7 +140,9 @@ func (plugin *LintPlugin) findLintResultFiles(streams ioutils.Streams, bazelStar
binDir := strings.TrimSpace(infoOutBuf.String())

var findOutBuf bytes.Buffer
findCmd := exec.Command("find", binDir, "-type", "f", "-name", "*-report.txt")
// `-mtime -1`: only look at files modified in the last day, to mitigate showing stale results of old bazel runs.
// `-size +1c`: don't show files containing zero bytes
findCmd := exec.Command("find", binDir, "-type", "f", "-mtime", "-1", "-size", "+1c", "-name", "*-report.txt")
findCmd.Stdout = &findOutBuf
findCmd.Stderr = streams.Stderr
findCmd.Stdin = streams.Stdin
Expand Down