dhall-to-cabal 1.3.0.1 → 1.3.1.0
raw patch · 36 files changed
+697/−370 lines, 36 filesdep +tasty-hunitdep −insert-ordered-containersdep ~Cabaldep ~basedep ~dhall
Dependencies added: tasty-hunit
Dependencies removed: insert-ordered-containers
Dependency ranges changed: Cabal, base, dhall
Files
- Changelog.md +20/−0
- dhall-to-cabal.cabal +31/−12
- dhall/defaults/CompilerOptions.dhall +3/−1
- dhall/prelude.dhall +2/−0
- dhall/types/Arch.dhall +3/−1
- dhall/types/Compiler.dhall +3/−1
- dhall/types/CompilerOptions.dhall +9/−7
- dhall/types/Extension.dhall +8/−0
- dhall/types/ModuleRenaming.dhall +7/−1
- dhall/types/SPDX/LicenseExceptionId.dhall +18/−8
- dhall/types/SPDX/LicenseId.dhall +128/−114
- exe/Main.hs +18/−6
- golden-tests/cabal-to-dhall/SPDX.dhall +5/−5
- golden-tests/cabal-to-dhall/conditional-dependencies.dhall +3/−2
- golden-tests/cabal-to-dhall/default-license-2.2.cabal +3/−0
- golden-tests/cabal-to-dhall/default-license-2.2.dhall +5/−0
- golden-tests/cabal-to-dhall/gh-36.dhall +3/−2
- golden-tests/cabal-to-dhall/mixins-no-signatures.cabal +9/−0
- golden-tests/cabal-to-dhall/mixins-no-signatures.dhall +54/−0
- golden-tests/cabal-to-dhall/otheros.dhall +3/−2
- golden-tests/cabal-to-dhall/sourcerepo-defaults.dhall +4/−4
- golden-tests/dhall-to-cabal/allrightsreserved-2.0.cabal +6/−0
- golden-tests/dhall-to-cabal/allrightsreserved-2.0.dhall +9/−0
- golden-tests/dhall-to-cabal/allrightsreserved-2.2.cabal +6/−0
- golden-tests/dhall-to-cabal/allrightsreserved-2.2.dhall +9/−0
- golden-tests/dhall-to-cabal/default-license-2.2.cabal +6/−0
- golden-tests/dhall-to-cabal/default-license-2.2.dhall +8/−0
- golden-tests/dhall-to-cabal/mixins-no-signatures.cabal +9/−0
- golden-tests/dhall-to-cabal/mixins-no-signatures.dhall +53/−0
- lib/CabalToDhall.hs +52/−20
- lib/Dhall/Extra.hs +3/−3
- lib/DhallLocation.hs +22/−14
- lib/DhallToCabal.hs +93/−75
- lib/DhallToCabal/ConfigTree.hs +1/−92
- tests/DhallToCabal/Tests.hs +69/−0
- tests/Tests.hs +12/−0
Changelog.md view
@@ -1,5 +1,25 @@ # dhall-to-cabal change log +## 1.3.1.0 -- 2018-10-23++* Allow `Cabal` version 2.4.0.0. There have been consequent changes to+ the extensions, compilers and licenses recognised.++* Allow `dhall` version 1.18.++* `dhall-to-cabal` and `cabal-to-dhall` now understand the `mixins`+ field properly.++ On the Dhall side, `types.ModuleRenaming` has changed significantly:+ it is now a union.++ `prelude.types.ModuleRenaming` has been added for convenient access+ to the new constructors.++* Fix issue with alpha-normalized expressions. This was identified in issue #124+ and fixed in issue #126.++ ## 1.3.0.1 -- 2018-08-10 ### Distribution Changes
dhall-to-cabal.cabal view
@@ -1,4 +1,4 @@-cabal-version: 2.2+cabal-version: 2.4 -- * * * * * * * * * * * * WARNING * * * * * * * * * * * * -- This file has been AUTO-GENERATED by dhall-to-cabal. --@@ -9,7 +9,7 @@ -- 'dhall-to-cabal -- dhall-to-cabal.dhall > dhall-to-cabal.cabal'. -- * * * * * * * * * * * * WARNING * * * * * * * * * * * * name: dhall-to-cabal-version: 1.3.0.1+version: 1.3.1.0 license: MIT license-file: LICENSE maintainer: ollie@ocharles.org.uk@@ -129,14 +129,13 @@ -Wno-missing-local-signatures -Wno-monomorphism-restriction -fno-warn-name-shadowing build-depends:- Cabal ^>=2.2,+ Cabal ^>=2.4, base ^>=4.10 || ^>=4.11 || ^>=4.12, bytestring ^>=0.10, containers ^>=0.5 || ^>=0.6, contravariant ^>=1.4 || ^>=1.5,- dhall ^>=1.16.0,+ dhall ^>=1.18.0, hashable ^>=1.2.6.1,- insert-ordered-containers ^>=0.2.1.0, text ^>=1.2, transformers ^>=0.5.2, vector ^>=0.12@@ -156,12 +155,11 @@ -Wno-missing-local-signatures -Wno-monomorphism-restriction -fno-warn-name-shadowing build-depends:- Cabal ^>=2.2,+ Cabal ^>=2.4, base ^>=4.10 || ^>=4.11 || ^>=4.12,- dhall ^>=1.16.0,+ dhall ^>=1.18.0, dhall-to-cabal -any, filepath ^>=1.4,- insert-ordered-containers ^>=0.2.1.0, microlens ^>=0.1.0.0 || ^>=0.2.0.0 || ^>=0.3.0.0 || ^>=0.4.0.0, optparse-applicative ^>=0.13.2 || ^>=0.14, prettyprinter ^>=1.2.0.1,@@ -184,7 +182,7 @@ -fno-warn-name-shadowing build-depends: base ^>=4.10 || ^>=4.11 || ^>=4.12,- dhall ^>=1.16.0,+ dhall ^>=1.18.0, bytestring ^>=0.10, dhall-to-cabal -any, optparse-applicative ^>=0.13.2 || ^>=0.14,@@ -204,7 +202,7 @@ build-depends: base ^>=4.10 || ^>=4.11 || ^>=4.12, directory ^>=1.3.0.2,- dhall ^>=1.16.0,+ dhall ^>=1.18.0, dhall-to-cabal -any, filepath ^>=1.4, optparse-applicative ^>=0.13.2 || ^>=0.14,@@ -222,15 +220,36 @@ -fno-warn-name-shadowing build-depends: base ^>=4.10 || ^>=4.11 || ^>=4.12,- Cabal ^>=2.2,+ Cabal ^>=2.4, Diff ^>=0.3.4, bytestring ^>=0.10,- dhall ^>=1.16.0,+ dhall ^>=1.18.0, dhall-to-cabal -any, filepath ^>=1.4, microlens ^>=0.1.0.0 || ^>=0.2.0.0 || ^>=0.3.0.0 || ^>=0.4.0.0, prettyprinter ^>=1.2.0.1, tasty ^>=0.11 || ^>=0.12 || ^>=1.0 || ^>=1.1, tasty-golden ^>=2.3,+ text ^>=1.2++test-suite unit-tests+ type: exitcode-stdio-1.0+ main-is: Tests.hs+ hs-source-dirs: tests+ other-modules:+ DhallToCabal.Tests+ default-language: Haskell2010+ ghc-options: -Weverything -Wno-safe -Wno-unsafe+ -Wno-implicit-prelude -Wno-missed-specialisations+ -Wno-all-missed-specialisations -Wno-missing-import-lists+ -Wno-missing-local-signatures -Wno-monomorphism-restriction+ -fno-warn-name-shadowing+ build-depends:+ base ^>=4.10 || ^>=4.11 || ^>=4.12,+ Cabal ^>=2.4,+ dhall ^>=1.18.0,+ dhall-to-cabal -any,+ tasty ^>=0.11 || ^>=0.12 || ^>=1.0 || ^>=1.1,+ tasty-hunit ^>=0.10.0.1, text ^>=1.2
dhall/defaults/CompilerOptions.dhall view
@@ -1,7 +1,9 @@ -- This file is auto-generated by dhall-to-cabal-meta. Look but don't touch (unless you want your edits to be over-written). let types = ./../types.dhall -in { GHC =+in { Eta =+ [] : List Text+ , GHC = [] : List Text , GHCJS = [] : List Text
dhall/prelude.dhall view
@@ -15,6 +15,8 @@ constructors ./types/SPDX/LicenseExceptionId.dhall , LicenseId = constructors ./types/SPDX/LicenseId.dhall+ , ModuleRenaming =+ constructors ./types/ModuleRenaming.dhall , TestTypes = constructors ./types/TestType.dhall , RepoType =
dhall/types/Arch.dhall view
@@ -1,4 +1,6 @@-< Alpha :+< AArch64 :+ {}+| Alpha : {} | Arm : {}
dhall/types/Compiler.dhall view
@@ -1,4 +1,6 @@-< GHC :+< Eta :+ {}+| GHC : {} | GHCJS : {}
dhall/types/CompilerOptions.dhall view
@@ -1,21 +1,23 @@-{ GHC :+{ Eta : List Text+, GHC :+ List Text , GHCJS : List Text-, HBC :+, NHC : List Text-, Helium :+, YHC : List Text , Hugs : List Text+, HBC :+ List Text+, Helium :+ List Text , JHC : List Text , LHC : List Text-, NHC :- List Text , UHC :- List Text-, YHC : List Text }
dhall/types/Extension.dhall view
@@ -10,6 +10,8 @@ Bool | BinaryLiterals : Bool+| BlockArguments :+ Bool | CApiFFI : Bool | CPP :@@ -136,6 +138,8 @@ Bool | NumDecimals : Bool+| NumericUnderscores :+ Bool | OverlappingInstances : Bool | OverloadedLabels :@@ -164,6 +168,8 @@ Bool | PostfixOperators : Bool+| QuantifiedConstraints :+ Bool | QuasiQuotes : Bool | Rank2Types :@@ -193,6 +199,8 @@ | ScopedTypeVariables : Bool | StandaloneDeriving :+ Bool+| StarIsType : Bool | StaticPointers : Bool
dhall/types/ModuleRenaming.dhall view
@@ -1,1 +1,7 @@-List { rename : Text, to : Text }+< renaming :+ List { rename : Text, to : Text }+| default :+ {}+| hiding :+ List Text+>
dhall/types/SPDX/LicenseExceptionId.dhall view
@@ -1,21 +1,21 @@-< Autoconf_exception_2_0 :+< DS389_exception : {}+| Autoconf_exception_2_0 :+ {} | Autoconf_exception_3_0 : {}-| DS389_exception :+| Bison_exception_2_2 : {} | Bootloader_exception : {} | Classpath_exception_2_0 : {}-| Bison_exception_2_2 :+| CLISP_exception_2_0 : {} | DigiRule_FOSS_exception : {} | ECos_exception_2_0 : {}-| CLISP_exception_2_0 :- {} | Fawkes_Runtime_exception : {} | FLTK_exception :@@ -24,27 +24,37 @@ {} | Freertos_exception_2_0 : {}+| GCC_exception_2_0 :+ {} | GCC_exception_3_1 : {} | Gnu_javamail_exception : {}-| GCC_exception_2_0 :- {} | I2p_gpl_java_exception : {} | Libtool_exception : {} | Linux_syscall_note : {}+| LLVM_exception :+ {} | LZMA_exception : {}+| Mif_exception :+ {} | Nokia_Qt_exception_1_1 : {} | OCCT_exception_1_0 : {}-| Mif_exception :+| OpenJDK_assembly_exception_1_0 : {} | Openvpn_openssl_exception :+ {}+| PS_or_PDF_font_exception_20170817 :+ {}+| Qt_GPL_exception_1_0 :+ {}+| Qt_LGPL_exception_1_1 : {} | Qwt_exception_1_0 : {}
dhall/types/SPDX/LicenseId.dhall view
@@ -22,80 +22,84 @@ {} | Afmparse : {}-| AGPL_3_0_only :+| AGPL_1_0_only : {}-| AGPL_3_0_or_later :+| AGPL_1_0_or_later : {} | AGPL_1_0 : {}-| AMDPLPA :- {}-| AML :+| AGPL_3_0_or_later : {} | Aladdin : {}-| ANTLR_PD :+| AGPL_3_0_only : {}-| Apache_1_0 :+| AML : {} | AMPAS : {}-| Apache_1_1 :+| AMDPLPA : {}-| Apache_2_0 :+| ANTLR_PD : {}-| APL_1_0 :+| Apache_1_0 : {}-| APSL_1_0 :+| Apache_2_0 : {} | APAFML : {}+| Apache_1_1 :+ {}+| APSL_1_0 :+ {} | APSL_1_1 : {}-| APSL_1_2 :+| APL_1_0 : {}+| APSL_2_0 :+ {} | Artistic_1_0_cl8 : {}-| Artistic_1_0_Perl :+| APSL_1_2 : {}-| APSL_2_0 :+| Artistic_1_0_Perl : {} | Artistic_1_0 : {}-| Artistic_2_0 :+| Bahyph : {} | Barr : {}-| Beerware :+| Artistic_2_0 : {}-| Bahyph :+| BitTorrent_1_0 : {} | BitTorrent_1_1 : {}-| Borceux :+| Beerware : {}-| BitTorrent_1_0 :+| BSD_1_Clause : {} | BSD_2_Clause_FreeBSD : {}-| BSD_2_Clause_NetBSD :+| Borceux : {}-| BSD_1_Clause :+| BSD_2_Clause_NetBSD : {} | BSD_2_Clause_Patent : {}-| BSD_2_Clause :+| BSD_3_Clause_Attribution : {} | BSD_3_Clause_Clear : {}-| BSD_3_Clause_LBNL :- {}-| BSD_3_Clause_Attribution :+| BSD_2_Clause : {} | BSD_3_Clause_No_Nuclear_License_2014 : {} | BSD_3_Clause_No_Nuclear_License : {}+| BSD_3_Clause_LBNL :+ {} | BSD_3_Clause : {} | BSD_4_Clause_UC :@@ -264,124 +268,126 @@ {} | EUPL_1_0 : {}-| Eurosym :- {} | Fair : {}-| FreeImage :+| Frameworx_1_0 : {}-| FSFAP :+| Eurosym : {}-| Frameworx_1_0 :+| FSFAP : {} | FSFUL : {}+| FreeImage :+ {} | FSFULLR : {}-| GFDL_1_1_only :+| FTL : {} | GFDL_1_1_or_later : {}-| FTL :+| GFDL_1_2_only : {}-| GFDL_1_2_or_later :+| GFDL_1_1_only : {} | GFDL_1_3_only : {}-| GFDL_1_2_only :+| GFDL_1_3_or_later : {}-| Giftware :+| GFDL_1_2_or_later : {} | GL2PS : {}-| GFDL_1_3_or_later :- {} | Glide : {}+| Giftware :+ {} | Glulxe : {}-| GPL_1_0_only :+| Gnuplot : {} | GPL_1_0_or_later : {}-| Gnuplot :+| GPL_2_0_only : {}-| GPL_2_0_or_later :+| GPL_1_0_only : {} | GPL_3_0_only : {}-| GPL_2_0_only :+| GPL_3_0_or_later : {}-| GSOAP_1_3b :+| GPL_2_0_or_later : {} | HaskellReport : {}-| GPL_3_0_or_later :- {} | HPND : {}+| GSOAP_1_3b :+ {} | IBM_pibs : {}-| IJG :+| ICU : {} | ImageMagick : {}-| ICU :+| IMatix : {}-| Imlib2 :+| IJG : {} | Info_ZIP : {}-| IMatix :+| Intel_ACPI : {}-| Intel :+| Imlib2 : {} | Interbase_1_0 : {}-| Intel_ACPI :- {} | IPA : {}+| Intel :+ {} | IPL_1_0 : {}-| JasPer_2_0 :+| ISC : {} | JSON : {}-| ISC :- {} | LAL_1_2 : {}+| JasPer_2_0 :+ {} | LAL_1_3 : {}-| Leptonica :+| Latex2e : {} | LGPL_2_0_only : {}-| Latex2e :- {} | LGPL_2_0_or_later : {}+| Leptonica :+ {} | LGPL_2_1_only : {}-| LGPL_3_0_only :+| LGPL_2_1_or_later : {} | LGPL_3_0_or_later : {}-| LGPL_2_1_or_later :+| LGPLLR : {}-| Libpng :+| LGPL_3_0_only : {} | Libtiff : {}-| LGPLLR :+| LiLiQ_P_1_1 : {}-| LiLiQ_R_1_1 :+| Libpng : {} | LiLiQ_Rplus_1_1 : {}-| LiLiQ_P_1_1 :+| Linux_OpenIB : {}+| LiLiQ_R_1_1 :+ {} | LPL_1_0 : {} | LPL_1_02 :@@ -392,15 +398,17 @@ {} | LPPL_1_0 : {}-| LPPL_1_3a :- {} | LPPL_1_3c : {}-| MirOS :+| MakeIndex : {}+| LPPL_1_3a :+ {}+| MIT_0 :+ {} | MIT_advertising : {}-| MakeIndex :+| MirOS : {} | MIT_CMU : {}@@ -434,48 +442,50 @@ {} | MTLL : {}-| NASA_1_3 :- {} | Naumen : {}-| NCSA :+| NBPL_1_0 : {}-| Net_SNMP :+| NASA_1_3 : {}-| NBPL_1_0 :+| Net_SNMP : {} | NetCDF : {}+| NCSA :+ {} | Newsletr : {}-| NLOD_1_0 :+| NGPL : {} | NLPL : {}-| NGPL :+| Nokia : {}-| NOSL :+| NLOD_1_0 : {} | Noweb : {}-| Nokia :+| NPL_1_0 : {}-| NPL_1_1 :+| NOSL : {} | NPOSL_3_0 : {}-| NPL_1_0 :- {} | NRL : {}+| NPL_1_1 :+ {} | NTP : {}-| OCLC_2_0 :+| OCCT_PL : {} | ODbL_1_0 : {}-| OCCT_PL :+| ODC_By_1_0 : {}+| OCLC_2_0 :+ {} | OFL_1_1 : {} | OGTSL :@@ -520,103 +530,107 @@ {} | OML : {}-| OSET_PL_2_1 :- {} | OSL_1_0 : {}-| OSL_2_0 :+| OSL_1_1 : {}-| OSL_2_1 :+| OSET_PL_2_1 : {}-| OSL_1_1 :+| OSL_2_1 : {} | OSL_3_0 : {}+| OSL_2_0 :+ {} | PDDL_1_0 : {}-| PHP_3_01 :+| PHP_3_0 : {} | Plexus : {}-| PHP_3_0 :+| PostgreSQL : {}-| Psfrag :+| PHP_3_01 : {} | Psutils : {}-| PostgreSQL :+| Python_2_0 : {}-| Qhull :+| Psfrag : {} | QPL_1_0 : {}-| Python_2_0 :- {} | Rdisc : {}+| Qhull :+ {} | RHeCos_1_1 : {}-| RPL_1_5 :+| RPL_1_1 : {} | RPSL_1_0 : {}-| RPL_1_1 :+| RSA_MD : {}-| RSCPL :+| RPL_1_5 : {} | Ruby : {}-| RSA_MD :+| SAX_PD : {}-| Saxpath :+| RSCPL : {} | SCEA : {}-| SAX_PD :- {} | Sendmail : {}+| Saxpath :+ {} | SGI_B_1_0 : {}-| SGI_B_2_0 :+| SGI_B_1_1 : {} | SimPL_2_0 : {}-| SGI_B_1_1 :+| SISSL_1_2 : {}-| SISSL :+| SGI_B_2_0 : {} | Sleepycat : {}-| SISSL_1_2 :+| SMLNJ : {}-| SMPPL :+| SISSL : {} | SNIA : {}-| SMLNJ :- {} | Spencer_86 : {}+| SMPPL :+ {} | Spencer_94 : {}-| SPL_1_0 :+| Spencer_99 : {} | SugarCRM_1_1_3 : {}-| Spencer_99 :- {} | SWL : {}-| TCL :+| SPL_1_0 : {}-| TMate :+| TCP_wrappers : {}-| TORQUE_1_1 :+| TMate : {}-| TCP_wrappers :+| TCL : {} | TOSL :+ {}+| TU_Berlin_1_0 :+ {}+| TORQUE_1_1 :+ {}+| TU_Berlin_2_0 : {} | Unicode_DFS_2015 : {}
exe/Main.hs view
@@ -30,7 +30,6 @@ import DhallToCabal import qualified Paths_dhall_to_cabal as Paths -import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap import qualified Data.Text.IO as StrictText import qualified Data.Text.Prettyprint.Doc as Pretty import qualified Data.Text.Prettyprint.Doc.Render.Text as Pretty@@ -38,6 +37,7 @@ import qualified Dhall.Core as Dhall import qualified Dhall.Core as Expr ( Expr(..), Var(..), shift ) import qualified Distribution.PackageDescription as Cabal+import qualified Dhall.Map as Map import qualified Dhall.Parser import qualified Dhall.TypeCheck as Dhall import qualified Distribution.PackageDescription.PrettyPrint as Cabal@@ -487,22 +487,22 @@ let intersection =- InsOrdHashMap.intersectionWith (==) left right+ Map.intersectionWith (==) left right -- The right record cannot have any fields not in left.- guard ( InsOrdHashMap.null ( InsOrdHashMap.difference right left ) )+ guard ( null ( Map.difference right left ) ) -- We must have at least one field with a common name- guard ( not ( InsOrdHashMap.null intersection ) )+ guard ( not ( null intersection ) ) -- All common fields must have identical types guard ( and intersection ) let extra =- InsOrdHashMap.difference left right+ Map.difference left right - guard ( not ( InsOrdHashMap.null extra ) )+ guard ( not ( null extra ) ) return ( Expr.Record extra ) @@ -574,6 +574,12 @@ <$> go t v <*> ( traverse ( `go` v ) elems ) + Expr.Some a ->+ Expr.Some <$> go a v++ Expr.None ->+ pure Expr.None+ Expr.Record fields -> Expr.Record <$> traverse ( `go` v ) fields @@ -603,6 +609,12 @@ Expr.Project e fs -> Expr.Project <$> go e v <*> pure fs++ Expr.ImportAlt l r ->+ Expr.ImportAlt <$> go l v <*> go r v++ Expr.IntegerToDouble ->+ pure Expr.IntegerToDouble Expr.Embed{} -> pure e
golden-tests/cabal-to-dhall/SPDX.dhall view
@@ -13,24 +13,24 @@ ( prelude.SPDX.or ( prelude.SPDX.license (prelude.types.LicenseId.AGPL_3_0_or_later {=})- ( [ prelude.types.LicenseExceptionId.Classpath_exception_2_0 {=}- ] : Optional types.LicenseExceptionId+ ( Some+ (prelude.types.LicenseExceptionId.Classpath_exception_2_0 {=}) ) ) ( prelude.SPDX.licenseVersionOrLater (prelude.types.LicenseId.Apache_2_0 {=})- ([] : Optional types.LicenseExceptionId)+ (None types.LicenseExceptionId) ) ) ( prelude.SPDX.or ( prelude.SPDX.ref "MyFancyLicense"- ([] : Optional types.LicenseExceptionId)+ (None types.LicenseExceptionId) ) ( prelude.SPDX.refWithFile "MyFancierLicense" "LICENSE.txt"- ([] : Optional types.LicenseExceptionId)+ (None types.LicenseExceptionId) ) ) )
golden-tests/cabal-to-dhall/conditional-dependencies.dhall view
@@ -10,7 +10,8 @@ , cabal-version = prelude.v "2.0" , library =- [ λ(config : types.Config)+ Some+ ( λ(config : types.Config) → if config.impl (prelude.types.Compilers.GHC {=}) ( prelude.unionVersionRanges@@ -58,7 +59,7 @@ ⫽ { build-depends = [ { bounds = prelude.anyVersion, package = "A" } ] }- ] : Optional (types.Config → types.Library)+ ) , license = prelude.types.Licenses.Unspecified {=} }
+ golden-tests/cabal-to-dhall/default-license-2.2.cabal view
@@ -0,0 +1,3 @@+cabal-version: 2.2+name: test+version: 1.0
+ golden-tests/cabal-to-dhall/default-license-2.2.dhall view
@@ -0,0 +1,5 @@+ let prelude = ./../../dhall/prelude.dhall++in let types = ./../../dhall/types.dhall++in prelude.defaults.Package ⫽ { name = "test", version = prelude.v "1.0" }
golden-tests/cabal-to-dhall/gh-36.dhall view
@@ -21,7 +21,8 @@ , cabal-version = prelude.v "2.0" , library =- [ λ(config : types.Config)+ Some+ ( λ(config : types.Config) → if config.impl (prelude.types.Compilers.GHC {=}) ( prelude.unionVersionRanges@@ -171,5 +172,5 @@ ⫽ { cpp-options = [ "-DWAI_SERVLET_DEBUG" ] } else prelude.defaults.Library- ] : Optional (types.Config → types.Library)+ ) }
+ golden-tests/cabal-to-dhall/mixins-no-signatures.cabal view
@@ -0,0 +1,9 @@+cabal-version: 2.2+name: mixins-test+version: 0++library+ mixins:+ foo,+ bar (Some.Module, Some.Other.Module, Third.Module as Renamed),+ baz hiding (Hidden, Also.Hidden)
+ golden-tests/cabal-to-dhall/mixins-no-signatures.dhall view
@@ -0,0 +1,54 @@+ let prelude = ./../../dhall/prelude.dhall++in let types = ./../../dhall/types.dhall++in prelude.defaults.Package+ ⫽ { name =+ "mixins-test"+ , version =+ prelude.v "0"+ , library =+ Some+ ( λ(config : types.Config)+ → prelude.defaults.Library+ ⫽ { mixins =+ [ { package =+ "foo"+ , renaming =+ { provides =+ prelude.types.ModuleRenaming.default {=}+ , requires =+ prelude.types.ModuleRenaming.default {=}+ }+ }+ , { package =+ "bar"+ , renaming =+ { provides =+ prelude.types.ModuleRenaming.renaming+ [ { rename = "Some.Module", to = "Some.Module" }+ , { rename =+ "Some.Other.Module"+ , to =+ "Some.Other.Module"+ }+ , { rename = "Third.Module", to = "Renamed" }+ ]+ , requires =+ prelude.types.ModuleRenaming.default {=}+ }+ }+ , { package =+ "baz"+ , renaming =+ { provides =+ prelude.types.ModuleRenaming.hiding+ [ "Hidden", "Also.Hidden" ]+ , requires =+ prelude.types.ModuleRenaming.default {=}+ }+ }+ ]+ }+ )+ }
golden-tests/cabal-to-dhall/otheros.dhall view
@@ -10,12 +10,13 @@ , cabal-version = prelude.v "2.0" , library =- [ λ(config : types.Config)+ Some+ ( λ(config : types.Config) → if config.os (prelude.types.OSs.OtherOS { _1 = "multics" }) then prelude.defaults.Library ⫽ { exposed-modules = [ "A", "B" ] } else prelude.defaults.Library ⫽ { exposed-modules = [ "A" ] }- ] : Optional (types.Config → types.Library)+ ) }
golden-tests/cabal-to-dhall/sourcerepo-defaults.dhall view
@@ -10,15 +10,15 @@ , source-repos = [ prelude.defaults.SourceRepo ⫽ { type =- [ prelude.types.RepoType.Git {=} ] : Optional types.RepoType+ Some (prelude.types.RepoType.Git {=}) , location =- [ "example.com" ] : Optional Text+ Some "example.com" } , prelude.defaults.SourceRepo ⫽ { type =- [ prelude.types.RepoType.Darcs {=} ] : Optional types.RepoType+ Some (prelude.types.RepoType.Darcs {=}) , location =- [ "example.org" ] : Optional Text+ Some "example.org" , kind = prelude.types.RepoKind.RepoThis {=} }
+ golden-tests/dhall-to-cabal/allrightsreserved-2.0.cabal view
@@ -0,0 +1,6 @@+cabal-version: 2.0+name: foo+version: 0+license: AllRightsReserved++library
+ golden-tests/dhall-to-cabal/allrightsreserved-2.0.dhall view
@@ -0,0 +1,9 @@+ let prelude = ../../dhall/prelude.dhall+in let types = ../../dhall/types.dhall+in prelude.defaults.Package+ // { name = "foo"+ , version = prelude.v "0"+ , cabal-version = prelude.v "2.0"+ , license = prelude.types.Licenses.AllRightsReserved {=}+ , library = prelude.unconditional.library prelude.defaults.Library+ }
+ golden-tests/dhall-to-cabal/allrightsreserved-2.2.cabal view
@@ -0,0 +1,6 @@+cabal-version: 2.2+name: foo+version: 0+license: NONE++library
+ golden-tests/dhall-to-cabal/allrightsreserved-2.2.dhall view
@@ -0,0 +1,9 @@+ let prelude = ../../dhall/prelude.dhall+in let types = ../../dhall/types.dhall+in prelude.defaults.Package+ // { name = "foo"+ , version = prelude.v "0"+ , cabal-version = prelude.v "2.2"+ , license = prelude.types.Licenses.AllRightsReserved {=}+ , library = prelude.unconditional.library prelude.defaults.Library+ }
+ golden-tests/dhall-to-cabal/default-license-2.2.cabal view
@@ -0,0 +1,6 @@+cabal-version: 2.2+name: foo+version: 0+license: NONE++library
+ golden-tests/dhall-to-cabal/default-license-2.2.dhall view
@@ -0,0 +1,8 @@+ let prelude = ../../dhall/prelude.dhall+in let types = ../../dhall/types.dhall+in prelude.defaults.Package+ // { name = "foo"+ , version = prelude.v "0"+ , cabal-version = prelude.v "2.2"+ , library = prelude.unconditional.library prelude.defaults.Library+ }
+ golden-tests/dhall-to-cabal/mixins-no-signatures.cabal view
@@ -0,0 +1,9 @@+cabal-version: 2.2+name: mixins-test+version: 0++library+ mixins:+ foo,+ bar (Some.Module, Some.Other.Module, Third.Module as Renamed),+ baz hiding (Hidden, Also.Hidden)
+ golden-tests/dhall-to-cabal/mixins-no-signatures.dhall view
@@ -0,0 +1,53 @@+ let prelude = ./../../dhall/prelude.dhall++in let types = ./../../dhall/types.dhall++in prelude.defaults.Package+ ⫽ { name =+ "mixins-test"+ , version =+ prelude.v "0"+ , library =+ [ λ(config : types.Config)+ → prelude.defaults.Library+ ⫽ { mixins =+ [ { package =+ "foo"+ , renaming =+ { provides =+ prelude.types.ModuleRenaming.default {=}+ , requires =+ prelude.types.ModuleRenaming.default {=}+ }+ }+ , { package =+ "bar"+ , renaming =+ { provides =+ prelude.types.ModuleRenaming.renaming+ [ { rename = "Some.Module", to = "Some.Module" }+ , { rename =+ "Some.Other.Module"+ , to =+ "Some.Other.Module"+ }+ , { rename = "Third.Module", to = "Renamed" }+ ]+ , requires =+ prelude.types.ModuleRenaming.default {=}+ }+ }+ , { package =+ "baz"+ , renaming =+ { provides =+ prelude.types.ModuleRenaming.hiding+ [ "Hidden", "Also.Hidden" ]+ , requires =+ prelude.types.ModuleRenaming.default {=}+ }+ }+ ]+ }+ ] : Optional (types.Config → types.Library)+ }
lib/CabalToDhall.hs view
@@ -23,12 +23,12 @@ import Numeric.Natural ( Natural ) import qualified Data.ByteString as ByteString-import qualified Data.HashMap.Strict.InsOrd as Map import qualified Data.Sequence as Seq import qualified Data.Text as StrictText import qualified Dhall import qualified Dhall.Core import qualified Dhall.Core as Expr ( Expr(..), Var(..) )+import qualified Dhall.Map as Map import qualified Dhall.Parser import qualified Dhall.TypeCheck import qualified Distribution.Compiler as Cabal@@ -148,7 +148,7 @@ type Default s a = ( PreludeReference -> Expr.Expr s a )- -> Map.InsOrdHashMap StrictText.Text ( Expr.Expr s a )+ -> Map.Map StrictText.Text ( Expr.Expr s a ) getDefault@@ -208,7 +208,7 @@ -> Expr.Expr s a -> ( StrictText.Text, Expr.Expr s a ) emptyOptionalDefault name ty =- ( name, Expr.OptionalLit ty Nothing )+ ( name, Expr.App Expr.None ty ) textFieldDefault@@ -228,7 +228,8 @@ compilerOptionsDefault :: Default s a compilerOptionsDefault _resolve = ( Map.fromList- [ emptyListDefault "GHC" Expr.Text+ [ emptyListDefault "Eta" Expr.Text+ , emptyListDefault "GHC" Expr.Text , emptyListDefault "GHCJS" Expr.Text , emptyListDefault "HBC" Expr.Text , emptyListDefault "Helium" Expr.Text@@ -433,9 +434,9 @@ nonDefaultFields :: ( Eq a )- => Map.InsOrdHashMap StrictText.Text ( Expr.Expr s a )- -> Map.InsOrdHashMap StrictText.Text ( Expr.Expr s a )- -> Map.InsOrdHashMap StrictText.Text ( Expr.Expr s a )+ => Map.Map StrictText.Text ( Expr.Expr s a )+ -> Map.Map StrictText.Text ( Expr.Expr s a )+ -> Map.Map StrictText.Text ( Expr.Expr s a ) nonDefaultFields defs fields = let withoutDefaults = Map.difference fields defs@@ -470,7 +471,7 @@ newtype RecordInputType a = RecordInputType { _unRecordInputType ::- Map.InsOrdHashMap Dhall.Text ( Dhall.InputType a )+ Map.Map Dhall.Text ( Dhall.InputType a ) } deriving ( Semigroup, Monoid ) @@ -751,9 +752,9 @@ { _unUnion :: ( a -> ( First ( Dhall.Text, DhallExpr )- , Map.InsOrdHashMap Dhall.Text DhallExpr+ , Map.Map Dhall.Text DhallExpr )- , Map.InsOrdHashMap Dhall.Text DhallExpr+ , Map.Map Dhall.Text DhallExpr ) } deriving ( Semigroup, Monoid )@@ -793,7 +794,9 @@ maybeToDhall t = Dhall.InputType { Dhall.embed =- \a -> Expr.OptionalLit ( Dhall.declared t ) ( Dhall.embed t <$> a )+ \a -> case a of+ Nothing -> Expr.App Expr.None (Dhall.declared t)+ Just x -> Expr.Some ( Dhall.embed t x ) , Dhall.declared = Expr.App Expr.Optional ( Dhall.declared t ) } @@ -829,6 +832,9 @@ in Dhall.InputType { Dhall.embed = \case+ Cabal.Eta ->+ constructor "Eta" ( Expr.RecordLit mempty )+ Cabal.GHC -> constructor "GHC" ( Expr.RecordLit mempty ) @@ -1496,15 +1502,41 @@ moduleRenaming :: Dhall.InputType Cabal.ModuleRenaming moduleRenaming =- ( \( Cabal.ModuleRenaming a ) -> a ) >$<- listOf- ( runRecordInputType- ( mconcat- [ recordField "rename" ( ( \( a, _ ) -> a ) >$< moduleName )- , recordField "to" ( ( \( _, a ) -> a ) >$< moduleName )- ]- )- )+ Dhall.InputType+ { Dhall.embed =+ \a ->+ case a of+ Cabal.ModuleRenaming renamed ->+ Expr.App+ ( Expr.Var "prelude" `Expr.Field` "types" `Expr.Field` "ModuleRenaming" `Expr.Field` "renaming" )+ ( Expr.ListLit+ Nothing+ ( fmap+ (\ ( src, dst ) ->+ Expr.RecordLit+ ( Map.fromList+ [ ( "rename", Dhall.embed moduleName src )+ , ( "to", Dhall.embed moduleName dst )+ ]+ )+ )+ ( Seq.fromList renamed )+ )+ )+ Cabal.DefaultRenaming ->+ Expr.App+ ( Expr.Var "prelude" `Expr.Field` "types" `Expr.Field` "ModuleRenaming" `Expr.Field` "default" )+ ( Expr.RecordLit mempty )+ Cabal.HidingRenaming hidden ->+ Expr.App+ ( Expr.Var "prelude" `Expr.Field` "types" `Expr.Field` "ModuleRenaming" `Expr.Field` "hiding" )+ ( Expr.ListLit+ Nothing+ ( Dhall.embed moduleName <$> Seq.fromList hidden )+ )+ , Dhall.declared =+ Expr.Var "types" `Expr.Field` "ModuleRenaming"+ } benchmark :: Dhall.InputType Cabal.Benchmark
lib/Dhall/Extra.hs view
@@ -16,14 +16,14 @@ import Data.List ( sortBy ) import Data.Ord ( comparing ) -import qualified Data.HashMap.Strict.InsOrd as Map import qualified Data.Text as StrictText import qualified Dhall import qualified Dhall.Core as Dhall ( Expr ) import qualified Dhall.Core as Expr ( Expr(..) )+import qualified Dhall.Map as Map -makeUnion :: Map.InsOrdHashMap StrictText.Text ( Dhall.Type a ) -> Dhall.Type a+makeUnion :: Map.Map StrictText.Text ( Dhall.Type a ) -> Dhall.Type a makeUnion alts = let extract expr = do@@ -47,7 +47,7 @@ a { Dhall.extract = join . Dhall.extract a } -sortInsOrdHashMap :: ( Hashable k, Ord k ) => Map.InsOrdHashMap k v -> Map.InsOrdHashMap k v+sortInsOrdHashMap :: Ord k => Map.Map k v -> Map.Map k v sortInsOrdHashMap = Map.fromList . sortBy ( comparing fst ) . Map.toList
lib/DhallLocation.hs view
@@ -34,14 +34,18 @@ { Dhall.Core.hash = Nothing , Dhall.Core.importType =- Dhall.Core.URL- "https://raw.githubusercontent.com"- ( Dhall.Core.File- ( Dhall.Core.Directory [ "dhall", version, "dhall-to-cabal", "dhall-lang" ] )- "prelude.dhall"+ Dhall.Core.Remote+ ( Dhall.Core.URL+ Dhall.Core.HTTPS+ "https://raw.githubusercontent.com"+ ( Dhall.Core.File+ ( Dhall.Core.Directory [ "dhall", version, "dhall-to-cabal", "dhall-lang" ] )+ "prelude.dhall"+ )+ Nothing+ Nothing+ Nothing )- ""- Nothing } , Dhall.Core.importMode = Dhall.Core.Code@@ -54,14 +58,18 @@ { Dhall.Core.hash = Nothing , Dhall.Core.importType =- Dhall.Core.URL- "https://raw.githubusercontent.com"- ( Dhall.Core.File- ( Dhall.Core.Directory [ "dhall", version, "dhall-to-cabal", "dhall-lang" ] )- "types.dhall"+ Dhall.Core.Remote+ ( Dhall.Core.URL+ Dhall.Core.HTTPS+ "https://raw.githubusercontent.com"+ ( Dhall.Core.File+ ( Dhall.Core.Directory [ "dhall", version, "dhall-to-cabal", "dhall-lang" ] )+ "types.dhall"+ )+ Nothing+ Nothing+ Nothing )- ""- Nothing } , Dhall.Core.importMode = Dhall.Core.Code
lib/DhallToCabal.hs view
@@ -4,7 +4,6 @@ {-# language GADTs #-} {-# language LambdaCase #-} {-# language OverloadedStrings #-}-{-# language PatternSynonyms #-} {-# language RecordWildCards #-} module DhallToCabal@@ -43,9 +42,10 @@ import Data.Maybe ( fromMaybe ) import Data.Monoid ( (<>) ) -import qualified Data.HashMap.Strict.InsOrd as Map import qualified Data.Text as StrictText import qualified Dhall+import qualified Dhall.Core+import qualified Dhall.Map as Map import qualified Dhall.Parser import qualified Dhall.TypeCheck import qualified Distribution.Compiler as Cabal@@ -74,7 +74,7 @@ import qualified Language.Haskell.Extension as Cabal import qualified Dhall.Core as Expr- ( Chunks(..), Const(..), Expr(..), Var(..) )+ ( Chunks(..), Const(..), Expr(..) ) import Dhall.Extra import DhallToCabal.ConfigTree ( ConfigTree(..), toConfigTree )@@ -176,14 +176,6 @@ category <- Dhall.field "category" Dhall.string - -- Cabal documentation states- --- -- > YOU PROBABLY DON'T WANT TO USE THIS FIELD.- --- -- So I guess we won't use this field.- buildDepends <-- pure []- setupBuildInfo <- Dhall.field "custom-setup" ( Dhall.maybe setupBuildInfo ) @@ -228,17 +220,15 @@ ( error "Could not parse version" ) ( Cabal.simpleParse ( StrictText.unpack text ) ) - extract =- \case- LamArr _Version (LamArr _v v) ->- go v-- e ->- error ( show e )+ extract e =+ go+ ( Dhall.Core.normalize ( e `Expr.App` "Version" `Expr.App` "v" )+ `asTypeOf` e+ ) go = \case- Expr.App ( V0 "v" ) ( Expr.TextLit ( Expr.Chunks [] text ) ) ->+ Expr.App "v" ( Expr.TextLit ( Expr.Chunks [] text ) ) -> return ( parse text ) e ->@@ -248,8 +238,8 @@ Expr.Pi "Version" ( Expr.Const Expr.Type ) $ Expr.Pi "v"- ( Expr.Pi "_" ( Dhall.expected Dhall.string ) ( V0 "Version" ) )- ( V0 "Version" )+ ( Expr.Pi "_" ( Dhall.expected Dhall.string ) "Version" )+ "Version" in Dhall.Type { .. } @@ -599,69 +589,74 @@ -pattern LamArr :: Expr.Expr s a -> Expr.Expr s a -> Expr.Expr s a-pattern LamArr a b <- Expr.Lam _ a b----pattern V0 :: Dhall.Text -> Expr.Expr s a-pattern V0 v = Expr.Var ( Expr.V v 0 )--- versionRange :: Dhall.Type Cabal.VersionRange versionRange = let- extract =- \case- LamArr _VersionRange (LamArr _anyVersion (LamArr _noVersion (LamArr _thisVersion (LamArr _notThisVersion (LamArr _laterVersion (LamArr _earlierVersion (LamArr _orLaterVersion (LamArr _orEarlierVersion (LamArr _withinVersion (LamArr _majorBoundVersion (LamArr _unionVersionRanges (LamArr _intersectVersionRanges (LamArr _differenceVersionRanges (LamArr _invertVersionRange versionRange)))))))))))))) ->- go versionRange-- _ ->- Nothing+ extract e =+ go+ ( Dhall.Core.normalize+ ( e+ `Expr.App` "VersionRange"+ `Expr.App` "anyVersion"+ `Expr.App` "noVersion"+ `Expr.App` "thisVersion"+ `Expr.App` "notThisVersion"+ `Expr.App` "laterVersion"+ `Expr.App` "earlierVersion"+ `Expr.App` "orLaterVersion"+ `Expr.App` "orEarlierVersion"+ `Expr.App` "withinVersion"+ `Expr.App` "majorBoundVersion"+ `Expr.App` "unionVersionRanges"+ `Expr.App` "intersectVersionRanges"+ `Expr.App` "differenceVersionRanges"+ `Expr.App` "invertVersionRange"+ )+ `asTypeOf` e+ ) go = \case- V0 "anyVersion" ->+ "anyVersion" -> return Cabal.anyVersion - V0 "noVersion" ->+ "noVersion" -> return Cabal.noVersion - Expr.App ( V0 "thisVersion" ) components ->+ Expr.App "thisVersion" components -> Cabal.thisVersion <$> Dhall.extract version components - Expr.App ( V0 "notThisVersion" ) components ->+ Expr.App "notThisVersion" components -> Cabal.notThisVersion <$> Dhall.extract version components - Expr.App ( V0 "laterVersion" ) components ->+ Expr.App "laterVersion" components -> Cabal.laterVersion <$> Dhall.extract version components - Expr.App ( V0 "earlierVersion" ) components ->+ Expr.App "earlierVersion" components -> Cabal.earlierVersion <$> Dhall.extract version components - Expr.App ( V0 "orLaterVersion" ) components ->+ Expr.App "orLaterVersion" components -> Cabal.orLaterVersion <$> Dhall.extract version components - Expr.App ( V0 "orEarlierVersion" ) components ->+ Expr.App "orEarlierVersion" components -> Cabal.orEarlierVersion <$> Dhall.extract version components - Expr.App ( Expr.App ( V0 "unionVersionRanges" ) a ) b ->+ Expr.App ( Expr.App "unionVersionRanges" a ) b -> Cabal.unionVersionRanges <$> go a <*> go b - Expr.App ( Expr.App ( V0 "intersectVersionRanges" ) a ) b ->+ Expr.App ( Expr.App "intersectVersionRanges" a ) b -> Cabal.intersectVersionRanges <$> go a <*> go b - Expr.App ( Expr.App ( V0 "differenceVersionRanges" ) a ) b ->+ Expr.App ( Expr.App "differenceVersionRanges" a ) b -> Cabal.differenceVersionRanges <$> go a <*> go b - Expr.App ( V0 "invertVersionRange" ) components ->+ Expr.App "invertVersionRange" components -> Cabal.invertVersionRange <$> go components - Expr.App ( V0 "withinVersion" ) components ->+ Expr.App "withinVersion" components -> Cabal.withinVersion <$> Dhall.extract version components - Expr.App ( V0 "majorBoundVersion" ) components ->+ Expr.App "majorBoundVersion" components -> Cabal.majorBoundVersion <$> Dhall.extract version components _ ->@@ -670,7 +665,7 @@ expected = let versionRange =- V0 "VersionRange"+ "VersionRange" versionToVersionRange = Expr.Pi@@ -737,41 +732,48 @@ spdxLicense :: Dhall.Type SPDX.LicenseExpression spdxLicense = let- extract =- \case- LamArr _spdx (LamArr _licenseExactVersion (LamArr _licenseVersionOrLater (LamArr _licenseRef (LamArr _licenseRefWithFile (LamArr _licenseAnd (LamArr _licenseOr license)))))) ->- go license-- _ ->- Nothing+ extract e =+ go+ ( Dhall.Core.normalize+ ( e+ `Expr.App` "SPDX"+ `Expr.App` "license"+ `Expr.App` "licenseVersionOrLater"+ `Expr.App` "ref"+ `Expr.App` "refWithFile"+ `Expr.App` "and"+ `Expr.App` "or"+ )+ `asTypeOf` e+ ) go = \case- Expr.App ( Expr.App ( V0 "license" ) identM ) exceptionMayM -> do+ Expr.App ( Expr.App "license" identM ) exceptionMayM -> do ident <- Dhall.extract spdxLicenseId identM exceptionMay <- Dhall.extract ( Dhall.maybe spdxLicenseExceptionId ) exceptionMayM return ( SPDX.ELicense ( SPDX.ELicenseId ident ) exceptionMay ) - Expr.App ( Expr.App ( V0 "licenseVersionOrLater" ) identM ) exceptionMayM -> do + Expr.App ( Expr.App "licenseVersionOrLater" identM ) exceptionMayM -> do ident <- Dhall.extract spdxLicenseId identM exceptionMay <- Dhall.extract ( Dhall.maybe spdxLicenseExceptionId ) exceptionMayM return ( SPDX.ELicense ( SPDX.ELicenseIdPlus ident ) exceptionMay ) - Expr.App ( Expr.App ( V0 "ref" ) identM ) exceptionMayM -> do+ Expr.App ( Expr.App "ref" identM ) exceptionMayM -> do ident <- Dhall.extract Dhall.string identM exceptionMay <- Dhall.extract ( Dhall.maybe spdxLicenseExceptionId ) exceptionMayM return ( SPDX.ELicense ( SPDX.ELicenseRef ( SPDX.mkLicenseRef' Nothing ident ) ) exceptionMay ) - Expr.App ( Expr.App ( Expr.App ( V0 "refWithFile" ) identM ) filenameM) exceptionMayM -> do+ Expr.App ( Expr.App ( Expr.App "refWithFile" identM ) filenameM) exceptionMayM -> do ident <- Dhall.extract Dhall.string identM filename <- Dhall.extract Dhall.string filenameM exceptionMay <- Dhall.extract ( Dhall.maybe spdxLicenseExceptionId ) exceptionMayM return ( SPDX.ELicense ( SPDX.ELicenseRef ( SPDX.mkLicenseRef' ( Just filename ) ident ) ) exceptionMay ) - Expr.App ( Expr.App ( V0 "and" ) a ) b ->+ Expr.App ( Expr.App "and" a ) b -> SPDX.EAnd <$> go a <*> go b - Expr.App ( Expr.App ( V0 "or" ) a ) b ->+ Expr.App ( Expr.App "or" a ) b -> SPDX.EOr <$> go a <*> go b _ ->@@ -780,7 +782,7 @@ expected = let licenseType =- V0 "SPDX"+ "SPDX" licenseIdAndException = Expr.Pi "id" ( Dhall.expected spdxLicenseId )@@ -863,7 +865,8 @@ compilerOptions = Dhall.record $ sequenceA- [ (,) <$> pure Cabal.GHC <*> Dhall.field "GHC" options+ [ (,) <$> pure Cabal.Eta <*> Dhall.field "Eta" options+ , (,) <$> pure Cabal.GHC <*> Dhall.field "GHC" options , (,) <$> pure Cabal.GHCJS <*> Dhall.field "GHCJS" options , (,) <$> pure Cabal.NHC <*> Dhall.field "NHC" options , (,) <$> pure Cabal.YHC <*> Dhall.field "YHC" options@@ -985,7 +988,7 @@ sortType Dhall.genericAuto unitType =- Expr.Record Map.empty+ Expr.Record mempty extract expr = do Expr.UnionLit k v alts <-@@ -1026,12 +1029,12 @@ let extractConfVar body = case body of- Expr.App ( Expr.App ( Expr.Field ( V0 "config" ) "impl" ) compiler ) version ->+ Expr.App ( Expr.App ( Expr.Field "config" "impl" ) compiler ) version -> Cabal.Impl <$> Dhall.extract compilerFlavor compiler <*> Dhall.extract versionRange version - Expr.App ( Expr.Field ( V0 "config" ) field ) x ->+ Expr.App ( Expr.Field "config" field ) x -> case field of "os" -> Cabal.OS <$> Dhall.extract operatingSystem x@@ -1326,10 +1329,25 @@ moduleRenaming :: Dhall.Type Cabal.ModuleRenaming moduleRenaming =- fmap Cabal.ModuleRenaming $- Dhall.list $- Dhall.record $- (,) <$> Dhall.field "rename" moduleName <*> Dhall.field "to" moduleName+ makeUnion+ ( Map.fromList+ [ ( "renaming"+ , fmap Cabal.ModuleRenaming+ ( Dhall.list+ ( Dhall.record+ ( (,) <$> Dhall.field "rename" moduleName <*> Dhall.field "to" moduleName )+ )+ )+ )+ , ( "default"+ , Dhall.record ( pure Cabal.DefaultRenaming )+ )+ , ( "hiding"+ , fmap Cabal.HidingRenaming+ ( Dhall.list moduleName )+ )+ ]+ ) sortType :: Dhall.Type a -> Dhall.Type a
lib/DhallToCabal/ConfigTree.hs view
@@ -81,7 +81,7 @@ ) where- + isConfigUse (App (Field (Var x') "os") _) | v == x' = True isConfigUse (App (Field (Var x') "arch") _) | v == x' = True isConfigUse (App (App (Field (Var x') "impl") _) _) | v == x' = True@@ -100,94 +100,3 @@ -subExpr- :: Applicative f- => ( Expr s a -> f ( Expr s a ) ) -> Expr s a -> f ( Expr s a )-subExpr f = \case- Lam a b c ->- Lam a <$> f b <*> f c-- Pi a b c ->- Pi a <$> f b <*> f c-- App a b ->- App <$> f a <*> f b-- Let a b c d ->- Let a <$> traverse f b <*> f c <*> f d-- Annot a b ->- Annot <$> f a <*> f b-- BoolAnd a b ->- BoolAnd <$> f a <*> f b-- BoolOr a b ->- BoolOr <$> f a <*> f b-- BoolEQ a b ->- BoolEQ <$> f a <*> f b-- BoolNE a b ->- BoolNE <$> f a <*> f b-- BoolIf a b c ->- BoolIf <$> f a <*> f b <*> f c-- NaturalPlus a b ->- NaturalPlus <$> f a <*> f b-- NaturalTimes a b ->- NaturalTimes <$> f a <*> f b-- TextLit (Chunks a b) ->- TextLit- <$>- ( Chunks- <$> traverse ( \(a,b) -> (,) <$> pure a <*> f b ) a <*> pure b- )-- TextAppend a b ->- TextAppend <$> f a <*> f b-- ListLit a b ->- ListLit <$> traverse f a <*> traverse f b-- ListAppend a b ->- ListAppend <$> f a <*> f b-- OptionalLit a b ->- OptionalLit <$> f a <*> traverse f b-- Record a ->- Record <$> traverse f a-- RecordLit a ->- RecordLit <$> traverse f a-- Union a ->- Union <$> traverse f a-- UnionLit a b c ->- UnionLit a <$> f b <*> traverse f c-- Combine a b ->- Combine <$> f a <*> f b-- Prefer a b ->- Prefer <$> f a <*> f b-- Merge a b t ->- Merge <$> f a <*> f b <*> traverse f t-- Constructors a ->- Constructors <$> f a-- Field a b ->- Field <$> f a <*> pure b-- Note a b ->- Note a <$> f b-- e ->- pure e
+ tests/DhallToCabal/Tests.hs view
@@ -0,0 +1,69 @@+{-# language OverloadedStrings #-}++module DhallToCabal.Tests+ ( versionSpec+ )+ where++import Data.Maybe ( fromMaybe )+import Dhall.Core ( Const(..), Expr(..), Chunks(..) )++import qualified Data.Text as StrictText+import qualified Dhall+import qualified Dhall.Core+import qualified Dhall.Parser+import qualified Dhall.TypeCheck+import qualified DhallToCabal+import qualified Distribution.Text as Cabal ( simpleParse )+import qualified Test.Tasty+import qualified Test.Tasty.HUnit+++versionSpec :: Test.Tasty.TestTree+versionSpec =+ Test.Tasty.testGroup+ "version"+ [ testExtraction+ "version"+ DhallToCabal.version+ ( Lam+ "Version"+ ( Const Type )+ ( Lam+ "v"+ ( Pi "_" ( Const Type ) ( Pi "_" Text "Version" ) )+ ( App "v" ( TextLit ( Chunks [] "1.0.0" ) ) )+ )+ )+ ( fromMaybe+ ( error "Could not parse version" )+ ( Cabal.simpleParse ( StrictText.unpack "1.0.0" ) )+ ) ]+++testExtraction+ :: ( Eq a, Show a )+ => Test.Tasty.TestName+ -> Dhall.Type a+ -> Dhall.Core.Expr Dhall.Parser.Src Dhall.TypeCheck.X+ -> a+ -> Test.Tasty.TestTree+testExtraction testName t expr expected =+ Test.Tasty.testGroup+ testName+ [ Test.Tasty.HUnit.testCase+ "original"+ ( Just expected Test.Tasty.HUnit.@=? Dhall.extract t expr )+ , Test.Tasty.HUnit.testCase+ "alphaNormalize"+ ( Just expected+ Test.Tasty.HUnit.@=?+ Dhall.extract t ( Dhall.Core.alphaNormalize expr )+ )+ , Test.Tasty.HUnit.testCase+ "betaNormalize"+ ( Just expected+ Test.Tasty.HUnit.@=?+ Dhall.extract t ( Dhall.Core.normalize expr )+ )+ ]
+ tests/Tests.hs view
@@ -0,0 +1,12 @@+module Main+ ( main+ )+ where++import qualified DhallToCabal.Tests+import qualified Test.Tasty+++main :: IO ()+main =+ Test.Tasty.defaultMain DhallToCabal.Tests.versionSpec