[英]Haskell stack ignores -Wall -Werror cabal ghc-options flags when building
I would like to always use the "-Wall -Werror" options when building with stack (executing stack build ) but adding these flags to ghc-options in package.yaml does nothing.我想在使用堆栈构建(执行堆栈构建)时始终使用“-Wall -Werror”选项,但是将这些标志添加到 package.yaml 中的 ghc-options 没有任何作用。 I would also like to avoid passing the --pedantic flag to stack build.
我还想避免将 --pedantic 标志传递给堆栈构建。 Here's the config files:
这是配置文件:
package.yaml
...
executables:
XYZ-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -Wall
- -Werror
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- XYZ
...
XYZ.cabal
...
executable XYZ-exe
main-is: Main.hs
hs-source-dirs:
app
ghc-options: -Wall -Werror -threaded -rtsopts -with-rtsopts=-N
...
The "-Wall -Werror" flags are specified in ghc-options but as-if ignored when building. “-Wall -Werror”标志在 ghc-options 中指定,但在构建时被忽略。 This is the output for stack build :
这是堆栈构建的输出:
stack build
Building all executables for `XYZ' once. After a successful build of all of
them, only specified executables will be rebuilt.
XYZ-0.1.0.0: configure (lib + exe)
Configuring XYZ-0.1.0.0...
XYZ-0.1.0.0: build (lib + exe)
Preprocessing library for XYZ-0.1.0.0..
Building library for XYZ-0.1.0.0..
[ 1 of 105] Compiling Data.List.Extras ( src\Data\List\Extras.hs, .stack-
work\dist\e626a42b\build\Data\List\Extras.o )
... the rest is omitted, all succeed ...
And here's the output for stack build --pedantic这是堆栈构建的输出--pedantic
stack build --pedantic
Building all executables for `HStat' once. After a successful build of all of them, only specified executables will be rebuilt.
HStat-0.1.0.0: configure (lib + exe)
Configuring HStat-0.1.0.0...
HStat-0.1.0.0: build (lib + exe)
Preprocessing library for HStat-0.1.0.0..
Building library for HStat-0.1.0.0..
[ 1 of 105] Compiling Data.List.Extras ( src\Data\List\Extras.hs, .stack-work\dist\e626a42b\build\Data\List\Extras.o )
src\Data\List\Extras.hs:4:1: error: [-Wunused-imports, -Werror=unused-imports]
The import of ‘Data.Maybe’ is redundant
except perhaps to import instances from ‘Data.Maybe’
To import instances alone, use: import Data.Maybe()
|
4 | import Data.Maybe
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
This works as expected - src\\Data\\List\\Extras.hs indeed does have an unused Data.Maybe import.这按预期工作 - src\\Data\\List\\Extras.hs 确实有一个未使用的 Data.Maybe 导入。 What am I doing wrong?
我究竟做错了什么?
The ghc-options flags had to be separately defined in the library part of package.yaml: ghc-options 标志必须在 package.yaml 的库部分单独定义:
library:
source-dirs: src
ghc-options:
- -Wall
- -Werror
- -fwarn-incomplete-uni-patterns
Doing that solved the issue.这样做解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.