Skip to content

Commit

Permalink
chore: mac portability (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle authored Oct 12, 2023
1 parent 27cc3b8 commit 2c236a1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
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

0 comments on commit 2c236a1

Please sign in to comment.