Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different with-http CPP check; fix remote imports in GHCJS #1330

Merged
merged 2 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dhall/dhall.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ Library
Build-Depends: semigroups == 0.18.*
Build-Depends: transformers == 0.4.2.*
Build-Depends: fail == 4.9.*
if flag(with-http)
CPP-Options:
-DWITH_HTTP
if impl(ghcjs)
Hs-Source-Dirs: ghcjs-src
Build-Depends:
Expand Down
3 changes: 2 additions & 1 deletion dhall/doctest/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ main = do
writeFile "file1" "./file2"

Test.DocTest.doctest
[ "--fast"
[ "-DWITH_HTTP"
, "--fast"
, "-i" <> (prefix </> "src")
, "-i" <> (prefix </> "ghc-src")
, prefix </> "src/Dhall.hs"
Expand Down
10 changes: 4 additions & 6 deletions dhall/ghc-src/Dhall/Import/HTTP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,10 @@ corsCompliant _ _ _ = return ()

type HTTPHeader = Network.HTTP.Types.Header

fetchFromHttpUrl
:: Manager
-> URL
-> Maybe [HTTPHeader]
-> StateT Status IO Text.Text
fetchFromHttpUrl manager childURL mheaders = do
fetchFromHttpUrl :: URL -> Maybe [HTTPHeader] -> StateT Status IO Text.Text
fetchFromHttpUrl childURL mheaders = do
manager <- liftIO $ newManager

let childURLString = Text.unpack (renderURL childURL)

request <- liftIO (HTTP.parseUrlThrow childURLString)
Expand Down
7 changes: 3 additions & 4 deletions dhall/ghcjs-src/Dhall/Import/HTTP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ import Dhall.URL (renderURL)
import Dhall.Import.Types

fetchFromHttpUrl
:: a
-> URL
:: URL
-> Maybe [(CI ByteString, ByteString)]
-> StateT Status IO Text.Text
fetchFromHttpUrl _ childURL Nothing = do
fetchFromHttpUrl childURL Nothing = do
let childURLText = renderURL childURL

let childURLString = Text.unpack childURLText
Expand All @@ -35,5 +34,5 @@ fetchFromHttpUrl _ childURL Nothing = do
_ -> fail (childURLString <> " returned a non-200 status code: " <> show statusCode)

return body
fetchFromHttpUrl _ _ _ = do
fetchFromHttpUrl _ _ = do
fail "Dhall does not yet support custom headers when built using GHCJS"
16 changes: 7 additions & 9 deletions dhall/src/Dhall/Import.hs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ import Dhall.Core
, bindingExprs
, chunkExprs
)
#ifdef MIN_VERSION_http_client
import Network.HTTP.Client (Manager)
#ifdef WITH_HTTP
import Dhall.Import.HTTP hiding (HTTPHeader)
#endif
import Dhall.Import.Types
Expand Down Expand Up @@ -703,22 +702,21 @@ fetchFresh Missing = throwM (MissingImports [])


fetchRemote :: URL -> StateT Status IO Data.Text.Text
#ifndef MIN_VERSION_http_client
#ifndef WITH_HTTP
fetchRemote (url@URL { headers = maybeHeadersExpression }) = do
let maybeHeaders = fmap toHeaders maybeHeadersExpression
let urlString = Text.unpack (Dhall.Core.pretty url)
Status { _stack } <- State.get
throwMissingImport (Imported _stack (CannotImportHTTPURL urlString maybeHeaders))
#else
fetchRemote url = do
manager <- liftIO $ newManager
zoom remote (State.put (fetchFromHTTP manager))
fetchFromHTTP manager url
zoom remote (State.put fetchFromHTTP)
fetchFromHTTP url
where
fetchFromHTTP :: Manager -> URL -> StateT Status IO Data.Text.Text
fetchFromHTTP manager (url'@URL { headers = maybeHeadersExpression }) = do
fetchFromHTTP :: URL -> StateT Status IO Data.Text.Text
fetchFromHTTP (url'@URL { headers = maybeHeadersExpression }) = do
let maybeHeaders = fmap toHeaders maybeHeadersExpression
fetchFromHttpUrl manager url' maybeHeaders
fetchFromHttpUrl url' maybeHeaders
#endif

-- | Given a well-typed (of type `List { header : Text, value Text }` or
Expand Down