ngx-export-distribution 0.5.2.2 → 0.5.3.0
raw patch · 4 files changed
+79/−54 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Changelog.md +7/−0
- NgxExport/Distribution.hs +1/−1
- ngx-export-distribution.cabal +1/−1
- nhm-tool.hs +70/−52
Changelog.md view
@@ -1,3 +1,10 @@+### 0.5.3.0++- *nhm-tool*: command *deps* now accepts option *-d* which expects the+ *builddir* where the build plan is located. Command *init* now generates+ *Makefile* which builds Cabal artifacts in directory *dist-nhm*. Parsing of+ command-line arguments was refactored.+ ### 0.5.2.2 - *nhm-tool*: command *init* generates *Makefile* which searches *nhm-tool* via
NgxExport/Distribution.hs view
@@ -252,7 +252,7 @@ -- shall expose the four dependent packages at the next steps. -- -- > $ ADD_CABAL_STORE=$(sed -n 's/^\(package-db\)\s\+/--\1=/p' .ghc.environment.x86_64-linux-$(ghc --numeric-version))--- > $ ADD_DIRECT_DEPS=$(sed -n 's/^package-db\s\+\(.*\)\(-\([0-9]\+\.\)*[0-9]\+\($\|-.*\)\)/--dependency=\1=\1\2/p' .ghc.environment.x86_64-linux-$(ghc --numeric-version))+-- > $ ADD_DIRECT_DEPS=$(sed -n 's/^package-id\s\+\(.*\)\(-\([0-9]\+\.\)*[0-9]\+\($\|-.*\)\)/--dependency=\1=\1\2/p' .ghc.environment.x86_64-linux-$(ghc --numeric-version)) -- > $ runhaskell --ghc-arg=-package=base --ghc-arg=-package=ngx-export-distribution Setup.hs configure --package-db=clear --package-db=global $ADD_CABAL_STORE $ADD_DIRECT_DEPS --prefix=/var/lib/nginx -- -- Shell variable /$ADD_CABAL_STORE/ wraps all /package-db/ records found in the
ngx-export-distribution.cabal view
@@ -1,5 +1,5 @@ name: ngx-export-distribution-version: 0.5.2.2+version: 0.5.3.0 synopsis: Build custom libraries for Nginx Haskell module description: Build custom libraries for <https://github.com/lyokha/nginx-haskell-module Nginx Haskell module>.
nhm-tool.hs view
@@ -30,16 +30,18 @@ , distDataTargetDir :: String , distDataPatchOnly :: Bool , distDataTargetLib :: String- , distDataWait :: Maybe ArgWait , distDataOwnVerbosity :: Verbosity , distDataOtherVerbosity :: Verbosity+ , distDataWaitArg :: Maybe String , distDataHelp :: Bool } defaultDistDataDir :: String defaultDistDataDir = ".hslibs" -data DepsData = DepsData { depsDataProject :: String+data DepsData = DepsData { depsDataBuilddir :: String+ , depsDataProject :: String+ , depsDataWaitArg :: Maybe String , depsDataHelp :: Bool } @@ -48,15 +50,13 @@ , initDataForce :: Bool , initDataToStdout :: Bool , initDataProject :: String- , initDataWait :: Maybe ArgWait+ , initDataWaitArg :: Maybe String , initDataHelp :: Bool } defaultInitDataPrefix :: String defaultInitDataPrefix = "/var/lib/nginx" -data ArgWait = ArgWaitA | ArgWaitD | ArgWaitT | ArgWaitP- data LddRec = LibHS String (Maybe FilePath) | LibFFI String (Maybe FilePath) | LibOther String (Maybe FilePath)@@ -96,9 +96,13 @@ ] when (isNothing section || section == Just HelpDeps) $ T.putStrLn "\n\- \ * nhm-tool deps project-name\n\n\+ \ * nhm-tool deps [-d dir] project-name\n\n\ \ print all direct dependencies of 'project-name',\n\- \ the output is compatible with the format of GHC environment files"+ \ the output is compatible with the format of GHC environment \+ \files\n\n\+ \ 'dir' is the cabal build directory where the build plan is \+ \located\n\+ \ (default is dist-newstyle)" when (isNothing section || section == Just HelpInit) $ T.putStrLn $ T.concat ["\n\ \ * nhm-tool init [-p dir] [-no-threaded] [-f | -to-stdout] \@@ -126,25 +130,26 @@ "dist" : args' -> do let distData = foldl parseDistArg (Just defaultArgs) args' defaultArgs = DistData defaultDistDataDir "" "" False ""- Nothing normal normal False+ normal normal Nothing False case distData of Nothing -> usage (Just HelpDist) False Just (normalizeDistData -> distData'@DistData {..}) -> if | distDataHelp -> usage (Just HelpDist) $ length args' == 1- | isJust distDataWait+ | isJust distDataWaitArg || null distDataTargetLib -> usage (Just HelpDist) False | otherwise -> cmdDist distData' "deps" : args' -> do let depsData = foldl parseDepsArg (Just defaultArgs) args'- defaultArgs = DepsData "" False+ defaultArgs = DepsData "" "" Nothing False case depsData of Nothing -> usage (Just HelpDeps) False Just depsData'@DepsData {..} -> if | depsDataHelp -> usage (Just HelpDeps) $ length args' == 1- | null depsDataProject ->+ | isJust depsDataWaitArg+ || null depsDataProject -> usage (Just HelpDeps) False | otherwise -> cmdDeps depsData' "init" : args' -> do@@ -156,7 +161,7 @@ Just initData'@InitData {..} -> if | initDataHelp -> usage (Just HelpInit) $ length args' == 1- | isJust initDataWait+ | isJust initDataWaitArg || null initDataProject || initDataForce && initDataToStdout -> usage (Just HelpInit) False@@ -182,22 +187,21 @@ parseDistArg :: Maybe DistData -> String -> Maybe DistData parseDistArg Nothing _ = Nothing parseDistArg (Just dist@DistData {..}) arg =- case distDataWait of+ case distDataWaitArg of Nothing ->- let optLong = length arg > 2- optValue = drop 2 arg- in if | "-d" `isPrefixOf` arg ->- if optLong- then Just dist' { distDataDir = optValue }- else Just dist { distDataWait = Just ArgWaitD }- | "-t" `isPrefixOf` arg ->- if optLong- then Just dist' { distDataTargetDir = optValue }- else Just dist { distDataWait = Just ArgWaitT }- | "-a" `isPrefixOf` arg ->- if optLong- then Just dist' { distDataArchive = optValue }- else Just dist { distDataWait = Just ArgWaitA }+ let (opt, value) = splitAt 2 arg+ in if | "-d" == opt ->+ if null value+ then Just dist { distDataWaitArg = Just opt }+ else Just dist' { distDataDir = value }+ | "-t" == opt ->+ if null value+ then Just dist { distDataWaitArg = Just opt }+ else Just dist' { distDataTargetDir = value }+ | "-a" == opt ->+ if null value+ then Just dist { distDataWaitArg = Just opt }+ else Just dist' { distDataArchive = value } | "-p" == arg -> Just dist' { distDataPatchOnly = True } | "-v" == arg ->@@ -212,33 +216,42 @@ | null distDataTargetLib -> Just dist' { distDataTargetLib = arg } | otherwise -> Nothing- Just ArgWaitD -> Just dist' { distDataDir = arg }- Just ArgWaitT -> Just dist' { distDataTargetDir = arg }- Just ArgWaitA -> Just dist' { distDataArchive = arg }+ Just "-d" -> Just dist' { distDataDir = arg }+ Just "-t" -> Just dist' { distDataTargetDir = arg }+ Just "-a" -> Just dist' { distDataArchive = arg } Just _ -> undefined- where dist' = dist { distDataWait = Nothing }+ where dist' = dist { distDataWaitArg = Nothing } parseDepsArg :: Maybe DepsData -> String -> Maybe DepsData parseDepsArg Nothing _ = Nothing parseDepsArg (Just deps@DepsData {..}) arg =- if | "-h" == arg || "-help" == arg || "--help" == arg ->- Just deps { depsDataHelp = True }- | "-" `isPrefixOf` arg -> Nothing- | null depsDataProject ->- Just deps { depsDataProject = arg }- | otherwise -> Nothing+ case depsDataWaitArg of+ Nothing ->+ let (opt, value) = splitAt 2 arg+ in if | "-d" == opt ->+ if null value+ then Just deps { depsDataWaitArg = Just opt }+ else Just deps' { depsDataBuilddir = value }+ | "-h" == arg || "-help" == arg || "--help" == arg ->+ Just deps' { depsDataHelp = True }+ | "-" `isPrefixOf` arg -> Nothing+ | null depsDataProject ->+ Just deps' { depsDataProject = arg }+ | otherwise -> Nothing+ Just "-d" -> Just deps' { depsDataBuilddir = arg }+ Just _ -> undefined+ where deps' = deps { depsDataWaitArg = Nothing } parseInitArg :: Maybe InitData -> String -> Maybe InitData parseInitArg Nothing _ = Nothing parseInitArg (Just init'@InitData {..}) arg =- case initDataWait of+ case initDataWaitArg of Nothing ->- let optLong = length arg > 2- optValue = drop 2 arg- in if | "-p" `isPrefixOf` arg ->- if optLong- then Just init'' { initDataPrefix = optValue }- else Just init' { initDataWait = Just ArgWaitP }+ let (opt, value) = splitAt 2 arg+ in if | "-p" == opt ->+ if null value+ then Just init' { initDataWaitArg = Just opt }+ else Just init'' { initDataPrefix = value } | "-no-threaded" == arg -> Just init'' { initDataNoThreaded = True } | "-f" == arg ->@@ -251,9 +264,9 @@ | null initDataProject -> Just init'' { initDataProject = arg } | otherwise -> Nothing- Just ArgWaitP -> Just init'' { initDataPrefix = arg }+ Just "-p" -> Just init'' { initDataPrefix = arg } Just _ -> undefined- where init'' = init' { initDataWait = Nothing }+ where init'' = init' { initDataWaitArg = Nothing } cmdDist :: DistData -> IO () cmdDist DistData {..} = do@@ -376,7 +389,10 @@ cmdDeps :: DepsData -> IO () cmdDeps DepsData {..} = do- units <- pjUnits <$> findAndDecodePlanJson (ProjectRelativeToDir ".")+ let buildDir = if null depsDataBuilddir+ then ProjectRelativeToDir "."+ else InBuildDir depsDataBuilddir+ units <- pjUnits <$> findAndDecodePlanJson buildDir let comps = [ uComps | Unit {..} <- M.elems units , uType == UnitTypeLocal@@ -489,20 +505,21 @@ \GHCVER := $(shell ghc --numeric-version)\n\ \GHCENV := .ghc.environment.$(MACHINE)-$(KERNEL)-$(GHCVER)\n\ \DEPLIBS := $(MACHINE)-$(KERNEL)-ghc-$(GHCVER)\n\- \DISTDIR := dist\n\- \DISTV2DIR := dist-newstyle\n\+ \BUILDDIR := dist-nhm\n\ \\n\ \all: $(DISTR)\n\ \\n\ \$(DISTR): $(SRC)\n\- \\tcabal install --lib --only-dependencies --package-env .\n\+ \\tcabal install --builddir=\"$(BUILDDIR)\" --lib --only-dependencies \\\n\+ \\t --package-env .\n\ \\tsed -i 's/\\(^package-id \\)/--\\1/' $(GHCENV)\n\ \\tif ! command -v $(NHMTOOL) >/dev/null; then \\\n\ \\t PATH=$$(dirname $$(cabal list-bin $(PKGDISTR))):$$PATH; \\\n\ \\tfi; \\\n\- \\t$(NHMTOOL) deps $(PKGNAME) >> $(GHCENV); \\\n\+ \\t$(NHMTOOL) deps $(PKGNAME) -d \"$(BUILDDIR)\" >> $(GHCENV); \\\n\ \\trunhaskell --ghc-arg=-package=base \\\n\ \\t --ghc-arg=-package=$(PKGDISTR) Setup.hs configure \\\n\+ \\t --builddir=\"$(BUILDDIR)\" \\\n\ \\t --package-db=clear --package-db=global \\\n\ \\t $$(sed -n 's/^\\(package-db\\)\\s\\+/--\\1=/p' $(GHCENV)) \\\n\ \\t $$(sed -n 's/^package-id\\s\\+\\(.*\\)'` \\\n\@@ -512,6 +529,7 @@ \\t --prefix=$(PREFIX); \\\n\ \\trunhaskell --ghc-arg=-package=base \\\n\ \\t --ghc-arg=-package=$(PKGDISTR) Setup.hs build \\\n\+ \\t --builddir=\"$(BUILDDIR)\" \\\n\ \\t --ghc-options=\"$(SRC) -o $(LIB) $(LINKRTS)\"\n\ \\n\ \install: $(DISTR)\n\@@ -521,7 +539,7 @@ \.PHONY: clean\n\ \\n\ \clean:\n\- \\trm -rf $(DISTDIR) $(DISTV2DIR) $(DEPLIBS)\n\+ \\trm -rf $(BUILDDIR) $(DEPLIBS)\n\ \\trm -f $(GHCENV) $(STUB) $(NAME).hi $(NAME).o\n\ \\trm -f $(LIB)\n\ \\n\