refactor: update version number handling

This commit is contained in:
Simon Michael 2012-01-31 06:01:31 +00:00
parent 6b784c0e65
commit c686645fab
8 changed files with 34 additions and 56 deletions

View File

@ -65,8 +65,6 @@ HADDOCKSOURCEFILES:= \
# hledger-chart/Hledger/*hs
# hledger-chart/Hledger/*/*hs
VERSIONHS=hledger/Hledger/Cli/Version.hs
CABALFILES:= \
hledger/hledger.cabal \
hledger-*/*.cabal
@ -99,10 +97,11 @@ VERSION3:=$(VERSION)
endif
# files which should be updated when the version changes
VERSIONSENSITIVEFILES=\
$(VERSIONHS) \
$(CABALFILES) \
MANUAL.md \
# DOWNLOAD.md \
# source file which should be touched to ensure up to date version string
VERSIONHS=hledger/Hledger/Cli/Version.hs
# get an accurate binary filename from the current source on the current platform
# nb not := as that would break the makefile when hledger is not compiling.

View File

@ -27,7 +27,7 @@ import Yesod.Core
import Yesod.Json
import Hledger hiding (today)
import Hledger.Cli
import Hledger.Cli hiding (version)
import Hledger.Web.Foundation
import Hledger.Web.Options
import Hledger.Web.Settings

View File

@ -10,11 +10,13 @@ import Distribution.PackageDescription.TH (packageVariable, package, pkgName, pk
import System.Console.CmdArgs
import System.Console.CmdArgs.Explicit
import Hledger.Cli hiding (progname,progversion)
import Hledger.Cli hiding (progname,version,prognameandversion)
import Hledger.Web.Settings
progname = $(packageVariable (pkgName . package))
progversion = progname ++ " " ++ $(packageVariable (pkgVersion . package)) :: String
progname, version :: String
progname = $(packageVariable (pkgName . package))
version = $(packageVariable (pkgVersion . package))
prognameandversion = progname ++ " " ++ version :: String
defbaseurlexample = (reverse $ drop 4 $ reverse $ defbaseurl defport) ++ "PORT"
@ -28,7 +30,7 @@ webmode = (mode "hledger-web" [("command","web")]
mainargsflag []){
modeGroupFlags = Group {
groupUnnamed = webflags
,groupHidden = []
,groupHidden = [flagNone ["binary-filename"] (setboolopt "binary-filename") "show the download filename for this executable, and exit"]
,groupNamed = [(generalflagstitle, generalflags1)]
}
,modeHelpSuffix=[

View File

@ -24,7 +24,7 @@ import Yesod.Logger (makeLogger)
#endif
import Hledger
import Hledger.Cli hiding (progname,progversion)
import Hledger.Cli hiding (progname,prognameandversion)
import Prelude hiding (putStrLn)
import Hledger.Utils.UTF8 (putStrLn)
import Hledger.Web
@ -33,7 +33,7 @@ import Hledger.Web
main :: IO ()
main = do
opts <- getHledgerWebOpts
when (debug_ $ cliopts_ opts) $ printf "%s\n" progversion >> printf "opts: %s\n" (show opts)
when (debug_ $ cliopts_ opts) $ printf "%s\n" prognameandversion >> printf "opts: %s\n" (show opts)
runWith opts
runWith :: WebOpts -> IO ()
@ -41,7 +41,7 @@ runWith opts = run opts
where
run opts
| "help" `in_` (rawopts_ $ cliopts_ opts) = putStr (showModeHelp webmode) >> exitSuccess
| "version" `in_` (rawopts_ $ cliopts_ opts) = putStrLn progversion >> exitSuccess
| "version" `in_` (rawopts_ $ cliopts_ opts) = putStrLn prognameandversion >> exitSuccess
| "binary-filename" `in_` (rawopts_ $ cliopts_ opts) = putStrLn (binaryfilename progname)
| otherwise = journalFilePathFromOpts (cliopts_ opts) >>= ensureJournalFile >> withJournalDo' opts web

View File

@ -25,8 +25,8 @@ import Hledger.Utils.UTF8 (getContents)
import Hledger
import Hledger.Cli.Format
import qualified Hledger.Cli.Format as Format
import Hledger.Cli.Version
import Hledger.Cli.Options
import Hledger.Cli.Version
{- |
A set of data definitions and account-matching patterns sufficient to
@ -144,7 +144,7 @@ rulesFileFor CliOpts{rules_file_=Nothing} csvfile = replaceExtension csvfile ".r
initialRulesFileContent :: String
initialRulesFileContent =
"# csv conversion rules file generated by "++(progversionstr progname)++"\n" ++
"# csv conversion rules file generated by " ++ prognameandversion ++ "\n" ++
"# Add rules to this file for more accurate conversion, see\n"++
"# http://hledger.org/MANUAL.html#convert\n" ++
"\n" ++

View File

@ -65,12 +65,12 @@ main = do
args <- getArgs
addons <- getHledgerAddonCommands
opts <- getHledgerCliOpts addons
when (debug_ opts) $ printf "%s\n" progversion >> printf "opts: %s\n" (show opts)
when (debug_ opts) $ printf "%s\n" prognameandversion >> printf "opts: %s\n" (show opts)
run' opts addons args
where
run' opts@CliOpts{command_=cmd} addons args
-- delicate, add tests before changing (eg --version, ADDONCMD --version, INTERNALCMD --version)
| (null matchedaddon) && "version" `in_` (rawopts_ opts) = putStrLn progversion
| (null matchedaddon) && "version" `in_` (rawopts_ opts) = putStrLn prognameandversion
| (null matchedaddon) && "binary-filename" `in_` (rawopts_ opts) = putStrLn $ binaryfilename progname
| null cmd = putStr $ showModeHelp mainmode'
| cmd `isPrefixOf` "add" = showModeHelpOr addmode $ journalFilePathFromOpts opts >>= ensureJournalFile >> withJournalDo opts add

View File

@ -11,7 +11,6 @@ import Data.List
import Data.List.Split
import Data.Maybe
import Data.Time.Calendar
import Distribution.PackageDescription.TH (packageVariable, package, pkgName, pkgVersion)
import Safe
import System.Console.CmdArgs
import System.Console.CmdArgs.Explicit
@ -24,11 +23,9 @@ import Text.Printf
import Hledger
import Hledger.Cli.Format as Format
import Hledger.Cli.Version
progname = $(packageVariable (pkgName . package))
progversion = progname ++ " " ++ $(packageVariable (pkgVersion . package)) :: String
-- 1. cmdargs mode and flag definitions, for the main and subcommand modes.
-- Flag values are parsed initially to simple RawOpts to permit reuse.

View File

@ -1,61 +1,41 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE CPP, TemplateHaskell #-}
{-
Version-related utilities. See the Makefile for details of our version
numbering policy.
Version number-related utilities. See also the Makefile.
-}
module Hledger.Cli.Version (
version
,progversionstr
,binaryfilename
progname,
version,
prognameandversion,
binaryfilename
)
where
import Data.List
import Distribution.PackageDescription.TH (packageVariable, package, pkgName, pkgVersion)
import System.Info (os, arch)
import Text.Printf
import Hledger.Utils
-- version and PATCHLEVEL are set by the make process
version :: String
version = "0.16.1"
-- package name and version from the cabal file
progname, version, prognameandversion :: String
progname = $(packageVariable (pkgName . package))
version = $(packageVariable (pkgVersion . package))
prognameandversion = progname ++ " " ++ version
-- developer build version strings include PATCHLEVEL (number of
-- patches since the last tag). If defined, it must be a number.
patchlevel :: String
#ifdef PATCHLEVEL
patchlevel = "." ++ show (PATCHLEVEL :: Int) -- must be numeric !
patchlevel = "." ++ show (PATCHLEVEL :: Int)
#else
patchlevel = ""
#endif
-- the package version plus patchlevel if specified
buildversion :: String
buildversion = version ++ patchlevel :: String
-- | Given a program name, return a human-readable version string. For
-- development builds, at least non-cabal builds, the patch level (ie the
-- number of patches applied since last release tag) will also be
-- included.
progversionstr :: String -> String
progversionstr progname = progname ++ "-" ++ versionstr ++ configmsg
where
versionstr = prettify $ splitAtElement '.' buildversion
where
prettify (major:minor:bugfix:patches:[]) =
printf "%s.%s%s%s" major minor bugfix' patches'
where
bugfix'
| bugfix `elem` ["0"{-,"98","99"-}] = ""
| otherwise = '.' : bugfix
patches'
| patches/="0" = "+"++patches
| otherwise = ""
prettify s = intercalate "." s
configmsg | null buildflags = ""
| otherwise = " with " ++ intercalate ", " buildflags
buildflags = []
buildversion = version ++ patchlevel
-- | Given a program name, return a precise platform-specific executable
-- name suitable for naming downloadable binaries. Can raise an error if