diff --git a/.azure/linux-cabal.bashrc b/.azure/linux-cabal.bashrc index 864dfa2ae..6e087c538 100644 --- a/.azure/linux-cabal.bashrc +++ b/.azure/linux-cabal.bashrc @@ -1 +1,7 @@ +if [ -z "$PROJECT_FILE" ]; then + export PROJECT_FILE="cabal.project" + if [ -f "cabal.project-$GHC_VERSION" ]; then + export PROJECT_FILE="cabal.project-$GHC_VERSION" + fi +fi export PATH=$HOME/.cabal/bin:/opt/cabal/$CABAL_VERSION/bin:/opt/ghc/$GHC_VERSION/bin:$HOME/.local/bin:$PATH diff --git a/.azure/linux-cabal.yml b/.azure/linux-cabal.yml index 1e93abedb..362c8585f 100644 --- a/.azure/linux-cabal.yml +++ b/.azure/linux-cabal.yml @@ -5,11 +5,8 @@ jobs: vmImage: ubuntu-16.04 strategy: matrix: - # Fail with compilation error building haddock-api - # ghc-8.8.2: - # GHC_VERSION: "8.8.2" - ghc-8.8.1: - GHC_VERSION: "8.8.1" + ghc-8.8.2: + GHC_VERSION: "8.8.2" ghc-8.6.5: GHC_VERSION: "8.6.5" ghc-8.4.4: @@ -43,24 +40,24 @@ jobs: displayName: Install ghc - bash: | source .azure/linux-cabal.bashrc - cabal v2-update + cabal v2-update --project-file $PROJECT_FILE echo "overwrite-policy: always" >> $HOME/.cabal/config displayName: Update cabal - bash: | source .azure/linux-cabal.bashrc - cabal v2-build --disable-tests --disable-benchmarks --only-dependencies + cabal v2-build --disable-tests --disable-benchmarks --only-dependencies --project-file $PROJECT_FILE displayName: Build dependencies - bash: | source .azure/linux-cabal.bashrc - cabal v2-build --disable-tests --disable-benchmarks + cabal v2-build --disable-tests --disable-benchmarks --project-file $PROJECT_FILE displayName: Build `hie` - bash: | source .azure/linux-cabal.bashrc - cabal v2-install # `hie` binary required locally for tests + cabal v2-install --project-file $PROJECT_FILE # `hie` binary required locally for tests displayName: Install `hie` - bash: | source .azure/linux-cabal.bashrc - cabal v2-build --enable-tests --enable-benchmarks --only-dependencies + cabal v2-build --enable-tests --enable-benchmarks --only-dependencies --project-file $PROJECT_FILE displayName: Build Test-dependencies - bash: | sudo apt update @@ -73,20 +70,20 @@ jobs: displayName: "Install Runtime Test-Dependencies: liquidhaskell" - bash: | source .azure/linux-cabal.bashrc - cabal v2-build hoogle - cabal v2-exec hoogle generate + cabal v2-build hoogle --project-file $PROJECT_FILE + cabal v2-exec hoogle generate --project-file $PROJECT_FILE displayName: "Install Runtime Test-Dependencies: hoogle database" - bash: | source .azure/linux-cabal.bashrc - cabal v2-test :unit-test + cabal v2-test :unit-test --project-file $PROJECT_FILE displayName: "Run Test: unit-test" - bash: | source .azure/linux-cabal.bashrc - cabal v2-test :dispatcher-test :plugin-dispatcher-test :wrapper-test + cabal v2-test :dispatcher-test :plugin-dispatcher-test :wrapper-test --project-file $PROJECT_FILE displayName: "Run Test: dispatcher-test, plugin-dispatcher-test and wrapper-test" - bash: | source .azure/linux-cabal.bashrc - cabal v2-test :func-test + cabal v2-test :func-test --project-file $PROJECT_FILE displayName: "Run Test: func-test" - bash: | mkdir -p .azure-cache diff --git a/.azure/macos-cabal.bashrc b/.azure/macos-cabal.bashrc new file mode 100644 index 000000000..44deaa783 --- /dev/null +++ b/.azure/macos-cabal.bashrc @@ -0,0 +1,8 @@ +if [ -z "$PROJECT_FILE" ]; then + export PROJECT_FILE="cabal.project" + if [ -f "cabal.project-$GHC_VERSION" ]; then + export PROJECT_FILE="cabal.project-$GHC_VERSION" + fi +fi +export CABAL_ROOT=$HOME/.cabal +export PATH=$CABAL_ROOT/bin:$PATH diff --git a/.azure/macos-installhs-cabal.yml b/.azure/macos-installhs-cabal.yml new file mode 100644 index 000000000..1d0b16013 --- /dev/null +++ b/.azure/macos-installhs-cabal.yml @@ -0,0 +1,42 @@ +jobs: +- job: MacOs_installhs_Cabal + timeoutInMinutes: 0 + pool: + vmImage: macOS-10.14 + variables: + PROJECT_FILE: "./install/shake.project" + steps: + - task: Cache@2 + inputs: + key: '"cabal-installhs" | "$(Agent.OS)" | $(Build.SourcesDirectory)/cabal.project | $(Build.SourcesDirectory)/haskell-ide-engine.cabal | $(Build.SourcesDirectory)/hie-plugin-api/hie-plugin-api.cabal' + path: .azure-cache + cacheHitVar: CACHE_RESTORED + displayName: "Download cache" + - bash: | + source .azure/macos-cabal.bashrc + mkdir -p $CABAL_ROOT + tar -vxzf .azure-cache/cabal-root.tar.gz -C / + mkdir -p dist-newstyle + tar -vxzf .azure-cache/cabal-dist.tar.gz + displayName: "Unpack cache" + condition: eq(variables.CACHE_RESTORED, 'true') + - bash: | + brew install cabal-install + which cabal + which ghc + cabal update + displayName: Install cabal and ghc + - bash: | + source .azure/windows-cabal.bashrc + cabal v2-run ./install.hs --project-file $PROJECT_FILE -- help + displayName: Run help of `install.hs` + - bash: | + source .azure/windows-cabal.bashrc + cabal v2-run ./install.hs --project-file $PROJECT_FILE -- latest + displayName: Run latest target of `install.hs` + - bash: | + source .azure/macos-cabal.bashrc + mkdir -p .azure-cache + tar -vczf .azure-cache/cabal-root.tar.gz $CABAL_ROOT + tar -vczf .azure-cache/cabal-dist.tar.gz dist-newstyle + displayName: "Pack cache" diff --git a/.azure/macos-installhs-stack.yml b/.azure/macos-installhs-stack.yml index 4b3a9a04e..0de8c9bdb 100644 --- a/.azure/macos-installhs-stack.yml +++ b/.azure/macos-installhs-stack.yml @@ -28,23 +28,23 @@ jobs: tar xz --strip-components=1 --include '*/stack' -C ~/.local/bin; displayName: Install stack - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc stack setup --stack-yaml $(YAML_FILE) displayName: Install GHC - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc stack --stack-yaml $(YAML_FILE) --install-ghc build --only-dependencies displayName: Build dependencies - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc stack build --stack-yaml $(YAML_FILE) displayName: Build `hie-install` - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc stack install.hs help displayName: Run help of `install.hs` - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc stack install.hs latest displayName: Run latest target of `install.hs` - bash: | diff --git a/.azure/macos.bashrc b/.azure/macos-stack.bashrc similarity index 100% rename from .azure/macos.bashrc rename to .azure/macos-stack.bashrc diff --git a/.azure/macos-stack.yml b/.azure/macos-stack.yml index 4b0cfd90b..fad15c141 100644 --- a/.azure/macos-stack.yml +++ b/.azure/macos-stack.yml @@ -47,19 +47,19 @@ jobs: tar vxz --strip-components=1 --include '*/stack' -C ~/.local/bin; displayName: Install stack - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc stack setup --stack-yaml $(YAML_FILE) displayName: Install GHC - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc stack --stack-yaml $(YAML_FILE) --install-ghc build --only-dependencies displayName: Build dependencies - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc stack build --stack-yaml $(YAML_FILE) displayName: Build `hie` - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc stack install --stack-yaml $(YAML_FILE) # `hie` binary required locally for tests mkdir .azure-deploy stack install --stack-yaml $(YAML_FILE) --local-bin-path .azure-deploy @@ -76,7 +76,7 @@ jobs: tar -vczf $(Build.ArtifactStagingDirectory)/$ARTIFACT_NAME.tar.xz * displayName: Install `hie` - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc stack build --stack-yaml $(YAML_FILE) --test --bench --only-dependencies displayName: Build Test-dependencies - bash: | @@ -86,26 +86,26 @@ jobs: brew install z3 displayName: "Install Runtime Test-Dependencies: z3" - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc stack install --resolver=lts-13.20 liquid-fixpoint-0.8.0.2 liquidhaskell-0.8.6.2 displayName: "Install Runtime Test-Dependencies: liquidhaskell" - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc stack build hoogle --stack-yaml=$(YAML_FILE) # This step frequently fails with http 403 stack exec hoogle generate --stack-yaml=$(YAML_FILE) || stack exec hoogle generate --stack-yaml=$(YAML_FILE) displayName: "Install Runtime Test-Dependencies: hoogle database" - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc brew install cabal-install displayName: "Install Runtime Unit Test-Dependencies: cabal" - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc stack test :unit-test --stack-yaml $(YAML_FILE) displayName: "Run Test: unit-test" # TODO: Enable dispatcher-test for ghc-8.4.* - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc GHC_MAJOR_VERSION=${YAML_FILE:6:3} if [ $GHC_MAJOR_VERSION != "8.4" ]; then TEST_TARGETS=:dispatcher-test :plugin-dispatcher-test :wrapper-test @@ -117,7 +117,7 @@ jobs: condition: False # TODO: Enable func-test for ghc-8.4.* - bash: | - source .azure/macos.bashrc + source .azure/macos-stack.bashrc GHC_MAJOR_VERSION=${YAML_FILE:6:3} if [ $GHC_MAJOR_VERSION != "8.4" ]; then stack test :func-test --stack-yaml $(YAML_FILE) diff --git a/.azure/windows-cabal.bashrc b/.azure/windows-cabal.bashrc index de43edfc8..4530c4f40 100644 --- a/.azure/windows-cabal.bashrc +++ b/.azure/windows-cabal.bashrc @@ -1,3 +1,9 @@ +if [ -z "$PROJECT_FILE" ]; then + export PROJECT_FILE="cabal.project" + if [ -f "cabal.project-$GHC_VERSION" ]; then + export PROJECT_FILE="cabal.project-$GHC_VERSION" + fi +fi if [ -z "$CABAL_DIR" ]; then CABAL_DIR="$APPDATA\\cabal" fi diff --git a/.azure/windows-cabal.yml b/.azure/windows-cabal.yml index ee3e185de..bf4e9b9ab 100644 --- a/.azure/windows-cabal.yml +++ b/.azure/windows-cabal.yml @@ -5,7 +5,8 @@ jobs: vmImage: windows-2019 strategy: matrix: - # It still is not in chocolatey + # ghc versions 8.8.1 and 8.8.2 are not usable in windows + # due to https://gitlab.haskell.org/ghc/ghc/issues/17575 # ghc-8.8.2: # GHC_VERSION: "8.8.2" ghc-8.6.5: @@ -51,28 +52,28 @@ jobs: displayName: Install cabal - bash: | source .azure/windows-cabal.bashrc - cabal v2-update + cabal v2-update --project-file $PROJECT_FILE echo "store-dir: $CABAL_STORE_DIR" >> $CABAL_ROOT/config echo "overwrite-policy: always" >> $CABAL_ROOT/config displayName: Update cabal - bash: | source .azure/windows-cabal.bashrc - cabal v2-build all --disable-tests --disable-benchmarks --only-dependencies + cabal v2-build all --disable-tests --disable-benchmarks --only-dependencies --project-file $PROJECT_FILE displayName: Build dependencies - bash: | source .azure/windows-cabal.bashrc - cabal v2-build all --disable-tests --disable-benchmarks + cabal v2-build all --disable-tests --disable-benchmarks --project-file $PROJECT_FILE displayName: Build `hie` - bash: | source .azure/windows-cabal.bashrc # `hie` binary required locally for tests # we have to use a separate store for install and builds # to workaround https://github.com/haskell/cabal/issues/6483 - cabal --store-dir ${CABAL_STORE_DIR}i v2-install + cabal --store-dir ${CABAL_STORE_DIR}i v2-install --project-file $PROJECT_FILE displayName: Install `hie` - bash: | source .azure/windows-cabal.bashrc - cabal v2-build all --enable-tests --enable-benchmarks --only-dependencies + cabal v2-build all --enable-tests --enable-benchmarks --only-dependencies --project-file $PROJECT_FILE displayName: Build Test-dependencies - bash: | mkdir -p /usr/local @@ -88,19 +89,19 @@ jobs: displayName: "Install Runtime Test-Dependencies: liquidhaskell" - bash: | source .azure/windows-cabal.bashrc - cabal v2-build hoogle - cabal v2-exec hoogle generate + cabal v2-build hoogle --project-file $PROJECT_FILE + cabal v2-exec hoogle generate --project-file $PROJECT_FILE displayName: "Install Runtime Test-Dependencies: hoogle database" - bash: | curl -sSkL http://www.stackage.org/stack/windows-x86_64 -o /usr/bin/stack.zip unzip -o /usr/bin/stack.zip -d /usr/bin/ mkdir -p "$STACK_ROOT" - # If we don't install the ghc used in test projects in advance, tests fail + # If we don't install the ghc used in test projects in advance, tests fail stack setup --stack-yaml stack-${GHC_VERSION}.yaml displayName: "Install Runtime Unit Test-Dependencies: stack" - bash: | source .azure/windows-cabal.bashrc - cabal v2-test :unit-test + cabal v2-test :unit-test --project-file $PROJECT_FILE displayName: "Run Test: unit-test" - bash: | source .azure/windows-cabal.bashrc @@ -108,11 +109,11 @@ jobs: stack setup --stack-yaml stack-8.8.1.yaml stack setup --stack-yaml stack-8.6.5.yaml # TODO Enable :dispatcher-test suite - cabal v2-test :plugin-dispatcher-test :wrapper-test # :dispatcher-test + cabal v2-test :plugin-dispatcher-test :wrapper-test # :dispatcher-test --project-file $PROJECT_FILE displayName: "Run Test: dispatcher-test, plugin-dispatcher-test and wrapper-test" - bash: | source .azure/windows-cabal.bashrc - cabal v2-test :func-test + cabal v2-test :func-test --project-file $PROJECT_FILE displayName: "Run Test: func-test" - bash: | source .azure/windows-cabal.bashrc diff --git a/.azure/windows-installhs-cabal.yml b/.azure/windows-installhs-cabal.yml index 662931078..84500a0b4 100644 --- a/.azure/windows-installhs-cabal.yml +++ b/.azure/windows-installhs-cabal.yml @@ -46,7 +46,7 @@ jobs: - bash: | source .azure/windows-cabal.bashrc cabal v2-run ./install.hs --project-file $PROJECT_FILE latest - displayName: Run build-latest target of `install.hs` + displayName: Run latest target of `install.hs` - bash: | source .azure/windows-cabal.bashrc mkdir -p .azure-cache diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e9345a9cb..0ed02f2c3 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -40,4 +40,5 @@ jobs: - template: ./.azure/linux-installhs-stack.yml - template: ./.azure/windows-installhs-stack.yml - template: ./.azure/windows-installhs-cabal.yml +- template: ./.azure/macos-installhs-cabal.yml - template: ./.azure/macos-installhs-stack.yml diff --git a/cabal.project-8.8.2 b/cabal.project-8.8.2 new file mode 100644 index 000000000..e38f8b79e --- /dev/null +++ b/cabal.project-8.8.2 @@ -0,0 +1,32 @@ +packages: + ./ + ./hie-plugin-api/ + + -- ./submodules/HaRe + +-- To avoid build error with ghc-8.8.2 +-- See https://github.com/haskell/haddock/issues/1123 +source-repository-package + type: git + location: https://github.com/haskell/haddock.git + subdir: haddock-api + tag: be8b02c4e3cffe7d45b3dad0a0f071d35a274d65 + +source-repository-package + type: git + location: https://github.com/jneira/cabal-helper.git + tag: ffb1f57a5ffc6b7ac3c46a9974c4420a6d2bb9b2 + +tests: true + +package haskell-ide-engine + test-show-details: direct + +-- Match the flag settings we use in stac builds +constraints: + haskell-ide-engine +pedantic + hie-plugin-api +pedantic + +write-ghc-environment-files: never + +index-state: 2020-02-05T07:49:28Z diff --git a/install/hie-install.cabal b/install/hie-install.cabal index 013d246fe..39e73f636 100644 --- a/install/hie-install.cabal +++ b/install/hie-install.cabal @@ -1,5 +1,5 @@ name: hie-install -version: 0.8.0.0 +version: 0.8.1.0 synopsis: Install the haskell-ide-engine license: BSD3 author: Many, TBD when we release diff --git a/install/shake.yaml b/install/shake.yaml index 8c30114fa..17b5d4abc 100644 --- a/install/shake.yaml +++ b/install/shake.yaml @@ -1,8 +1,20 @@ # Used to provide a different environment for the shake build script -resolver: lts-14.11 # GHC 8.6.5 +resolver: lts-13.19 # last lts with GHC 8.6.5 +# resolver: nightly-2020-01-31 # GHC 8.8.2 +# resolver: nightly-2020-01-21 # last nightly GHC 8.8.1 +# resolver: lts-13.19 # last lts GHC 8.6.4 +# resolver: lts-12.26 # last lts GHC 8.4.4 +# resolver: lts-12.14 # last lts GHC 8.4.3 +# resolver: nightly-2018-05-30 # last nightly for GHC 8.4.2 packages: - . +extra-deps: +- shake-0.18.5 +# for resolvers with ghc < 8.6 +# - shake-0.17 + + nix: packages: [ zlib ] diff --git a/install/src/Cabal.hs b/install/src/Cabal.hs index 72fd00b04..8429b59d9 100644 --- a/install/src/Cabal.hs +++ b/install/src/Cabal.hs @@ -1,27 +1,19 @@ {-# LANGUAGE CPP #-} - module Cabal where import Development.Shake -import Development.Shake.Command import Development.Shake.FilePath import Control.Monad -import Data.Maybe ( isNothing - , isJust - ) -import Control.Monad.Extra ( whenMaybe ) -import System.Directory ( findExecutable - , copyFile - ) +import System.Directory ( copyFile ) import Version import Print import Env -import Data.Functor.Identity #if RUN_FROM_STACK import Control.Exception ( throwIO ) #else import Cabal.Config +import Data.Functor.Identity #endif getInstallDir :: IO FilePath @@ -38,23 +30,23 @@ execCabal = command [] "cabal" execCabal_ :: [String] -> Action () execCabal_ = execCabal -cabalBuildData :: Action () -cabalBuildData = do - execCabal_ ["v2-build", "hoogle"] - execCabal_ ["v2-exec", "hoogle", "generate"] +cabalBuildData :: [String] -> Action () +cabalBuildData args = do + execCabal_ $ ["v2-build", "hoogle"] ++ args + execCabal_ $ ["v2-exec", "hoogle", "generate"] ++ args getGhcPathOfOrThrowError :: VersionNumber -> Action GhcPath -getGhcPathOfOrThrowError versionNumber = +getGhcPathOfOrThrowError versionNumber = getGhcPathOf versionNumber >>= \case Nothing -> do printInStars $ ghcVersionNotFoundFailMsg versionNumber error (ghcVersionNotFoundFailMsg versionNumber) Just p -> return p -cabalInstallHie :: VersionNumber -> Action () -cabalInstallHie versionNumber = do +cabalInstallHie :: VersionNumber -> [String] -> Action () +cabalInstallHie versionNumber args = do localBin <- liftIO $ getInstallDir - cabalVersion <- getCabalVersion + cabalVersion <- getCabalVersion args ghcPath <- getGhcPathOfOrThrowError versionNumber let isCabal3 = checkVersion [3,0,0,0] cabalVersion @@ -62,19 +54,24 @@ cabalInstallHie versionNumber = do | otherwise = "--symlink-bindir" installMethod | isWindowsSystem && isCabal3 = ["--install-method=copy"] | otherwise = [] + + projectFile <- getProjectFile versionNumber + execCabal_ $ [ "v2-install" , "-w", ghcPath , "--write-ghc-environment-files=never" , installDirOpt, localBin , "--max-backjumps=5000" - , "exe:hie" + , "exe:hie", "exe:hie-wrapper" , "--overwrite-policy=always" + , "--project-file=" ++ projectFile ] ++ installMethod + ++ args let minorVerExe = "hie-" ++ versionNumber <.> exe - majorVerExe = "hie-" ++ dropExtension versionNumber <.> exe + majorVerExe = "hie-" ++ dropExtension versionNumber <.> exe liftIO $ do copyFile (localBin "hie" <.> exe) (localBin minorVerExe) @@ -87,20 +84,27 @@ cabalInstallHie versionNumber = do ++ minorVerExe ++ " to " ++ localBin -checkCabal_ :: Action () -checkCabal_ = checkCabal >> return () +getProjectFile :: VersionNumber -> Action FilePath +getProjectFile ver = do + existFile <- doesFileExist $ "cabal.project-" ++ ver + return $ if existFile + then "cabal.project-" ++ ver + else "cabal.project" + +checkCabal_ :: [String] -> Action () +checkCabal_ args = checkCabal args >> return () -- | check `cabal` has the required version -checkCabal :: Action String -checkCabal = do - cabalVersion <- getCabalVersion +checkCabal :: [String] -> Action String +checkCabal args = do + cabalVersion <- getCabalVersion args unless (checkVersion requiredCabalVersion cabalVersion) $ do printInStars $ cabalInstallIsOldFailMsg cabalVersion error $ cabalInstallIsOldFailMsg cabalVersion return cabalVersion -getCabalVersion :: Action String -getCabalVersion = trimmedStdout <$> execCabal ["--numeric-version"] +getCabalVersion :: [String] -> Action String +getCabalVersion args = trimmedStdout <$> (execCabal $ ["--numeric-version"] ++ args) -- | Error message when the `cabal` binary is an older version cabalInstallIsOldFailMsg :: String -> String @@ -119,3 +123,21 @@ requiredCabalVersion | isWindowsSystem = requiredCabalVersionForWindows requiredCabalVersionForWindows :: RequiredVersion requiredCabalVersionForWindows = [3, 0, 0, 0] + +getVerbosityArg :: Verbosity -> String +getVerbosityArg v = "-v" ++ cabalVerbosity + where cabalVerbosity = case v of + Silent -> "0" +#if MIN_VERSION_shake(0,18,4) + Error -> "0" + Warn -> "1" + Info -> "1" + Verbose -> "2" +#else + Quiet -> "0" + Normal -> "1" + Loud -> "2" + Chatty -> "2" +#endif + Diagnostic -> "3" + diff --git a/install/src/Env.hs b/install/src/Env.hs index 83c23b0fc..c53557aa4 100644 --- a/install/src/Env.hs +++ b/install/src/Env.hs @@ -1,15 +1,11 @@ module Env where import Development.Shake -import Development.Shake.Command import Control.Monad.IO.Class import Control.Monad import Development.Shake.FilePath -import System.Info ( os - , arch - ) +import System.Info ( os ) import Data.Maybe ( isJust - , isNothing , mapMaybe ) import System.Directory ( findExecutable diff --git a/install/src/Help.hs b/install/src/Help.hs index a512f2593..547cf39a5 100644 --- a/install/src/Help.hs +++ b/install/src/Help.hs @@ -2,21 +2,18 @@ module Help where import Development.Shake -import Data.List ( intersperse - , intercalate - ) +import Data.List ( intercalate ) import Env import Print import Version import BuildSystem -import Cabal stackCommand :: TargetDescription -> String -stackCommand target = "stack install.hs " ++ fst target +stackCommand target = "stack install.hs " ++ fst target ++ " [options]" cabalCommand :: TargetDescription -> String -cabalCommand target = "cabal v2-run install.hs --project-file install/shake.project " ++ fst target +cabalCommand target = "cabal v2-run install.hs --project-file install/shake.project -- " ++ fst target ++ " [options]" buildCommand :: TargetDescription -> String buildCommand | isRunFromCabal = cabalCommand @@ -37,7 +34,7 @@ shortHelpMessage = do printUsage printLine "" printLine "Targets:" - mapM_ (printLineIndented . showTarget (spaces hieVersions)) (targets hieVersions) + mapM_ (printLineIndented . showHelpItem (spaces hieVersions)) (targets hieVersions) printLine "" where spaces hieVersions = space (targets hieVersions) @@ -68,7 +65,10 @@ helpMessage versions@BuildableVersions {..} = do printUsage printLine "" printLine "Targets:" - mapM_ (printLineIndented . showTarget spaces) targets + mapM_ (printLineIndented . showHelpItem spaces) targets + printLine "" + printLine "Options:" + mapM_ (printLineIndented . showHelpItem spaces) options printLine "" where spaces = space targets @@ -81,6 +81,11 @@ helpMessage versions@BuildableVersions {..} = do , if isRunFromCabal then [cabalGhcsTarget] else [stackDevTarget] , [macosIcuTarget] ] + options = [ ("-j[N], --jobs[=N]", "Allow N jobs/threads at once [default number of CPUs].") + , ("-s, --silent", "Don't print anything.") + , ("-q, --quiet", "Print less (pass repeatedly for even less).") + , ("-V, --verbose", "Print more (pass repeatedly for even more).") + ] -- All targets with their respective help message. generalTargets = [helpTarget] diff --git a/install/src/HieInstall.hs b/install/src/HieInstall.hs index d46e2bffe..c98cb157d 100644 --- a/install/src/HieInstall.hs +++ b/install/src/HieInstall.hs @@ -1,43 +1,13 @@ module HieInstall where import Development.Shake -import Development.Shake.Command -import Development.Shake.FilePath import Control.Monad -import Control.Monad.IO.Class -import Control.Monad.Extra ( unlessM - , mapMaybeM - ) -import Data.Maybe ( isJust ) -import System.Directory ( listDirectory ) import System.Environment ( unsetEnv ) -import System.Info ( os - , arch - ) - -import Data.Maybe ( isNothing - , mapMaybe - ) -import Data.List ( dropWhileEnd - , intersperse - , intercalate - , sort - , sortOn - ) -import qualified Data.Text as T -import Data.Char ( isSpace ) -import Data.Version ( parseVersion - , makeVersion - , showVersion - ) -import Data.Function ( (&) ) -import Text.ParserCombinators.ReadP ( readP_to_S ) import BuildSystem import Stack import Cabal import Version -import Print import Env import Help @@ -53,37 +23,50 @@ defaultMain = do -- used for stack-based targets stackVersions <- getHieVersions - let versions = if isRunFromStack then stackVersions else cabalVersions + let versions = if isRunFromStack then stackVersions else cabalVersions let toolsVersions = BuildableVersions stackVersions cabalVersions let latestVersion = last versions shakeArgs shakeOptions { shakeFiles = "_build" } $ do + + shakeOptionsRules <- getShakeOptionsRules + + let verbosityArg = if isRunFromStack then Stack.getVerbosityArg else Cabal.getVerbosityArg + + let args = [verbosityArg (shakeVerbosity shakeOptionsRules)] + + phony "show-options" $ do + putNormal $ "Options:" + putNormal $ " Verbosity level: " ++ show (shakeVerbosity shakeOptionsRules) + want ["short-help"] -- general purpose targets phony "submodules" updateSubmodules phony "short-help" shortHelpMessage phony "help" (helpMessage toolsVersions) - - phony "check" (if isRunFromStack then checkStack else checkCabal_) + + phony "check" (if isRunFromStack then checkStack args else checkCabal_ args) phony "data" $ do + need ["show-options"] need ["submodules"] need ["check"] - if isRunFromStack then stackBuildData else cabalBuildData + if isRunFromStack then stackBuildData args else cabalBuildData args forM_ versions (\version -> phony ("hie-" ++ version) $ do + need ["show-options"] need ["submodules"] need ["check"] if isRunFromStack then - stackInstallHieWithErrMsg (Just version) + stackInstallHieWithErrMsg (Just version) args else - cabalInstallHie version + cabalInstallHie version args ) - + unless (null versions) $ do phony "latest" (need ["hie-" ++ latestVersion]) phony "hie" (need ["data", "latest"]) @@ -92,7 +75,9 @@ defaultMain = do -- Default `stack.yaml` uses ghc-8.8.2 and we can't build hie in windows -- TODO: Enable for windows when it uses ghc-8.8.3 when (isRunFromStack && not isWindowsSystem) $ - phony "dev" $ stackInstallHieWithErrMsg Nothing + phony "dev" $ do + need ["show-options"] + stackInstallHieWithErrMsg Nothing args -- cabal specific targets when isRunFromCabal $ do @@ -101,20 +86,23 @@ defaultMain = do phony "ghcs" $ showInstalledGhcs ghcPaths -- macos specific targets - phony "icu-macos-fix" - (need ["icu-macos-fix-install"] >> need ["icu-macos-fix-build"]) + phony "icu-macos-fix" $ do + need ["show-options"] + need ["icu-macos-fix-install"] + need ["icu-macos-fix-build"] + phony "icu-macos-fix-install" (command_ [] "brew" ["install", "icu4c"]) - phony "icu-macos-fix-build" $ mapM_ buildIcuMacosFix versions + phony "icu-macos-fix-build" $ mapM_ (flip buildIcuMacosFix $ args) versions -buildIcuMacosFix :: VersionNumber -> Action () -buildIcuMacosFix version = execStackWithGhc_ - version +buildIcuMacosFix :: VersionNumber -> [String] -> Action () +buildIcuMacosFix version args = execStackWithGhc_ + version $ [ "build" , "text-icu" , "--extra-lib-dirs=/usr/local/opt/icu4c/lib" , "--extra-include-dirs=/usr/local/opt/icu4c/include" - ] + ] ++ args -- | update the submodules that the project is in the state as required by the `stack.yaml` files updateSubmodules :: Action () diff --git a/install/src/Print.hs b/install/src/Print.hs index 41216022b..063525e7e 100644 --- a/install/src/Print.hs +++ b/install/src/Print.hs @@ -1,10 +1,8 @@ module Print where import Development.Shake -import Development.Shake.Command import Control.Monad.IO.Class import Data.List ( dropWhileEnd - , dropWhile ) import Data.Char ( isSpace ) @@ -37,11 +35,11 @@ type TargetDescription = (String, String) -- | Number of spaces the target name including whitespace should have. -- At least twenty, maybe more if target names are long. At most the length of the longest target plus five. -space :: [TargetDescription] -> Int -space phonyTargets = maximum (20 : map ((+ 5) . length . fst) phonyTargets) +space :: [(String,String)] -> Int +space helpItems = maximum (20 : map ((+ 5) . length . fst) helpItems) -- | Show a target. -- Concatenates the target with its help message and inserts whitespace between them. -showTarget :: Int -> TargetDescription -> String -showTarget spaces (target, msg) = - target ++ replicate (spaces - length target) ' ' ++ msg +showHelpItem :: Int -> (String,String) -> String +showHelpItem spaces (helpItemKey, msg) = + helpItemKey ++ replicate (spaces - length helpItemKey) ' ' ++ msg diff --git a/install/src/Stack.hs b/install/src/Stack.hs index ec8aabcd0..3049ec9cb 100644 --- a/install/src/Stack.hs +++ b/install/src/Stack.hs @@ -1,38 +1,32 @@ +{-# LANGUAGE CPP #-} module Stack where import Development.Shake -import Development.Shake.Command import Development.Shake.FilePath -import Control.Exception import Control.Monad -import Data.List import System.Directory ( copyFile ) -import System.FilePath ( splitSearchPath, searchPathSeparator, () ) -import System.Environment ( lookupEnv, setEnv, getEnvironment ) -import System.IO.Error ( isDoesNotExistError ) -import BuildSystem +-- import System.FilePath ( () ) import Version import Print -import Env -stackInstallHieWithErrMsg :: Maybe VersionNumber -> Action () -stackInstallHieWithErrMsg mbVersionNumber = - stackInstallHie mbVersionNumber +stackInstallHieWithErrMsg :: Maybe VersionNumber -> [String] -> Action () +stackInstallHieWithErrMsg mbVersionNumber args = + stackInstallHie mbVersionNumber args `actionOnException` liftIO (putStrLn stackBuildFailMsg) -- | copy the built binaries into the localBinDir -stackInstallHie :: Maybe VersionNumber -> Action () -stackInstallHie mbVersionNumber = do - versionNumber <- +stackInstallHie :: Maybe VersionNumber -> [String] -> Action () +stackInstallHie mbVersionNumber args = do + versionNumber <- case mbVersionNumber of Nothing -> do - execStackWithCfgFile_ "stack.yaml" ["install"] - getGhcVersionOfCfgFile "stack.yaml" + execStackWithCfgFile_ "stack.yaml" $ ["install"] ++ args + getGhcVersionOfCfgFile "stack.yaml" args Just vn -> do - execStackWithGhc_ vn ["install"] + execStackWithGhc_ vn $ ["install"] ++ args return vn - - localBinDir <- getLocalBin + + localBinDir <- getLocalBin args let hie = "hie" <.> exe liftIO $ do copyFile (localBinDir hie) @@ -40,31 +34,31 @@ stackInstallHie mbVersionNumber = do copyFile (localBinDir hie) (localBinDir "hie-" ++ dropExtension versionNumber <.> exe) -getGhcVersionOfCfgFile :: String -> Action VersionNumber -getGhcVersionOfCfgFile stackFile = do - Stdout ghcVersion <- - execStackWithCfgFile stackFile ["exec", "ghc", "--", "--numeric-version"] +getGhcVersionOfCfgFile :: String -> [String] -> Action VersionNumber +getGhcVersionOfCfgFile stackFile args = do + Stdout ghcVersion <- + execStackWithCfgFile stackFile $ ["exec", "ghc"] ++ args ++ ["--", "--numeric-version"] return $ trim ghcVersion -- | check `stack` has the required version -checkStack :: Action () -checkStack = do - stackVersion <- trimmedStdout <$> execStackShake ["--numeric-version"] +checkStack :: [String] -> Action () +checkStack args = do + stackVersion <- trimmedStdout <$> (execStackShake $ ["--numeric-version"] ++ args) unless (checkVersion requiredStackVersion stackVersion) $ do printInStars $ stackExeIsOldFailMsg stackVersion error $ stackExeIsOldFailMsg stackVersion -- | Get the local binary path of stack. -- Equal to the command `stack path --local-bin` -getLocalBin :: Action FilePath -getLocalBin = do - Stdout stackLocalDir' <- execStackShake ["path", "--local-bin"] +getLocalBin :: [String] -> Action FilePath +getLocalBin args = do + Stdout stackLocalDir' <- execStackShake $ ["path", "--local-bin"] ++ args return $ trim stackLocalDir' -stackBuildData :: Action () -stackBuildData = do - execStackShake_ ["build", "hoogle"] - execStackShake_ ["exec", "hoogle", "generate"] +stackBuildData :: [String] -> Action () +stackBuildData args = do + execStackShake_ $ ["build", "hoogle"] ++ args + execStackShake_ $ ["exec", "hoogle", "generate"] ++ args -- | Execute a stack command for a specified ghc, discarding the output execStackWithGhc_ :: VersionNumber -> [String] -> Action () @@ -82,7 +76,7 @@ execStackWithCfgFile_ = execStackWithCfgFile -- | Execute a stack command for a specified stack.yaml file execStackWithCfgFile :: CmdResult r => String -> [String] -> Action r -execStackWithCfgFile stackFile args = +execStackWithCfgFile stackFile args = command [] "stack" (("--stack-yaml=" ++ stackFile) : args) -- | Execute a stack command with the same resolver as the build script @@ -118,3 +112,20 @@ stackBuildFailMsg = ++ "If this does not work, open an issue at \n" ++ "\thttps://github.com/haskell/haskell-ide-engine" +getVerbosityArg :: Verbosity -> String +getVerbosityArg v = "--verbosity=" ++ stackVerbosity + where stackVerbosity = case v of + Silent -> "silent" +#if MIN_VERSION_shake(0,18,4) + Error -> "error" + Warn -> "warn" + Info -> "info" + Verbose -> "info" +#else + Quiet -> "error" + Normal -> "warn" + Loud -> "info" + Chatty -> "info" +#endif + + Diagnostic -> "debug" \ No newline at end of file diff --git a/install/src/Version.hs b/install/src/Version.hs index 0d89b4b95..464700414 100644 --- a/install/src/Version.hs +++ b/install/src/Version.hs @@ -6,7 +6,6 @@ import Data.Version ( Version , showVersion ) import Text.ParserCombinators.ReadP ( readP_to_S ) -import Control.Monad.IO.Class type VersionNumber = String diff --git a/stack-8.8.2.yaml b/stack-8.8.2.yaml index da9ba0672..fd4ed7b89 100644 --- a/stack-8.8.2.yaml +++ b/stack-8.8.2.yaml @@ -16,6 +16,8 @@ extra-deps: - constrained-dynamic-0.1.0.0 - floskell-0.10.2 - ghc-lib-parser-ex-8.8.4.0 +# To avoid build error with ghc-8.8.2 +# See https://github.com/haskell/haddock/issues/1123 - git: https://github.com/haskell/haddock.git commit: be8b02c4e3cffe7d45b3dad0a0f071d35a274d65 subdirs: