on master help sign in
Cleanup GHC API version checks

Previously we had a mix of GHC_STABLE and checks on __GLASGOW_HASKELL__. This PR changes this to always check on MIN_GHC_API_VERSION. Depending on whether you use ghc-lib or not (now controlled by a cabal flag), this macro expands to MIN_VERSION_ghc or MIN_VERSION_ghc_lib.

commit2c24f2be15fd088553f3c0e67379cf5014ccba11 authorMoritz Kiefer <moritz.kiefer@purelyfunctional.org> dateMon 16 Sep 2019, 11:31 (7 years ago) parent6164d0d
11 files changed+126−22
azure-pipelines.yml+44 ghcide.cabal+22−4 include/ghc-api-version.h+10 src/Development/IDE/Core/Compile.hs+3−2 src/Development/IDE/GHC/CPP.hs+5−4 src/Development/IDE/GHC/Compat.hs+10−5 src/Development/IDE/GHC/Util.hs+3−2 src/Development/IDE/Import/FindImports.hs+3−2 src/Development/IDE/Spans/Calculate.hs+2−1 stack-ghc-lib.yaml+23 stack.yaml+1−2
azure-pipelines.yml+44
@@ -101,3 +101,47 @@ jobs:
101101 --data "{\"text\":\"<!here> *FAILED* $(Agent.JobName): <https://dev.azure.com/digitalasset/ghcide/_build/results?buildId=$(Build.BuildId)|$MESSAGE>\n\"}" \
102102 $(Slack.URL)
103103 condition: and(failed(), eq(variables['Build.SourceBranchName'], 'master'))
104+ - job: ghcide_stack_ghc_lib_88
105+ timeoutInMinutes: 60
106+ pool:
107+ vmImage: 'ubuntu-latest'
108+ steps:
109+ - checkout: self
110+ - task: CacheBeta@0
111+ inputs:
112+ key: stack-cache-v1 | $(Agent.OS) | $(Build.SourcesDirectory)/stack-ghc-lib.yaml | $(Build.SourcesDirectory)/ghcide.cabal
113+ path: .azure-cache
114+ cacheHitVar: CACHE_RESTORED
115+ displayName: "Cache stack artifacts"
116+ - bash: |
117+ mkdir -p ~/.stack
118+ tar xzf .azure-cache/stack-root.tar.gz -C $HOME
119+ displayName: "Unpack cache"
120+ condition: eq(variables.CACHE_RESTORED, 'true')
121+ - bash: |
122+ ./fmt.sh
123+ displayName: "HLint via ./fmt.sh"
124+ - bash: |
125+ sudo apt-get install -y g++ gcc libc6-dev libffi-dev libgmp-dev make zlib1g-dev
126+ curl -sSL https://get.haskellstack.org/ | sh
127+ displayName: 'Install Stack'
128+ - bash: stack setup --stack-yaml=stack-ghc-lib.yaml
129+ displayName: 'stack setup --stack-yaml=stack-ghc-lib.yaml'
130+ - bash: stack build --only-dependencies --stack-yaml=stack-ghc-lib.yaml
131+ displayName: 'stack build --only-dependencies --stack-yaml=stack-ghc-lib.yaml'
132+ - bash: stack test --stack-yaml=stack-ghc-lib.yaml || stack test --stack-yaml=stack-ghc-lib.yaml || stack test --stack-yaml=stack-ghc-lib.yaml
133+ # ghcide stack tests are flaky, see https://github.com/digital-asset/daml/issues/2606.
134+ displayName: 'stack test --stack-yaml=stack-ghc-lib.yaml'
135+ - bash: |
136+ mkdir -p .azure-cache
137+ tar czf .azure-cache/stack-root.tar.gz -C $HOME .stack
138+ displayName: "Pack cache"
139+ - bash: |
140+ set -euo pipefail
141+ MESSAGE=$(git log --pretty=format:%s -n1)
142+ curl -XPOST \
143+ -i \
144+ -H 'Content-type: application/json' \
145+ --data "{\"text\":\"<!here> *FAILED* $(Agent.JobName): <https://dev.azure.com/digitalasset/ghcide/_build/results?buildId=$(Build.BuildId)|$MESSAGE>\n\"}" \
146+ $(Slack.URL)
147+ condition: and(failed(), eq(variables['Build.SourceBranchName'], 'master'))
ghcide.cabal+22−4
@@ -14,11 +14,17 @@ description:
1414homepage: https://github.com/digital-asset/ghcide#readme
1515bug-reports: https://github.com/digital-asset/ghcide/issues
1616tested-with: GHC==8.6.5
17+extra-source-files: include/ghc-api-version.h README.md
1718
1819source-repository head
1920 type: git
2021 location: https://github.com/digital-asset/ghcide.git
2122
23+flag ghc-lib
24+ description: build against ghc-lib instead of the ghc package
25+ default: False
26+ manual: True
27+
2228library
2329 default-language: Haskell2010
2430 build-depends:
@@ -33,9 +39,6 @@ library
3339 directory,
3440 extra,
3541 filepath,
36− ghc-boot-th,
37− ghc-boot,
38− ghc >= 8.4,
3942 hashable,
4043 haskell-lsp-types,
4144 haskell-lsp >= 0.15,
@@ -55,13 +58,22 @@ library
5558 transformers,
5659 unordered-containers,
5760 utf8-string
61+ if flag(ghc-lib)
62+ build-depends:
63+ ghc-lib >= 8.8,
64+ ghc-lib-parser >= 8.8
65+ cpp-options: -DGHC_LIB
66+ else
67+ build-depends:
68+ ghc-boot-th,
69+ ghc-boot,
70+ ghc >= 8.4
5871 if !os(windows)
5972 build-depends:
6073 unix
6174 c-sources:
6275 cbits/getmodtime.c
6376
64− cpp-options: -DGHC_STABLE
6577 default-extensions:
6678 BangPatterns
6779 DeriveFunctor
@@ -79,6 +91,8 @@ library
7991
8092 hs-source-dirs:
8193 src
94+ include-dirs:
95+ include
8296 exposed-modules:
8397 Development.IDE.Core.FileStore
8498 Development.IDE.Core.OfInterest
@@ -116,6 +130,8 @@ library
116130 Development.IDE.Spans.Type
117131
118132executable ghcide
133+ if flag(ghc-lib)
134+ buildable: False
119135 default-language: Haskell2010
120136 hs-source-dirs: exe
121137 ghc-options: -threaded
@@ -144,6 +160,8 @@ executable ghcide
144160 ViewPatterns
145161
146162test-suite ghcide-tests
163+ if flag(ghc-lib)
164+ buildable: False
147165 type: exitcode-stdio-1.0
148166 default-language: Haskell2010
149167 build-tool-depends:
include/ghc-api-version.hnew file+10
@@ -0,0 +1,10 @@
1+#ifndef GHC_API_VERSION_H
2+#define GHC_API_VERSION_H
3+
4+#ifdef GHC_LIB
5+#define MIN_GHC_API_VERSION(x,y,z) MIN_VERSION_ghc_lib(x,y,z)
6+#else
7+#define MIN_GHC_API_VERSION(x,y,z) MIN_VERSION_ghc(x,y,z)
8+#endif
9+
10+#endif
src/Development/IDE/Core/Compile.hs+3−2
@@ -3,6 +3,7 @@
33
44{-# LANGUAGE RankNTypes #-}
55{-# LANGUAGE CPP #-}
6+#include "ghc-api-version.h"
67
78-- | Based on https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/API.
89-- Given a list of paths to find libraries, and a file to compile, produce a list of 'CoreModule' values.
@@ -225,7 +226,7 @@ getModSummaryFromBuffer fp contents dflags parsed = do
225226 { ml_hs_file = Just fp
226227 , ml_hi_file = derivedFile "hi"
227228 , ml_obj_file = derivedFile "o"
228−#ifndef GHC_STABLE
229+#if MIN_GHC_API_VERSION(8,8,0)
229230 , ml_hie_file = derivedFile "hie"
230231#endif
231232 -- This does not consider the dflags configuration
@@ -250,7 +251,7 @@ getModSummaryFromBuffer fp contents dflags parsed = do
250251 , ms_hsc_src = sourceType
251252 , ms_obj_date = Nothing
252253 , ms_iface_date = Nothing
253−#ifndef GHC_STABLE
254+#if MIN_GHC_API_VERSION(8,8,0)
254255 , ms_hie_date = Nothing
255256#endif
256257 , ms_srcimps = [imp | (True, imp) <- imports]
src/Development/IDE/GHC/CPP.hs+5−4
@@ -9,6 +9,7 @@
99
1010{-# LANGUAGE CPP, NamedFieldPuns, NondecreasingIndentation, BangPatterns, MultiWayIf #-}
1111{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
12+#include "ghc-api-version.h"
1213
1314-----------------------------------------------------------------------------
1415--
@@ -27,7 +28,7 @@ import Module
2728import DynFlags
2829import Panic
2930import FileCleanup
30−#ifndef GHC_STABLE
31+#if MIN_GHC_API_VERSION(8,8,0)
3132import LlvmCodeGen (LlvmVersion (..))
3233#endif
3334
@@ -136,11 +137,11 @@ getBackendDefs :: DynFlags -> IO [String]
136137getBackendDefs dflags | hscTarget dflags == HscLlvm = do
137138 llvmVer <- figureLlvmVersion dflags
138139 return $ case llvmVer of
139−#ifdef GHC_STABLE
140− Just n -> [ "-D__GLASGOW_HASKELL_LLVM__=" ++ format n ]
141−#else
140+#if MIN_GHC_API_VERSION(8,8,0)
142141 Just (LlvmVersion n) -> [ "-D__GLASGOW_HASKELL_LLVM__=" ++ format (n,0) ]
143142 Just (LlvmVersionOld m n) -> [ "-D__GLASGOW_HASKELL_LLVM__=" ++ format (m,n) ]
143+#else
144+ Just n -> [ "-D__GLASGOW_HASKELL_LLVM__=" ++ format n ]
144145#endif
145146 _ -> []
146147 where
src/Development/IDE/GHC/Compat.hs+10−5
@@ -2,6 +2,7 @@
22-- SPDX-License-Identifier: Apache-2.0
33
44{-# LANGUAGE CPP #-}
5+#include "ghc-api-version.h"
56
67-- | Attempt at hiding the GHC version differences we can.
78module Development.IDE.GHC.Compat(
@@ -21,7 +22,11 @@ import StringBuffer
2122import DynFlags
2223import GHC.LanguageExtensions.Type
2324
24−#ifndef GHC_STABLE
25+#if MIN_GHC_API_VERSION(8,8,0)
26+import Data.List.Extra (enumerate)
27+#endif
28+
29+#if MIN_GHC_API_VERSION(8,8,0)
2530import HieAst
2631import HieBin
2732import HieTypes
@@ -53,7 +58,7 @@ data HieFile = HieFile {hie_module :: (), hie_exports :: [AvailInfo]}
5358data HieFileResult = HieFileResult { hie_file_result :: HieFile }
5459#endif
5560
56−#if __GLASGOW_HASKELL__ < 806
61+#if !MIN_GHC_API_VERSION(8,6,0)
5762includePathsGlobal, includePathsQuote :: [String] -> [String]
5863includePathsGlobal = id
5964includePathsQuote = const []
@@ -61,7 +66,7 @@ includePathsQuote = const []
6166
6267
6368addIncludePathsQuote :: FilePath -> DynFlags -> DynFlags
64−#if __GLASGOW_HASKELL__ >= 806
69+#if MIN_GHC_API_VERSION(8,6,0)
6570addIncludePathsQuote path x = x{includePaths = f $ includePaths x}
6671 where f i = i{includePathsQuote = path : includePathsQuote i}
6772#else
@@ -69,9 +74,9 @@ addIncludePathsQuote path x = x{includePaths = path : includePaths x}
6974#endif
7075
7176ghcEnumerateExtensions :: [Extension]
72−#if __GLASGOW_HASKELL__ >= 808
77+#if MIN_GHC_API_VERSION(8,8,0)
7378ghcEnumerateExtensions = enumerate
74−#elif __GLASGOW_HASKELL__ >= 806
79+#elif MIN_GHC_API_VERSION(8,6,0)
7580ghcEnumerateExtensions = [Cpp .. StarIsType]
7681#else
7782ghcEnumerateExtensions = [Cpp .. EmptyDataDeriving]
src/Development/IDE/GHC/Util.hs+3−2
@@ -3,6 +3,7 @@
33
44{-# OPTIONS_GHC -Wno-missing-fields #-} -- to enable prettyPrint
55{-# LANGUAGE CPP #-}
6+#include "ghc-api-version.h"
67
78-- | GHC utility functions. Importantly, code using our GHC should never:
89--
@@ -22,7 +23,7 @@ module Development.IDE.GHC.Util(
2223
2324import Config
2425import Data.List.Extra
25−#if __GLASGOW_HASKELL__ >= 806
26+#if MIN_GHC_API_VERSION(8,6,0)
2627import Fingerprint
2728#endif
2829import GHC
@@ -88,7 +89,7 @@ fakeDynFlags = defaultDynFlags settings mempty
8889 , sPlatformConstants = platformConstants
8990 , sProgramName = "ghc"
9091 , sProjectVersion = cProjectVersion
91−#if __GLASGOW_HASKELL__ >= 806
92+#if MIN_GHC_API_VERSION(8,6,0)
9293 , sOpt_P_fingerprint = fingerprint0
9394#endif
9495 }
src/Development/IDE/Import/FindImports.hs+3−2
@@ -2,6 +2,7 @@
22-- SPDX-License-Identifier: Apache-2.0
33
44{-# LANGUAGE CPP #-}
5+#include "ghc-api-version.h"
56
67module Development.IDE.Import.FindImports
78 ( locateModule
@@ -108,7 +109,7 @@ notFoundErr dfs modName reason =
108109 { fr_pkgs_hidden = map (moduleUnitId . fst) pkg_hiddens
109110 , fr_mods_hidden = map (moduleUnitId . fst) mod_hiddens
110111 }
111−#if __GLASGOW_HASKELL__ >= 806
112+#if MIN_GHC_API_VERSION(8,6,0)
112113 LookupUnusable unusable ->
113114 let unusables' = map get_unusable unusable
114115 get_unusable (m, ModUnusable r) = (moduleUnitId m, r)
@@ -125,7 +126,7 @@ notFound = NotFound
125126 , fr_pkg = Nothing
126127 , fr_pkgs_hidden = []
127128 , fr_mods_hidden = []
128−#if __GLASGOW_HASKELL__ >= 806
129+#if MIN_GHC_API_VERSION(8,6,0)
129130 , fr_unusables = []
130131#endif
131132 , fr_suggestions = []
src/Development/IDE/Spans/Calculate.hs+2−1
@@ -5,6 +5,7 @@
55
66{-# LANGUAGE CPP #-}
77{-# LANGUAGE RankNTypes #-}
8+#include "ghc-api-version.h"
89
910-- | Get information on modules, identifiers, etc.
1011
@@ -34,7 +35,7 @@ import Development.IDE.GHC.Util
3435
3536-- A lot of things gained an extra X argument in GHC 8.6, which we mostly ignore
3637-- this U ignores that arg in 8.6, but is hidden in 8.4
37−#if __GLASGOW_HASKELL__ >= 806
38+#if MIN_GHC_API_VERSION(8,6,0)
3839#define U _
3940#else
4041#define U
stack-ghc-lib.yamlnew file+23
@@ -0,0 +1,23 @@
1+resolver: nightly-2019-09-16
2+packages:
3+- .
4+extra-deps:
5+- git: https://github.com/alanz/haskell-lsp.git
6+ commit: bfbd8630504ebc57b70948689c37b85cfbe589da
7+ subdirs:
8+ - .
9+ - haskell-lsp-types
10+- git: https://github.com/bubba/lsp-test.git
11+ commit: d126623dc6895d325e3d204d74e2a22d4f515587
12+- git: https://github.com/mpickering/hie-bios.git
13+ commit: 89e4ba24f87aac9909d9814b0e8c51b679a0ccd4
14+- ghc-lib-parser-8.8.1
15+- ghc-lib-8.8.1
16+nix:
17+ packages: [zlib]
18+flags:
19+ ghcide:
20+ ghc-lib: True
21+ghc-options:
22+ ghc-lib-parser: -O0
23+ ghc-lib: -O0
stack.yaml+1−2
@@ -1,4 +1,4 @@
1−resolver: nightly-2019-05-20
1+resolver: nightly-2019-09-16
22packages:
33- .
44
@@ -14,4 +14,3 @@ extra-deps:
1414 commit: 89e4ba24f87aac9909d9814b0e8c51b679a0ccd4
1515nix:
1616 packages: [zlib]
17−allow-newer: true