refactor: update version number handling
This commit is contained in:
parent
6b784c0e65
commit
c686645fab
5
Makefile
5
Makefile
@ -65,8 +65,6 @@ HADDOCKSOURCEFILES:= \
|
|||||||
# hledger-chart/Hledger/*hs
|
# hledger-chart/Hledger/*hs
|
||||||
# hledger-chart/Hledger/*/*hs
|
# hledger-chart/Hledger/*/*hs
|
||||||
|
|
||||||
VERSIONHS=hledger/Hledger/Cli/Version.hs
|
|
||||||
|
|
||||||
CABALFILES:= \
|
CABALFILES:= \
|
||||||
hledger/hledger.cabal \
|
hledger/hledger.cabal \
|
||||||
hledger-*/*.cabal
|
hledger-*/*.cabal
|
||||||
@ -99,10 +97,11 @@ VERSION3:=$(VERSION)
|
|||||||
endif
|
endif
|
||||||
# files which should be updated when the version changes
|
# files which should be updated when the version changes
|
||||||
VERSIONSENSITIVEFILES=\
|
VERSIONSENSITIVEFILES=\
|
||||||
$(VERSIONHS) \
|
|
||||||
$(CABALFILES) \
|
$(CABALFILES) \
|
||||||
MANUAL.md \
|
MANUAL.md \
|
||||||
# DOWNLOAD.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
|
# 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.
|
# nb not := as that would break the makefile when hledger is not compiling.
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import Yesod.Core
|
|||||||
import Yesod.Json
|
import Yesod.Json
|
||||||
|
|
||||||
import Hledger hiding (today)
|
import Hledger hiding (today)
|
||||||
import Hledger.Cli
|
import Hledger.Cli hiding (version)
|
||||||
import Hledger.Web.Foundation
|
import Hledger.Web.Foundation
|
||||||
import Hledger.Web.Options
|
import Hledger.Web.Options
|
||||||
import Hledger.Web.Settings
|
import Hledger.Web.Settings
|
||||||
|
|||||||
@ -10,11 +10,13 @@ import Distribution.PackageDescription.TH (packageVariable, package, pkgName, pk
|
|||||||
import System.Console.CmdArgs
|
import System.Console.CmdArgs
|
||||||
import System.Console.CmdArgs.Explicit
|
import System.Console.CmdArgs.Explicit
|
||||||
|
|
||||||
import Hledger.Cli hiding (progname,progversion)
|
import Hledger.Cli hiding (progname,version,prognameandversion)
|
||||||
import Hledger.Web.Settings
|
import Hledger.Web.Settings
|
||||||
|
|
||||||
|
progname, version :: String
|
||||||
progname = $(packageVariable (pkgName . package))
|
progname = $(packageVariable (pkgName . package))
|
||||||
progversion = progname ++ " " ++ $(packageVariable (pkgVersion . package)) :: String
|
version = $(packageVariable (pkgVersion . package))
|
||||||
|
prognameandversion = progname ++ " " ++ version :: String
|
||||||
|
|
||||||
defbaseurlexample = (reverse $ drop 4 $ reverse $ defbaseurl defport) ++ "PORT"
|
defbaseurlexample = (reverse $ drop 4 $ reverse $ defbaseurl defport) ++ "PORT"
|
||||||
|
|
||||||
@ -28,7 +30,7 @@ webmode = (mode "hledger-web" [("command","web")]
|
|||||||
mainargsflag []){
|
mainargsflag []){
|
||||||
modeGroupFlags = Group {
|
modeGroupFlags = Group {
|
||||||
groupUnnamed = webflags
|
groupUnnamed = webflags
|
||||||
,groupHidden = []
|
,groupHidden = [flagNone ["binary-filename"] (setboolopt "binary-filename") "show the download filename for this executable, and exit"]
|
||||||
,groupNamed = [(generalflagstitle, generalflags1)]
|
,groupNamed = [(generalflagstitle, generalflags1)]
|
||||||
}
|
}
|
||||||
,modeHelpSuffix=[
|
,modeHelpSuffix=[
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import Yesod.Logger (makeLogger)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
import Hledger
|
import Hledger
|
||||||
import Hledger.Cli hiding (progname,progversion)
|
import Hledger.Cli hiding (progname,prognameandversion)
|
||||||
import Prelude hiding (putStrLn)
|
import Prelude hiding (putStrLn)
|
||||||
import Hledger.Utils.UTF8 (putStrLn)
|
import Hledger.Utils.UTF8 (putStrLn)
|
||||||
import Hledger.Web
|
import Hledger.Web
|
||||||
@ -33,7 +33,7 @@ import Hledger.Web
|
|||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
opts <- getHledgerWebOpts
|
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 opts
|
||||||
|
|
||||||
runWith :: WebOpts -> IO ()
|
runWith :: WebOpts -> IO ()
|
||||||
@ -41,7 +41,7 @@ runWith opts = run opts
|
|||||||
where
|
where
|
||||||
run opts
|
run opts
|
||||||
| "help" `in_` (rawopts_ $ cliopts_ opts) = putStr (showModeHelp webmode) >> exitSuccess
|
| "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)
|
| "binary-filename" `in_` (rawopts_ $ cliopts_ opts) = putStrLn (binaryfilename progname)
|
||||||
| otherwise = journalFilePathFromOpts (cliopts_ opts) >>= ensureJournalFile >> withJournalDo' opts web
|
| otherwise = journalFilePathFromOpts (cliopts_ opts) >>= ensureJournalFile >> withJournalDo' opts web
|
||||||
|
|
||||||
|
|||||||
@ -25,8 +25,8 @@ import Hledger.Utils.UTF8 (getContents)
|
|||||||
import Hledger
|
import Hledger
|
||||||
import Hledger.Cli.Format
|
import Hledger.Cli.Format
|
||||||
import qualified Hledger.Cli.Format as Format
|
import qualified Hledger.Cli.Format as Format
|
||||||
import Hledger.Cli.Version
|
|
||||||
import Hledger.Cli.Options
|
import Hledger.Cli.Options
|
||||||
|
import Hledger.Cli.Version
|
||||||
|
|
||||||
{- |
|
{- |
|
||||||
A set of data definitions and account-matching patterns sufficient to
|
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 :: String
|
||||||
initialRulesFileContent =
|
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"++
|
"# Add rules to this file for more accurate conversion, see\n"++
|
||||||
"# http://hledger.org/MANUAL.html#convert\n" ++
|
"# http://hledger.org/MANUAL.html#convert\n" ++
|
||||||
"\n" ++
|
"\n" ++
|
||||||
|
|||||||
@ -65,12 +65,12 @@ main = do
|
|||||||
args <- getArgs
|
args <- getArgs
|
||||||
addons <- getHledgerAddonCommands
|
addons <- getHledgerAddonCommands
|
||||||
opts <- getHledgerCliOpts addons
|
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
|
run' opts addons args
|
||||||
where
|
where
|
||||||
run' opts@CliOpts{command_=cmd} addons args
|
run' opts@CliOpts{command_=cmd} addons args
|
||||||
-- delicate, add tests before changing (eg --version, ADDONCMD --version, INTERNALCMD --version)
|
-- 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 matchedaddon) && "binary-filename" `in_` (rawopts_ opts) = putStrLn $ binaryfilename progname
|
||||||
| null cmd = putStr $ showModeHelp mainmode'
|
| null cmd = putStr $ showModeHelp mainmode'
|
||||||
| cmd `isPrefixOf` "add" = showModeHelpOr addmode $ journalFilePathFromOpts opts >>= ensureJournalFile >> withJournalDo opts add
|
| cmd `isPrefixOf` "add" = showModeHelpOr addmode $ journalFilePathFromOpts opts >>= ensureJournalFile >> withJournalDo opts add
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import Data.List
|
|||||||
import Data.List.Split
|
import Data.List.Split
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Data.Time.Calendar
|
import Data.Time.Calendar
|
||||||
import Distribution.PackageDescription.TH (packageVariable, package, pkgName, pkgVersion)
|
|
||||||
import Safe
|
import Safe
|
||||||
import System.Console.CmdArgs
|
import System.Console.CmdArgs
|
||||||
import System.Console.CmdArgs.Explicit
|
import System.Console.CmdArgs.Explicit
|
||||||
@ -24,11 +23,9 @@ import Text.Printf
|
|||||||
|
|
||||||
import Hledger
|
import Hledger
|
||||||
import Hledger.Cli.Format as Format
|
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.
|
-- 1. cmdargs mode and flag definitions, for the main and subcommand modes.
|
||||||
-- Flag values are parsed initially to simple RawOpts to permit reuse.
|
-- Flag values are parsed initially to simple RawOpts to permit reuse.
|
||||||
|
|
||||||
|
|||||||
@ -1,61 +1,41 @@
|
|||||||
{-# LANGUAGE CPP #-}
|
{-# LANGUAGE CPP, TemplateHaskell #-}
|
||||||
{-
|
{-
|
||||||
Version-related utilities. See the Makefile for details of our version
|
Version number-related utilities. See also the Makefile.
|
||||||
numbering policy.
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module Hledger.Cli.Version (
|
module Hledger.Cli.Version (
|
||||||
version
|
progname,
|
||||||
,progversionstr
|
version,
|
||||||
,binaryfilename
|
prognameandversion,
|
||||||
|
binaryfilename
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
import Data.List
|
import Data.List
|
||||||
|
import Distribution.PackageDescription.TH (packageVariable, package, pkgName, pkgVersion)
|
||||||
import System.Info (os, arch)
|
import System.Info (os, arch)
|
||||||
import Text.Printf
|
import Text.Printf
|
||||||
|
|
||||||
import Hledger.Utils
|
import Hledger.Utils
|
||||||
|
|
||||||
|
|
||||||
-- version and PATCHLEVEL are set by the make process
|
-- package name and version from the cabal file
|
||||||
|
progname, version, prognameandversion :: String
|
||||||
version :: String
|
progname = $(packageVariable (pkgName . package))
|
||||||
version = "0.16.1"
|
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
|
patchlevel :: String
|
||||||
#ifdef PATCHLEVEL
|
#ifdef PATCHLEVEL
|
||||||
patchlevel = "." ++ show (PATCHLEVEL :: Int) -- must be numeric !
|
patchlevel = "." ++ show (PATCHLEVEL :: Int)
|
||||||
#else
|
#else
|
||||||
patchlevel = ""
|
patchlevel = ""
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
-- the package version plus patchlevel if specified
|
||||||
buildversion :: String
|
buildversion :: String
|
||||||
buildversion = version ++ patchlevel :: String
|
buildversion = version ++ patchlevel
|
||||||
|
|
||||||
-- | 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 = []
|
|
||||||
|
|
||||||
-- | Given a program name, return a precise platform-specific executable
|
-- | Given a program name, return a precise platform-specific executable
|
||||||
-- name suitable for naming downloadable binaries. Can raise an error if
|
-- name suitable for naming downloadable binaries. Can raise an error if
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user