packages feed

ngx-export-distribution 0.5.1.3 → 0.5.2.0

raw patch · 5 files changed

+109/−83 lines, 5 filesdep ~parsecPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: parsec

API changes (from Hackage documentation)

Files

Changelog.md view
@@ -1,3 +1,12 @@+### 0.5.2.0++- Docs: suggest using precise direct dependencies at the configure step. This+  should fix warnings *This package indirectly depends on multiple versions of+  the same package* which used to print out very long lists of inconsistencies.+  Additionally, this seems to speed up builds when there are multiple versions+  of dependent packages in the Cabal store.+- *nhm-tool*: implement the suggestion in *nhm-tool init*.+ ### 0.5.1.3  - Refactored to avoid using *head* and *tail* as it triggers *x-partial*
LICENSE view
@@ -1,7 +1,7 @@ The following license covers this documentation, and the source code, except where otherwise indicated. -Copyright 2021-2023, Alexey Radkov. All rights reserved.+Copyright 2021-2024, Alexey Radkov. All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
NgxExport/Distribution.hs view
@@ -3,7 +3,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  NgxExport.Distribution--- Copyright   :  (c) Alexey Radkov 2021-2023+-- Copyright   :  (c) Alexey Radkov 2021-2024 -- License     :  BSD-style -- -- Maintainer  :  alexey.radkov@gmail.com@@ -133,7 +133,7 @@ -- configuration step (which will be interpreted as the prefix part of the -- /rpath/ by  /nhm-tool dist/) and explicit ghc option /-o/ at the build -- step which is as well used by /nhm-tool dist/ as the name of the target--- library.+-- library. To avoid complexity, bootstrap the project with /nhm-tool init/.  -- $cabal-v1 --@@ -222,7 +222,7 @@  -- $deps-cabal-v2 ----- Nowadays, Cabal recommends building packages using /Nix-style local builds/.+-- Nowadays, Cabal recommends building packages as /Nix-style local builds/. -- This means that dependent packages do not get installed in places known to -- GHC. However, they can be built inside GHC /package environments/. Let's -- build dependencies and put them in a package environment in the current@@ -230,27 +230,16 @@ -- -- > $ cabal install --lib --only-dependencies --package-env . --+-- This command creates both the package environment and the /build plan/. We+-- must tune the package environment by replacing existing /package-id/ records+-- with precise direct dependencies of the target library. With+-- [cabal-plan](https://hackage.haskell.org/package/cabal-plan), finding the+-- direct dependencies in the cabal build plan is easy.+-- -- > $ sed -i 's/\(^package-id \)/--\1/' .ghc.environment.x86_64-linux-$(ghc --numeric-version) -- -- This /sed/ command comments out all lines that start with word /package-id/--- in file /.ghc.environment.x86_64-linux-9.6.2/ which has been created by the--- first command. We will put all needed packages into this file after the next--- step.------ > $ ADD_CABAL_STORE=$(sed -n 's/^\(package-db\)\s\+/--\1=/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 --prefix=/var/lib/nginx------ Shell variable /$ADD_CABAL_STORE/ wraps all /package-db/ records found in the--- GHC environment file into the list of options suitable for passing to the--- /configure/ command. Normally, this list shall contain only one directory--- /$HOME\/.cabal\/store\/ghc-$(ghc --numeric-version)\/package.db/ with all--- packages ever built by /cabal v2-build/.------ Before running the /configure/ command, we commented out all packages listed--- in the GHC environment file. The build step requires linking the target--- library against the direct dependencies and their dependencies in turn. With--- [cabal-plan](https://hackage.haskell.org/package/cabal-plan), finding the--- direct dependencies in the /cabal plan/ can be done automatically.+-- in file /.ghc.environment.x86_64-linux-9.6.2/. -- -- > $ nhm-tool deps ngx-distribution-test >> .ghc.environment.x86_64-linux-$(ghc --numeric-version) --@@ -263,8 +252,19 @@ -- > package-id ngx-export-1.7.7.1-7f7a3d21f396899b6466d425218188ba097f7cc49638994748bb4e4828d9e354 -- -- will appear at the end of file /.ghc.environment.x86_64-linux-9.6.2/. This--- shall expose the four dependent packages at the next step.+-- 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))+-- > $ 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+-- GHC environment file into the list of options suitable for passing to the+-- /configure/ command. Normally, this list shall contain only one directory+-- /$HOME\/.cabal\/store\/ghc-$(ghc --numeric-version)\/package.db/ with all+-- packages ever built by /cabal v2-build/. Variable /$ADD_DIRECT_DEPS/ does+-- similar job with /package-id/ records.+-- -- > $ runhaskell --ghc-arg=-package=base --ghc-arg=-package=ngx-export-distribution Setup.hs build --ghc-options="ngx_distribution_test.hs -o ngx_distribution_test.so -threaded" -- -- This should build library /ngx_distribution_test.so/ and link it against@@ -301,6 +301,14 @@ -- With ghc older than /9.0.1/, build with -- -- > $ make LINKRTS=-lHSrts_thr-ghc$(ghc --numeric-version)+--+-- To delete intermediate build files, run+--+-- > $ make clean+--+-- or, to additionally delete the built artifact,+--+-- > $ make clean-all  -- $drawbacks --
ngx-export-distribution.cabal view
@@ -1,8 +1,8 @@ name:                       ngx-export-distribution-version:                    0.5.1.3-synopsis:                   Build custom libraries for Nginx haskell module+version:                    0.5.2.0+synopsis:                   Build custom libraries for Nginx Haskell module description:                Build custom libraries for-        <https://github.com/lyokha/nginx-haskell-module Nginx haskell module>.+        <https://github.com/lyokha/nginx-haskell-module Nginx Haskell module>. homepage:                   https://github.com/lyokha/nginx-haskell-module license:                    BSD3 license-file:               LICENSE@@ -10,7 +10,7 @@ author:                     Alexey Radkov <alexey.radkov@gmail.com> maintainer:                 Alexey Radkov <alexey.radkov@gmail.com> stability:                  experimental-copyright:                  2021-2023 Alexey Radkov+copyright:                  2021-2024 Alexey Radkov category:                   Network build-type:                 Simple cabal-version:              1.20@@ -36,9 +36,11 @@                           , containers                           , ansi-terminal                           , cabal-plan-                          , parsec+                          , parsec >= 3.0.0    main-is:                  nhm-tool.hs++  other-modules:            Paths_ngx_export_distribution    ghc-options:             -Wall 
nhm-tool.hs view
@@ -3,7 +3,7 @@  module Main where -import Text.Parsec+import Text.Parsec hiding (uncons) import Distribution.Simple.Program.Types import Distribution.Simple.Program import Distribution.Verbosity@@ -23,6 +23,8 @@ import System.FilePath import System.Exit import System.IO+import Data.Version (showVersion)+import Paths_ngx_export_distribution (version)  data DistData = DistData { distDataDir :: String                          , distDataArchive :: String@@ -63,12 +65,16 @@  data HelpSection = HelpDist | HelpDeps | HelpInit deriving Eq +progVersion :: String+progVersion = "nhm-tool " ++ showVersion version+ usage :: Maybe HelpSection -> Bool -> IO () usage section success = do     when (isNothing section) $-        putStrLn "nhm-tool: help building custom Haskell handlers for Nginx\n\-                 \this is a tool from \-                 \https://github.com/lyokha/nginx-haskell-module\n"+        putStrLn $ progVersion +++            ": help building custom Haskell handlers for Nginx,\n\+            \this is a tool from \+            \https://github.com/lyokha/nginx-haskell-module\n"     putStrLn "Usage:"     when (isNothing section || section == Just HelpDist) $         T.putStrLn $ T.concat ["\n\@@ -107,9 +113,9 @@         ]     when (isNothing section) $         T.putStrLn "\n\-        \  * nhm-tool [-h | -help | --help]\n\n\-        \    show this help message and exit, applicable in sub-commands \-        \as well"+        \  * nhm-tool [-h | -help | --help | -v | -version | --version]\n\n\+        \    show this help message or version and exit,\n\+        \    help options are applicable in sub-commands as well"     if success         then exitSuccess         else exitFailure@@ -125,22 +131,23 @@             case distData of                 Nothing -> usage (Just HelpDist) False                 Just (normalizeDistData -> distData'@DistData {..}) ->-                    if distDataHelp-                        then usage (Just HelpDist) $ length args' == 1-                        else if isJust distDataWait || null distDataTargetLib-                                 then usage (Just HelpDist) False-                                 else cmdDist distData'+                    if | distDataHelp ->+                             usage (Just HelpDist) $ length args' == 1+                       | isJust distDataWait+                         || null distDataTargetLib ->+                             usage (Just HelpDist) False+                       | otherwise -> cmdDist distData'         "deps" : args' -> do             let depsData = foldl parseDepsArg (Just defaultArgs) args'                 defaultArgs = DepsData "" False             case depsData of                 Nothing -> usage (Just HelpDeps) False                 Just depsData'@DepsData {..} ->-                    if depsDataHelp-                        then usage (Just HelpDeps) $ length args' == 1-                        else if null depsDataProject-                                 then usage (Just HelpDeps) False-                                 else cmdDeps depsData'+                    if | depsDataHelp ->+                             usage (Just HelpDeps) $ length args' == 1+                       | null depsDataProject ->+                             usage (Just HelpDeps) False+                       | otherwise -> cmdDeps depsData'         "init" : args' -> do             let initData = foldl parseInitArg (Just defaultArgs) args'                 defaultArgs = InitData defaultInitDataPrefix False False False@@ -148,15 +155,17 @@             case initData of                 Nothing -> usage (Just HelpInit) False                 Just initData'@InitData {..} ->-                    if initDataHelp-                        then usage (Just HelpInit) $ length args' == 1-                        else if isJust initDataWait || null initDataProject ||-                                    initDataForce && initDataToStdout-                                 then usage (Just HelpInit) False-                                 else cmdInit initData'-        "-h" : args' -> usage Nothing $ null args'-        "-help" : args' -> usage Nothing $ null args'-        "--help" : args' -> usage Nothing $ null args'+                    if | initDataHelp ->+                             usage (Just HelpInit) $ length args' == 1+                       | isJust initDataWait+                         || null initDataProject+                         || initDataForce && initDataToStdout ->+                             usage (Just HelpInit) False+                       | otherwise -> cmdInit initData'+        [arg] | arg `elem` ["-h", "-help", "--help"] ->+                  usage Nothing True+              | arg `elem` ["-v", "-version", "--version"] ->+                  putStrLn progVersion >> exitSuccess         args' -> usage Nothing $ null args'     where normalizeDistData dist@DistData {..} =               dist { distDataTargetDir =@@ -201,10 +210,9 @@                   | "-h" == arg || "-help" == arg || "--help" == arg ->                         Just dist' { distDataHelp = True }                   | "-" `isPrefixOf` arg -> Nothing-                  | otherwise ->-                         if null distDataTargetLib-                             then Just dist' { distDataTargetLib = arg }-                             else Nothing+                  | 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 }@@ -217,10 +225,9 @@     if | "-h" == arg || "-help" == arg || "--help" == arg ->              Just deps { depsDataHelp = True }        | "-" `isPrefixOf` arg -> Nothing-       | otherwise ->-              if null depsDataProject-                  then Just deps { depsDataProject = arg }-                  else Nothing+       | null depsDataProject ->+             Just deps { depsDataProject = arg }+       | otherwise -> Nothing  parseInitArg :: Maybe InitData -> String -> Maybe InitData parseInitArg Nothing _ = Nothing@@ -242,10 +249,9 @@                   | "-h" == arg || "-help" == arg || "--help" == arg ->                         Just init'' { initDataHelp = True }                   | "-" `isPrefixOf` arg -> Nothing-                  | otherwise ->-                         if null initDataProject-                             then Just init'' { initDataProject = arg }-                             else Nothing+                  | null initDataProject ->+                        Just init'' { initDataProject = arg }+                  | otherwise -> Nothing         Just ArgWaitP -> Just init'' { initDataPrefix = arg }         Just _ -> undefined         where init'' = init' { initDataWait = Nothing }@@ -375,7 +381,8 @@     let comps = [ uComps                 | Unit {..} <- M.elems units                 , uType == UnitTypeLocal-                , toPkgName uPId == T.pack depsDataProject+                , let uPkgName = (\(PkgId (PkgName name) _) -> name) uPId+                , uPkgName == T.pack depsDataProject                 ]     when (null comps) $ do         hPutStrLn stderr $ "Failed to find plan for " ++ depsDataProject@@ -387,7 +394,6 @@                      ) S.empty comps     forM_ (S.toList deps) $ \(UnitId unit) ->         putStrLn $ "package-id " ++ T.unpack unit-    where toPkgName (PkgId (PkgName name) _) = name  cmdInit :: InitData -> IO () cmdInit init'@InitData {..} = do@@ -490,15 +496,19 @@      \$(DISTR): $(SRC)\n\      \\tcabal install --lib --only-dependencies --package-env .\n\      \\tsed -i 's/\\(^package-id \\)/--\\1/' $(GHCENV)\n\-     \\trunhaskell --ghc-arg=-package=base \\\n\-     \\t --ghc-arg=-package=$(PKGDISTR) Setup.hs configure \\\n\-     \\t --package-db=clear --package-db=global \\\n\-     \\t $$(sed -n 's/^\\(package-db\\)\\s\\+/--\\1=/p' $(GHCENV)) \\\n\-     \\t --prefix=$(PREFIX)\n\      \\tnhm-tool deps $(PKGNAME) >> $(GHCENV)\n\      \\trunhaskell --ghc-arg=-package=base \\\n\-     \\t --ghc-arg=-package=$(PKGDISTR) Setup.hs build \\\n\-     \\t --ghc-options=\"$(SRC) -o $(LIB) $(LINKRTS)\"\n\+     \\t  --ghc-arg=-package=$(PKGDISTR) Setup.hs configure \\\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\+     \\t    `'\\(-\\([0-9]\\+\\.\\)*[0-9]\\+\\($$\\|-.*\\)\\)/'` \\\n\+     \\t    `'--dependency=\\1=\\1\\2/p' \\\n\+     \\t    $(GHCENV)) \\\n\+     \\t  --prefix=$(PREFIX)\n\+     \\trunhaskell --ghc-arg=-package=base \\\n\+     \\t  --ghc-arg=-package=$(PKGDISTR) Setup.hs build \\\n\+     \\t  --ghc-options=\"$(SRC) -o $(LIB) $(LINKRTS)\"\n\      \\n\      \install: $(DISTR)\n\      \\tinstall -d $(PREFIX)\n\@@ -519,13 +529,10 @@ projectHs InitData {..} = T.concat     ["{-# LANGUAGE TemplateHaskell #-}\n\n\      \module "-    ,T.pack $ fst $-        foldl (\(a, tr) v -> if v == '-' || v == '_'-                                 then (a, True)-                                 else if tr || null a-                                          then (a ++ [toUpper v], False)-                                          else (a ++ [v], False)-              ) ("", False) initDataProject-    , " where\n\n"+    ,T.pack $ foldr (\v -> if v == '-' || v == '_'+                               then maybe [] (uncurry $ (:) . toUpper) . uncons+                               else (v :)+                    ) "" $ '_' : initDataProject+    ," where\n\n"     ]