Cabal依赖于当前软件包库的其他可执行文件?

时间:2019-07-13 18:29:40

标签: haskell cabal

这是我当前的阴谋文件的简化版本:

cabal-version: 1.12
name:           app
version:        0.1.0.0
author:         CabalSaneDefault
maintainer:     nobody
license:        BSD3
license-file:   LICENSE
build-type:     Simple
extra-source-files:
    ChangeLog.md

library
  other-modules:
      Paths_app
  default-extensions: LambdaCase
  build-depends:
      HUnit
    , QuickCheck
    , aeson
    , aeson-pretty
  default-language: Haskell2010

executable app
  main-is: Main.hs
  other-modules:
      AdminSettings
      App
      App404
      AppAdmin
      AppAdminGalleryImage
      AppAdminSinglePage
  hs-source-dirs:
      src
  default-extensions: LambdaCase
  ghc-options: -Wall -O2
  build-depends:
      HUnit
    , QuickCheck
    , aeson
    , aeson-pretty
  default-language: Haskell2010

executable app-test
  main-is: Test.hs
  other-modules:
      Paths_app
  hs-source-dirs:
      src-test
  default-extensions: LambdaCase
  ghc-options: -Wall -O2
  build-depends:
      HUnit
    , QuickCheck
    , aeson
    , aeson-pretty
    , app
  default-language: Haskell2010

本质上是一个库app,它同时定义了可执行文件app和库。我定义了另一个app-test可执行文件,并添加了app作为依赖项。但是,在运行app-test“可执行文件”(通过cabal v2-repl app-test / GHCi)时,如果我尝试导入模块,它将找不到它:

src-test/Test.hs:10:1: error:
    Could not find module ‘Routes’
    Perhaps you meant Rules (needs flag -package-key ghc-8.6.4)
    Use -v to see a list of the files searched for.
   |
10 | import Routes
   | ^^^^^^^^^^^^^

这可能吗?

1 个答案:

答案 0 :(得分:-1)

我正在使用hpack生成阴谋文件,但未指定source-dirs目录:

library: 
  ghc-options: -Wall
  source-dirs: src

随后会生成以下内容的合适的阴谋:

library
  exposed-modules:
      AdminSettings
      App
      App404
      AppAdmin
      AppAdminGalleryImage
      ...
  other-modules:
      Paths_app
  hs-source-dirs:
      src
  default-extensions: LambdaCase
  ghc-options: -Wall
  build-depends:
      HUnit
    , QuickCheck
    , aeson
    , aeson-pretty