-
Notifications
You must be signed in to change notification settings - Fork 483
test: verify incremental builds with alias re-exported libraries (#4572) #14129
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
rgrinberg
merged 1 commit into
ocaml:main
from
robinbb:robinbb-issue-4572-alias-reexport
Apr 10, 2026
Merged
Changes from all commits
Commits
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
94 changes: 94 additions & 0 deletions
94
test/blackbox-tests/test-cases/per-module-lib-deps/alias-reexport.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,94 @@ | ||
| Incremental builds with library re-exporting a dependency via module alias. | ||
|
|
||
| When library "alias" re-exports library "impl" via (module Impl = Impl), | ||
| a consumer that accesses Impl through Alias must be recompiled when | ||
| impl.cmi changes. The -opaque flag means soft changes (implementation | ||
| only, no cmi change) can safely skip recompilation, but cmi changes | ||
| must always trigger it. | ||
|
|
||
| See: https://github.com/ocaml/dune/issues/4572 | ||
|
|
||
| $ cat > dune-project <<EOF | ||
| > (lang dune 3.23) | ||
| > EOF | ||
|
|
||
| A library where we'll perform the changes: | ||
|
|
||
| $ mkdir impl | ||
| $ cat > impl/dune <<EOF | ||
| > (library (name impl)) | ||
| > EOF | ||
| $ cat > impl/impl.ml <<EOF | ||
| > let foo = "initial build" | ||
| > EOF | ||
|
|
||
| Another library which exposes an alias to impl: | ||
|
|
||
| $ mkdir alias | ||
| $ cat > alias/dune <<EOF | ||
| > (library (name alias) (libraries impl)) | ||
| > EOF | ||
| $ cat > alias/alias.ml <<EOF | ||
| > module Impl = Impl | ||
| > EOF | ||
|
|
||
| A binary which depends on Alias to access Impl. An empty unused file | ||
| makes this a multi-module executable: | ||
|
|
||
| $ mkdir bin | ||
| $ cat > bin/dune <<EOF | ||
| > (executable (name main) (libraries alias)) | ||
| > EOF | ||
| $ cat > bin/main.ml <<EOF | ||
| > let () = print_endline Alias.Impl.foo | ||
| > EOF | ||
| $ touch bin/unused.ml | ||
|
|
||
| The first build succeeds: | ||
|
|
||
| $ dune exec ./bin/main.exe | ||
| initial build | ||
|
|
||
| Soft update — impl.cmi is NOT modified (only implementation changes). | ||
| With -opaque, skipping recompilation of main.ml is correct because | ||
| main.ml doesn't depend on impl's implementation, only its interface: | ||
|
|
||
| $ cat > impl/impl.ml <<EOF | ||
| > let foo = "second build, no change to cmi" | ||
| > EOF | ||
|
|
||
| $ dune exec ./bin/main.exe | ||
| second build, no change to cmi | ||
|
|
||
| main.cmx is NOT rebuilt (correct — only impl changed, and -opaque | ||
| means we don't track impl's implementation): | ||
|
|
||
| $ dune trace cat | jq -s 'include "dune"; [.[] | targetsMatchingFilter(test("Main"))]' | ||
| [] | ||
|
|
||
| unused.cmx is also NOT rebuilt (correct — it references nothing): | ||
|
|
||
| $ dune trace cat | jq -s 'include "dune"; [.[] | targetsMatchingFilter(test("Unused"))]' | ||
| [] | ||
|
|
||
| Hard update — impl.cmi IS modified (new value added). main.ml must | ||
| be recompiled because Alias re-exports Impl and the interface changed: | ||
|
|
||
| $ cat > impl/impl.ml <<EOF | ||
| > let new_value = 42 | ||
| > let foo = "third build, forced a cmi update" | ||
| > EOF | ||
|
|
||
| $ dune exec ./bin/main.exe | ||
| third build, forced a cmi update | ||
|
|
||
| Main is rebuilt (necessary — impl.cmi changed and main.ml uses | ||
| Impl through the Alias re-export): | ||
|
|
||
| $ dune trace cat | jq -s 'include "dune"; [.[] | targetsMatchingFilter(test("Main"))] | length | . > 0' | ||
| true | ||
|
|
||
| Unused is NOT rebuilt (correct — it doesn't reference impl): | ||
|
|
||
| $ dune trace cat | jq -s 'include "dune"; [.[] | targetsMatchingFilter(test("Unused"))] | length' | ||
| 0 | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the length and predicate here? Seeing the target would be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alas, yes, as the length is actually different on different platforms (Mac vs. non-Mac), which caused what I had here originally (the unfiltered uncounted output) to fail CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... because the output was different on different platforms, and even the filtered output was different (hence the non-zero count check instead of a firm count).