From 5de0870c516d1da4deb3007175da25b04e7516e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Had=C5=BEi=C4=87?= Date: Tue, 26 Jul 2022 10:16:43 +0200 Subject: [PATCH 01/11] Added language extensions support to the hgettext tool --- hgettext.cabal | 9 +++++---- src-exe/hgettext.hs | 11 ++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/hgettext.cabal b/hgettext.cabal index 8fa680e..a25e2f8 100644 --- a/hgettext.cabal +++ b/hgettext.cabal @@ -18,7 +18,7 @@ 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: GHC==8.2.2, GHC==8.0.2, GHC==7.10.3, GHC==7.8.4, GHC==7.6.3, GHC==7.4.2 +tested-with: GHC==8.2.2, GHC==8.0.2, GHC==8.0.1, GHC==7.10.3, GHC==7.8.4, GHC==7.6.3, GHC==7.4.2 source-repository head type: git @@ -60,8 +60,9 @@ executable hgettext , containers , filepath - build-depends: deepseq >=1.1 && <1.5 - , haskell-src-exts >=1.18 && <1.21 - , uniplate >=1.6.12 && <1.7 + build-depends: deepseq >=1.1 && <1.5 + , haskell-src-exts >=1.18 && <1.21 + , uniplate >=1.6.12 && <1.7 + , split >=0.2.3.4 && <0.2.4 ghc-options: -Wall diff --git a/src-exe/hgettext.hs b/src-exe/hgettext.hs index 085ec54..4e3f125 100644 --- a/src-exe/hgettext.hs +++ b/src-exe/hgettext.hs @@ -4,6 +4,7 @@ import Control.DeepSeq import Control.Exception import Control.Monad import Data.Generics.Uniplate.Data +import Data.List.Split (splitOn) import qualified Data.Map as Map import qualified Data.Set as Set import Data.Version (showVersion) @@ -18,6 +19,7 @@ import Paths_hgettext (version) data Options = Options { outputFile :: FilePath , keyword :: String + , extensions :: [H.Extension] , printVersion :: Bool } deriving Show @@ -32,13 +34,16 @@ options = , Option ['k'] ["keyword"] (ReqArg (\d opts -> opts {keyword = d}) "WORD") "function name, in which wrapped searched words" + , Option ['e'] ["lang-exts"] + (ReqArg (\es opts -> opts {extensions = map (\e -> H.parseExtension e) (splitOn "," es)}) "EXTENSIONS...") + "language extensions to enable/disable when parsing input (prefix \"No\" to an extension to disable it)" , Option [] ["version"] (NoArg (\opts -> opts {printVersion = True})) "print version of hgettexts" ] defaultOptions :: Options -defaultOptions = Options "messages.po" "__" False +defaultOptions = Options "messages.po" "__" [] False parseArgs :: [String] -> IO (Options, [String]) parseArgs args = @@ -116,13 +121,13 @@ process opts fl = do where readSource "-" = do c <- getContents - case H.parseFileContents c of + case H.parseFileContentsWithExts (extensions opts) c of H.ParseFailed loc msg -> do putStrLn (concat [ ":", show (H.srcLine loc), ":", show (H.srcColumn loc), ": error: ", msg ]) exitFailure H.ParseOk m -> return m readSource f = do - pm <- H.parseFile f + pm <- H.parseFileWithExts (extensions opts) f case pm of H.ParseFailed loc msg -> do putStrLn (concat [ f, ":", show (H.srcLine loc), ":", show (H.srcColumn loc), ": error: ", msg ]) From e4965a870d90d52f24134da1b8f1c15af42470c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Had=C5=BEi=C4=87?= Date: Wed, 27 Jul 2022 08:57:23 +0200 Subject: [PATCH 02/11] A more standard option value name --- src-exe/hgettext.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-exe/hgettext.hs b/src-exe/hgettext.hs index 4e3f125..f5e50ed 100644 --- a/src-exe/hgettext.hs +++ b/src-exe/hgettext.hs @@ -35,7 +35,7 @@ options = (ReqArg (\d opts -> opts {keyword = d}) "WORD") "function name, in which wrapped searched words" , Option ['e'] ["lang-exts"] - (ReqArg (\es opts -> opts {extensions = map (\e -> H.parseExtension e) (splitOn "," es)}) "EXTENSIONS...") + (ReqArg (\es opts -> opts {extensions = map (\e -> H.parseExtension e) (splitOn "," es)}) "EXTENSION...") "language extensions to enable/disable when parsing input (prefix \"No\" to an extension to disable it)" , Option [] ["version"] (NoArg (\opts -> opts {printVersion = True})) From a7ba5f7bc2624b91ddbbeeff7846947f56605c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Had=C5=BEi=C4=87?= Date: Wed, 27 Jul 2022 09:50:17 +0200 Subject: [PATCH 03/11] Added support for C pre-processing --- hgettext.cabal | 10 ++++++---- src-exe/hgettext.hs | 26 +++++++++++++++----------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/hgettext.cabal b/hgettext.cabal index a25e2f8..9e3d633 100644 --- a/hgettext.cabal +++ b/hgettext.cabal @@ -60,9 +60,11 @@ executable hgettext , containers , filepath - build-depends: deepseq >=1.1 && <1.5 - , haskell-src-exts >=1.18 && <1.21 - , uniplate >=1.6.12 && <1.7 - , split >=0.2.3.4 && <0.2.4 + build-depends: deepseq >=1.1 && <1.5 + , cpphs >=1.20.9.1 && <1.20.10 + , haskell-src-exts >=1.18 && <1.21 + , uniplate >=1.6.12 && <1.7 + , split >=0.2.3.4 && <0.2.4 + , extra >=1.7.10 && <1.8 ghc-options: -Wall diff --git a/src-exe/hgettext.hs b/src-exe/hgettext.hs index f5e50ed..6ca6184 100644 --- a/src-exe/hgettext.hs +++ b/src-exe/hgettext.hs @@ -8,11 +8,13 @@ import Data.List.Split (splitOn) import qualified Data.Map as Map import qualified Data.Set as Set import Data.Version (showVersion) +import Language.Preprocessor.Cpphs as C import qualified Language.Haskell.Exts as H import System.Console.GetOpt import System.Environment import System.Exit import System.IO (IOMode(WriteMode), hPutStr, hSetEncoding, utf8, withFile) +import System.IO.Extra (readFileUTF8) import Paths_hgettext (version) @@ -20,6 +22,8 @@ data Options = Options { outputFile :: FilePath , keyword :: String , extensions :: [H.Extension] + , cpp :: Bool + , cpp_defs :: [(String, String)] , printVersion :: Bool } deriving Show @@ -37,13 +41,19 @@ options = , Option ['e'] ["lang-exts"] (ReqArg (\es opts -> opts {extensions = map (\e -> H.parseExtension e) (splitOn "," es)}) "EXTENSION...") "language extensions to enable/disable when parsing input (prefix \"No\" to an extension to disable it)" + , Option [] ["cpp"] + (NoArg (\opts -> opts {cpp = True})) + "do the C pre-processing" + , Option [] ["cpp-defs"] + (ReqArg (\defs opts -> opts {cpp_defs = map (\def -> let l = splitOn "=" def in (head l, last l)) (splitOn "," defs)}) "IDENTIFIER=VALUE...") + "C pre-processing defines list" , Option [] ["version"] (NoArg (\opts -> opts {printVersion = True})) "print version of hgettexts" ] defaultOptions :: Options -defaultOptions = Options "messages.po" "__" [] False +defaultOptions = Options "messages.po" "__" [] False [] False parseArgs :: [String] -> IO (Options, [String]) parseArgs args = @@ -119,18 +129,12 @@ process opts fl = do writeFileUtf8 (outputFile opts) $ do writePOTFile [ formatMessage s (Set.toList locs) | (s,locs) <- Map.toList entries ] where - readSource "-" = do - c <- getContents - case H.parseFileContentsWithExts (extensions opts) c of - H.ParseFailed loc msg -> do - putStrLn (concat [ ":", show (H.srcLine loc), ":", show (H.srcColumn loc), ": error: ", msg ]) - exitFailure - H.ParseOk m -> return m readSource f = do - pm <- H.parseFileWithExts (extensions opts) f - case pm of + let rf = if f == "-" then "" else f + c <- (if f == "-" then getContents else readFileUTF8 f) >>= if cpp opts then C.runCpphs (C.defaultCpphsOptions {C.defines = cpp_defs opts}) rf else return + case H.parseFileContentsWithMode (H.defaultParseMode {H.parseFilename = rf, H.extensions = extensions opts}) c of H.ParseFailed loc msg -> do - putStrLn (concat [ f, ":", show (H.srcLine loc), ":", show (H.srcColumn loc), ": error: ", msg ]) + putStrLn (concat [ rf, ":", show (H.srcLine loc), ":", show (H.srcColumn loc), ": error: ", msg ]) exitFailure H.ParseOk m -> return m From 466d3b2b85040616e85932fb5cca6202a5863de5 Mon Sep 17 00:00:00 2001 From: Andreas Abel Date: Sat, 3 Sep 2022 22:10:58 +0200 Subject: [PATCH 04/11] Haskell-CI on GitHub for GHC 7.4 - 8.6; allow Cabal-2.2 and extra >= 0.1 Relax extra to >= 0.1 to allow building with GHC < 8 --- .github/workflows/haskell-ci.yml | 223 +++++++++++++++++++++++++++++++ .travis.yml | 100 -------------- cabal.haskell-ci | 4 + hgettext.cabal | 28 +++- 4 files changed, 249 insertions(+), 106 deletions(-) create mode 100644 .github/workflows/haskell-ci.yml delete mode 100644 .travis.yml create mode 100644 cabal.haskell-ci diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml new file mode 100644 index 0000000..35e70d2 --- /dev/null +++ b/.github/workflows/haskell-ci.yml @@ -0,0 +1,223 @@ +# This GitHub workflow config has been generated by a script via +# +# haskell-ci 'github' 'hgettext.cabal' +# +# To regenerate the script (for example after adjusting tested-with) run +# +# haskell-ci regenerate +# +# For more information, see https://github.com/haskell-CI/haskell-ci +# +# version: 0.15.20220826 +# +# REGENDATA ("0.15.20220826",["github","hgettext.cabal"]) +# +name: Haskell-CI +on: + push: + branches: + - master + - ci* + pull_request: + branches: + - master + - ci* +jobs: + linux: + name: Haskell-CI - Linux - ${{ matrix.compiler }} + runs-on: ubuntu-20.04 + timeout-minutes: + 60 + container: + image: buildpack-deps:bionic + continue-on-error: ${{ matrix.allow-failure }} + strategy: + matrix: + include: + - compiler: ghc-8.6.5 + compilerKind: ghc + compilerVersion: 8.6.5 + setup-method: hvr-ppa + allow-failure: false + - compiler: ghc-8.4.4 + compilerKind: ghc + compilerVersion: 8.4.4 + setup-method: hvr-ppa + allow-failure: false + - compiler: ghc-8.2.2 + compilerKind: ghc + compilerVersion: 8.2.2 + setup-method: hvr-ppa + allow-failure: false + - compiler: ghc-8.0.2 + compilerKind: ghc + compilerVersion: 8.0.2 + setup-method: hvr-ppa + allow-failure: false + - compiler: ghc-7.10.3 + compilerKind: ghc + compilerVersion: 7.10.3 + setup-method: hvr-ppa + allow-failure: false + - compiler: ghc-7.8.4 + compilerKind: ghc + compilerVersion: 7.8.4 + setup-method: hvr-ppa + allow-failure: false + - compiler: ghc-7.6.3 + compilerKind: ghc + compilerVersion: 7.6.3 + setup-method: hvr-ppa + allow-failure: false + - compiler: ghc-7.4.2 + compilerKind: ghc + compilerVersion: 7.4.2 + setup-method: hvr-ppa + allow-failure: false + fail-fast: false + steps: + - name: apt + 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) + env: + HCKIND: ${{ matrix.compilerKind }} + HCNAME: ${{ matrix.compiler }} + HCVER: ${{ matrix.compilerVersion }} + - name: Set PATH and environment variables + run: | + echo "$HOME/.cabal/bin" >> $GITHUB_PATH + echo "LANG=C.UTF-8" >> "$GITHUB_ENV" + 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" + 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" + echo "ARG_BENCH=--enable-benchmarks" >> "$GITHUB_ENV" + echo "HEADHACKAGE=false" >> "$GITHUB_ENV" + echo "ARG_COMPILER=--$HCKIND --with-compiler=$HC" >> "$GITHUB_ENV" + echo "GHCJSARITH=0" >> "$GITHUB_ENV" + env: + HCKIND: ${{ matrix.compilerKind }} + HCNAME: ${{ matrix.compiler }} + HCVER: ${{ matrix.compilerVersion }} + - name: env + run: | + env + - name: write cabal config + run: | + mkdir -p $CABAL_DIR + cat >> $CABAL_CONFIG <> $CABAL_CONFIG < cabal-plan.xz + echo 'de73600b1836d3f55e32d80385acc055fd97f60eaa0ab68a755302685f5d81bc cabal-plan.xz' | sha256sum -c - + xz -d < cabal-plan.xz > $HOME/.cabal/bin/cabal-plan + rm -f cabal-plan.xz + chmod a+x $HOME/.cabal/bin/cabal-plan + cabal-plan --version + - name: checkout + uses: actions/checkout@v2 + with: + path: source + - name: initial cabal.project for sdist + run: | + touch cabal.project + echo "packages: $GITHUB_WORKSPACE/source/." >> cabal.project + cat cabal.project + - name: sdist + run: | + mkdir -p sdist + $CABAL sdist all --output-dir $GITHUB_WORKSPACE/sdist + - name: unpack + run: | + mkdir -p unpacked + find sdist -maxdepth 1 -type f -name '*.tar.gz' -exec tar -C $GITHUB_WORKSPACE/unpacked -xzvf {} \; + - name: generate cabal.project + run: | + PKGDIR_hgettext="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/hgettext-[0-9.]*')" + echo "PKGDIR_hgettext=${PKGDIR_hgettext}" >> "$GITHUB_ENV" + rm -f cabal.project cabal.project.local + touch cabal.project + touch cabal.project.local + echo "packages: ${PKGDIR_hgettext}" >> cabal.project + if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo "package hgettext" >> cabal.project ; fi + if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo " ghc-options: -Werror=missing-methods" >> cabal.project ; fi + cat >> cabal.project <> cabal.project.local + cat cabal.project + cat cabal.project.local + - name: dump install plan + run: | + $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dry-run all + cabal-plan + - name: cache + uses: actions/cache@v2 + with: + key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }} + path: ~/.cabal/store + restore-keys: ${{ runner.os }}-${{ matrix.compiler }}- + - name: install dependencies + run: | + $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --dependencies-only -j2 all + $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dependencies-only -j2 all + - name: build w/o tests + run: | + $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all + - name: build + run: | + $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH all --write-ghc-environment-files=always + - name: cabal check + run: | + cd ${PKGDIR_hgettext} || false + ${CABAL} -vnormal check + - name: haddock + run: | + $CABAL v2-haddock --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all + - name: unconstrained build + run: | + rm -f cabal.project.local + $CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks all diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 969f79f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,100 +0,0 @@ -# This Travis job script has been generated by a script via -# -# make_travis_yml_2.hs 'hgettext.cabal' '-o' '.travis.yml' -# -# For more information, see https://github.com/hvr/multi-ghc-travis -# -language: c -sudo: false - -git: - submodules: false # whether to recursively clone submodules - -cache: - directories: - - $HOME/.cabal/packages - - $HOME/.cabal/store - -before_cache: - - rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log - # remove files that are regenerated by 'cabal update' - - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.* - - rm -fv $HOME/.cabal/packages/hackage.haskell.org/*.json - - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.cache - - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar - - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx - -matrix: - include: - - compiler: "ghc-7.4.2" - # env: TEST=--disable-tests BENCH=--disable-benchmarks - addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.4.2], sources: [hvr-ghc]}} - - compiler: "ghc-7.6.3" - # env: TEST=--disable-tests BENCH=--disable-benchmarks - addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.6.3], sources: [hvr-ghc]}} - - compiler: "ghc-7.8.4" - # env: TEST=--disable-tests BENCH=--disable-benchmarks - addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.8.4], sources: [hvr-ghc]}} - - compiler: "ghc-7.10.3" - # env: TEST=--disable-tests BENCH=--disable-benchmarks - addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.10.3], sources: [hvr-ghc]}} - - compiler: "ghc-8.0.2" - # env: TEST=--disable-tests BENCH=--disable-benchmarks - addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.0.2], sources: [hvr-ghc]}} - - compiler: "ghc-8.2.2" - # env: TEST=--disable-tests BENCH=--disable-benchmarks - env: INSTALLED=false - addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.2.2], sources: [hvr-ghc]}} - -before_install: - - HC=${CC} - - HCPKG=${HC/ghc/ghc-pkg} - - unset CC - - PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$PATH - -install: - - cabal --version - - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]" - - BENCH=${BENCH---enable-benchmarks} - - TEST=${TEST---enable-tests} - - HADDOCK=${HADDOCK-true} - - INSTALLED=${INSTALLED-true} - - travis_retry cabal update -v - - sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config - - rm -fv cabal.project.local - - "echo 'packages: .' > cabal.project" - - if [ -f "./configure.ac" ]; then - (cd "."; autoreconf -i); - fi - - rm -f cabal.project.freeze - - cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 all - - cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project" --dep -j2 all - - rm -rf "."/.ghc.environment.* "."/dist - - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX) - -# Here starts the actual work to be performed for the package under test; -# any command which exits with a non-zero exit code causes the build to fail. -script: - # test that source-distributions can be generated - - (cd "."; cabal sdist) - - mv "."/dist/hgettext-*.tar.gz ${DISTDIR}/ - - cd ${DISTDIR} - - find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \; - - "printf 'packages: hgettext-*/*.cabal\n' > cabal.project" - # this builds all libraries and executables (without tests/benchmarks) - - cabal new-build -w ${HC} --disable-tests --disable-benchmarks all - - # Build with installed constraints for packages in global-db - - if $INSTALLED; then - echo cabal new-build -w ${HC} --disable-tests --disable-benchmarks $(${HCPKG} list --global --simple-output --names-only | sed 's/\([a-zA-Z0-9-]\{1,\}\) */--constraint="\1 installed" /g') all | sh; - else echo "Not building with installed constraints"; fi - - # build & run tests, build benchmarks - - cabal new-build -w ${HC} ${TEST} ${BENCH} all - - # haddock - - rm -rf ./dist-newstyle - - if $HADDOCK; then cabal new-haddock -w ${HC} --disable-tests --disable-benchmarks all; else echo "Skipping haddock generation";fi - -# REGENDATA ["hgettext.cabal","-o",".travis.yml"] -# EOF diff --git a/cabal.haskell-ci b/cabal.haskell-ci new file mode 100644 index 0000000..51a36a7 --- /dev/null +++ b/cabal.haskell-ci @@ -0,0 +1,4 @@ +branches: master ci* + +-- We atm only support Cabal<=2.2.*, but GHC 8.6.5 comes with Cabal-2.4 +installed: +all -Cabal -binary -containers -process -text -unix \ No newline at end of file diff --git a/hgettext.cabal b/hgettext.cabal index 9e3d633..260810c 100644 --- a/hgettext.cabal +++ b/hgettext.cabal @@ -18,7 +18,21 @@ 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: GHC==8.2.2, GHC==8.0.2, GHC==8.0.1, GHC==7.10.3, GHC==7.8.4, GHC==7.6.3, GHC==7.4.2 +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 == 8.6.5 + GHC == 8.4.4 + GHC == 8.2.2 + GHC == 8.0.2 + GHC == 7.10.3 + GHC == 7.8.4 + GHC == 7.6.3 + GHC == 7.4.2 source-repository head type: git @@ -31,9 +45,10 @@ library other-modules: Internal hs-source-dirs: src - build-depends: base >=4.5 && <4.11 - , Cabal >=1.14 && <1.25 || == 2.0.* - , containers >=0.4.2 && <0.6 + build-depends: base >=4.5 && <4.13 + , Cabal >=1.14 && <1.25 || >= 2.0 && < 2.3 + -- Cabal >= 2.4 fails on matchGlobFile + , containers >=0.4.2 && <0.7 , directory >=1.1 && <1.4 , filepath >=1.3 && <1.5 , process >=1.1 && <1.7 @@ -62,9 +77,10 @@ executable hgettext build-depends: deepseq >=1.1 && <1.5 , cpphs >=1.20.9.1 && <1.20.10 - , haskell-src-exts >=1.18 && <1.21 + , haskell-src-exts >=1.18 && <1.24 , uniplate >=1.6.12 && <1.7 , split >=0.2.3.4 && <0.2.4 - , extra >=1.7.10 && <1.8 + , extra >=0.1 && <1.8 + -- readFileUTF8 exists since extra-0.1 ghc-options: -Wall From 0f849b87acc3cac1dd887f6e11351f11d660ac78 Mon Sep 17 00:00:00 2001 From: Andreas Abel Date: Sun, 4 Sep 2022 08:28:59 +0200 Subject: [PATCH 05/11] Bump version to 0.1.40; CHANGELOG --- CHANGELOG.md | 12 ++++++++++++ hgettext.cabal | 13 ++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d57dfcb --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +0.1.40 +====== + +_Andreas Abel, 2022-09-04_ + +The `hgettext` tool can now parse Haskell files with: +(contributions by Nikola Hadžić) +- `LANGUAGE` extensions [#19](https://github.com/haskell-hvr/hgettext/issues/19) +- CPP directives [#21](https://github.com/haskell-hvr/hgettext/issues/21) + +Tested with GHC 7.4 - 8.6. +Requires `Cabal ≤ 2.2`, thus, does not build with GHC 8.8 and above. diff --git a/hgettext.cabal b/hgettext.cabal index 260810c..9153765 100644 --- a/hgettext.cabal +++ b/hgettext.cabal @@ -1,16 +1,16 @@ cabal-version: 1.14 name: hgettext -version: 0.1.31.0 +version: 0.1.40 build-type: Simple license: BSD3 license-file: LICENSE -author: Vasyl Pasternak -maintainer: Herbert Valerio Riedel +author: Vasyl Pasternak, Herbert Valerio Riedel, Nikola Hadžić +maintainer: https://github.com/haskell-hvr/hgettext copyright: 2009 Vasyl Pasternak category: Text -bug-reports: https://github.com/hvr/hgettext/issues +bug-reports: https://github.com/haskell-hvr/hgettext/issues synopsis: Bindings to libintl.h (gettext, bindtextdomain) description: This package provides bindings to the @gettext@ internationalization and localization (i18n) library. . @@ -34,9 +34,12 @@ tested-with: GHC == 7.6.3 GHC == 7.4.2 +extra-source-files: + CHANGELOG.md + source-repository head type: git - location: https://github.com/hvr/hgettext.git + location: https://github.com/haskell-hvr/hgettext.git library default-language: Haskell2010 From 1d1a7ff531e6e212efbcf09c8eff4eee660120ab Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Tue, 11 Jan 2022 11:01:04 +0100 Subject: [PATCH 06/11] Fix build with Cabal >= 2.4 Fixes #15 --- hgettext.cabal | 5 ++--- src/Distribution/Simple/I18N/GetText.hs | 10 +++++----- src/Internal.hs | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/hgettext.cabal b/hgettext.cabal index 9153765..4c6cffc 100644 --- a/hgettext.cabal +++ b/hgettext.cabal @@ -48,9 +48,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..315495f 100644 --- a/src/Distribution/Simple/I18N/GetText.hs +++ b/src/Distribution/Simple/I18N/GetText.hs @@ -90,7 +90,7 @@ import System.Exit import System.FilePath import System.Process -import Internal +import Internal (fromPackageName, matchFileGlob) -- | Default main function, same as -- @@ -150,7 +150,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 @@ -208,10 +208,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..ac178b3 100644 --- a/src/Internal.hs +++ b/src/Internal.hs @@ -3,6 +3,13 @@ module Internal where import Distribution.Simple +#if MIN_VERSION_Cabal(2,4,0) +import Distribution.Simple.Glob (matchDirFileGlob) +import Distribution.Types.PackageDescription +import Distribution.Verbosity (Verbosity) +#else +import qualified Distribution.Simple.Utils as Utils (matchFileGlob) +#endif fromPackageName :: PackageName -> String #if MIN_VERSION_Cabal(2,0,0) @@ -10,3 +17,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 From 825f84405fe58586c249cb1229ad18aecbe32f51 Mon Sep 17 00:00:00 2001 From: Andreas Abel Date: Sun, 4 Sep 2022 08:50:49 +0200 Subject: [PATCH 07/11] Cosmetic changes, e.g. to remove incomplete-pattern warning --- src/Distribution/Simple/I18N/GetText.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Distribution/Simple/I18N/GetText.hs b/src/Distribution/Simple/I18N/GetText.hs index 315495f..d43f945 100644 --- a/src/Distribution/Simple/I18N/GetText.hs +++ b/src/Distribution/Simple/I18N/GetText.hs @@ -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 = @@ -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 = From 027e2a3b375598f20a85c1c596b16556b310eef8 Mon Sep 17 00:00:00 2001 From: Andreas Abel Date: Sun, 4 Sep 2022 08:55:39 +0200 Subject: [PATCH 08/11] Extend CI to 7.4 - 9.4 --- .github/workflows/haskell-ci.yml | 66 ++++++++++++++++++++++++++------ hgettext.cabal | 11 +++--- 2 files changed, 59 insertions(+), 18 deletions(-) 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 4c6cffc..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 From 78e82ce90d990fc69ac494054b549f89ad0ef6d9 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Tue, 6 Sep 2022 10:00:34 +0200 Subject: [PATCH 09/11] Import `Verbosity` and `PackageDescription` unconditionally --- src/Internal.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Internal.hs b/src/Internal.hs index ac178b3..a92fa16 100644 --- a/src/Internal.hs +++ b/src/Internal.hs @@ -5,11 +5,11 @@ module Internal where import Distribution.Simple #if MIN_VERSION_Cabal(2,4,0) import Distribution.Simple.Glob (matchDirFileGlob) -import Distribution.Types.PackageDescription -import Distribution.Verbosity (Verbosity) #else import qualified Distribution.Simple.Utils as Utils (matchFileGlob) #endif +import Distribution.Types.PackageDescription +import Distribution.Verbosity (Verbosity) fromPackageName :: PackageName -> String #if MIN_VERSION_Cabal(2,0,0) From bd16c19876f09c6c3e8fd9937eab4e8d52c86a95 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Wed, 7 Sep 2022 22:52:53 +0200 Subject: [PATCH 10/11] Fix compilation for GHC 8.2 / 8.4 --- src/Distribution/Simple/I18N/GetText.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Distribution/Simple/I18N/GetText.hs b/src/Distribution/Simple/I18N/GetText.hs index d43f945..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) From 86e6211def60119099d4b6585420f9aecb67063c Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Thu, 8 Sep 2022 08:23:35 +0200 Subject: [PATCH 11/11] Fix compilation for Cabal < 2.4' --- src/Internal.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Internal.hs b/src/Internal.hs index a92fa16..131559c 100644 --- a/src/Internal.hs +++ b/src/Internal.hs @@ -5,10 +5,11 @@ 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.Types.PackageDescription import Distribution.Verbosity (Verbosity) fromPackageName :: PackageName -> String