簡體   English   中英

Haskell 堆棧在構建時忽略 -Wall -Werror cabal ghc-options 標志

[英]Haskell stack ignores -Wall -Werror cabal ghc-options flags when building

我想在使用堆棧構建(執行堆棧構建)時始終使用“-Wall -Werror”選項,但是將這些標志添加到 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 ...

這是堆棧構建的輸出--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.Maybe 導入。 我究竟做錯了什么?

ghc-options 標志必須在 package.yaml 的部分單獨定義:

library:
  source-dirs: src
  ghc-options:
  - -Wall
  - -Werror
  - -fwarn-incomplete-uni-patterns

這樣做解決了問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM