1
可能重複:
Haskell: Correct practice to specify version in source?驚天動地預處理符號
它是沒有辦法的陰謀元數據導出到我的代碼?使用自動工具,我定義了例如configure.ac
中的程序版本,並將其作爲我的代碼的定義。在cabal中,目前,我必須在兩個地方保存程序版本 - 在.cabal和--version
。優雅的解決方案
可能重複:
Haskell: Correct practice to specify version in source?驚天動地預處理符號
它是沒有辦法的陰謀元數據導出到我的代碼?使用自動工具,我定義了例如configure.ac
中的程序版本,並將其作爲我的代碼的定義。在cabal中,目前,我必須在兩個地方保存程序版本 - 在.cabal和--version
。優雅的解決方案
讓我用shell會話回答這個問題:
~ $ 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: [email protected]]
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: [email protected]
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:陰謀生成一個名爲Paths_<pkgname>
定義常量version :: Version
模塊)
請參閱http://stackoverflow.com /問題/ 9857710 /哈斯克爾糾正實踐到指定版本,在源/ 9857861 – 2012-07-26 15:53:11