-
Notifications
You must be signed in to change notification settings - Fork 704
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
Adds cabal doctest #4480
Adds cabal doctest #4480
Conversation
This adds the `doctest` command to cabal. It does however not yet work as the driver is baiscally a stub. This is therfore only the first step towards haskell#2327.
This is a rather rough cut. But it allows to run `cabal doctest` already.
Note, that this PR is likely incomplete, and I'd like to get some feedback early on about the code so far. I'm certain there's likely some logic missing for full doctest support. Please also note that this PR depends on sol/doctest#156 |
However, the current state of affairs is that:
already works. |
Pinging @phadej as well, who implemented https://github.com/phadej/cabal-doctest and might know the innards of |
@@ -309,6 +311,16 @@ hscolourProgram = (simpleProgram "hscolour") { | |||
_ -> "" | |||
} | |||
|
|||
doctestProgram :: Program | |||
doctestProgram = (simpleProgram "doctest") { |
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.
Ok for now; but we should compile doctest against used ghc (and in fact also haddock)
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.
I'd leave a todo.
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.
Could (and more likely should?) cabal-install depend on doctest and haddock then, and use their binaries installed alongside cabal, unless explicitly overwritten?
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.
On second thought, that might actually not be sufficient, as cabal-install could be compiled by a different ghc than the one it is used with, unless I'm mistaken.
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.
@angerman That's correct. In general, we don't have this problem for haddock because it is distributed with GHC, so we can use the same detection code that finds the correct ghc-pkg for a ghc to also get the correct haddock. For now, I'm OK with requiring people to do some footwork to get the correct doctest if they're using a different ghc, but we should test and make sure we get a reasonable error message in this case (similar to what happens when ghc and ghc-pkg versions mismatch.)
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.
I think teaching cabal-install how to compile correct versions of haddock and doctest is worthwhile, and fits into the new-build model (we need a simulated build-tools-depends) but it is definitely out of scope for this ticket. Maybe we should make a ticket for it.
This hopefully makes the CI happy. Also added the comment regarding the need to have doctest and haddock be built against the same ghc.
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.
This looks totally reasonable, but of course, the important work of passing the correct -package
flags has not been done yet ;)
We'll need tests eventually, which is going to require updates to test suite (since you will need to feed it path to correct doctest.) I can advise when we get there.
Cabal/Distribution/Simple.hs
Outdated
@@ -290,6 +292,21 @@ hscolourAction hooks flags args = do | |||
(getBuildConfig hooks verbosity distPref) | |||
hooks flags' args | |||
|
|||
doctestAcion :: UserHooks -> DoctestFlags -> Args -> IO () |
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.
s/Acion/Action/
@@ -309,6 +311,16 @@ hscolourProgram = (simpleProgram "hscolour") { | |||
_ -> "" | |||
} | |||
|
|||
doctestProgram :: Program | |||
doctestProgram = (simpleProgram "doctest") { |
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.
@angerman That's correct. In general, we don't have this problem for haddock because it is distributed with GHC, so we can use the same detection code that finds the correct ghc-pkg for a ghc to also get the correct haddock. For now, I'm OK with requiring people to do some footwork to get the correct doctest if they're using a different ghc, but we should test and make sure we get a reasonable error message in this case (similar to what happens when ghc and ghc-pkg versions mismatch.)
@@ -309,6 +311,16 @@ hscolourProgram = (simpleProgram "hscolour") { | |||
_ -> "" | |||
} | |||
|
|||
doctestProgram :: Program | |||
doctestProgram = (simpleProgram "doctest") { |
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.
I think teaching cabal-install how to compile correct versions of haddock and doctest is worthwhile, and fits into the new-build model (we need a simulated build-tools-depends) but it is definitely out of scope for this ticket. Maybe we should make a ticket for it.
doctestProgram = (simpleProgram "doctest") { | ||
programFindLocation = \v p -> findProgramOnSearchPath v p "doctest" | ||
, programFindVersion = findProgramVersion "--version" $ \str -> | ||
-- "doctest version 0.11.2" |
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.
Hmm... we kind of really want the GHC version too, so you can check for compatibility. Not sure how to fix the API to make this possible.
cabal-install/main/Main.hs
Outdated
@@ -761,6 +763,14 @@ haddockAction haddockFlags extraArgs globalFlags = do | |||
createTarGzFile dest docDir name | |||
notice verbosity $ "Documentation tarball created: " ++ dest | |||
|
|||
doctestAcion :: DoctestFlags -> [String] -> Action |
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.
s/Acion/Action/
Cabal/Distribution/Simple/Doctest.hs
Outdated
k (["--no-magic"], argTargets args) | ||
|
||
-- ----------------------------------------------------------------------------- | ||
-- TODO: move somewhere else (this is copied from Haddock.hs!) |
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.
Yes please do :)
This basically reuses cabals logic for computing the command line arguments.
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.
This is so sweet. Do you want to merge this now (perhaps as a "hidden" command) and then keep fixing bugs as they come up?
Re: -Wall
, this is butting up with the "how do we specify doctest-specific packages/parameters" problem, because what you really wanted was to say -Wall
for library build, but no -Wall
for doctest. Do you think this problem is a show-stopper? If it is we could add a hack to solve this particular problem (e.g., a flag which enables some sort of ghc-options
filtering; NOT turned on by default), while trying to hash out a design for the rest of the parameters.
-> BuildInfo | ||
-> IO DoctestArgs | ||
mkDoctestArgs verbosity tmp lbi clbi inFiles bi = do | ||
let vanillaOpts = (componentGhcOptions normal lbi bi clbi (buildDir lbi)) |
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.
Since there is modest duplication here with existing code (which is not easy to remove, so don't) I'd like forward and backward pointers between the code, as a reminder that if someone changes one you might have to change the other.
Cabal/Distribution/Simple/Doctest.hs
Outdated
then return vanillaOpts | ||
else if withSharedLib lbi | ||
then return sharedOpts | ||
else die' verbosity $ "Must have canilla or shared lirbaries " |
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.
s/canilla/vanilla/
I'm fine with this a non-hidden command. Someone would need to find it anyway. And more visibility means more bug reports :-) I'm perfectly fine with We'll have to wait for sol/doctest#156 before merging this though. Especially as the version bump will likely lead to |
We'll now ignore |
What is the scope of this PR (I.e. what should be possible after this). Some feature creep is already happening there; without discussing the design. I'm against /just/ introducing If the lightweight support isn't possible (even simple cases doesn't work out) then lets's merge what we have to do proper RFC. @RyanGlScott will hopefully comment about problems he run into with Emmett packages |
I think I would would need to a see a test case to gauge how well I like the proposed implementation of this feature, since I can't tell from the code what this will end up looking like in practice. Also, I'd prefer the name |
@phadej, @RyanGlScott: this PR is mostly here to get this ball rolling, #2327 has been started over two years ago, and I believe there needs to be some progress. My motivation might be different from others, as I'm primarily focused on getting rid of In any case, do I believe that it should be as trivial as After giving the So what would this change for a package?
|
Note that |
So with the latest changes this is what we get (e.g. for
@RyanGlScott would this work as a test case for you? |
The inplace package-db was not passed by default, as I had initially assumed. We also no encode the requirement for doctest 0.11.3, which sports the --no-magic flag.
This seems to lack documentation and a changelog note. OK for now, since it's expected to be buggy. |
@sol, I'm a bit confused, are you saying that the current behaviour doesn't match http://cabal.readthedocs.io/en/latest/developing-packages.html#buildtoolsmap (i.e. as tools like
we could warn that a version was specified for unknown
if this is in fact the case, this sounds like a bug/regression to me cc @Ericson2314 |
I don't think the documentation is wrong. As I understand it there is merely some undocumented behavior. As an example, here are two things that you can't infer from the documentation:
I'm still not sure if that is desirable. As mentioned earlier, I could imagine that the version constraint is used by third party tools (specifically
Yes, I'm not suggesting to change anything here.
I opened #5464 for that. |
We currently don't use that version information in Nix. When we convert a Cabal file into a Nix expression, all dependencies become inputs of the build function and whoever calls that function must provide in whatever versions they deem appropriate. So the build expression itself does not know which version are legal or not; it simply tries to build whatever configuration the upper layer sets up. Now, this might change at some point in the future, but I don't think it will be any time soon. Maybe it's a good idea to have Cabal warn about the fact unsupported tools cannot be version-checked Cabal. The problem I see is that |
This adds cabal doctest logic, modelled after cabal haddock.
Resolves #2327