1

重複の可能性:
Haskell:ソースでバージョンを指定する正しい方法は?

Cabal メタデータをコードにエクスポートする方法はありますか? autotools を使用して、たとえば、プログラムのバージョンをconfigure.ac定義し、それを自分のコードの定義として取得します。cabal では、現在、プログラムのバージョンを .cabal と の 2 か所で管理する必要があり--versionます。エレガントなソリューションはありますか?

4

1 に答える 1

1

シェルセッションでこれに答えさせてください:

~ $ cd /tmp/
/tmp $ mkdir test
/tmp $ cd test/
/tmp/test $ cabal init
Package name? [default: test] 
Package version? [default: 0.1.0.0] 
Please choose a license:
 * 1) (none)
   2) GPL-2
   3) GPL-3
   4) LGPL-2.1
   5) LGPL-3
   6) BSD3
   7) MIT
   8) PublicDomain
   9) AllRightsReserved
  10) Other (specify)
Your choice? [default: (none)] 
Author name? [default: Joachim Breitner] 
Maintainer email? [default: mail@joachim-breitner.de] 
Project homepage URL? 
Project synopsis? 
Project category:
 * 1) (none)
   2) Codec
   3) Concurrency
   4) Control
   5) Data
   6) Database
   7) Development
   8) Distribution
   9) Game
  10) Graphics
  11) Language
  12) Math
  13) Network
  14) Sound
  15) System
  16) Testing
  17) Text
  18) Web
  19) Other (specify)
Your choice? [default: (none)] 
What does the package build:
   1) Library
   2) Executable
Your choice? 2
Include documentation on what each field means (y/n)? [default: n] 

Guessing dependencies...

Generating LICENSE...
Warning: unknown license type, you must put a copy in LICENSE yourself.
Generating Setup.hs...
Generating test.cabal...

Warning: no synopsis given. You should edit the .cabal file and add one.
You may want to edit the .cabal file and add a Description field.
/tmp/test $ vim *.cabal
/tmp/test $ cat *.cabal
name:                test
version:             0.1.0.0
license-file:        LICENSE
author:              Joachim Breitner
maintainer:          mail@joachim-breitner.de
build-type:          Simple
cabal-version:       >=1.8

executable test
  main-is: Main.hs
  build-depends:       base ==4.5.*

/tmp/test $ echo 'main = return ()' > Main.hs
/tmp/test $ cabal configure && cabal build
Resolving dependencies...
Configuring test-0.1.0.0...
Warning: The 'license-file' field refers to the file 'LICENSE' which does not
exist.
Building test-0.1.0.0...
Preprocessing executable 'test' for test-0.1.0.0...
[1 of 1] Compiling Main             ( Main.hs, dist/build/test/test-tmp/Main.o )
Linking dist/build/test/test ...
/tmp/test $ find dist/
dist/
dist/package.conf.inplace
dist/setup-config
dist/build
dist/build/autogen
dist/build/autogen/Paths_test.hs
dist/build/autogen/cabal_macros.h
dist/build/test
dist/build/test/test-tmp
dist/build/test/test-tmp/Main.o
dist/build/test/test-tmp/Main.hi
dist/build/test/test
/tmp/test $ grep -i version dist/build/autogen/Paths_test.hs
    version,
import Data.Version (Version(..))
version :: Version
version = Version {versionBranch = [0,1,0,0], versionTags = []}
/tmp/test $ echo 'import Paths_test' > Main.hs
/tmp/test $ echo 'main = print version' >> Main.hs
/tmp/test $ cabal build
Building test-0.1.0.0...
Preprocessing executable 'test' for test-0.1.0.0...
[1 of 2] Compiling Paths_test       ( dist/build/autogen/Paths_test.hs, dist/build/test/test-tmp/Paths_test.o )
[2 of 2] Compiling Main             ( Main.hs, dist/build/test/test-tmp/Main.o )
Linking dist/build/test/test ...
/tmp/test $ ./dist/build/test/test
Version {versionBranch = [0,1,0,0], versionTags = []}

(TL; DR:cabalPaths_<pkgname>は、定数を定義するというモジュールを生成しますversion :: Version。)

于 2012-07-26T18:29:43.060 に答える