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

Generate version macros for preprocessors #847

Merged
merged 5 commits into from
Apr 29, 2019
Merged

Generate version macros for preprocessors #847

merged 5 commits into from
Apr 29, 2019

Conversation

aherrmann
Copy link
Member

GHC is capable of defining version macros itself. However, this does not affect the preprocessors c2hs and hsc2hs. Cabal, for example, generates its own version macros header file for these preprocessors. This PR adds this capability to rules_haskell.

Closes #821

  • Generate version macros for dependencies that define the version attribute.
  • Add version_macros field to HaskellBuildInfo.
  • Pass -include <version_macros_header> through cpp_flags as defined by cc_interop_info.
  • Add regression test for c2hs, hsc2hs, and regular Haskell files with -XCPP.
  • Remove patch to unix-compat inlining version macros. See hazel: windows: fix unix-compat #828

Copy link
Contributor

@guibou guibou left a comment

Choose a reason for hiding this comment

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

LGTM. Some nits about using f string formating if python 3.6 is available.

haskell/private/haskell_impl.bzl Show resolved Hide resolved

def cpp_ifndef(macro, body):
"""CPP ifndef block."""
return "#ifndef {macro}\n{body}\n#endif /* {macro} */".format(
Copy link
Contributor

Choose a reason for hiding this comment

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

return f"#ifndef {macro}\n{body}\n#endif /* {macro} */"

Is enough (provided that python version in >= 3.6

Copy link
Member Author

Choose a reason for hiding this comment

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

If I try that I'm getting

    return f"#ifndef {macro}\n{body}\n#endif /* {macro} */"
                                                          ^
SyntaxError: invalid syntax

despite

$ nix-shell --pure --run 'python3 --version'
Python 3.6.8

Is there some escape I'm missing?

Copy link
Contributor

Choose a reason for hiding this comment

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

Python 3.6.8 (default, Dec 24 2018, 03:01:30) 
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> macro = "hello"
>>> body = "world"
>>> f"#ifndef {macro}\n{body}\n#endif /* {macro} */"
'#ifndef hello\nworld\n#endif /* hello */'

You should be right.

Perhaps the python used by your bazel install is not a python 3.6, despite what your shell claim.

Don't waste time with this nitpick ;)

haskell/private/version_macros.py Outdated Show resolved Hide resolved
["major1", "major2", "minor"],
" \\\n".join([
"(",
" (major1) < {} ||".format(major1),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also a good place for f strisgs

f"  (major1) < {major1} ||"

...

Copy link
Member Author

Choose a reason for hiding this comment

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

Same issue here

    f"  (major1) < {major1} ||",
                              ^
SyntaxError: invalid syntax

@aherrmann
Copy link
Member Author

rebased on master

GHC is capable of defining version macros itself. However, this does not
affect the preprocessors c2hs and hsc2hs. Cabal, for example, generates
its own version macros header for these preprocessors. This change adds
this capability to rules_haskell.
Tests for version macros in
- .hs files
- .hsc files
- .chs files
unix-compat had failed to build due to missing version macros in hsc
files.
The code was repeated in haskell/private/haskell_impl.bzl and
haskell/import.bzl.
@aherrmann aherrmann merged commit 23eaaa8 into master Apr 29, 2019
@aherrmann aherrmann deleted the version_macros branch April 29, 2019 13:53
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.

Missing version macros on hsc files.
3 participants