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

Warn when a test-suite / executable / benchmark also builds the library code? #1008

Closed
mgsloan opened this issue Sep 18, 2015 · 7 comments
Closed

Comments

@mgsloan
Copy link
Contributor

mgsloan commented Sep 18, 2015

It's not so uncommon to see test-suite / executable / benchmark stanzas which don't depend on the library, and instead compile it when they are built. This tends to happens when there isn't an hs-source-dirs on both the library and the other stanza.

Why is it good to avoid this?

I was hoping that we could catch this case just by checking if the build-depends of the non-library stanza includes the library. However, it looks like it's not an error to have it both depend on the library and build all the library's source files. So, the implementation of this would need to detect when the hs-source-dirs of the auxiliary stanza overlaps with the hs-source-dirs of the library.

Maybe there are legitimate cases for having these auxiliary stanzas also build the main library code? The only one I can think of is that it might be desirable for a test or benchmark to rebuild the library code with a different set of flags.

@mgsloan mgsloan changed the title Warn when a test-suite / executable / benchmark also build the library code? Warn when a test-suite / executable / benchmark also builds the library code? Sep 18, 2015
@mgsloan mgsloan added this to the P3: Optional milestone Sep 18, 2015
mgsloan added a commit to mgsloan/conduit that referenced this issue Sep 18, 2015
This avoids unnecessary recompilation, and fixes the "stack test
--coverage" results for this package.

commercialhaskell/stack#1008
commercialhaskell/stack#1009
@snoyberg
Copy link
Contributor

The only one I can think of is that it might be desirable for a test or benchmark to rebuild the library code with a different set of flags.

This is especially true when using CPP to expose new identifiers for the test suite. I think this change is too invasive for stack to make, though perhaps if we add a lint option in the future, this could be part of it.

@mgsloan
Copy link
Contributor Author

mgsloan commented Sep 18, 2015

Makes sense! I've closed this in favor of the issue about the lint command, and added a comment to #1009. The message to the user will mention that this case might be the cause.

@mgsloan mgsloan closed this as completed Sep 18, 2015
@mgsloan
Copy link
Contributor Author

mgsloan commented Sep 18, 2015

Another common case I just thought of is that when the test-suite also builds the library, it can access non exposed modules.

@soenkehahn
Copy link

Some other cases where the test suite doesn't depend on the library:

  • Sometimes it's desirable to build the test-suite with -O0 (and the production code with -O1 or similar). (Which is an instance of the "different flags" scenario mentioned above.)
  • Sometimes a package only consists of executables and a test suite. A library doesn't exist.

@mgsloan
Copy link
Contributor Author

mgsloan commented Oct 21, 2015

Yes, this is an unfortunate compromise. We could work around https://ghc.haskell.org/trac/ghc/ticket/1853 , but it would require a lot of hacks:

  • Build each of the test components separately, so that mix files can be moved out of the way between builds
  • Manually munging the tix files to know about the folders the mix files got moved to. We're already doing some tix file munging, but this'd be a bit more substantial..

My preference is to fix it for 8.0 rather than do anything complicated in stack to fix this.

@arianvp
Copy link

arianvp commented Dec 4, 2019

Another common case I just thought of is that when the test-suite also builds the library, it can access non exposed modules.

Cabal now has a notion of internal libraries in cabal files which I think could be used to circumvent this issue. Your test suite and your library can both depend on the internal library

@epoberezkin
Copy link

Could you please share some example hpack package.yaml for the package that contains an executable, a library and the test that tests this library? However I am moving things around, the stack tests --coverage still rebuilds the library and does not generate coverage... Thank you.

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

No branches or pull requests

5 participants