diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index 35e70d2..e25f543 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -34,6 +34,31 @@ jobs: strategy: matrix: include: + - compiler: ghc-9.4.2 + compilerKind: ghc + compilerVersion: 9.4.2 + setup-method: ghcup + allow-failure: false + - compiler: ghc-9.2.4 + compilerKind: ghc + compilerVersion: 9.2.4 + setup-method: ghcup + allow-failure: false + - compiler: ghc-9.0.2 + compilerKind: ghc + compilerVersion: 9.0.2 + setup-method: ghcup + allow-failure: false + - compiler: ghc-8.10.7 + compilerKind: ghc + compilerVersion: 8.10.7 + setup-method: ghcup + allow-failure: false + - compiler: ghc-8.8.4 + compilerKind: ghc + compilerVersion: 8.8.4 + setup-method: hvr-ppa + allow-failure: false - compiler: ghc-8.6.5 compilerKind: ghc compilerVersion: 8.6.5 @@ -80,13 +105,21 @@ jobs: run: | apt-get update apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5 - apt-add-repository -y 'ppa:hvr/ghc' - apt-get update - apt-get install -y "$HCNAME" - mkdir -p "$HOME/.ghcup/bin" - curl -sL https://downloads.haskell.org/ghcup/0.1.18.0/x86_64-linux-ghcup-0.1.18.0 > "$HOME/.ghcup/bin/ghcup" - chmod a+x "$HOME/.ghcup/bin/ghcup" - "$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false) + if [ "${{ matrix.setup-method }}" = ghcup ]; then + mkdir -p "$HOME/.ghcup/bin" + curl -sL https://downloads.haskell.org/ghcup/0.1.18.0/x86_64-linux-ghcup-0.1.18.0 > "$HOME/.ghcup/bin/ghcup" + chmod a+x "$HOME/.ghcup/bin/ghcup" + "$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false) + "$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false) + else + apt-add-repository -y 'ppa:hvr/ghc' + apt-get update + apt-get install -y "$HCNAME" + mkdir -p "$HOME/.ghcup/bin" + curl -sL https://downloads.haskell.org/ghcup/0.1.18.0/x86_64-linux-ghcup-0.1.18.0 > "$HOME/.ghcup/bin/ghcup" + chmod a+x "$HOME/.ghcup/bin/ghcup" + "$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false) + fi env: HCKIND: ${{ matrix.compilerKind }} HCNAME: ${{ matrix.compiler }} @@ -98,11 +131,20 @@ jobs: echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV" echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV" HCDIR=/opt/$HCKIND/$HCVER - HC=$HCDIR/bin/$HCKIND - echo "HC=$HC" >> "$GITHUB_ENV" - echo "HCPKG=$HCDIR/bin/$HCKIND-pkg" >> "$GITHUB_ENV" - echo "HADDOCK=$HCDIR/bin/haddock" >> "$GITHUB_ENV" - echo "CABAL=$HOME/.ghcup/bin/cabal-3.6.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" + if [ "${{ matrix.setup-method }}" = ghcup ]; then + HC=$HOME/.ghcup/bin/$HCKIND-$HCVER + echo "HC=$HC" >> "$GITHUB_ENV" + echo "HCPKG=$HOME/.ghcup/bin/$HCKIND-pkg-$HCVER" >> "$GITHUB_ENV" + echo "HADDOCK=$HOME/.ghcup/bin/haddock-$HCVER" >> "$GITHUB_ENV" + echo "CABAL=$HOME/.ghcup/bin/cabal-3.6.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" + else + HC=$HCDIR/bin/$HCKIND + echo "HC=$HC" >> "$GITHUB_ENV" + echo "HCPKG=$HCDIR/bin/$HCKIND-pkg" >> "$GITHUB_ENV" + echo "HADDOCK=$HCDIR/bin/haddock" >> "$GITHUB_ENV" + echo "CABAL=$HOME/.ghcup/bin/cabal-3.6.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" + fi + HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))') echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV" echo "ARG_TESTS=--enable-tests" >> "$GITHUB_ENV" diff --git a/hgettext.cabal b/hgettext.cabal index 9153765..745dd51 100644 --- a/hgettext.cabal +++ b/hgettext.cabal @@ -19,12 +19,11 @@ description: This package provides bindings to the @gettext@ internation A user-contributed tutorial can be found in the [Haskell Wiki](https://wiki.haskell.org/Internationalization_of_Haskell_programs_using_gettext). tested-with: - -- Constraint Cabal < 2.1 prevents building with GHC > 8.6 - -- GHC == 9.4.2 - -- GHC == 9.2.4 - -- GHC == 9.0.2 - -- GHC == 8.10.7 - -- GHC == 8.8.4 + GHC == 9.4.2 + GHC == 9.2.4 + GHC == 9.0.2 + GHC == 8.10.7 + GHC == 8.8.4 GHC == 8.6.5 GHC == 8.4.4 GHC == 8.2.2 @@ -48,9 +47,8 @@ library other-modules: Internal hs-source-dirs: src - build-depends: base >=4.5 && <4.13 - , Cabal >=1.14 && <1.25 || >= 2.0 && < 2.3 - -- Cabal >= 2.4 fails on matchGlobFile + build-depends: base >=4.5 && <4.18 + , Cabal >=1.14 && <1.25 || >= 2.0 && < 2.5 || >=3.0 && <3.9 , containers >=0.4.2 && <0.7 , directory >=1.1 && <1.4 , filepath >=1.3 && <1.5 diff --git a/src/Distribution/Simple/I18N/GetText.hs b/src/Distribution/Simple/I18N/GetText.hs index f2bc7c8..a095522 100644 --- a/src/Distribution/Simple/I18N/GetText.hs +++ b/src/Distribution/Simple/I18N/GetText.hs @@ -78,7 +78,7 @@ import Distribution.Simple import Distribution.Simple.InstallDirs as I import Distribution.Simple.LocalBuildInfo import Distribution.Simple.Setup -import Distribution.Simple.Utils +import Distribution.Simple.Utils (warn) import Distribution.Verbosity import Control.Arrow (second) @@ -90,7 +90,7 @@ import System.Exit import System.FilePath import System.Process -import Internal +import Internal (fromPackageName, matchFileGlob) -- | Default main function, same as -- @@ -125,11 +125,13 @@ installGetTextHooks uh = updateLocalBuildInfo :: LocalBuildInfo -> LocalBuildInfo updateLocalBuildInfo l = let sMap = getCustomFields l - [domDef, catDef] = map ($ sMap) [getDomainDefine, getMsgCatalogDefine] + domDef = getDomainDefine sMap + catDef = getMsgCatalogDefine sMap dom = getDomainNameDefault sMap (getPackageName l) tar = targetDataDir l - [catMS, domMS] = map (uncurry formatMacro) [(domDef, dom), (catDef, tar)] - in (appendCPPOptions [domMS,catMS] . appendExtension [EnableExtension CPP]) l + catMS = formatMacro domDef dom + domMS = formatMacro catDef tar + in appendCPPOptions [domMS,catMS] $ appendExtension [EnableExtension CPP] l installPOFiles :: Verbosity -> LocalBuildInfo -> IO () installPOFiles verb l = @@ -150,7 +152,7 @@ installPOFiles verb l = -- only warn for now, as the package may still be usable even if the msg catalogs are missing ExitFailure n -> warn verb ("'msgfmt' exited with non-zero status (rc = " ++ show n ++ ")") in do - filelist <- getPoFilesDefault sMap + filelist <- getPoFilesDefault verb l sMap -- copy all whose name is in the form of dir/{loc}.po to the -- destDir/{loc}/LC_MESSAGES/dom.mo -- with the 'msgfmt' tool @@ -179,8 +181,8 @@ appendCPPOptions opts l = where updBuildInfo x = x{cppOptions = updOpts (cppOptions x)} updOpts s = nub (s ++ opts) -formatMacro :: Show a => [Char] -> a -> [Char] -formatMacro name value = "-D" ++ name ++ "=" ++ (show value) +formatMacro :: Show a => String -> a -> String +formatMacro name value = "-D" ++ name ++ "=" ++ show value targetDataDir :: LocalBuildInfo -> FilePath targetDataDir l = @@ -208,10 +210,10 @@ getDomainDefine al = findInParametersDefault al "x-gettext-domain-def" "__MESSAG getMsgCatalogDefine :: [(String, String)] -> String getMsgCatalogDefine al = findInParametersDefault al "x-gettext-msg-cat-def" "__MESSAGE_CATALOG_DIR__" -getPoFilesDefault :: [(String, String)] -> IO [String] -getPoFilesDefault al = toFileList $ findInParametersDefault al "x-gettext-po-files" "" +getPoFilesDefault :: Verbosity -> LocalBuildInfo -> [(String, String)] -> IO [String] +getPoFilesDefault verb l al = toFileList $ findInParametersDefault al "x-gettext-po-files" "" where toFileList "" = return [] - toFileList x = liftM concat $ mapM matchFileGlob $ split' x + toFileList x = liftM concat $ mapM (matchFileGlob verb (localPkgDescr l)) $ split' x -- from Blow your mind (HaskellWiki) -- splits string by newline, space and comma split' x = concatMap lines $ concatMap words $ unfoldr (\b -> fmap (const . (second $ drop 1) . break (==',') $ b) . listToMaybe $ b) x diff --git a/src/Internal.hs b/src/Internal.hs index 69d3ea2..131559c 100644 --- a/src/Internal.hs +++ b/src/Internal.hs @@ -3,6 +3,14 @@ module Internal where import Distribution.Simple +#if MIN_VERSION_Cabal(2,4,0) +import Distribution.Simple.Glob (matchDirFileGlob) +import Distribution.Types.PackageDescription +#else +import qualified Distribution.Simple.Utils as Utils (matchFileGlob) +import Distribution.PackageDescription +#endif +import Distribution.Verbosity (Verbosity) fromPackageName :: PackageName -> String #if MIN_VERSION_Cabal(2,0,0) @@ -10,3 +18,11 @@ fromPackageName = unPackageName #else fromPackageName (PackageName s) = s #endif + +matchFileGlob :: Verbosity -> PackageDescription -> FilePath -> IO [FilePath] +#if MIN_VERSION_Cabal(2,4,0) +-- | Newer versions of Cabal have removed this function in favour of more configurable implementation +matchFileGlob verb descr = matchDirFileGlob verb (specVersion descr) "." +#else +matchFileGlob _ _ = Utils.matchFileGlob +#endif