From 03606a64dff533f4aa74be5942c3535c7d6e8292 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 11 Oct 2023 17:32:18 -0700 Subject: [PATCH] chore: mac portability --- BUILD.bazel | 8 ++++++++ example/lint.sh | 4 ++-- plugin.go | 6 ++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 89ccd1c4..ad141395 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -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") @@ -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( diff --git a/example/lint.sh b/example/lint.sh index 282fc257..7d8cd24a 100755 --- a/example/lint.sh +++ b/example/lint.sh @@ -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 diff --git a/plugin.go b/plugin.go index 6fc5e6be..24b07e30 100644 --- a/plugin.go +++ b/plugin.go @@ -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{ @@ -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