Skip to content

Add utility function mapSourceRepos #93

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

Merged
merged 8 commits into from
Jun 14, 2018
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
5 changes: 4 additions & 1 deletion dhall-to-cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion dhall-to-cabal.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
109 changes: 31 additions & 78 deletions dhall/prelude.dhall
Original file line number Diff line number Diff line change
@@ -1,118 +1,71 @@
{ 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 =
constructors ./types/SPDX/LicenseExceptionId.dhall
, 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 =
Expand Down
18 changes: 10 additions & 8 deletions dhall/types.dhall
Original file line number Diff line number Diff line change
@@ -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 =
Expand All @@ -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 =
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ 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 =
"${gitHubRoot}/issues"
, 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
}
]
}
Expand Down
52 changes: 52 additions & 0 deletions dhall/utils/majorVersions.dhall
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions dhall/utils/mapSourceRepos.dhall
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions dhall/utils/package.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ GitHub-project =
./GitHub-project.dhall
, majorVersions =
./majorVersions.dhall
, mapSourceRepos =
./mapSourceRepos.dhall
}
17 changes: 17 additions & 0 deletions golden-tests/dhall-to-cabal/map-source-repo.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: repo
Copy link
Member

Choose a reason for hiding this comment

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

I think what we actually really want is a test that mapSourceRepo produces some normalized Dhall, but it might be a little out of scope for this PR. If you want to add a new section to the golden tests (that basically golden test one Dhall file normalizes to another), I'd be on board with that. If not, it can be done later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That section would be usefult to test other prelude functions in isolation (among other things), right?
I agree it would be usefult but if you dont mind i would prefer to add it in another pr.

Copy link
Member

Choose a reason for hiding this comment

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

Another PR is good with me!

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

Loading