-
Notifications
You must be signed in to change notification settings - Fork 103
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
Add more documentation to declaring conditionals. #141
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,6 +134,49 @@ becomes | |
extra-lib-dirs: | ||
lib/darwin | ||
|
||
Multiple conditionals must fall under one `when`, for example: | ||
|
||
when: | ||
- condition: os(darwin) | ||
extra-lib-dirs: lib/darwin | ||
- condition: os(linux) | ||
extra-lib-dirs: /usr/lib/x64 | ||
|
||
becomes | ||
|
||
if os(darwin) | ||
extra-lib-dirs: | ||
lib/darwin | ||
if os(linux) | ||
extra-lib-dirs: | ||
/usr/lib/x64 | ||
|
||
If conditionals are declared under different `when` clauses only the last one | ||
will make it to the `.cabal` file: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it may not necessarily be the last one. This is again resulting from how YAML works. This is an object (think of it as a hash map), duplicate keys are not allowed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right that this behaviour is on the YAML side of things (and is actually wrong according to the spec: http://yaml.org/spec/1.1/#id932806), but I find it very useful that it behaves as it does, and would actually propose to add tests for this behaviour and file bug reports to https://hackage.haskell.org/package/yaml if the behaviour ever changes. Here are two examples why: Aliases with overriding:
Predefined aliases:
The second example is a massive hack, but I'm not aware of any other way to do this given that hpack insists on printing warnings for unused fields even if I prefix them with underscores. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @liskin Hey, interesting! How about we don't emit warnings for unknown top-level field that starts with an underscore? That way you can use fields that start with underscores for building kind of a I would certainly accept a patch. So if you think thats the way to go, then feel free to open a PR! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you go: #146 :-) |
||
|
||
when: | ||
- condition: os(darwin) | ||
extra-lib-dirs: lib/darwin | ||
when: | ||
- condition: os(linux) | ||
extra-lib-dirs: /usr/lib/x64 | ||
|
||
becomes: | ||
|
||
if os(linux) | ||
extra-lib-dirs: | ||
/usr/lib/x64 | ||
|
||
Unlike with `.cabal` files compound predicates need to be in parens, for example: | ||
|
||
when: | ||
- condition: (!os(darwin) && !os(windows)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the issue here is not that you have a "compound predicate" here. It's merely the
|
||
ghc-options: ... | ||
|
||
If they are not the YAML parser will throw this mysterious error: | ||
|
||
./package.yaml:41:31: did not find expected alphabetic or numeric character while scanning an anchor | ||
|
||
Conditionals with an else branch: | ||
|
||
- Must have a `condition` field | ||
|
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.
Minor note generally, but cabal library converts Darwin to osx