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

Improve doctest support #342

Merged
merged 2 commits into from
Jul 18, 2018
Merged

Improve doctest support #342

merged 2 commits into from
Jul 18, 2018

Conversation

mrkkrp
Copy link
Member

@mrkkrp mrkkrp commented Jul 17, 2018

This PR redesigns the haskell_doctest rule to make it capable to do everything normal doctest test suites do. In particular now it's possible to:

  • Specify which modules to test (doctest allows that, and in fact if we always go for all modules it's not going to work because some modules may contain things that doctest doesn't like). Specifying module names is the sanest approach here because filenames of modules may change if pre-processing is involved, etc. If the modules attribute is not specified we default to testing all modules.
  • Only direct dependencies are checked, and the rule has nothing to do with aspects now.
  • cbits and hopefully all other cases are supported, approach similar to what we are doing with Haddocks is used: record important flags, then pass them to the tool that invokes GHC(i).
  • It's now possible to pass arbitrary flags to doctest executable, because that's what one can do without Bazel.

@mrkkrp mrkkrp requested review from judah and mboes July 17, 2018 07:10
@judah
Copy link
Collaborator

judah commented Jul 17, 2018

I was able to reproduce the darwin build failure on my laptop, and fix it by prefixing "-optl" to the arguments:

diff --git a/haskell/doctest.bzl b/haskell/doctest.bzl
index ee491b2..7213ae8 100644
--- a/haskell/doctest.bzl
+++ b/haskell/doctest.bzl
@@ -112,9 +112,9 @@ def _haskell_doctest_single(target, ctx):
     if not set.is_member(seen_libs, lib_name):
       set.mutable_insert(seen_libs, lib_name)
       args.add([
-        "-l{0}".format(lib_name),
+        "-optl-l{0}".format(lib_name),
         # For some reason plain -L doesn't seem to work.
-        "-L{0}".format(paths.dirname(lib.path)),
+        "-optlL{0}".format(paths.dirname(lib.path)),
       ])

Not sure whether that also works on Linux or if we need to special-case it.

@judah
Copy link
Collaborator

judah commented Jul 17, 2018

Actually, that probably should be -optl-L{0}, not -optlL{0}. Interestingly, though, if I deleted that line altogether it still worked.

@mrkkrp
Copy link
Member Author

mrkkrp commented Jul 18, 2018

Doesn't seem to work without -L. Will try -optl-L now.

@judah
Copy link
Collaborator

judah commented Jul 18, 2018

Quick clarification: the -opt-l (lower-case "l") change in the diff I posted did seem to be required in order to get the build working on Darwin.

),
"modules": attr.string_list(
doc = """List of names of modules that will be tested. If the list is
omitted, all modules provided by `deps` will be tested.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarify that this is all exposed modules provided by deps? (Assuming I'm reading the code correctly above)


Note that your toolchain must be equipped with `doctest` executable, i.e.
you should specify location of the executable using the `doctest` attribute
when you invoke `haskell_toolchain`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's now configured by doctest_toolchain rather than haskell_toolchain. (Sorry, looks like I forgot to update this doc when I made that change earlier.)

@@ -210,7 +210,7 @@ def _compilation_defaults(hs, cc, java, dep_info, srcs, extra_srcs, cpp_defines,
DefaultCompileInfo: Populated default compilation settings.
"""
args = hs.actions.args()
haddock_args = hs.actions.args()
ghc_args = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a refactoring suggestion; up to you whether it's worth it: consider moving l.272-282 below. Nearly all of args and ghc_args seem duplicated; it seems like we should be able to structure the code like:

ghc_args = []
ghc_args += ["-hide-all-packages"]
ghc_args += ...
...

args = hs.actions.args()
args.add(ghc_args)
# then add -hidir, -odir, etc to args

In theory it might even be possible to extract the computation of ghc_args into a separate function. Again, up to you whether it's worth it at this point.

@mrkkrp mrkkrp merged commit 6df346f into master Jul 18, 2018
@mrkkrp mrkkrp deleted the improve-doctest-support branch July 18, 2018 05:56
mboes added a commit that referenced this pull request Jul 18, 2018
Each PR individually was passing tests, but the combination was not.
judah added a commit that referenced this pull request Jul 26, 2018
Currently, `-c opt` will turn on optimization for all Haskell
rules with no way to disable it.  Previously, it was possible
to do so with `compiler_flags = ["-O0"]`, but that behavior was
changed in #342:
https://github.com/tweag/rules_haskell/pull/342/files#diff-33a8c46955e2a9917090b5258346aee2L247

Some Haskell packages take a *lot* of memory and a lot longer to compile with
optimizations.  So it's useful for us to be able to control this tradeoff.
judah added a commit to FormationAI/rules_haskell that referenced this pull request Jul 27, 2018
Currently, `-c opt` will turn on optimization for all Haskell
rules with no way to disable it.  Previously, it was possible
to do so with `compiler_flags = ["-O0"]`, but that behavior was
changed in tweag#342:
https://github.com/tweag/rules_haskell/pull/342/files#diff-33a8c46955e2a9917090b5258346aee2L247

Some Haskell packages take a *lot* of memory and a lot longer to compile with
optimizations.  So it's useful for us to be able to control this tradeoff.
mrkkrp pushed a commit that referenced this pull request Jul 27, 2018
* Allow rules to override -O2 with their own compiler_flags.

Currently, `-c opt` will turn on optimization for all Haskell
rules with no way to disable it.  Previously, it was possible
to do so with `compiler_flags = ["-O0"]`, but that behavior was
changed in #342:
https://github.com/tweag/rules_haskell/pull/342/files#diff-33a8c46955e2a9917090b5258346aee2L247

Some Haskell packages take a *lot* of memory and a lot longer to compile with
optimizations.  So it's useful for us to be able to control this tradeoff.
thumphries pushed a commit to thumphries/rules_haskell that referenced this pull request Jul 27, 2018
* Allow rules to override -O2 with their own compiler_flags.

Currently, `-c opt` will turn on optimization for all Haskell
rules with no way to disable it.  Previously, it was possible
to do so with `compiler_flags = ["-O0"]`, but that behavior was
changed in tweag#342:
https://github.com/tweag/rules_haskell/pull/342/files#diff-33a8c46955e2a9917090b5258346aee2L247

Some Haskell packages take a *lot* of memory and a lot longer to compile with
optimizations.  So it's useful for us to be able to control this tradeoff.
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

Successfully merging this pull request may close these issues.

2 participants