Haskell - 带定制预处理器的包装箱包装 [英] Haskell - Packaging cabal package with custom preprocessors

查看:117
本文介绍了Haskell - 带定制预处理器的包装箱包装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一个自定义的预处理程序,它可以创建* .hs文件形式的* .tpl文件。它通过使用 Build-Type:Custom Setup.hs 中指定。一切正常,但我无法从它创建tar.gz包(使用 cabal sdist )。

I've implemented a custom preprocessor which creates *.hs files form *.tpl files. It is specified in Setup.hs by using a Build-Type: Custom. Everything works fine, but I can't create tar.gz package from it (using cabal sdist).

Cabal抱怨说,它无法找到由预处理器生成的暴露模块。错误消息是:

Cabal complains, that it can not find the exposed modules which are generated by the preprocessor. The error message is

cabal: Error: Could not find module with any
suffix: ["gc","chs","hsc","x","y","ly","cpphs","hs","lhs"]

如何让Cabal知道模块不会丢失的事实,或者可以将tpl添加到已知的文件扩展名中,或者是什么?

How can I make Cabal aware of the fact that the module is not missing, or maybe add tpl to the known file extensions, or something?

推荐答案

这是与<$ c有关的已知问题$ c> cabal sdist 。使用 ./ dist / setup / setup sdist 来代替。

下面是一个例子:

Here's an example:

$ cat preprocessor-test.cabal 
name:                preprocessor-test
version:             0.1.0.0
build-type:          Custom
cabal-version:       >=1.10
extra-source-files:  PreprocessorTest/*.prepro

library
  exposed-modules:     PreprocessorTest.PreprocessorTest
  build-depends:       base ==4.5.*
  -- hs-source-dirs:
  default-language:    Haskell2010

$ cat Setup.hs 
#!/usr/bin/env runhaskell

import Distribution.Simple
import Distribution.Simple.PreProcess
import Distribution.Simple.Utils
import Distribution.PackageDescription
import Distribution.Simple.LocalBuildInfo
import System.Cmd (rawSystem)
import System.FilePath ((</>))

main = let hooks = simpleUserHooks
           dummy = ("prepro", dummyPreprocessor)
       in defaultMainWithHooks hooks
          { hookedPreProcessors = dummy:knownSuffixHandlers  }

dummyPreprocessor :: BuildInfo -> LocalBuildInfo -> PreProcessor
dummyPreprocessor build local = PreProcessor {
  platformIndependent = True,
  runPreProcessor =
    mkSimplePreProcessor $ \inFile outFile verbosity -> do
      notice verbosity (inFile ++ " is being preprocessed to " ++ outFile)
      rawSystem "cp" [inFile, outFile]
      return ()
  }
$ cat PreprocessorTest/PreprocessorTest.prepro 
module PreprocessorTest.PreprocessorTest
       where

preprocessorTest :: Int
preprocessorTest = 1

$ cabal configure
Resolving dependencies...
[1 of 1] Compiling Main             ( Setup.hs, dist/setup/Main.o )
Linking ./dist/setup/setup ...
Configuring preprocessor-test-0.1.0.0...

$ cabal build    
Building preprocessor-test-0.1.0.0...
Preprocessing library preprocessor-test-0.1.0.0...
PreprocessorTest/PreprocessorTest.prepro is being preprocessed to
dist/build/PreprocessorTest/PreprocessorTest.hs
[1 of 1] Compiling PreprocessorTest.PreprocessorTest ( dist/build/PreprocessorTest/PreprocessorTest.hs, dist/build/PreprocessorTest/PreprocessorTest.o )
Registering preprocessor-test-0.1.0.0...

$ ./dist/setup/setup sdist
Distribution quality errors:
No 'synopsis' or 'description' field.
The 'license' field is missing or specified as AllRightsReserved.
Distribution quality warnings:
No 'category' field.
No 'maintainer' field.
Note: the public hackage server would reject this package.
Building source dist for preprocessor-test-0.1.0.0...
Preprocessing library preprocessor-test-0.1.0.0...
PreprocessorTest/PreprocessorTest.prepro is being preprocessed to
dist/src/sdist.-6767/preprocessor-test-0.1.0.0/dist/build/PreprocessorTest/PreprocessorTest.hs
Source tarball created: dist/preprocessor-test-0.1.0.0.tar.gz

$ tar tzf dist/preprocessor-test-0.1.0.0.tar.gz
preprocessor-test-0.1.0.0/
preprocessor-test-0.1.0.0/dist/
preprocessor-test-0.1.0.0/dist/build/
preprocessor-test-0.1.0.0/dist/build/PreprocessorTest/
preprocessor-test-0.1.0.0/dist/build/PreprocessorTest/PreprocessorTest.hs
preprocessor-test-0.1.0.0/Setup.hs
preprocessor-test-0.1.0.0/PreprocessorTest/
preprocessor-test-0.1.0.0/PreprocessorTest/PreprocessorTest.prepro
preprocessor-test-0.1.0.0/preprocessor-test.cabal

这篇关于Haskell - 带定制预处理器的包装箱包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆