diff --git a/dhall-to-cabal.cabal b/dhall-to-cabal.cabal index 9a7a2b42..2001d8ba 100644 --- a/dhall-to-cabal.cabal +++ b/dhall-to-cabal.cabal @@ -37,7 +37,6 @@ extra-source-files: dhall/defaults/Package.dhall dhall/defaults/Benchmark.dhall dhall/unconditional.dhall - dhall/GitHub-project.dhall dhall/prelude.dhall dhall/types/VersionRange.dhall dhall/types/OS.dhall @@ -93,6 +92,10 @@ extra-source-files: dhall/types/SPDX/Or.dhall dhall/types/SPDX/LicenseExceptionId.dhall dhall/types/SPDX/LicenseId.dhall + dhall/utils/package.dhall + dhall/utils/GitHub-project.dhall + dhall/utils/majorVersions.dhall + dhall/utils/mapSourceRepos.dhall golden-tests/dhall-to-cabal/*.dhall golden-tests/dhall-to-cabal/*.cabal golden-tests/cabal-to-dhall/*.dhall diff --git a/dhall-to-cabal.dhall b/dhall-to-cabal.dhall index 73fa8c4d..267daae9 100644 --- a/dhall-to-cabal.dhall +++ b/dhall-to-cabal.dhall @@ -98,7 +98,6 @@ in prelude.utils.GitHub-project , "dhall/defaults/Package.dhall" , "dhall/defaults/Benchmark.dhall" , "dhall/unconditional.dhall" - , "dhall/GitHub-project.dhall" , "dhall/prelude.dhall" , "dhall/types/VersionRange.dhall" , "dhall/types/OS.dhall" @@ -154,6 +153,10 @@ in prelude.utils.GitHub-project , "dhall/types/SPDX/Or.dhall" , "dhall/types/SPDX/LicenseExceptionId.dhall" , "dhall/types/SPDX/LicenseId.dhall" + , "dhall/utils/package.dhall" + , "dhall/utils/GitHub-project.dhall" + , "dhall/utils/majorVersions.dhall" + , "dhall/utils/mapSourceRepos.dhall" , "golden-tests/dhall-to-cabal/*.dhall" , "golden-tests/dhall-to-cabal/*.cabal" , "golden-tests/cabal-to-dhall/*.dhall" diff --git a/dhall/prelude.dhall b/dhall/prelude.dhall index 035079c3..0e628f49 100644 --- a/dhall/prelude.dhall +++ b/dhall/prelude.dhall @@ -1,14 +1,14 @@ { types = { BuildTypes = - constructors ./types/BuildType.dhall + constructors ./types/BuildType.dhall , OSs = - constructors ./types/OS.dhall + constructors ./types/OS.dhall , Compilers = - constructors ./types/Compiler.dhall + constructors ./types/Compiler.dhall , Extensions = - constructors ./types/Extension.dhall + constructors ./types/Extension.dhall , Languages = - constructors ./types/Language.dhall + constructors ./types/Language.dhall , Licenses = constructors ./types/License.dhall , LicenseExceptionId = @@ -16,103 +16,56 @@ , LicenseId = constructors ./types/SPDX/LicenseId.dhall , TestTypes = - constructors ./types/TestType.dhall + constructors ./types/TestType.dhall + , RepoType = + constructors ./types/RepoType.dhall + , RepoKind = + constructors ./types/RepoKind.dhall } , defaults = { CompilerOptions = - ./defaults/CompilerOptions.dhall + ./defaults/CompilerOptions.dhall , Library = - ./defaults/Library.dhall + ./defaults/Library.dhall , Benchmark = - ./defaults/Benchmark.dhall + ./defaults/Benchmark.dhall , Executable = - ./defaults/Executable.dhall + ./defaults/Executable.dhall , Package = - ./defaults/Package.dhall + ./defaults/Package.dhall , SourceRepo = - ./defaults/SourceRepo.dhall + ./defaults/SourceRepo.dhall , TestSuite = - ./defaults/TestSuite.dhall + ./defaults/TestSuite.dhall } , anyVersion = - ./types/VersionRange/AnyVersion.dhall + ./types/VersionRange/AnyVersion.dhall , earlierVersion = - ./types/VersionRange/EarlierVersion.dhall + ./types/VersionRange/EarlierVersion.dhall , orEarlierVersion = - ./types/VersionRange/OrEarlierVersion.dhall + ./types/VersionRange/OrEarlierVersion.dhall , intersectVersionRanges = - ./types/VersionRange/IntersectVersionRanges.dhall + ./types/VersionRange/IntersectVersionRanges.dhall , unionVersionRanges = - ./types/VersionRange/UnionVersionRanges.dhall + ./types/VersionRange/UnionVersionRanges.dhall , majorBoundVersion = - ./types/VersionRange/MajorBoundVersion.dhall + ./types/VersionRange/MajorBoundVersion.dhall , orLaterVersion = - ./types/VersionRange/OrLaterVersion.dhall + ./types/VersionRange/OrLaterVersion.dhall , laterVersion = - ./types/VersionRange/LaterVersion.dhall + ./types/VersionRange/LaterVersion.dhall , thisVersion = - ./types/VersionRange/ThisVersion.dhall + ./types/VersionRange/ThisVersion.dhall , notThisVersion = - ./types/VersionRange/NotThisVersion.dhall + ./types/VersionRange/NotThisVersion.dhall , withinVersion = - ./types/VersionRange/WithinVersion.dhall + ./types/VersionRange/WithinVersion.dhall , v = - ./types/Version/v.dhall + ./types/Version/v.dhall , noVersion = - ./types/VersionRange/NoVersion.dhall + ./types/VersionRange/NoVersion.dhall , utils = - { majorVersions = - let majorVersions - : Text - → List ./types/Version.dhall - → { package : Text, bounds : ./types/VersionRange.dhall } - = λ ( package - : Text - ) - → λ(versions : List ./types/Version.dhall ) - → { package = - package - , bounds = - Optional/fold - ./types/VersionRange.dhall - ( List/fold - ./types/Version.dhall - versions - (Optional ./types/VersionRange.dhall ) - ( λ ( v - : ./types/Version.dhall - ) - → λ(r : Optional ./types/VersionRange.dhall ) - → Optional/fold - ./types/VersionRange.dhall - r - (Optional ./types/VersionRange.dhall ) - ( λ ( r - : ./types/VersionRange.dhall - ) - → [ ./types/VersionRange/UnionVersionRanges.dhall - ( ./types/VersionRange/MajorBoundVersion.dhall - v - ) - r - ] : Optional ./types/VersionRange.dhall - ) - ( [ ./types/VersionRange/MajorBoundVersion.dhall - v - ] : Optional ./types/VersionRange.dhall - ) - ) - ([] : Optional ./types/VersionRange.dhall ) - ) - ./types/VersionRange.dhall - (λ(a : ./types/VersionRange.dhall ) → a) - ./types/VersionRange/NoVersion.dhall - } - - in majorVersions - , GitHub-project = - ./GitHub-project.dhall - } + ./utils/package.dhall , unconditional = ./unconditional.dhall , SPDX = diff --git a/dhall/types.dhall b/dhall/types.dhall index 01833d56..905a950c 100644 --- a/dhall/types.dhall +++ b/dhall/types.dhall @@ -1,15 +1,15 @@ { Arch = ./types/Arch.dhall , Benchmark = - ./types/Benchmark.dhall + ./types/Benchmark.dhall , BuildType = - ./types/BuildType.dhall + ./types/BuildType.dhall , Compiler = ./types/Compiler.dhall , CompilerOptions = ./types/CompilerOptions.dhall , Config = - ./types/Config.dhall + ./types/Config.dhall , CustomSetup = ./types/CustomSetup.dhall , Dependency = @@ -25,11 +25,11 @@ , ForeignLibrary = ./types/ForeignLibrary.dhall , Language = - ./types/Language.dhall + ./types/Language.dhall , Languages = - ./types/Language.dhall + ./types/Language.dhall , Library = - ./types/Library.dhall + ./types/Library.dhall , License = ./types/License.dhall , LicenseExceptionId = @@ -54,12 +54,14 @@ ./types/SetupBuildInfo.dhall , SPDX = ./types/SPDX.dhall +, SourceRepo = + ./types/SourceRepo.dhall , TestSuite = ./types/TestSuite.dhall , TestType = ./types/TestType.dhall , Version = - ./types/Version.dhall + ./types/Version.dhall , VersionRange = - ./types/VersionRange.dhall + ./types/VersionRange.dhall } diff --git a/dhall/GitHub-project.dhall b/dhall/utils/GitHub-project.dhall similarity index 74% rename from dhall/GitHub-project.dhall rename to dhall/utils/GitHub-project.dhall index 8aec257f..e295f42c 100644 --- a/dhall/GitHub-project.dhall +++ b/dhall/utils/GitHub-project.dhall @@ -5,7 +5,7 @@ in let gitHubProject = → let gitHubRoot = "https://github.com/${github.owner}/${github.repo}" - in ./defaults/Package.dhall + in ../defaults/Package.dhall ⫽ { name = github.repo , bug-reports = @@ -13,12 +13,12 @@ in let gitHubProject = , homepage = gitHubRoot , source-repos = - [ ./defaults/SourceRepo.dhall + [ ../defaults/SourceRepo.dhall ⫽ { location = [ gitHubRoot ] : Optional Text , type = - [ (constructors ./types/RepoType.dhall ).Git {=} - ] : Optional ./types/RepoType.dhall + [ (constructors ../types/RepoType.dhall ).Git {=} + ] : Optional ../types/RepoType.dhall } ] } diff --git a/dhall/utils/majorVersions.dhall b/dhall/utils/majorVersions.dhall new file mode 100644 index 00000000..0a81df56 --- /dev/null +++ b/dhall/utils/majorVersions.dhall @@ -0,0 +1,52 @@ + let Version = + ../types/Version.dhall +in let VersionRange = + ../types/VersionRange.dhall +in let Versions = + { UnionVersionRanges = + ../types/VersionRange/UnionVersionRanges.dhall + , MajorBoundVersion = + ../types/VersionRange/MajorBoundVersion.dhall + , NoVersion = + ../types/VersionRange/NoVersion.dhall + } + +in let majorVersions + : Text + → List Version + → { package : Text, bounds : VersionRange } + = λ(package : Text) + → λ(versions : List Version ) + → { package = + package + , bounds = + Optional/fold + VersionRange + ( List/fold + Version + versions + (Optional VersionRange ) + ( λ(v : Version ) + → λ(r : Optional VersionRange ) + → Optional/fold + VersionRange + r + (Optional VersionRange ) + ( λ(r : VersionRange ) + → [ Versions.UnionVersionRanges + ( Versions.MajorBoundVersion v ) + r + ] : Optional VersionRange + ) + ( [ Versions.MajorBoundVersion v + ] : Optional VersionRange + ) + ) + ([] : Optional VersionRange ) + ) + VersionRange + (λ(a : VersionRange ) → a) + Versions.NoVersion + } + +in majorVersions diff --git a/dhall/utils/mapSourceRepos.dhall b/dhall/utils/mapSourceRepos.dhall new file mode 100644 index 00000000..b9c2d5e6 --- /dev/null +++ b/dhall/utils/mapSourceRepos.dhall @@ -0,0 +1,23 @@ + let SourceRepo = ../types/SourceRepo.dhall + +in let Package = ../types/Package.dhall + +in let mapSourceRepos + : (SourceRepo → SourceRepo) → Package → Package + = λ(f : SourceRepo → SourceRepo) + → λ(pkg : Package) + → pkg + ⫽ { source-repos = + List/build + SourceRepo + ( λ(list : Type) + → λ(cons : SourceRepo → list → list) + → List/fold + SourceRepo + pkg.source-repos + list + (λ(x : SourceRepo) → cons (f x)) + ) + } + +in mapSourceRepos diff --git a/dhall/utils/package.dhall b/dhall/utils/package.dhall new file mode 100644 index 00000000..9277f90d --- /dev/null +++ b/dhall/utils/package.dhall @@ -0,0 +1,7 @@ +{ GitHub-project = + ./GitHub-project.dhall +, majorVersions = + ./majorVersions.dhall +, mapSourceRepos = + ./mapSourceRepos.dhall +} diff --git a/golden-tests/dhall-to-cabal/map-source-repo.cabal b/golden-tests/dhall-to-cabal/map-source-repo.cabal new file mode 100644 index 00000000..d9cf1c47 --- /dev/null +++ b/golden-tests/dhall-to-cabal/map-source-repo.cabal @@ -0,0 +1,17 @@ +name: repo +version: 1.0.0 +cabal-version: 2.0 +build-type: Simple +license: UnspecifiedLicense +homepage: https://github.com/owner/repo +bug-reports: https://github.com/owner/repo/issues + +source-repository this + type: git + location: https://github.com/owner/repo + tag: 1.0.0 + +executable foo + main-is: Main.hs + scope: public + diff --git a/golden-tests/dhall-to-cabal/map-source-repo.dhall b/golden-tests/dhall-to-cabal/map-source-repo.dhall new file mode 100644 index 00000000..60c01c01 --- /dev/null +++ b/golden-tests/dhall-to-cabal/map-source-repo.dhall @@ -0,0 +1,33 @@ + let prelude = ./dhall/prelude.dhall + +in let types = ./dhall/types.dhall + +in let updateRepo = + prelude.utils.mapSourceRepos + ( λ(srcRepo : types.SourceRepo) + → srcRepo + ⫽ { tag = + [ "1.0.0" ] : Optional Text + , kind = + prelude.types.RepoKind.RepoThis {=} + } + ) + +in let project = + prelude.utils.GitHub-project { owner = "owner", repo = "repo" } + +in updateRepo + ( project + ⫽ { version = + prelude.v "1.0.0" + , executables = + [ { name = + "foo" + , executable = + λ(config : ./dhall/types/Config.dhall) + → ./dhall/defaults/Executable.dhall + ⫽ { main-is = "Main.hs" } + } + ] + } + )