-
Notifications
You must be signed in to change notification settings - Fork 483
test: regression guard for ppx_runtime_libraries cmi-dep coverage #14440
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
Merged
robinbb
merged 2 commits into
ocaml:main
from
robinbb:robinbb-test-ppx-runtime-libraries-guard
May 11, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
test/blackbox-tests/test-cases/per-module-lib-deps/ppx-runtime-libraries.t
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| A library declared as [(kind ppx_rewriter) (ppx_runtime_libraries | ||
| baz)] declares libraries the consumer needs at compile time | ||
| *after* preprocessing. The runtime libraries' modules are | ||
| referenced by ppx-rewritten output, so ocamldep on the consumer's | ||
| source cannot reason about which of them are referenced — the | ||
| next ppx invocation may use any module of [baz]. | ||
|
|
||
| The compile rule for any consumer of such a ppx must therefore | ||
| have a dep that covers every cmi in the runtime library's objdir. | ||
| A glob over the objdir is the natural shape; this test pins that | ||
| shape, guarding against any future inter-library dep handling | ||
| that narrows the recorded deps for ppx_runtime_libraries-induced | ||
| libraries. | ||
|
|
||
| $ make_dune_project 3.24 | ||
|
|
||
| [baz] is a regular unwrapped library that the ppx's expansion | ||
| would reference at runtime. | ||
|
|
||
| $ mkdir baz | ||
| $ cat > baz/dune <<EOF | ||
| > (library (name baz) (wrapped false)) | ||
|
robinbb marked this conversation as resolved.
Outdated
|
||
| > EOF | ||
| $ cat > baz/baz_mod.ml <<EOF | ||
| > let value = 0 | ||
| > EOF | ||
|
|
||
| [bar] is a [ppx_rewriter] declaring [baz] as a runtime library. | ||
|
robinbb marked this conversation as resolved.
Outdated
|
||
| The [ppx.driver] entry lets dune treat [bar] as a [pps] target | ||
| without ppxlib; the driver itself is a no-op stub that satisfies | ||
| dune's invocation contract enough for rule generation. | ||
|
|
||
| $ mkdir bar | ||
| $ cat > bar/dune <<EOF | ||
| > (library | ||
| > (name bar) | ||
| > (kind ppx_rewriter) | ||
| > (ppx_runtime_libraries baz) | ||
| > (ppx.driver (main Bar.main))) | ||
| > EOF | ||
| $ cat > bar/bar.ml <<EOF | ||
| > let main () = | ||
| > let out = ref "" in | ||
| > let args = | ||
| > [ ("-o", Arg.Set_string out, "") | ||
| > ; ("--impl", Arg.Set_string (ref ""), "") | ||
| > ; ("--as-ppx", Arg.Set (ref false), "") | ||
| > ; ("--cookie", Arg.Set (ref false), "") | ||
| > ] | ||
| > in | ||
| > let anon _ = () in | ||
| > Arg.parse (Arg.align args) anon ""; | ||
| > close_out (open_out !out) | ||
| > EOF | ||
|
|
||
| [foo] uses [bar] as a preprocessor. [foo.ml] does not mention | ||
|
robinbb marked this conversation as resolved.
Outdated
|
||
| [Baz_mod] textually — the ppx's runtime references would only | ||
| appear post-pp. Without [(libraries ...)], [foo]'s | ||
| [requires_compile] is populated entirely by [add_pp_runtime_deps] | ||
| in [src/dune_rules/lib.ml]: [bar] (the pps) plus its runtime | ||
| closure ([baz]). | ||
|
|
||
| $ mkdir foo | ||
| $ cat > foo/dune <<EOF | ||
| > (library (name foo) (wrapped false) (preprocess (pps bar))) | ||
|
robinbb marked this conversation as resolved.
Outdated
|
||
| > EOF | ||
| $ cat > foo/foo.ml <<EOF | ||
| > let _ = () | ||
| > EOF | ||
|
|
||
| The compile rule's recorded deps for [foo.cmi] must cover every | ||
| cmi in [baz/.baz.objs/byte/]. Without that, a change to any cmi | ||
| in [baz] would not invalidate [foo.cmi]'s rule and an incremental | ||
| rebuild could silently use a stale [foo.cmi]. The [-I | ||
| baz/.baz.objs/byte] flag is already on the compile command line | ||
| via [requires_compile] (so the initial build succeeds regardless), | ||
| but only the rule's recorded deps drive incremental correctness. | ||
|
robinbb marked this conversation as resolved.
Outdated
|
||
|
|
||
| $ dune rules --root . --format=json --deps _build/default/foo/.foo.objs/byte/foo.cmi | | ||
| > jq -r 'include "dune"; .[] | depsGlobs | ||
| > | select(.dir | endswith("baz/.baz.objs/byte")) | ||
| > | "\(.dir) \(.predicate)"' | sort -u | ||
|
robinbb marked this conversation as resolved.
Outdated
|
||
| _build/default/baz/.baz.objs/byte *.cmi | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.