Skip to content
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

Don't bundle ppx_inline_test tests in release mode #897

Closed
g2p opened this issue Jun 19, 2018 · 18 comments
Closed

Don't bundle ppx_inline_test tests in release mode #897

g2p opened this issue Jun 19, 2018 · 18 comments

Comments

@g2p
Copy link

g2p commented Jun 19, 2018

These tests can introduce extra dependencies and bloat release binaries.
Don't build them when installing from OPAM.
See janestreet/ppx_inline_test#13 (comment)

@rgrinberg
Copy link
Member

@diml what do you think of just hard coding -inline-test-drop in production for now as you said in janestreet/ppx_inline_test#13 (comment)

Later on, we could improve the ENV stanza to perhaps control this feature.

@ghost
Copy link

ghost commented Aug 6, 2018

No more hard-coding please, however we can add support for release flags in ppx rewriters. For instance we could write this in the dune file of ppx_inline_test:

(library
 ...
 (kind (ppx_rewriter (release_flags (-inline-test-drop))))

@rgrinberg
Copy link
Member

Okay, but I would suggest a syntax that is more consistent with how we handle env:

(library
 ...
 (kind (ppx_rewriter ((dev ...) (release (flags (-inline-test-drop))))

@ghost
Copy link

ghost commented Aug 13, 2018

BTW, we were talking about this with @avsm the other day. Another way to sort this out would be to use variants and have a test variant. For instance the method above wouldn't work when the tests are written in a library inside a functor, while it would work with variants. So we should probably wait a bit before committing to this.

@rgrinberg
Copy link
Member

That seems alright as well. Although it would also create a lot of installed bloat if we're now including a variant for every single library with tests.

Why doesn't the approach work with a functor btw? -inline-test-drop will not drop attributes inside functors?

@ghost
Copy link

ghost commented Aug 14, 2018

Let's say Foo.Make from library foo includes inline tests and you use Foo.Make in library bar. The release flag method will only work if both foo and bar are part of the same workspace. if foo was previously installed, then it won't work. Thought maybe that's an acceptable restriction.

BTW, instead of specifying multiple flags, we could also just pass the build profile:

(library
 ...
 (kind (ppx_rewriter (flags (-profile %{profile}))))

@hannesm
Copy link
Member

hannesm commented Apr 2, 2019

I ran into this issue when I used https://github.com/janestreet/ppx_inline_test and wanting to compile with a custom runtime, noticing that ppx_inline_test actually carries along some dependencies that require more Unix symbols than we have on MirageOS:

ld: error: undefined symbol: caml_out_channel_pos_fd
>>> referenced by expect_test_collector.ml:91 (collector/expect_test_collector.ml:91)
>>>               _build/main.native.o:(.text+0x98015)

ld: error: undefined symbol: expect_test_collector_before_test
>>> referenced by expect_test_collector.ml:96 (collector/expect_test_collector.ml:96)
>>>               _build/main.native.o:(.text+0x98092)

ld: error: undefined symbol: expect_test_collector_after_test
>>> referenced by expect_test_collector.ml:121 (collector/expect_test_collector.ml:121)
>>>               _build/main.native.o:(.text+0x98286)

ld: error: undefined symbol: Base_hash_string
>>> referenced by string.mli:329 (src/string.mli:329)
>>>               _build/main.native.o:(.text+0x9E678)
...

is the feature mentioned above on the roadmap of dune? would be great to have inline tests and being able to run on MirageOS! :)

@ghost
Copy link

ghost commented Apr 4, 2019

To keep things simple, let's pass the profile via a cookie, just as we do for the library name. Then we can simply change ppx_inline_test to inspect this cookie.

@ghost
Copy link

ghost commented Apr 4, 2019

Actually we should only pass it if a ppx requests it, to avoid extra rebuilds when not needed. I'm creating a ticket to describe the feature.

@ghost
Copy link

ghost commented Apr 4, 2019

I submitted a concrete proposal in #2020.

etaque added a commit to dividat/ocaml-semver that referenced this issue Jun 4, 2019
Cases already covered up by external tests.
Allows us to get rid of a runtime dep, see ocaml/dune#897
@hannesm
Copy link
Member

hannesm commented Feb 24, 2020

Now that > 1.5 years passed, and some work references this issue or 2020, I wonder whether it is possible to have inline tests which do not lead to runtime-dependencies in release mode?

@ghost
Copy link

ghost commented Feb 24, 2020

The last bit to make this work, i.e. respecting Dune's setting in ppx_inline_test hasn't been done. I just wrote a patch for it: janestreet/ppx_inline_test#21

It's currently being reviewed in Jane Street internal repo. Once it's merged, I'll backport it to the last release of ppx_inline_test.

@hannesm
Copy link
Member

hannesm commented Feb 24, 2020

thanks jeremie :)

@hannesm
Copy link
Member

hannesm commented Feb 24, 2020

does this mean that e.g. ppx_expect will need a similar patch (from my dune file, I use (inline_tests) and (preprocess (pps ppx_expect))?

@ghost
Copy link

ghost commented Feb 25, 2020

Nope, ppx_expect depends on ppx_inline_test and shares its frontend. So only ppx_inline_test needs to be updated.

Incidentally, we were talking last week with @NathanReb about forking ppx_expect into a simpler and leaner project. The current split ppx_inline_test/ppx_expect is because of historical reasons and not really needed anymore.

@ghost
Copy link

ghost commented Mar 2, 2020

New release of ppx_inline_test submitted: ocaml/opam-repository#15933

At this point there is nothing more to do on the Dune side, so I'm closing this ticket.

@ghost ghost closed this as completed Mar 2, 2020
@hannesm
Copy link
Member

hannesm commented Mar 30, 2020

@diml my intuition is that since ppx_inline_test v0.13.1, a dune build --profile=release should avoid any ppx_expect and ppx_inline_test.runtime-deps dependencies, is this correct? what is the minimal dune version to use here?

My experience, as stated in ocaml/opam-repository#16097 (comment) is different. Am I missing anything? Did you check a complete example that the dependencies are avoided?

@ghost
Copy link

ghost commented Mar 30, 2020

Not exactly, it makes sure the tests themselves are not part of the final executable but the code still needs to be preprocessed and there is currently no mechanism to avoid the runtime dependencies. Note that the code still needs to be preprocessed because if we leave the let%expect_test blocks in the code the compiler will choke on them.

Our plan with @NathanReb is to first add a new syntax in ppx_inline_test to have test blocks that can be safely left uninterpreted in the code. This will rely on attributes since they are ignored by the compiler. The syntax will be:

[@@@test
 ...
]

For instance:

[@@@test
 let some_helper = ...
 let%expect_test = ...
]

Then we will need a new feature in dune to have testing ppx rewriters be conditionally applied.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants