我希望在使用堆栈进行构建时始终使用“ -Wall -Werror”选项(执行 stack build ),但是将这些标志添加到package.yaml中的ghc-options不会执行任何操作。我还想避免将--pedantic标志传递给堆栈构建。这是配置文件:
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
...
“-Wall -Werror”标志在ghc-options中指定,但是在构建时被忽略。这是堆栈构建的输出:
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 ...
这是 stack build --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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
这按预期工作-src \ Data \ List \ Extras.hs确实有未使用的Data。也许可以导入。我在做什么错了?
答案 0 :(得分:2)
ghc-options标志必须在package.yaml的库部分中分别定义:
library:
source-dirs: src
ghc-options:
- -Wall
- -Werror
- -fwarn-incomplete-uni-patterns
这样做可以解决问题。