From 3b7c8cc869d389748d2dd61e938de7a7644571fd Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Tue, 19 Feb 2019 23:44:12 +0200 Subject: [PATCH] Add copy-fields setting --- .travis.yml | 4 +- fixtures/cabal.project.copy-fields.all | 15 ++ fixtures/cabal.project.copy-fields.all.stderr | 1 + .../cabal.project.copy-fields.all.travis.yml | 180 ++++++++++++++++++ fixtures/cabal.project.copy-fields.none | 15 ++ .../cabal.project.copy-fields.none.stderr | 1 + .../cabal.project.copy-fields.none.travis.yml | 170 +++++++++++++++++ fixtures/cabal.project.copy-fields.some | 15 ++ .../cabal.project.copy-fields.some.stderr | 1 + .../cabal.project.copy-fields.some.travis.yml | 176 +++++++++++++++++ fixtures/cabal.project.empty-line.travis.yml | 4 +- haskell-ci.cabal | 35 ++-- src/HaskellCI.hs | 80 ++++---- src/HaskellCI/Config.hs | 9 +- src/HaskellCI/Config/CopyFields.hs | 32 ++++ src/HaskellCI/Project.hs | 23 ++- test/Tests.hs | 5 + 17 files changed, 708 insertions(+), 58 deletions(-) create mode 100644 fixtures/cabal.project.copy-fields.all create mode 100644 fixtures/cabal.project.copy-fields.all.stderr create mode 100644 fixtures/cabal.project.copy-fields.all.travis.yml create mode 100644 fixtures/cabal.project.copy-fields.none create mode 100644 fixtures/cabal.project.copy-fields.none.stderr create mode 100644 fixtures/cabal.project.copy-fields.none.travis.yml create mode 100644 fixtures/cabal.project.copy-fields.some create mode 100644 fixtures/cabal.project.copy-fields.some.stderr create mode 100644 fixtures/cabal.project.copy-fields.some.travis.yml create mode 100644 src/HaskellCI/Config/CopyFields.hs diff --git a/.travis.yml b/.travis.yml index c4bcfcd6..679d818c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -97,9 +97,9 @@ install: - rm -f cabal.project - touch cabal.project - "printf 'packages: \".\"\\n' >> cabal.project" - - "printf 'write-ghc-environment-files: always\\n' >> cabal.project" - echo 'package haskell-ci' >> cabal.project - "echo ' ghc-options: -Werror' >> cabal.project" + - "printf 'write-ghc-environment-files: always\\n' >> cabal.project" - "echo 'keep-going: False' >> cabal.project" - echo 'package bytestring' >> cabal.project - "echo ' tests: False' >> cabal.project" @@ -128,9 +128,9 @@ script: - rm -f cabal.project - touch cabal.project - "printf 'packages: \"haskell-ci-*/*.cabal\"\\n' >> cabal.project" - - "printf 'write-ghc-environment-files: always\\n' >> cabal.project" - echo 'package haskell-ci' >> cabal.project - "echo ' ghc-options: -Werror' >> cabal.project" + - "printf 'write-ghc-environment-files: always\\n' >> cabal.project" - "echo 'keep-going: False' >> cabal.project" - echo 'package bytestring' >> cabal.project - "echo ' tests: False' >> cabal.project" diff --git a/fixtures/cabal.project.copy-fields.all b/fixtures/cabal.project.copy-fields.all new file mode 100644 index 00000000..3e8ac267 --- /dev/null +++ b/fixtures/cabal.project.copy-fields.all @@ -0,0 +1,15 @@ +packages: + servant/ + servant-client/ + servant-docs/ + servant-server/ + +package servant + tests: False + +constraints: foundation >= 0.14 + +allow-newer: + servant-js:servant +allow-newer: + servant-js:servant-foreign diff --git a/fixtures/cabal.project.copy-fields.all.stderr b/fixtures/cabal.project.copy-fields.all.stderr new file mode 100644 index 00000000..79f80914 --- /dev/null +++ b/fixtures/cabal.project.copy-fields.all.stderr @@ -0,0 +1 @@ +*INFO* Generating Travis-CI config for testing for GHC versions: 7.8.1 7.8.2 7.8.3 7.8.4 7.10.1 7.10.2 7.10.3 8.0.1 8.0.2 8.2.1 8.2.2 8.4.1 8.4.2 8.4.3 8.4.4 8.6.1 8.6.2 8.6.3 diff --git a/fixtures/cabal.project.copy-fields.all.travis.yml b/fixtures/cabal.project.copy-fields.all.travis.yml new file mode 100644 index 00000000..aee9074a --- /dev/null +++ b/fixtures/cabal.project.copy-fields.all.travis.yml @@ -0,0 +1,180 @@ +# This Travis job script has been generated by a script via +# +# haskell-ci '-o' 'cabal.project.empty-line.travis.yml' '--copy-fields=all' 'cabal.project.empty-line' +# +# For more information, see https://github.com/haskell-CI/haskell-ci +# +language: c +dist: xenial + +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 + + - rm -rfv $HOME/.cabal/packages/head.hackage + +matrix: + include: + - compiler: "ghc-8.6.3" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.3], sources: [hvr-ghc]}} + - compiler: "ghc-8.6.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.2], sources: [hvr-ghc]}} + - compiler: "ghc-8.6.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.1], sources: [hvr-ghc]}} + - compiler: "ghc-8.4.4" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.4], sources: [hvr-ghc]}} + - compiler: "ghc-8.4.3" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.3], sources: [hvr-ghc]}} + - compiler: "ghc-8.4.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.2], sources: [hvr-ghc]}} + - compiler: "ghc-8.4.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.1], sources: [hvr-ghc]}} + - compiler: "ghc-8.2.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.2.2], sources: [hvr-ghc]}} + - compiler: "ghc-8.2.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.2.1], sources: [hvr-ghc]}} + - compiler: "ghc-8.0.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.0.2], sources: [hvr-ghc]}} + - compiler: "ghc-8.0.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.0.1], sources: [hvr-ghc]}} + - compiler: "ghc-7.10.3" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.10.3], sources: [hvr-ghc]}} + - compiler: "ghc-7.10.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.10.2], sources: [hvr-ghc]}} + - compiler: "ghc-7.10.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.10.1], sources: [hvr-ghc]}} + - compiler: "ghc-7.8.4" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.8.4], sources: [hvr-ghc]}} + - compiler: "ghc-7.8.3" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.8.3], sources: [hvr-ghc]}} + - compiler: "ghc-7.8.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.8.2], sources: [hvr-ghc]}} + - compiler: "ghc-7.8.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.8.1], sources: [hvr-ghc]}} + +before_install: + - HC=${CC} + - HCPKG=${HC/ghc/ghc-pkg} + - unset CC + - ROOTDIR=$(pwd) + - mkdir -p $HOME/.local/bin + - "PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$HOME/local/bin:$PATH" + - HCNUMVER=$(( $(${HC} --numeric-version|sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1 * 10000 + \2 * 100 + \3/') )) + - echo $HCNUMVER + +install: + - cabal --version + - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]" + - BENCH=${BENCH---enable-benchmarks} + - TEST=${TEST---enable-tests} + - UNCONSTRAINED=${UNCONSTRAINED-true} + - GHCHEAD=${GHCHEAD-false} + - travis_retry cabal update -v + - "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config" + - rm -fv cabal.project cabal.project.local + - grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$' + - rm -f cabal.project + - touch cabal.project + - "printf 'packages: \"servant\"\\n' >> cabal.project" + - "printf 'packages: \"servant-client\"\\n' >> cabal.project" + - "printf 'packages: \"servant-docs\"\\n' >> cabal.project" + - "printf 'packages: \"servant-server\"\\n' >> cabal.project" + - echo 'package servant' >> cabal.project + - "echo ' tests: False' >> cabal.project" + - "echo 'constraints: foundation >= 0.14' >> cabal.project" + - "echo 'allow-newer: servant-js:servant' >> cabal.project" + - "echo 'allow-newer: servant-js:servant-foreign' >> cabal.project" + - "printf 'write-ghc-environment-files: always\\n' >> cabal.project" + - touch cabal.project.local + - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(servant|servant-client|servant-docs|servant-server)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done" + - cat cabal.project || true + - cat cabal.project.local || true + - if [ -f "servant/configure.ac" ]; then (cd "servant" && autoreconf -i); fi + - if [ -f "servant-client/configure.ac" ]; then (cd "servant-client" && autoreconf -i); fi + - if [ -f "servant-docs/configure.ac" ]; then (cd "servant-docs" && autoreconf -i); fi + - if [ -f "servant-server/configure.ac" ]; then (cd "servant-server" && autoreconf -i); fi + - rm -f cabal.project.freeze + - cabal new-freeze -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project.copy-fields.all" --dry + - "cat \"cabal.project.copy-fields.all.freeze\" | sed -E 's/^(constraints: *| *)//' | sed 's/any.//'" + - rm "cabal.project.copy-fields.all.freeze" + - cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project.copy-fields.all" --dep -j2 all + - cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project.copy-fields.all" --dep -j2 all + - rm -rf .ghc.environment.* "servant"/dist "servant-client"/dist "servant-docs"/dist "servant-server"/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 + - cabal new-sdist all + - mv dist-newstyle/sdist/*.tar.gz ${DISTDIR}/ + - cd ${DISTDIR} || false + - find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \; + - rm -f cabal.project + - touch cabal.project + - "printf 'packages: \"servant-*/*.cabal\"\\n' >> cabal.project" + - "printf 'packages: \"servant-client-*/*.cabal\"\\n' >> cabal.project" + - "printf 'packages: \"servant-docs-*/*.cabal\"\\n' >> cabal.project" + - "printf 'packages: \"servant-server-*/*.cabal\"\\n' >> cabal.project" + - echo 'package servant' >> cabal.project + - "echo ' tests: False' >> cabal.project" + - "echo 'constraints: foundation >= 0.14' >> cabal.project" + - "echo 'allow-newer: servant-js:servant' >> cabal.project" + - "echo 'allow-newer: servant-js:servant-foreign' >> cabal.project" + - "printf 'write-ghc-environment-files: always\\n' >> cabal.project" + - touch cabal.project.local + - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(servant|servant-client|servant-docs|servant-server)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done" + - cat cabal.project || true + - cat cabal.project.local || true + # this builds all libraries and executables (without tests/benchmarks) + - cabal new-build -w ${HC} --disable-tests --disable-benchmarks all + + # build & run tests, build benchmarks + - cabal new-build -w ${HC} ${TEST} ${BENCH} all + - if [ "x$TEST" = "x--enable-tests" ]; then cabal new-test -w ${HC} ${TEST} ${BENCH} all; fi + + # cabal check + - (cd servant-* && cabal check) + - (cd servant-client-* && cabal check) + - (cd servant-docs-* && cabal check) + - (cd servant-server-* && cabal check) + + # haddock + - cabal new-haddock -w ${HC} ${TEST} ${BENCH} all + + # Build without installed constraints for packages in global-db + - if $UNCONSTRAINED; then rm -f cabal.project.local; cabal new-build -w ${HC} --disable-tests --disable-benchmarks all; else echo "Not building without installed constraints"; fi + +# REGENDATA ["-o","cabal.project.empty-line.travis.yml","--copy-fields=all","cabal.project.empty-line"] +# EOF diff --git a/fixtures/cabal.project.copy-fields.none b/fixtures/cabal.project.copy-fields.none new file mode 100644 index 00000000..3e8ac267 --- /dev/null +++ b/fixtures/cabal.project.copy-fields.none @@ -0,0 +1,15 @@ +packages: + servant/ + servant-client/ + servant-docs/ + servant-server/ + +package servant + tests: False + +constraints: foundation >= 0.14 + +allow-newer: + servant-js:servant +allow-newer: + servant-js:servant-foreign diff --git a/fixtures/cabal.project.copy-fields.none.stderr b/fixtures/cabal.project.copy-fields.none.stderr new file mode 100644 index 00000000..79f80914 --- /dev/null +++ b/fixtures/cabal.project.copy-fields.none.stderr @@ -0,0 +1 @@ +*INFO* Generating Travis-CI config for testing for GHC versions: 7.8.1 7.8.2 7.8.3 7.8.4 7.10.1 7.10.2 7.10.3 8.0.1 8.0.2 8.2.1 8.2.2 8.4.1 8.4.2 8.4.3 8.4.4 8.6.1 8.6.2 8.6.3 diff --git a/fixtures/cabal.project.copy-fields.none.travis.yml b/fixtures/cabal.project.copy-fields.none.travis.yml new file mode 100644 index 00000000..12a5a60c --- /dev/null +++ b/fixtures/cabal.project.copy-fields.none.travis.yml @@ -0,0 +1,170 @@ +# This Travis job script has been generated by a script via +# +# haskell-ci '-o' 'cabal.project.empty-line.travis.yml' '--copy-fields=none' 'cabal.project.empty-line' +# +# For more information, see https://github.com/haskell-CI/haskell-ci +# +language: c +dist: xenial + +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 + + - rm -rfv $HOME/.cabal/packages/head.hackage + +matrix: + include: + - compiler: "ghc-8.6.3" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.3], sources: [hvr-ghc]}} + - compiler: "ghc-8.6.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.2], sources: [hvr-ghc]}} + - compiler: "ghc-8.6.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.1], sources: [hvr-ghc]}} + - compiler: "ghc-8.4.4" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.4], sources: [hvr-ghc]}} + - compiler: "ghc-8.4.3" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.3], sources: [hvr-ghc]}} + - compiler: "ghc-8.4.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.2], sources: [hvr-ghc]}} + - compiler: "ghc-8.4.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.1], sources: [hvr-ghc]}} + - compiler: "ghc-8.2.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.2.2], sources: [hvr-ghc]}} + - compiler: "ghc-8.2.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.2.1], sources: [hvr-ghc]}} + - compiler: "ghc-8.0.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.0.2], sources: [hvr-ghc]}} + - compiler: "ghc-8.0.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.0.1], sources: [hvr-ghc]}} + - compiler: "ghc-7.10.3" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.10.3], sources: [hvr-ghc]}} + - compiler: "ghc-7.10.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.10.2], sources: [hvr-ghc]}} + - compiler: "ghc-7.10.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.10.1], sources: [hvr-ghc]}} + - compiler: "ghc-7.8.4" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.8.4], sources: [hvr-ghc]}} + - compiler: "ghc-7.8.3" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.8.3], sources: [hvr-ghc]}} + - compiler: "ghc-7.8.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.8.2], sources: [hvr-ghc]}} + - compiler: "ghc-7.8.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.8.1], sources: [hvr-ghc]}} + +before_install: + - HC=${CC} + - HCPKG=${HC/ghc/ghc-pkg} + - unset CC + - ROOTDIR=$(pwd) + - mkdir -p $HOME/.local/bin + - "PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$HOME/local/bin:$PATH" + - HCNUMVER=$(( $(${HC} --numeric-version|sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1 * 10000 + \2 * 100 + \3/') )) + - echo $HCNUMVER + +install: + - cabal --version + - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]" + - BENCH=${BENCH---enable-benchmarks} + - TEST=${TEST---enable-tests} + - UNCONSTRAINED=${UNCONSTRAINED-true} + - GHCHEAD=${GHCHEAD-false} + - travis_retry cabal update -v + - "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config" + - rm -fv cabal.project cabal.project.local + - grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$' + - rm -f cabal.project + - touch cabal.project + - "printf 'packages: \"servant\"\\n' >> cabal.project" + - "printf 'packages: \"servant-client\"\\n' >> cabal.project" + - "printf 'packages: \"servant-docs\"\\n' >> cabal.project" + - "printf 'packages: \"servant-server\"\\n' >> cabal.project" + - "printf 'write-ghc-environment-files: always\\n' >> cabal.project" + - touch cabal.project.local + - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(servant|servant-client|servant-docs|servant-server)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done" + - cat cabal.project || true + - cat cabal.project.local || true + - if [ -f "servant/configure.ac" ]; then (cd "servant" && autoreconf -i); fi + - if [ -f "servant-client/configure.ac" ]; then (cd "servant-client" && autoreconf -i); fi + - if [ -f "servant-docs/configure.ac" ]; then (cd "servant-docs" && autoreconf -i); fi + - if [ -f "servant-server/configure.ac" ]; then (cd "servant-server" && autoreconf -i); fi + - rm -f cabal.project.freeze + - cabal new-freeze -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project.copy-fields.none" --dry + - "cat \"cabal.project.copy-fields.none.freeze\" | sed -E 's/^(constraints: *| *)//' | sed 's/any.//'" + - rm "cabal.project.copy-fields.none.freeze" + - cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project.copy-fields.none" --dep -j2 all + - cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project.copy-fields.none" --dep -j2 all + - rm -rf .ghc.environment.* "servant"/dist "servant-client"/dist "servant-docs"/dist "servant-server"/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 + - cabal new-sdist all + - mv dist-newstyle/sdist/*.tar.gz ${DISTDIR}/ + - cd ${DISTDIR} || false + - find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \; + - rm -f cabal.project + - touch cabal.project + - "printf 'packages: \"servant-*/*.cabal\"\\n' >> cabal.project" + - "printf 'packages: \"servant-client-*/*.cabal\"\\n' >> cabal.project" + - "printf 'packages: \"servant-docs-*/*.cabal\"\\n' >> cabal.project" + - "printf 'packages: \"servant-server-*/*.cabal\"\\n' >> cabal.project" + - "printf 'write-ghc-environment-files: always\\n' >> cabal.project" + - touch cabal.project.local + - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(servant|servant-client|servant-docs|servant-server)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done" + - cat cabal.project || true + - cat cabal.project.local || true + # this builds all libraries and executables (without tests/benchmarks) + - cabal new-build -w ${HC} --disable-tests --disable-benchmarks all + + # build & run tests, build benchmarks + - cabal new-build -w ${HC} ${TEST} ${BENCH} all + - if [ "x$TEST" = "x--enable-tests" ]; then cabal new-test -w ${HC} ${TEST} ${BENCH} all; fi + + # cabal check + - (cd servant-* && cabal check) + - (cd servant-client-* && cabal check) + - (cd servant-docs-* && cabal check) + - (cd servant-server-* && cabal check) + + # haddock + - cabal new-haddock -w ${HC} ${TEST} ${BENCH} all + + # Build without installed constraints for packages in global-db + - if $UNCONSTRAINED; then rm -f cabal.project.local; cabal new-build -w ${HC} --disable-tests --disable-benchmarks all; else echo "Not building without installed constraints"; fi + +# REGENDATA ["-o","cabal.project.empty-line.travis.yml","--copy-fields=none","cabal.project.empty-line"] +# EOF diff --git a/fixtures/cabal.project.copy-fields.some b/fixtures/cabal.project.copy-fields.some new file mode 100644 index 00000000..3e8ac267 --- /dev/null +++ b/fixtures/cabal.project.copy-fields.some @@ -0,0 +1,15 @@ +packages: + servant/ + servant-client/ + servant-docs/ + servant-server/ + +package servant + tests: False + +constraints: foundation >= 0.14 + +allow-newer: + servant-js:servant +allow-newer: + servant-js:servant-foreign diff --git a/fixtures/cabal.project.copy-fields.some.stderr b/fixtures/cabal.project.copy-fields.some.stderr new file mode 100644 index 00000000..79f80914 --- /dev/null +++ b/fixtures/cabal.project.copy-fields.some.stderr @@ -0,0 +1 @@ +*INFO* Generating Travis-CI config for testing for GHC versions: 7.8.1 7.8.2 7.8.3 7.8.4 7.10.1 7.10.2 7.10.3 8.0.1 8.0.2 8.2.1 8.2.2 8.4.1 8.4.2 8.4.3 8.4.4 8.6.1 8.6.2 8.6.3 diff --git a/fixtures/cabal.project.copy-fields.some.travis.yml b/fixtures/cabal.project.copy-fields.some.travis.yml new file mode 100644 index 00000000..52019d85 --- /dev/null +++ b/fixtures/cabal.project.copy-fields.some.travis.yml @@ -0,0 +1,176 @@ +# This Travis job script has been generated by a script via +# +# haskell-ci '-o' 'cabal.project.empty-line.travis.yml' '--copy-fields=some' 'cabal.project.empty-line' +# +# For more information, see https://github.com/haskell-CI/haskell-ci +# +language: c +dist: xenial + +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 + + - rm -rfv $HOME/.cabal/packages/head.hackage + +matrix: + include: + - compiler: "ghc-8.6.3" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.3], sources: [hvr-ghc]}} + - compiler: "ghc-8.6.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.2], sources: [hvr-ghc]}} + - compiler: "ghc-8.6.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.1], sources: [hvr-ghc]}} + - compiler: "ghc-8.4.4" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.4], sources: [hvr-ghc]}} + - compiler: "ghc-8.4.3" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.3], sources: [hvr-ghc]}} + - compiler: "ghc-8.4.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.2], sources: [hvr-ghc]}} + - compiler: "ghc-8.4.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.1], sources: [hvr-ghc]}} + - compiler: "ghc-8.2.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.2.2], sources: [hvr-ghc]}} + - compiler: "ghc-8.2.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.2.1], sources: [hvr-ghc]}} + - compiler: "ghc-8.0.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.0.2], sources: [hvr-ghc]}} + - compiler: "ghc-8.0.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.0.1], sources: [hvr-ghc]}} + - compiler: "ghc-7.10.3" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.10.3], sources: [hvr-ghc]}} + - compiler: "ghc-7.10.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.10.2], sources: [hvr-ghc]}} + - compiler: "ghc-7.10.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.10.1], sources: [hvr-ghc]}} + - compiler: "ghc-7.8.4" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.8.4], sources: [hvr-ghc]}} + - compiler: "ghc-7.8.3" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.8.3], sources: [hvr-ghc]}} + - compiler: "ghc-7.8.2" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.8.2], sources: [hvr-ghc]}} + - compiler: "ghc-7.8.1" + # env: TEST=--disable-tests BENCH=--disable-benchmarks + addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.8.1], sources: [hvr-ghc]}} + +before_install: + - HC=${CC} + - HCPKG=${HC/ghc/ghc-pkg} + - unset CC + - ROOTDIR=$(pwd) + - mkdir -p $HOME/.local/bin + - "PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$HOME/local/bin:$PATH" + - HCNUMVER=$(( $(${HC} --numeric-version|sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1 * 10000 + \2 * 100 + \3/') )) + - echo $HCNUMVER + +install: + - cabal --version + - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]" + - BENCH=${BENCH---enable-benchmarks} + - TEST=${TEST---enable-tests} + - UNCONSTRAINED=${UNCONSTRAINED-true} + - GHCHEAD=${GHCHEAD-false} + - travis_retry cabal update -v + - "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config" + - rm -fv cabal.project cabal.project.local + - grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$' + - rm -f cabal.project + - touch cabal.project + - "printf 'packages: \"servant\"\\n' >> cabal.project" + - "printf 'packages: \"servant-client\"\\n' >> cabal.project" + - "printf 'packages: \"servant-docs\"\\n' >> cabal.project" + - "printf 'packages: \"servant-server\"\\n' >> cabal.project" + - "echo 'constraints: foundation >= 0.14' >> cabal.project" + - "echo 'allow-newer: servant-js:servant' >> cabal.project" + - "echo 'allow-newer: servant-js:servant-foreign' >> cabal.project" + - "printf 'write-ghc-environment-files: always\\n' >> cabal.project" + - touch cabal.project.local + - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(servant|servant-client|servant-docs|servant-server)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done" + - cat cabal.project || true + - cat cabal.project.local || true + - if [ -f "servant/configure.ac" ]; then (cd "servant" && autoreconf -i); fi + - if [ -f "servant-client/configure.ac" ]; then (cd "servant-client" && autoreconf -i); fi + - if [ -f "servant-docs/configure.ac" ]; then (cd "servant-docs" && autoreconf -i); fi + - if [ -f "servant-server/configure.ac" ]; then (cd "servant-server" && autoreconf -i); fi + - rm -f cabal.project.freeze + - cabal new-freeze -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project.copy-fields.some" --dry + - "cat \"cabal.project.copy-fields.some.freeze\" | sed -E 's/^(constraints: *| *)//' | sed 's/any.//'" + - rm "cabal.project.copy-fields.some.freeze" + - cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project.copy-fields.some" --dep -j2 all + - cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project.copy-fields.some" --dep -j2 all + - rm -rf .ghc.environment.* "servant"/dist "servant-client"/dist "servant-docs"/dist "servant-server"/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 + - cabal new-sdist all + - mv dist-newstyle/sdist/*.tar.gz ${DISTDIR}/ + - cd ${DISTDIR} || false + - find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \; + - rm -f cabal.project + - touch cabal.project + - "printf 'packages: \"servant-*/*.cabal\"\\n' >> cabal.project" + - "printf 'packages: \"servant-client-*/*.cabal\"\\n' >> cabal.project" + - "printf 'packages: \"servant-docs-*/*.cabal\"\\n' >> cabal.project" + - "printf 'packages: \"servant-server-*/*.cabal\"\\n' >> cabal.project" + - "echo 'constraints: foundation >= 0.14' >> cabal.project" + - "echo 'allow-newer: servant-js:servant' >> cabal.project" + - "echo 'allow-newer: servant-js:servant-foreign' >> cabal.project" + - "printf 'write-ghc-environment-files: always\\n' >> cabal.project" + - touch cabal.project.local + - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(servant|servant-client|servant-docs|servant-server)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done" + - cat cabal.project || true + - cat cabal.project.local || true + # this builds all libraries and executables (without tests/benchmarks) + - cabal new-build -w ${HC} --disable-tests --disable-benchmarks all + + # build & run tests, build benchmarks + - cabal new-build -w ${HC} ${TEST} ${BENCH} all + - if [ "x$TEST" = "x--enable-tests" ]; then cabal new-test -w ${HC} ${TEST} ${BENCH} all; fi + + # cabal check + - (cd servant-* && cabal check) + - (cd servant-client-* && cabal check) + - (cd servant-docs-* && cabal check) + - (cd servant-server-* && cabal check) + + # haddock + - cabal new-haddock -w ${HC} ${TEST} ${BENCH} all + + # Build without installed constraints for packages in global-db + - if $UNCONSTRAINED; then rm -f cabal.project.local; cabal new-build -w ${HC} --disable-tests --disable-benchmarks all; else echo "Not building without installed constraints"; fi + +# REGENDATA ["-o","cabal.project.empty-line.travis.yml","--copy-fields=some","cabal.project.empty-line"] +# EOF diff --git a/fixtures/cabal.project.empty-line.travis.yml b/fixtures/cabal.project.empty-line.travis.yml index 43ef260a..12c37691 100644 --- a/fixtures/cabal.project.empty-line.travis.yml +++ b/fixtures/cabal.project.empty-line.travis.yml @@ -134,10 +134,10 @@ install: - "printf 'packages: \"servant-client\"\\n' >> cabal.project" - "printf 'packages: \"servant-docs\"\\n' >> cabal.project" - "printf 'packages: \"servant-server\"\\n' >> cabal.project" - - "printf 'write-ghc-environment-files: always\\n' >> cabal.project" - "echo 'constraints: foundatiion >= 0.14' >> cabal.project" - "echo 'allow-newer: servant-js:servant' >> cabal.project" - "echo 'allow-newer: servant-js:servant-foreign' >> cabal.project" + - "printf 'write-ghc-environment-files: always\\n' >> cabal.project" - touch cabal.project.local - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(servant|servant-client|servant-docs|servant-server)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done" - cat cabal.project || true @@ -169,10 +169,10 @@ script: - "printf 'packages: \"servant-client-*/*.cabal\"\\n' >> cabal.project" - "printf 'packages: \"servant-docs-*/*.cabal\"\\n' >> cabal.project" - "printf 'packages: \"servant-server-*/*.cabal\"\\n' >> cabal.project" - - "printf 'write-ghc-environment-files: always\\n' >> cabal.project" - "echo 'constraints: foundatiion >= 0.14' >> cabal.project" - "echo 'allow-newer: servant-js:servant' >> cabal.project" - "echo 'allow-newer: servant-js:servant-foreign' >> cabal.project" + - "printf 'write-ghc-environment-files: always\\n' >> cabal.project" - touch cabal.project.local - "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | grep -vE -- '^(servant|servant-client|servant-docs|servant-server)$' | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done" - cat cabal.project || true diff --git a/haskell-ci.cabal b/haskell-ci.cabal index 3e16f35c..64a2ca24 100644 --- a/haskell-ci.cabal +++ b/haskell-ci.cabal @@ -29,27 +29,41 @@ author: Herbert Valerio Riedel, Oleg Grenrus maintainer: hvr@gnu.org category: Development build-type: Simple -tested-with: GHC ==8.6.3 || ==8.4.4 || ==8.2.2 || ==8.0.2 +tested-with: ghc ==8.6.3 || ==8.4.4 || ==8.2.2 || ==8.0.2 extra-source-files: fixtures/cabal.haskell-ci - fixtures/haskell-ci.cabal - fixtures/haskell-ci.cabal.stderr - fixtures/haskell-ci.cabal.travis.yml - fixtures/cabal.project.empty-line - fixtures/cabal.project.empty-line.stderr - fixtures/cabal.project.empty-line.travis.yml + fixtures/cabal.project.fail-versions fixtures/cabal.project.fail-versions.stderr + + fixtures/haskell-ci.cabal + fixtures/cabal.project.empty-line fixtures/cabal.project.messy + fixtures/cabal.project.copy-fields.all + fixtures/cabal.project.copy-fields.some + fixtures/cabal.project.copy-fields.none + + fixtures/haskell-ci.cabal.stderr + fixtures/cabal.project.empty-line.stderr fixtures/cabal.project.messy.stderr + fixtures/cabal.project.copy-fields.all.stderr + fixtures/cabal.project.copy-fields.some.stderr + fixtures/cabal.project.copy-fields.none.stderr + + fixtures/haskell-ci.cabal.travis.yml + fixtures/cabal.project.empty-line.travis.yml fixtures/cabal.project.messy.travis.yml - fixtures/doc/tutorial/tutorial.cabal + fixtures/cabal.project.copy-fields.all.travis.yml + fixtures/cabal.project.copy-fields.some.travis.yml + fixtures/cabal.project.copy-fields.none.travis.yml + fixtures/servant-client-core/*.cabal fixtures/servant-client/*.cabal fixtures/servant-docs/*.cabal fixtures/servant-foreign/*.cabal fixtures/servant-server/*.cabal fixtures/servant/*.cabal + fixtures/doc/tutorial/tutorial.cabal source-repository head type: git @@ -65,6 +79,7 @@ library HaskellCI.Cli HaskellCI.Config HaskellCI.Config.ConstraintSet + HaskellCI.Config.CopyFields HaskellCI.Config.Doctest HaskellCI.Config.Dump HaskellCI.Config.Folds @@ -85,9 +100,7 @@ library HaskellCI.TestedWith -- vendored from Cabal development version - other-modules: - Distribution.Fields.Pretty - + other-modules: Distribution.Fields.Pretty ghc-options: -Wall -Wcompat -Wnoncanonical-monad-instances -Wnoncanonical-monadfail-instances diff --git a/src/HaskellCI.hs b/src/HaskellCI.hs index 53f9aa5a..333ace0d 100644 --- a/src/HaskellCI.hs +++ b/src/HaskellCI.hs @@ -99,6 +99,7 @@ import qualified Distribution.Types.PackageDescription.Lens as L import HaskellCI.Cli import HaskellCI.Config +import HaskellCI.Config.CopyFields import HaskellCI.Config.ConstraintSet import HaskellCI.Config.Doctest import HaskellCI.Config.Dump @@ -914,45 +915,56 @@ genTravisFromConfigs argv opts isCabalProject config prj@Project { prjPackages = tellStrLns $ [ shForJob versions' (pkgJobs pkg) $ "printf 'packages: \"" ++ p ++ "\"\\n' >> cabal.project" ] - tellStrLns - [ sh $ "printf 'write-ghc-environment-files: always\\n' >> cabal.project" - ] - F.forM_ (prjConstraints prj) $ \xs -> do - let s = concat (lines xs) - tellStrLns - [ sh $ "echo 'constraints: " ++ s ++ "' >> cabal.project" - ] - F.forM_ (prjAllowNewer prj) $ \xs -> do - let s = concat (lines xs) - tellStrLns - [ sh $ "echo 'allow-newer: " ++ s ++ "' >> cabal.project" - ] - unless (null (cfgLocalGhcOptions config)) $ forM_ pkgs $ \Pkg{pkgName} -> do - let s = unwords $ map (show . PU.showToken) $ cfgLocalGhcOptions config - tellStrLns - [ sh $ "echo 'package " ++ pkgName ++ "' >> cabal.project" - , sh $ "echo ' ghc-options: " ++ s ++ "' >> cabal.project" - ] - when (prjReorderGoals prj) $ - tellStrLns - [ sh $ "echo 'reorder-goals: True' >> cabal.project" + case cfgCopyFields config of + CopyFieldsNone -> return () + CopyFieldsAll -> unless (null (prjOrigFields prj)) $ tellStrLns + [ sh $ "echo '" ++ l ++ "' >> cabal.project" + | l <- lines $ C.showFields' 2 $ prjOrigFields prj + , not (null l) ] + CopyFieldsSome -> do + F.forM_ (prjConstraints prj) $ \xs -> do + let s = concat (lines xs) + tellStrLns + [ sh $ "echo 'constraints: " ++ s ++ "' >> cabal.project" + ] + F.forM_ (prjAllowNewer prj) $ \xs -> do + let s = concat (lines xs) + tellStrLns + [ sh $ "echo 'allow-newer: " ++ s ++ "' >> cabal.project" + ] + unless (null (cfgLocalGhcOptions config)) $ forM_ pkgs $ \Pkg{pkgName} -> do + let s = unwords $ map (show . PU.showToken) $ cfgLocalGhcOptions config + tellStrLns + [ sh $ "echo 'package " ++ pkgName ++ "' >> cabal.project" + , sh $ "echo ' ghc-options: " ++ s ++ "' >> cabal.project" + ] - F.forM_ (prjMaxBackjumps prj) $ \bj -> - tellStrLns - [ sh $ "echo 'max-backjumps: " ++ show bj ++ "' >> cabal.project" - ] + when (prjReorderGoals prj) $ + tellStrLns + [ sh $ "echo 'reorder-goals: True' >> cabal.project" + ] - case prjOptimization prj of - OptimizationOn -> return () - OptimizationOff -> tellStrLns [ sh $ "echo 'optimization: False' >> cabal.project " ] - OptimizationLevel l -> tellStrLns [ sh $ "echo 'optimization: " ++ show l ++ "' >> cabal.project " ] + F.forM_ (prjMaxBackjumps prj) $ \bj -> + tellStrLns + [ sh $ "echo 'max-backjumps: " ++ show bj ++ "' >> cabal.project" + ] - F.forM_ (prjSourceRepos prj) $ \repo -> do - let repo' = PP.render $ C.prettyFieldGrammar (C.sourceRepoFieldGrammar $ C.RepoKindUnknown "unused") repo - tellStrLns [ sh $ "echo 'source-repository-package' >> cabal.project" ] - tellStrLns [ sh $ "echo ' " ++ l ++ "' >> cabal.project" | l <- lines repo' ] + case prjOptimization prj of + OptimizationOn -> return () + OptimizationOff -> tellStrLns [ sh $ "echo 'optimization: False' >> cabal.project " ] + OptimizationLevel l -> tellStrLns [ sh $ "echo 'optimization: " ++ show l ++ "' >> cabal.project " ] + + F.forM_ (prjSourceRepos prj) $ \repo -> do + let repo' = PP.render $ C.prettyFieldGrammar (C.sourceRepoFieldGrammar $ C.RepoKindUnknown "unused") repo + tellStrLns [ sh $ "echo 'source-repository-package' >> cabal.project" ] + tellStrLns [ sh $ "echo ' " ++ l ++ "' >> cabal.project" | l <- lines repo' ] + + -- mandatory cabal.project setup + tellStrLns + [ sh $ "printf 'write-ghc-environment-files: always\\n' >> cabal.project" + ] unless (null (cfgRawProject config)) $ tellStrLns [ sh $ "echo '" ++ l ++ "' >> cabal.project" diff --git a/src/HaskellCI/Config.hs b/src/HaskellCI/Config.hs index 048a32bf..e9279148 100644 --- a/src/HaskellCI/Config.hs +++ b/src/HaskellCI/Config.hs @@ -20,17 +20,18 @@ import qualified Distribution.CabalSpecVersion as C import qualified Distribution.Compat.CharParsing as C import qualified Distribution.Compat.Newtype as C import qualified Distribution.FieldGrammar as C +import qualified Distribution.Fields.Pretty as C import qualified Distribution.Parsec.Class as C import qualified Distribution.Parsec.Common as C import qualified Distribution.Parsec.Newtypes as C import qualified Distribution.Parsec.Parser as C import qualified Distribution.Parsec.ParseResult as C -import qualified Distribution.Fields.Pretty as C import qualified Distribution.Pretty as C import qualified Distribution.Types.Version as C import qualified Text.PrettyPrint as PP import HaskellCI.Config.ConstraintSet +import HaskellCI.Config.CopyFields import HaskellCI.Config.Doctest import HaskellCI.Config.Folds import HaskellCI.Config.HLint @@ -45,7 +46,8 @@ import HaskellCI.TestedWith data Config = Config { cfgCabalInstallVersion :: Maybe Version , cfgJobs :: Maybe Jobs - , cfgTestedWith :: TestedWithJobs + , cfgTestedWith :: !TestedWithJobs + , cfgCopyFields :: !CopyFields , cfgLocalGhcOptions :: [String] , cfgCache :: !Bool , cfgCheck :: !Bool @@ -80,6 +82,7 @@ emptyConfig = Config { cfgCabalInstallVersion = defaultCabalInstallVersion , cfgJobs = Nothing , cfgTestedWith = TestedWithUniform + , cfgCopyFields = CopyFieldsSome , cfgDoctest = DoctestConfig { cfgDoctestEnabled = False , cfgDoctestOptions = [] @@ -129,6 +132,8 @@ configGrammar = Config ^^^ metahelp "JOBS" "jobs (N:M - cabal:ghc)" <*> C.optionalFieldDef "jobs-selection" #cfgTestedWith TestedWithUniform ^^^ metahelp "uniform|any" "Jobs selection across packages" + <*> C.optionalFieldDef "copy-fields" #cfgCopyFields CopyFieldsSome + ^^^ metahelp "none|some|all" "Copy ? fields from cabal.project fields" <*> C.monoidalFieldAla "local-ghc-options" (C.alaList' C.NoCommaFSep C.Token') #cfgLocalGhcOptions ^^^ metahelp "OPTS" "--ghc-options for local packages" <*> C.booleanFieldDef "cache" #cfgCache True diff --git a/src/HaskellCI/Config/CopyFields.hs b/src/HaskellCI/Config/CopyFields.hs new file mode 100644 index 00000000..026864be --- /dev/null +++ b/src/HaskellCI/Config/CopyFields.hs @@ -0,0 +1,32 @@ +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE MultiParamTypeClasses #-} +module HaskellCI.Config.CopyFields where + +import qualified Distribution.Compat.CharParsing as C +import qualified Distribution.Parsec.Class as C +import qualified Distribution.Pretty as C +import qualified Text.PrettyPrint as PP + +data CopyFields + = CopyFieldsNone + | CopyFieldsSome + | CopyFieldsAll + deriving (Eq, Ord, Show, Enum, Bounded) + +------------------------------------------------------------------------------- +-- Functions +------------------------------------------------------------------------------- + +showCopyFields :: CopyFields -> String +showCopyFields CopyFieldsNone = "none" +showCopyFields CopyFieldsSome = "some" +showCopyFields CopyFieldsAll = "all" + +instance C.Pretty CopyFields where + pretty = PP.text . showCopyFields + +instance C.Parsec CopyFields where + parsec = C.choice + [ f <$ C.string (showCopyFields f) + | f <- [ minBound .. maxBound ] + ] diff --git a/src/HaskellCI/Project.hs b/src/HaskellCI/Project.hs index d37d9e15..266fc57b 100644 --- a/src/HaskellCI/Project.hs +++ b/src/HaskellCI/Project.hs @@ -21,6 +21,7 @@ import qualified Distribution.Parsec.Newtypes as C import qualified Distribution.Parsec.Parser as C import qualified Distribution.Parsec.ParseResult as C import qualified Distribution.Types.SourceRepo as C +import qualified Distribution.Fields.Pretty as C import HaskellCI.Newtypes import HaskellCI.Optimization @@ -37,11 +38,12 @@ data Project a = Project , prjMaxBackjumps :: Maybe Int , prjOptimization :: Optimization , prjSourceRepos :: [C.SourceRepo] + , prjOrigFields :: [C.PrettyField] } deriving (Show, Functor, Foldable, Traversable, Generic) emptyProject :: Project [a] -emptyProject = Project [] [] [] False Nothing OptimizationOn [] +emptyProject = Project [] [] [] False Nothing OptimizationOn [] [] -- | Parse project file. Extracts only few fields. -- @@ -53,14 +55,15 @@ parseProjectFile fp bs = do fields0 <- either (Left . show) Right $ C.readFields bs let (fields1, sections) = C.partitionFields fields0 let fields2 = M.filterWithKey (\k _ -> k `elem` knownFields) fields1 - case C.runParseResult $ parse fields2 sections of + case C.runParseResult $ parse fields0 fields2 sections of (_, Right x) -> return x (ws, Left (_, es)) -> Left $ renderParseError fp bs es ws where - knownFields = C.fieldGrammarKnownFieldList grammar + knownFields = C.fieldGrammarKnownFieldList $ grammar [] - parse fields sections = do - prj <- C.parseFieldGrammar C.cabalSpecLatest fields grammar + parse origFields fields sections = do + let prettyOrigFields = C.fromParsecFields $ filter notPackages origFields + prj <- C.parseFieldGrammar C.cabalSpecLatest fields $ grammar prettyOrigFields foldr ($) prj <$> traverse parseSec (concat sections) parseSec :: C.Section C.Position -> C.ParseResult (Project String -> Project String) @@ -71,8 +74,13 @@ parseProjectFile fp bs = do parseSec _ = return id -grammar :: C.ParsecFieldGrammar (Project String) (Project String) -grammar = Project +notPackages :: C.Field ann -> Bool +notPackages (C.Field (C.Name _ "packages") _) = False +notPackages _ = True + + +grammar :: [C.PrettyField] -> C.ParsecFieldGrammar (Project String) (Project String) +grammar origFields = Project <$> C.monoidalFieldAla "packages" (C.alaList' C.FSep PackageLocation) #prjPackages <*> C.monoidalFieldAla "constraints" (C.alaList' C.CommaVCat NoCommas) #prjConstraints <*> C.monoidalFieldAla "allow-newer" (C.alaList' C.CommaVCat NoCommas) #prjAllowNewer @@ -80,3 +88,4 @@ grammar = Project <*> C.optionalFieldAla "max-backjumps" Int' #prjMaxBackjumps <*> C.optionalFieldDef "optimization" #prjOptimization OptimizationOn <*> pure [] + <*> pure origFields diff --git a/test/Tests.hs b/test/Tests.hs index 005e5cc5..ef229383 100644 --- a/test/Tests.hs +++ b/test/Tests.hs @@ -32,6 +32,11 @@ main = do , fixtureGoldenTest "cabal.project.empty-line" , fixtureGoldenTest "cabal.project.fail-versions" , fixtureGoldenTest "cabal.project.messy" + , testGroup "copy-fields" + [ fixtureGoldenTest "cabal.project.copy-fields.all" + , fixtureGoldenTest "cabal.project.copy-fields.some" + , fixtureGoldenTest "cabal.project.copy-fields.none" + ] ] linesToArgv :: String -> Maybe [String]