-
Notifications
You must be signed in to change notification settings - Fork 80
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
Conversation
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.
LGTM. Some nits about using f string formating if python 3.6 is available.
|
||
def cpp_ifndef(macro, body): | ||
"""CPP ifndef block.""" | ||
return "#ifndef {macro}\n{body}\n#endif /* {macro} */".format( |
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.
return f"#ifndef {macro}\n{body}\n#endif /* {macro} */"
Is enough (provided that python version in >= 3.6
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.
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?
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.
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 ;)
["major1", "major2", "minor"], | ||
" \\\n".join([ | ||
"(", | ||
" (major1) < {} ||".format(major1), |
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 also a good place for f strisgs
f" (major1) < {major1} ||"
...
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.
Same issue here
f" (major1) < {major1} ||",
^
SyntaxError: invalid syntax
6ca0da1
to
5357ca8
Compare
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.
5357ca8
to
bf77c14
Compare
GHC is capable of defining version macros itself. However, this does not affect the preprocessors
c2hs
andhsc2hs
. Cabal, for example, generates its own version macros header file for these preprocessors. This PR adds this capability to rules_haskell.Closes #821
version
attribute.version_macros
field toHaskellBuildInfo
.-include <version_macros_header>
throughcpp_flags
as defined bycc_interop_info
.c2hs
,hsc2hs
, and regular Haskell files with-XCPP
.unix-compat
inlining version macros. See hazel: windows: fix unix-compat #828