-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an option that dumps package details to JSON (#3293)
* Initial stab at package json dump * expose ipkg json dump as new option * make dependency output easier to ingest by another tool * Add a test for ipkg json dump * cleanup * maybe just don't collide with existing equally good fixity * make new operator private * Add new module to api ipkg file * Add note to CHANGELOG_NEXT * correct the docs for the dump-ipkg-json command
- Loading branch information
1 parent
0174618
commit 88a5328
Showing
12 changed files
with
207 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
module Idris.Package.ToJson | ||
|
||
import Idris.Package.Types | ||
import Libraries.Data.String.Extra | ||
import Data.List | ||
import Core.FC | ||
import Core.Name.Namespace | ||
import Data.Maybe | ||
|
||
%default total | ||
|
||
-- We don't bother with a robust JSON implementation | ||
-- for this one-off JSON serialization. | ||
|
||
private infixl 0 ~~= | ||
|
||
interface ToJson v where | ||
toJson : v -> String | ||
|
||
ToJson String where | ||
toJson str = "\"\{str}\"" | ||
|
||
ToJson Bool where | ||
toJson False = "false" | ||
toJson True = "true" | ||
|
||
ToJson a => ToJson (List a) where | ||
toJson xs = "[\{join "," $ map toJson xs}]" | ||
|
||
(~=) : ToJson v => String -> v -> String | ||
(~=) field value = "\{toJson field}: \{toJson value}" | ||
|
||
(~~=) : ToJson v => String -> Maybe v -> Maybe String | ||
(~~=) field = map (field ~=) | ||
|
||
ToJson PkgVersion where | ||
toJson v = "\"\{show v}\"" | ||
|
||
ToJson PkgVersionBounds where | ||
toJson (MkPkgVersionBounds lowerBound lowerInclusive upperBound upperInclusive) = | ||
let fields = | ||
[ "lowerInclusive" ~= lowerInclusive | ||
, "lowerBound" ~= maybe "*" show lowerBound | ||
, "upperInclusive" ~= upperInclusive | ||
, "upperBound" ~= maybe "*" show upperBound | ||
] | ||
in | ||
"{\{join "," fields}}" | ||
|
||
ToJson Depends where | ||
toJson (MkDepends pkgname pkgbounds) = "{\{pkgname ~= pkgbounds}}" | ||
|
||
ToJson ModuleIdent where | ||
toJson ident = "\"\{show ident}\"" | ||
|
||
namespace Package | ||
export | ||
toJson : PkgDesc -> String | ||
toJson (MkPkgDesc | ||
name | ||
version | ||
langversion | ||
authors | ||
maintainers | ||
license | ||
brief | ||
readme | ||
homepage | ||
sourceloc | ||
bugtracker | ||
depends | ||
modules | ||
mainmod | ||
executable | ||
options | ||
sourcedir | ||
builddir | ||
outputdir | ||
prebuild | ||
postbuild | ||
preinstall | ||
postinstall | ||
preclean | ||
postclean) = | ||
let optionalFields = catMaybes $ | ||
[ "version" ~~= version | ||
, "langversion" ~~= langversion | ||
, "authors" ~~= authors | ||
, "maintainers" ~~= maintainers | ||
, "license" ~~= license | ||
, "brief" ~~= brief | ||
, "readme" ~~= readme | ||
, "homepage" ~~= homepage | ||
, "sourceloc" ~~= sourceloc | ||
, "bugtracker" ~~= bugtracker | ||
, "main" ~~= fst <$> mainmod | ||
, "executable" ~~= executable | ||
, "opts" ~~= snd <$> options | ||
, "sourcedir" ~~= sourcedir | ||
, "builddir" ~~= builddir | ||
, "outputdir" ~~= outputdir | ||
, "prebuild" ~~= snd <$> prebuild | ||
, "postbuild" ~~= snd <$> postbuild | ||
, "preinstall" ~~= snd <$> preinstall | ||
, "postinstall" ~~= snd <$> postinstall | ||
, "preclean" ~~= snd <$> preclean | ||
, "postclean" ~~= snd <$> postclean | ||
] | ||
fields = | ||
[ "name" ~= name | ||
, "depends" ~= depends | ||
, "modules" ~= fst <$> modules | ||
] ++ optionalFields | ||
in | ||
"{\{join "," fields}}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name": "test","depends": [{"contrib": {"lowerInclusive": true,"lowerBound": "*","upperInclusive": true,"upperBound": "*"}},{"idris2": {"lowerInclusive": true,"lowerBound": "0.7.0","upperInclusive": true,"upperBound": "*"}}],"modules": ["And.A.Proof","Yet.Another.Path"],"version": "0.1.0","langversion": {"lowerInclusive": true,"lowerBound": "0.7.0","upperInclusive": true,"upperBound": "*"},"authors": "Average Joe","maintainers": "Average Joe","license": "MIT","brief": "A basic test","readme": "https://github.com/idris-lang/Idris2/README.md","homepage": "https://github.com/idris-lang/Idris2","sourceloc": "https://github.com/idris-lang/Idris2","bugtracker": "https://github.com/idris-lang/Idris2/issues","main": "Main","executable": "test-exec","opts": "--codegen node","sourcedir": "src","builddir": "build","outputdir": "out","prebuild": "make pre","postbuild": "make post","preinstall": "make pre-install","postinstall": "make post-install","preclean": "make pre-clean","postclean": "make post-clean"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
. ../../../testutils.sh | ||
|
||
idris2 --dump-ipkg-json test.ipkg | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module And.A.Proof | ||
|
||
import Yet.Another.Path as Val | ||
|
||
%default total | ||
|
||
equality : Val.val === 2+3 | ||
equality = Refl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Main | ||
|
||
main : IO () | ||
main = pure () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Yet.Another.Path | ||
|
||
%default total | ||
|
||
public export | ||
val : Nat | ||
val = 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package test | ||
version = 0.1.0 | ||
authors = "Average Joe" | ||
maintainers = "Average Joe" | ||
license = "MIT" | ||
brief = "A basic test" | ||
readme = "https://github.com/idris-lang/Idris2/README.md" | ||
homepage = "https://github.com/idris-lang/Idris2" | ||
sourceloc = "https://github.com/idris-lang/Idris2" | ||
bugtracker = "https://github.com/idris-lang/Idris2/issues" | ||
|
||
-- the Idris2 version required (e.g. langversion >= 0.5.1) | ||
langversion >= 0.7.0 | ||
|
||
-- packages to add to search path | ||
depends = contrib, | ||
idris2 >= 0.7.0 | ||
|
||
-- modules to install | ||
modules = And.A.Proof, | ||
Yet.Another.Path | ||
|
||
-- main file (i.e. file to load at REPL) | ||
main = Main | ||
|
||
-- name of executable | ||
executable = test-exec | ||
opts = "--codegen node" | ||
sourcedir = "src" | ||
builddir = "build" | ||
outputdir = "out" | ||
|
||
-- script to run before building | ||
prebuild = "make pre" | ||
|
||
-- script to run after building | ||
postbuild = "make post" | ||
|
||
-- script to run after building, before installing | ||
preinstall = "make pre-install" | ||
|
||
-- script to run after installing | ||
postinstall = "make post-install" | ||
|
||
-- script to run before cleaning | ||
preclean = "make pre-clean" | ||
|
||
-- script to run after cleaning | ||
postclean = "make post-clean" |