fix(gen_srcs): skip unnecessary load symbols#87
Merged
Conversation
0af7ccf to
705fe48
Compare
705fe48 to
8bb3b04
Compare
0f89d27 to
2137d8b
Compare
miridius
added a commit
that referenced
this pull request
May 11, 2026
Self-review findings on #87: - **`has-binary?` + `has-tests?` from same reduce**: `has-binary?` already derives from emitted rule `:type`; `has-tests?` was scanning paths via a separate predicate. Drift risk. Fold into the same reduce: `[hb? ht? acc]`. - **`test-path?` regex anchored**: `#"_test.clj"` was unanchored — matched `_test.cljs`, `_test.cljbar` etc. Tighten to `#"_test\.cljc?$"`. Side effect: the `(or clj-path? cljc-path?)` guard in the now-deleted `has-tests?` predicate becomes redundant. - **Tests rewritten**: - Helper `load-symbols` parses the load() symbol set (drops the bzl-path) — replaces fragile `str/includes?` checks. - Helper `run-gen-dir!` sets up a temp dir, calls gen-dir, returns the BUILD content, cleans up. - New coverage: .cljc tests, .cljs-only (negative), clojure_binary via `:bazel/clojure_binary` metadata, subdirs-only with no own-files. - Empty-dir test extended: `__clj_lib` / `__clj_files` absent, package() still present.
b1cf607 to
7945bd3
Compare
731ce83 to
cc5659a
Compare
english
approved these changes
May 11, 2026
Comment on lines
+263
to
+265
| ;; ---- gen-dir load-symbol pruning ---- | ||
|
|
||
| ;; ---- gen-dir load-symbol pruning ---- |
Contributor
There was a problem hiding this comment.
Suggested change
| ;; ---- gen-dir load-symbol pruning ---- | |
| ;; ---- gen-dir load-symbol pruning ---- | |
| ;; ---- gen-dir load-symbol pruning ---- |
Contributor
Author
There was a problem hiding this comment.
Done — duplicated heading removed in c0a9ebf.
cc5659a to
c0a9ebf
Compare
`gen_srcs` always emitted
`load("@rules_clojure//:rules.bzl", "clojure_library", "clojure_test")`
in every BUILD file, even when:
1. There were no `clojure_test` targets — the "clojure_test" symbol was
loaded but never used.
2. The directory had no `.clj` files at all — the entire `load()`
statement was unnecessary.
Both conditions are detected from a single `reduce` over the rules that
`ns-rules` emits — `has-binary?` and `has-tests?` come from the same
pass (`= :clojure_binary :type`, `= :clojure_test :type`). No
re-scanning of paths.
Empty directories (`has-content?` false) get a BUILD with the docstring
header + `package()` only — no load, no `__clj_lib` / `__clj_files`
filegroup. Matches Gazelle's behaviour.
Also:
- `test-path?` regex anchored: `#"_test.clj"` was unanchored — matched
`_test.cljs`, `_test.cljbar`, etc. Tightened to `#"_test\.cljc?$"`.
- `.clj-kondo/config.edn` with
`exclude-destructured-keys-in-fn-args` + `exclude-destructured-as` —
this codebase uses map destructuring in fn args as documentation of
expected keys, so unused-binding warnings are noise.
- `.gitignore` adjusted so `.clj-kondo/.cache/` is ignored but
`.clj-kondo/config.edn` is tracked.
Test coverage (gen_build_test.clj):
- `load-symbols` helper parses the load() symbol set out of generated
BUILD content; `run-gen-dir!` sets up a temp dir, calls gen-dir,
returns content, cleans up.
- `gen-dir-load-symbols`: covers .clj test, .cljc test, .cljs-only
(negative — `ns-rules` emits `clojure_test` only for clj/cljc), no
tests.
- `gen-dir-includes-clojure-binary-when-ns-has-bazel-clojure-binary-meta`:
a ns with `:bazel/clojure_binary` metadata adds "clojure_binary" to
the load.
- `gen-dir-subdirs-only`: dir with no own files but a clj-only subdir
still emits load + `__clj_lib` referencing the subdir.
- `gen-dir-skips-load-for-empty-dirs`: `__clj_lib` / `__clj_files`
absent, `package()` still emitted.
c0a9ebf to
e6c6037
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on #85.
Problem
gen_srcsalways emitsload("@rules_clojure//:rules.bzl", "clojure_library", "clojure_test")in every BUILD file, even when:clojure_testtargets — the"clojure_test"symbol is loaded but never used..cljfiles at all — the entireload()statement is unnecessary.Solution
Two changes to
gen-dir, both derived from a single pass over the rulesns-rulesemits —has-binary?andhas-tests?come from the samereduce(= :clojure_binary :type,= :clojure_test :type). No re-scanning of paths.1. Only include
"clojure_test"when test files existBefore (directory with only
core.clj, after #85's docstring + load-before-package):After:
2. Skip
load()for empty directoriesDirectories with no source files and no clj subdirs (
has-content?false) get a BUILD with only the docstring header +package()— no load, no__clj_lib/__clj_files. Matches Gazelle's behaviour.Before:
After:
Also
test-path?regex anchored:#"_test.clj"was unanchored — matched_test.cljs,_test.cljbar, etc. Tightened to#"_test\.cljc?$"so the(or clj-path? cljc-path?)guard inhas-tests?becomes redundant..clj-kondo/config.ednwithexclude-destructured-keys-in-fn-argsandexclude-destructured-as— this codebase uses map destructuring in fn args as documentation of expected keys, so unused-binding warnings on those are noise..gitignoreadjusted so.clj-kondo/.cache/is ignored but.clj-kondo/config.ednis tracked.