Skip to content

Commit cd49b65

Browse files
sjakobimergify[bot]
authored andcommitted
Move HsYAML-based code to new package dhall-yaml (#1514)
* Shared code for the dhall-to-yaml[-ng] executables stays in dhall-json. * Shared tests are in dhall-yaml. Fixes #1435.
1 parent e931451 commit cd49b65

38 files changed

+489
-279
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ install:
4747

4848
script:
4949
- export PATH="${PATH}:$(pwd)/bin"
50-
- stack build --flag dhall-json:gpl --copy-bins --local-bin-path ./bin
50+
- stack build --copy-bins --local-bin-path ./bin
5151
- source .travis-functions.sh
5252
- tar -jcvf $(mk_release_name dhall) bin/dhall
53-
- tar -jcvf $(mk_release_name dhall-json) bin/dhall-to-json bin/dhall-to-yaml bin/json-to-dhall bin/yaml-to-dhall
53+
- tar -jcvf $(mk_release_name dhall-json) bin/dhall-to-json bin/dhall-to-yaml bin/json-to-dhall
5454
- tar -jcvf $(mk_release_name dhall-bash) bin/dhall-to-bash
5555
- tar -jcvf $(mk_release_name dhall-lsp-server) bin/dhall-lsp-server
5656
- tar -jcvf $(mk_release_name dhall-nix) bin/dhall-to-nix
57+
- tar -jcvf $(mk_release_name dhall-yaml) bin/dhall-to-yaml-ng bin/yaml-to-dhall
5758
- mkdir -p uploads
5859
- mv *.tar.bz2 uploads/
5960

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ the following packages:
1010
* [`dhall`](./dhall) - [![Hackage](https://img.shields.io/hackage/v/dhall.svg)](https://hackage.haskell.org/package/dhall)
1111
* [`dhall-bash`](./dhall-bash) - [![Hackage](https://img.shields.io/hackage/v/dhall-bash.svg)](https://hackage.haskell.org/package/dhall-bash)
1212
* [`dhall-json`](./dhall-json) - [![Hackage](https://img.shields.io/hackage/v/dhall-json.svg)](https://hackage.haskell.org/package/dhall-json)
13+
* [`dhall-yaml`](./dhall-yaml) - [![Hackage](https://img.shields.io/hackage/v/dhall-yaml.svg)](https://hackage.haskell.org/package/dhall-yaml)
1314
* [`dhall-nix`](./dhall-nix) - [![Hackage](https://img.shields.io/hackage/v/dhall-nix.svg)](https://hackage.haskell.org/package/dhall-nix)
1415

1516
Navigate to each package's directory for their respective `README`s
@@ -38,6 +39,7 @@ visit one of the following links:
3839
* [https://hydra.dhall-lang.org/job/dhall-haskell/master/linux-dhall/latest](https://hydra.dhall-lang.org/job/dhall-haskell/master/linux-dhall/latest)
3940
* [https://hydra.dhall-lang.org/job/dhall-haskell/master/linux-dhall-bash/latest](https://hydra.dhall-lang.org/job/dhall-haskell/master/linux-dhall-bash/latest)
4041
* [https://hydra.dhall-lang.org/job/dhall-haskell/master/linux-dhall-json/latest](https://hydra.dhall-lang.org/job/dhall-haskell/master/linux-dhall-json/latest)
42+
* [https://hydra.dhall-lang.org/job/dhall-haskell/master/linux-dhall-yaml/latest](https://hydra.dhall-lang.org/job/dhall-haskell/master/linux-dhall-yaml/latest)
4143
* [https://hydra.dhall-lang.org/job/dhall-haskell/master/linux-dhall-nix/latest](https://hydra.dhall-lang.org/job/dhall-haskell/master/linux-dhall-nix/latest)
4244
* [https://hydra.dhall-lang.org/job/dhall-haskell/master/linux-dhall-lsp-server/latest](https://hydra.dhall-lang.org/job/dhall-haskell/master/linux-dhall-lsp-server/latest)
4345

@@ -67,6 +69,7 @@ download image archives for each package using the following URLs:
6769
* [https://hydra.dhall-lang.org/job/dhall-haskell/master/image-dhall/latest/download/1/docker-image-dhall.tar.gz](https://hydra.dhall-lang.org/job/dhall-haskell/master/image-dhall/latest/download/1/docker-image-dhall.tar.gz)
6870
* [https://hydra.dhall-lang.org/job/dhall-haskell/master/image-dhall-bash/latest/download/1/docker-image-dhall-bash.tar.gz](https://hydra.dhall-lang.org/job/dhall-haskell/master/image-dhall-bash/latest/download/1/docker-image-dhall-bash.tar.gz)
6971
* [https://hydra.dhall-lang.org/job/dhall-haskell/master/image-dhall-json/latest/download/1/docker-image-dhall-json.tar.gz](https://hydra.dhall-lang.org/job/dhall-haskell/master/image-dhall-json/latest/download/1/docker-image-dhall-json.tar.gz)
72+
* [https://hydra.dhall-lang.org/job/dhall-haskell/master/image-dhall-yaml/latest/download/1/docker-image-dhall-yaml.tar.gz](https://hydra.dhall-lang.org/job/dhall-haskell/master/image-dhall-yaml/latest/download/1/docker-image-dhall-yaml.tar.gz)
7073
* [https://hydra.dhall-lang.org/job/dhall-haskell/master/image-dhall-lsp-server/latest/download/1/docker-image-dhall-lsp-server.tar.gz](https://hydra.dhall-lang.org/job/dhall-haskell/master/image-dhall-lsp-server/latest/download/1/docker-image-dhall-lsp-server.tar.gz)
7174
* [https://hydra.dhall-lang.org/job/dhall-haskell/master/image-dhall-nix/latest/download/1/docker-image-dhall-nix.tar.gz](https://hydra.dhall-lang.org/job/dhall-haskell/master/image-dhall-nix/latest/download/1/docker-image-dhall-nix.tar.gz)
7275

appveyor.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ for:
4949
- if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-json-%DEPLOY_TAG%" "%DEPLOY_DIR%\dhall-to-json.exe")
5050
- if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-json-%DEPLOY_TAG%" "%DEPLOY_DIR%\dhall-to-yaml.exe")
5151
- if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-json-%DEPLOY_TAG%" "%DEPLOY_DIR%\json-to-dhall.exe")
52-
- if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-json-%DEPLOY_TAG%" "%DEPLOY_DIR%\yaml-to-dhall.exe")
5352
- if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-bash-%DEPLOY_TAG%" "%DEPLOY_DIR%\dhall-to-bash.exe")
5453
- if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-lsp-server-%DEPLOY_TAG%" "%DEPLOY_DIR%\dhall-lsp-server.exe")
54+
- if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-yaml-%DEPLOY_TAG%" "%DEPLOY_DIR%\dhall-to-yaml-ng.exe")
55+
- if /I "%DEPLOY_TAG%" NEQ "" (7z a "bin\dhall-yaml-%DEPLOY_TAG%" "%DEPLOY_DIR%\yaml-to-dhall.exe")
5556

5657
test_script:
5758
# chcp 65001 (utf-8) needed to make doctest work
5859
- chcp 65001 && stack test dhall
5960
- stack test dhall-json
61+
- stack test dhall-yaml
6062
- stack test dhall-bash
6163
- stack test dhall-lsp-server
6264
- stack bench dhall --benchmark-arguments "--quick --min-duration=0 --include-first-iter"
@@ -79,6 +81,8 @@ artifacts:
7981
name: dhall
8082
- path: bin\dhall-json-%DEPLOY_TAG%
8183
name: dhall-json
84+
- path: bin\dhall-yaml-%DEPLOY_TAG%
85+
name: dhall-yaml
8286
- path: bin\dhall-bash-%DEPLOY_TAG%
8387
name: dhall-bash
8488
- path: bin\dhall-lsp-server-%DEPLOY_TAG%
@@ -88,7 +92,7 @@ deploy:
8892
- provider: GitHub
8993
auth_token:
9094
secure: Gs/tiz6Jtg/Zjd4zGHDhuSv4Y9a+zJ574LWwzOe2bvZNGX/M8XupkxdGmBpDlnOf
91-
artifact: dhall, dhall-json, dhall-bash, dhall-lsp-server
95+
artifact: dhall, dhall-json, dhall-yaml, dhall-bash, dhall-lsp-server
9296
on:
9397
APPVEYOR_REPO_TAG: true
9498
STACK_YAML: stack.yaml

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
packages: ./dhall ./dhall-bash ./dhall-json ./dhall-lsp-server ./dhall-nix
1+
packages: ./dhall ./dhall-bash ./dhall-json ./dhall-yaml ./dhall-lsp-server ./dhall-nix

default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ in
1313
dhall-json
1414
dhall-lsp-server
1515
dhall-nix
16+
dhall-yaml
1617
;
1718

1819
inherit (shared_ghcjs) dhall-try;

dhall-json/LICENSE.BSD3 renamed to dhall-json/LICENSE

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
The following license applies to this package when built without the
2-
`-fgpl` Cabal configure flag
3-
41
Copyright (c) 2018 Gabriel Gonzalez
52
All rights reserved.
63

dhall-json/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ Full documentation here:
1010

1111
## Introduction
1212

13-
This `dhall-json` package provides a Dhall to JSON compiler and a Dhall to YAML
14-
compiler. The reason this package is called `dhall-json` is that the Haskell
15-
`yaml` library uses the same data structure as Haskell's `aeson` library for
16-
JSON
13+
This `dhall-json` package provides a Dhall to JSON compiler, and a Dhall to YAML
14+
compiler based on that. The `dhall-to-yaml` executable is a "basic" version of
15+
the `dhall-to-yaml-ng` executable in the `dhall-yaml` package.
1716

1817
## Example
1918

@@ -30,3 +29,9 @@ foo:
3029
bar:
3130
baz: true
3231
```
32+
33+
## Development
34+
35+
This package's `dhall-to-yaml` and `dhall-yaml`'s `dhall-to-yaml-ng` should be
36+
kept as closely in sync as possible. Common code for these executables lives
37+
in this package, tests live in `dhall-yaml`.

dhall-json/dhall-json.cabal

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Cabal-Version: >=1.8.0.2
44
Build-Type: Simple
55
Tested-With: GHC == 7.10.3, GHC == 8.4.3, GHC == 8.6.1
66
License: BSD3
7-
License-Files: LICENSE.BSD3, LICENSE.GPLv3
7+
License-File: LICENSE
88
Copyright: 2017 Gabriel Gonzalez
99
Author: Gabriel Gonzalez
1010
Maintainer: Gabriel439@gmail.com
@@ -26,24 +26,18 @@ Extra-Source-Files:
2626
CHANGELOG.md
2727
tasty/data/*.dhall
2828
tasty/data/*.json
29-
tasty/data/*.txt
30-
tasty/data/*.yaml
3129

3230
Source-Repository head
3331
Type: git
3432
Location: https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-json
3533

36-
Flag gpl
37-
Description: Use GPL-licensed components like HsYAML, and enable yaml-to-dhall binary
38-
Default: False
39-
Manual: True
40-
4134
Library
4235
Hs-Source-Dirs: src
4336
Build-Depends:
4437
base >= 4.8.0.0 && < 5 ,
4538
aeson >= 1.0.0.0 && < 1.5 ,
4639
aeson-pretty < 0.9 ,
40+
aeson-yaml >= 1.0.4 && < 1.1 ,
4741
bytestring < 0.11,
4842
containers ,
4943
dhall >= 1.27.0 && < 1.28,
@@ -58,21 +52,11 @@ Library
5852
Exposed-Modules:
5953
Dhall.JSON
6054
Dhall.JSONToDhall
61-
Dhall.Yaml
62-
if flag(gpl)
63-
Exposed-Modules:
64-
Dhall.YamlToDhall
55+
Dhall.JSON.Yaml
56+
Dhall.DhallToYaml.Main
6557
Other-Modules:
6658
Dhall.JSON.Util
6759
GHC-Options: -Wall
68-
if flag(gpl)
69-
CPP-Options: -DGPL
70-
Build-Depends:
71-
HsYAML >= 0.2 && < 0.3,
72-
HsYAML-aeson >= 0.2 && < 0.3
73-
else
74-
Build-Depends:
75-
aeson-yaml >= 1.0.2 && < 1.1
7660

7761
Executable dhall-to-json
7862
Hs-Source-Dirs: dhall-to-json
@@ -94,13 +78,8 @@ Executable dhall-to-yaml
9478
Hs-Source-Dirs: dhall-to-yaml
9579
Main-Is: Main.hs
9680
Build-Depends:
97-
base ,
98-
aeson ,
99-
bytestring < 0.11,
100-
dhall ,
101-
dhall-json ,
102-
optparse-applicative ,
103-
text
81+
base ,
82+
dhall-json
10483
Other-Modules:
10584
Paths_dhall_json
10685
GHC-Options: -Wall
@@ -126,39 +105,17 @@ Executable json-to-dhall
126105
Paths_dhall_json
127106
GHC-Options: -Wall
128107

129-
Executable yaml-to-dhall
130-
if !flag(gpl)
131-
Buildable: False
132-
Hs-Source-Dirs: yaml-to-dhall
133-
Main-Is: Main.hs
134-
Build-Depends:
135-
base ,
136-
aeson ,
137-
ansi-terminal >= 0.6.3.1 && < 0.11,
138-
bytestring < 0.11,
139-
dhall ,
140-
dhall-json ,
141-
exceptions >= 0.8.3 && < 0.11,
142-
optparse-applicative ,
143-
prettyprinter ,
144-
prettyprinter-ansi-terminal >= 1.1.1 && < 1.2 ,
145-
text < 1.3
146-
if !impl(ghc >= 8.0) && !impl(eta >= 0.8.4)
147-
Build-Depends: semigroups == 0.18.*
148-
Other-Modules:
149-
Paths_dhall_json
150-
GHC-Options: -Wall
151-
152108
Test-Suite tasty
153109
Type: exitcode-stdio-1.0
154110
Hs-Source-Dirs: tasty
155111
Main-Is: Main.hs
156112
Build-Depends:
157-
base,
113+
base ,
158114
aeson ,
159115
bytestring ,
160116
dhall ,
161117
dhall-json ,
162118
tasty < 1.3,
163119
text ,
164120
tasty-hunit >= 0.2
121+
GHC-Options: -Wall

dhall-json/dhall-to-yaml/Main.hs

Lines changed: 4 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,8 @@
1-
{-# LANGUAGE OverloadedStrings #-}
2-
{-# LANGUAGE RecordWildCards #-}
31
module Main where
42

5-
import Control.Applicative (optional, (<|>))
6-
import Control.Exception (SomeException)
7-
import Data.Monoid ((<>))
8-
import Dhall.JSON (parsePreservationAndOmission, parseConversion)
9-
import Dhall.Yaml (Options(..), dhallToYaml, parseDocuments, parseQuoted)
10-
import Options.Applicative (Parser, ParserInfo)
11-
12-
import qualified Control.Exception
13-
import qualified Data.ByteString
14-
import qualified Data.Text.IO as Text.IO
15-
import qualified Data.Version
16-
import qualified GHC.IO.Encoding
17-
import qualified Options.Applicative as Options
18-
import qualified Paths_dhall_json as Meta
19-
import qualified System.Exit
20-
import qualified System.IO
21-
22-
parseOptions :: Parser (Maybe Options)
23-
parseOptions =
24-
Just
25-
<$> ( Options
26-
<$> parseExplain
27-
<*> Dhall.JSON.parsePreservationAndOmission
28-
<*> parseDocuments
29-
<*> parseQuoted
30-
<*> Dhall.JSON.parseConversion
31-
<*> optional parseFile
32-
<*> optional parseOutput
33-
)
34-
<|> parseVersion
35-
where
36-
parseExplain =
37-
Options.switch
38-
( Options.long "explain"
39-
<> Options.help "Explain error messages in detail"
40-
)
41-
42-
parseFile =
43-
Options.strOption
44-
( Options.long "file"
45-
<> Options.help "Read expression from a file instead of standard input"
46-
<> Options.metavar "FILE"
47-
)
48-
49-
parseVersion =
50-
Options.flag'
51-
Nothing
52-
( Options.long "version"
53-
<> Options.help "Display version"
54-
)
55-
56-
parseOutput =
57-
Options.strOption
58-
( Options.long "output"
59-
<> Options.help "Write YAML to a file instead of standard output"
60-
<> Options.metavar "FILE"
61-
)
62-
63-
parserInfo :: ParserInfo (Maybe Options)
64-
parserInfo =
65-
Options.info
66-
(Options.helper <*> parseOptions)
67-
( Options.fullDesc
68-
<> Options.progDesc "Compile Dhall to YAML"
69-
)
3+
import qualified Dhall.DhallToYaml.Main
4+
import qualified Dhall.JSON.Yaml
5+
import qualified Paths_dhall_json as Meta
706

717
main :: IO ()
72-
main = do
73-
GHC.IO.Encoding.setLocaleEncoding GHC.IO.Encoding.utf8
74-
75-
maybeOptions <- Options.execParser parserInfo
76-
77-
case maybeOptions of
78-
Nothing -> do
79-
putStrLn (Data.Version.showVersion Meta.version)
80-
81-
Just options@(Options {..}) -> do
82-
handle $ do
83-
contents <- case file of
84-
Nothing -> Text.IO.getContents
85-
Just path -> Text.IO.readFile path
86-
87-
let write =
88-
case output of
89-
Nothing -> Data.ByteString.putStr
90-
Just file_ -> Data.ByteString.writeFile file_
91-
92-
write =<< dhallToYaml options file contents
93-
94-
handle :: IO a -> IO a
95-
handle = Control.Exception.handle handler
96-
where
97-
handler :: SomeException -> IO a
98-
handler e = do
99-
System.IO.hPutStrLn System.IO.stderr ""
100-
System.IO.hPrint System.IO.stderr e
101-
System.Exit.exitFailure
8+
main = Dhall.DhallToYaml.Main.main Meta.version Dhall.JSON.Yaml.dhallToYaml

dhall-json/release.nix

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)