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

'gpl' cabal flag to switch between HsYAML and aeson-yaml #1417

Merged
merged 16 commits into from
Oct 15, 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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ install:

script:
- export PATH="${PATH}:$(pwd)/bin"
- stack build --copy-bins --local-bin-path ./bin
- stack build --flag dhall-json:gpl --copy-bins --local-bin-path ./bin
- source .travis-functions.sh
- tar -jcvf $(mk_release_name dhall) bin/dhall
- tar -jcvf $(mk_release_name dhall-json) bin/dhall-to-json bin/dhall-to-yaml bin/json-to-dhall bin/yaml-to-dhall
Expand Down
42 changes: 28 additions & 14 deletions dhall-json/dhall-json.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ Source-Repository head
Type: git
Location: https://github.com/dhall-lang/dhall-haskell/tree/master/dhall-json

Flag gpl
Description: Use GPL-licensed components like HsYAML, and enable yaml-to-dhall binary
Default: False
Manual: True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a manual flag? Why not like Cabal choose whatever if it's unspecified? This opens the door to more potential build plans, if you don't care.

Copy link
Sponsor Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That didn't seem like an explicit opt-in.

How can you not care about something that will cause you to have to relicense your project GPL? If you're using dhall-json as a library, that's something you have to consider. And if you're not, it's easy to do cabal v2-install -fgpl dhall-json.

I personally wouldn't expect a Dhall (which is otherwise BSD3) utility package to semi-randomly have this effect. Curious what others think.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @patrickmn that this flag should definitely be manual (since we don't want cabal's solver to govern the decision of what license to use) and off by default (since I imagine most users will prefer a BSD license but they can enable the GPL version if they better YAML support and are willing to convince management/customers that it's safe)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I say you do want Cabal to choose unless you actually care. But it seems like we disagree there, and that's ok - we've had the conversation which is more important

Copy link
Sponsor Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW there shouldn't be a case where aeson-yaml won't build; it only depends on aeson, bytestring, text, unordered-containers and vector.


Library
Hs-Source-Dirs: src
Build-Depends:
Expand All @@ -56,37 +61,44 @@ Library
Dhall.JSON
Dhall.JSONToDhall
Dhall.Yaml
Dhall.YamlToDhall
if flag(gpl)
Exposed-Modules:
Dhall.YamlToDhall
Other-Modules:
Dhall.JSON.Util


GHC-Options: -Wall
if impl(eta)
Build-Depends:
utf8-string >= 1.0 && <= 1.1
Maven-Depends:
Build-Depends:
utf8-string >= 1.0 && <= 1.1
Maven-Depends:
com.fasterxml.jackson.core:jackson-core:2.9.6,
com.fasterxml.jackson.core:jackson-databind:2.9.6,
com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.9.6
Other-Modules: Dhall.Yaml.Eta
Java-Sources: java/Utils.java
Other-Modules: Dhall.Yaml.Eta
Java-Sources: java/Utils.java
else
if flag(gpl)
CPP-Options: -DGPL
Build-Depends:
HsYAML >= 0.2 && < 0.3,
HsYAML-aeson >= 0.2 && < 0.3
else
Build-Depends:
HsYAML >= 0.2 && <0.3,
HsYAML-aeson >= 0.2 && <0.3
aeson-yaml >= 1.0.1 && < 1.1

Executable dhall-to-json
Hs-Source-Dirs: dhall-to-json
Main-Is: Main.hs
Build-Depends:
base ,
aeson ,
base ,
aeson ,
aeson-pretty >= 0.8.5 && < 0.9 ,
bytestring < 0.11,
dhall ,
dhall-json ,
optparse-applicative ,
bytestring < 0.11,
dhall ,
dhall-json ,
optparse-applicative ,
text
Other-Modules:
Paths_dhall_json
Expand Down Expand Up @@ -129,6 +141,8 @@ Executable json-to-dhall
GHC-Options: -Wall

Executable yaml-to-dhall
if !flag(gpl)
Buildable: False
Hs-Source-Dirs: yaml-to-dhall
Main-Is: Main.hs
Build-Depends:
Expand Down
21 changes: 19 additions & 2 deletions dhall-json/src/Dhall/Yaml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ import qualified Data.Vector
import qualified Dhall
import qualified Options.Applicative
#if defined(ETA_VERSION)
import Dhall.Yaml.Eta ( jsonToYaml )
import Dhall.Yaml.Eta (jsonToYaml)
#else
#if defined(GPL)
import qualified Data.YAML.Aeson
import qualified Data.YAML as Y
import qualified Data.YAML.Event as YE
import qualified Data.YAML.Token as YT
import qualified Data.YAML.Schema as YS
import qualified Data.Text as Text
#else
import qualified Data.Aeson.Yaml
import qualified Data.ByteString.Lazy
#endif
#endif


Expand Down Expand Up @@ -92,7 +97,7 @@ jsonToYaml
-> Bool
-> ByteString
jsonToYaml json documents quoted =

#if defined(GPL)
case (documents, json) of
(True, Data.Aeson.Array elems)
-> Data.ByteString.intercalate "\n---\n"
Expand Down Expand Up @@ -128,4 +133,16 @@ jsonToYaml json documents quoted =
schemaEncoder = if quoted
then customSchemaEncoder
else defaultSchemaEncoder
#else
Data.ByteString.Lazy.toStrict $ case (documents, json) of
(True, Data.Aeson.Array elems)
-> (if quoted
then Data.Aeson.Yaml.encodeQuotedDocuments
else Data.Aeson.Yaml.encodeDocuments
) (Data.Vector.toList elems)
_ -> (if quoted
then Data.Aeson.Yaml.encodeQuoted
else Data.Aeson.Yaml.encode
) json
#endif
#endif
44 changes: 36 additions & 8 deletions nix/shared.nix
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ let
(pkgsNew.sdist ../dhall-bash)
{ };

dhall-json =
dhall-nix =
haskellPackagesNew.callCabal2nix
"dhall-json"
(pkgsNew.sdist ../dhall-json)
"dhall-nix"
(pkgsNew.sdist ../dhall-nix)
{ };

dhall-lsp-server =
Expand All @@ -207,11 +207,39 @@ let
(pkgsNew.sdist ../dhall-lsp-server)
{ };

dhall-nix =
haskellPackagesNew.callCabal2nix
"dhall-nix"
(pkgsNew.sdist ../dhall-nix)
{ };
dhall-json =
# Replace this with
# `haskellPackagesNew.callCabal2nixWithOptions` once we
# upgrade to a newer version of Nixpkgs
let
src = pkgsNew.sdist ../dhall-json;

filter = path: type:
pkgsNew.lib.hasSuffix "dhall-json.cabal" path;

expr =
haskellPackagesNew.haskellSrc2nix {
name = "dhall-json";

src =
if pkgsNew.lib.canCleanSource src
then pkgsNew.lib.cleanSourceWith { inherit src filter; }
else src;

extraCabal2nixOptions = "-fgpl";
};

drv = haskellPackagesNew.callPackage expr {};

in
pkgsNew.haskell.lib.overrideCabal drv (old: {
inherit src;

preConfigure = ''
# Generated from ${expr}
${old.preConfigure or ""}
'';
});

dhall-try =
pkgsNew.haskell.lib.overrideCabal
Expand Down
1 change: 1 addition & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extra-deps:
- HsYAML-aeson-0.2.0.0@sha256:04796abfc01cffded83f37a10e6edba4f0c0a15d45bef44fc5bb4313d9c87757,1791
- ordered-containers-0.2.2@sha256:ebf2be3f592d9cf148ea6b8375f8af97148d44f82d8d04476899285e965afdbf,810
- lsp-test-0.6.1.0@sha256:df0fc403c03b6d036be13de3ff23d9951ae2506080135cd6862eded2c969a6da,3483
- aeson-yaml-1.0.1.0@sha256:2861ca3a35120f0a3a06b209174e4530529861956c0443ef57a2f2f09de9cbee,1975
nix:
packages:
- ncurses
Expand Down