0 | module Pack.Database.Types
2 | import Core.Name.Namespace
5 | import Data.List.Elem
6 | import Data.SortedMap
8 | import Derive.Prelude
9 | import Idris.Package.Types
10 | import Pack.Core.Types
13 | %language ElabReflection
26 | data MetaCommit : Type where
27 | MC : Commit -> MetaCommit
28 | Latest : Branch -> MetaCommit
29 | Fetch : Branch -> MetaCommit
31 | %runElab derive "MetaCommit" [Show,Eq]
34 | FromString MetaCommit where
35 | fromString s = case forget $
split (':' ==) s of
36 | ["latest",branch] => Latest $
MkBranch branch
37 | ["fetch-latest",branch] => Fetch $
MkBranch branch
38 | _ => MC $
MkCommit s
41 | Interpolation MetaCommit where
42 | interpolate (Latest b) = "latest:\{b}"
43 | interpolate (Fetch b) = "fetch-latest:\{b}"
44 | interpolate (MC c) = "\{c}"
47 | toLatest : MetaCommit -> MetaCommit
48 | toLatest (MC x) = Latest (MkBranch x.value)
53 | data FetchMethod : Type where
56 | MissingOnly : FetchMethod
65 | ClearCommits : FetchMethod
67 | %runElab derive "FetchMethod" [Show,Eq,Ord]
87 | corePkgs : List CorePkg
88 | corePkgs = [Prelude, Base, Contrib, Linear, Network, Test, Papers, IdrisApi]
91 | Interpolation CorePkg where
92 | interpolate Prelude = "prelude"
93 | interpolate Base = "base"
94 | interpolate Contrib = "contrib"
95 | interpolate Linear = "linear"
96 | interpolate Network = "network"
97 | interpolate Test = "test"
98 | interpolate Papers = "papers"
99 | interpolate IdrisApi = "idris2"
102 | Cast CorePkg Body where
103 | cast Prelude = "prelude"
105 | cast Contrib = "contrib"
106 | cast Linear = "linear"
107 | cast Network = "network"
109 | cast Papers = "papers"
110 | cast IdrisApi = "idris2"
113 | Cast CorePkg (Path Rel) where
114 | cast c = PRel [< cast c]
118 | corePkgName : CorePkg -> PkgName
119 | corePkgName = MkPkgName . interpolate
123 | coreIpkgFile : CorePkg -> Body
124 | coreIpkgFile IdrisApi = "idris2api.ipkg"
125 | coreIpkgFile c = cast c <+> ".ipkg"
130 | coreIpkgPath : CorePkg -> File Rel
131 | coreIpkgPath IdrisApi = MkF neutral "idris2api.ipkg"
132 | coreIpkgPath c = MkF (neutral /> "libs" //> c) (coreIpkgFile c)
136 | readCorePkg : String -> Maybe CorePkg
137 | readCorePkg "prelude" = Just Prelude
138 | readCorePkg "base" = Just Base
139 | readCorePkg "contrib" = Just Contrib
140 | readCorePkg "linear" = Just Linear
141 | readCorePkg "network" = Just Network
142 | readCorePkg "test" = Just Test
143 | readCorePkg "papers" = Just Papers
144 | readCorePkg "idris2" = Just IdrisApi
145 | readCorePkg _ = Nothing
149 | isCorePkg : String -> Bool
150 | isCorePkg = isJust . readCorePkg
162 | data Package_ : (f : Type -> Type) -> (c : Type) -> Type where
168 | Git : (url : f URL)
170 | -> (ipkg : f $
File Rel)
171 | -> (pkgPath : f $
Bool)
172 | -> (testIpkg : Maybe (File Rel))
173 | -> (notice : Maybe String)
174 | -> (runsOn : Maybe (List MachineType))
182 | Local : (dir : Path Abs)
183 | -> (ipkg : File Rel)
184 | -> (pkgPath : Bool)
185 | -> (testIpkg : Maybe (File Rel))
189 | Core : (core : CorePkg) -> Package_ f c
192 | Functor (Package_ I) where
193 | map f (Git u c i p t n ro) = Git u (f c) i p t n ro
194 | map f (Local d i p t) = Local d i p t
195 | map f (Core c) = Core c
198 | traverse : Applicative f => (URL -> a -> f b) -> Package_ I a -> f (Package_ I b)
199 | traverse g (Git u c i p t n ro) = (\c' => Git u c' i p t n ro) <$> g u c
200 | traverse _ (Local d i p t) = pure $
Local d i p t
201 | traverse _ (Core c) = pure $
Core c
207 | Package = Package_ I Commit
212 | 0 UserPackage : Type
213 | UserPackage = Package_ Maybe MetaCommit
216 | 0 PackageMap : Type
217 | PackageMap = SortedMap PkgName Package
221 | CustomMap = SortedMap DBName (SortedMap PkgName UserPackage)
225 | data IsCore : Package -> Type where
226 | ItIsCore : IsCore (Core c)
229 | Uninhabited (IsCore $
Local {}) where
230 | uninhabited _ impossible
233 | Uninhabited (IsCore $
Git {}) where
234 | uninhabited _ impossible
239 | isCore : (p : Package) -> Dec (IsCore p)
240 | isCore (Core {}) = Yes ItIsCore
241 | isCore (Git {}) = No absurd
242 | isCore (Local {}) = No absurd
246 | data IsLocal : Package -> Type where
247 | ItIsLocal : IsLocal (Local {})
250 | Uninhabited (IsLocal $
Core {}) where
251 | uninhabited _ impossible
254 | Uninhabited (IsLocal $
Git {}) where
255 | uninhabited _ impossible
260 | isLocal : (p : Package) -> Dec (IsLocal p)
261 | isLocal (Core {}) = No absurd
262 | isLocal (Git {}) = No absurd
263 | isLocal (Local {}) = Yes ItIsLocal
267 | data IsGit : Package -> Type where
268 | ItIsGit : IsGit (Git {})
271 | Uninhabited (IsGit $
Core {}) where
272 | uninhabited _ impossible
275 | Uninhabited (IsGit $
Local {}) where
276 | uninhabited _ impossible
281 | isGit : (p : Package) -> Dec (IsGit p)
282 | isGit (Core {}) = No absurd
283 | isGit (Git {}) = Yes ItIsGit
284 | isGit (Local {}) = No absurd
289 | usePackagePath : Package_ I c -> Bool
290 | usePackagePath (Git _ _ _ pp _ _ _) = pp
291 | usePackagePath (Local _ _ pp _) = pp
292 | usePackagePath (Core _) = False
296 | ipkg : (dir : Path Abs) -> Package -> File Abs
297 | ipkg dir (Git _ _ i _ _ _ _) = toAbsFile dir i
298 | ipkg dir (Local _ i _ _) = toAbsFile dir i
299 | ipkg dir (Core c) = toAbsFile dir (coreIpkgPath c)
307 | data PkgStatus : Package -> Type where
308 | Missing : Hash -> PkgStatus p
309 | Installed : Hash -> (withDocs : Bool) -> PkgStatus p
312 | hash : PkgStatus p -> Hash
313 | hash (Missing h) = h
314 | hash (Installed h _) = h
320 | record ResolvedLib t where
326 | status : PkgStatus pkg
327 | deps : List (DPair Package PkgStatus)
329 | namespace ResolvedLib
332 | nameStr : ResolvedLib t -> String
333 | nameStr = value . name
337 | reTag : ResolvedLib s -> Desc t -> ResolvedLib t
338 | reTag rl d = {desc := d} rl
342 | dependencies : ResolvedLib t -> List PkgName
343 | dependencies rp = dependencies rp.desc
347 | isInstalled : ResolvedLib t -> Bool
348 | isInstalled rl = case rl.status of
352 | namespace AppStatus
355 | data AppStatus : Package -> Type where
357 | Missing : Hash -> AppStatus p
360 | Installed : Hash -> AppStatus p
364 | BinInstalled : Hash -> AppStatus p
370 | record ResolvedApp t where
376 | status : AppStatus pkg
378 | deps : List (DPair Package PkgStatus)
380 | namespace ResolveApp
383 | nameStr : ResolvedApp t -> String
384 | nameStr = value . name
388 | dependencies : ResolvedApp t -> List PkgName
389 | dependencies rp = dependencies rp.desc
393 | reTag : ResolvedApp s -> Desc t -> ResolvedApp t
394 | reTag rl d = {desc := d} rl
399 | usePackagePath : ResolvedApp t -> Bool
400 | usePackagePath = usePackagePath . pkg
406 | data LibOrApp : (t,s : PkgDesc -> Type) -> Type where
407 | Lib : ResolvedLib t -> LibOrApp t s
408 | App : (withWrapperScript : Bool) -> ResolvedApp s -> LibOrApp t s
413 | dependencies : LibOrApp t s -> List PkgName
414 | dependencies (Lib x) = dependencies x
415 | dependencies (App _ x) = dependencies x
419 | pkg : LibOrApp t s -> Package
420 | pkg (Lib x) = x.pkg
421 | pkg (App _ x) = x.pkg
425 | desc : LibOrApp t t -> Desc t
426 | desc (Lib x) = x.desc
427 | desc (App _ x) = x.desc
431 | name : LibOrApp t s -> PkgName
432 | name (Lib x) = x.name
433 | name (App _ x) = x.name
437 | libName : LibOrApp t s -> Maybe PkgName
438 | libName (Lib x) = Just x.name
439 | libName (App _ _) = Nothing
453 | idrisVersion : PkgVersion
454 | packages : SortedMap PkgName (Package_ I c)
460 | , packages $= map (map f)
469 | MetaDB = DB_ MetaCommit
473 | setVersion : PkgVersion -> DB -> DB
474 | setVersion v = {idrisVersion := v}
479 | {auto _ : Applicative f}
480 | -> (URL -> a -> f b)
484 | let ic := g db.idrisURL db.idrisCommit
485 | pkgs := traverse (traverse g) db.packages
486 | in [| adj ic pkgs |]
488 | adj : b -> SortedMap PkgName (Package_ I b) -> DB_ b
489 | adj ic cb = {idrisCommit := ic, packages := cb} db
491 | tomlBool : Bool -> String
492 | tomlBool True = "true"
493 | tomlBool False = "false"
495 | testPath : Maybe (File Rel) -> Maybe String
496 | testPath = map (\x => "test = \{quote x}")
498 | notice : Maybe String -> Maybe String
499 | notice = map (\x => "notice = \{quote x}")
503 | printPair : (PkgName,Package) -> List String
504 | printPair (x, Git url commit ipkg pp t n ro) =
506 | , "type = \"github\""
507 | , "url = \{quote url}"
508 | , "commit = \{quote commit}"
509 | , "ipkg = \{quote ipkg}"
510 | , "packagePath = \{tomlBool pp}"
511 | ] ++ (catMaybes [testPath t, notice n, runsOn ro])
513 | printPair (x, Local dir ipkg pp t) =
515 | , "type = \"local\""
516 | , "path = \{quote dir}"
517 | , "ipkg = \{quote ipkg}"
518 | , "packagePath = \{tomlBool pp}"
519 | ] ++ (catMaybes [testPath t])
521 | printPair (x, Core c) =
523 | , "type = \"core\""
528 | printDB : DB -> String
529 | printDB (MkDB u c v db) =
536 | in unlines $
header :: (SortedMap.toList db >>= \p => "" :: printPair p)
543 | mergeUP : UserPackage -> UserPackage -> UserPackage
544 | mergeUP (Git u1 c1 i1 p1 t1 n1 ro1) (Git u2 c2 i2 p2 t2 n2 ro2) =
545 | Git (u1<|>u2)(c1<|>c2)(i1<|>i2)(p1<|>p2)(t1<|>t2)(n1<|>n2)(ro1<|>ro2)
553 | 0 corePkgsTest : (c : CorePkg) -> Elem c Types.corePkgs
554 | corePkgsTest Prelude = %search
555 | corePkgsTest Base = %search
556 | corePkgsTest Contrib = %search
557 | corePkgsTest Linear = %search
558 | corePkgsTest Network = %search
559 | corePkgsTest Test = %search
560 | corePkgsTest Papers = %search
561 | corePkgsTest IdrisApi = %search
565 | 0 corePkgRoundTrip : (c : CorePkg) -> readCorePkg (interpolate c) === Just c
566 | corePkgRoundTrip Prelude = Refl
567 | corePkgRoundTrip Base = Refl
568 | corePkgRoundTrip Contrib = Refl
569 | corePkgRoundTrip Linear = Refl
570 | corePkgRoundTrip Network = Refl
571 | corePkgRoundTrip Test = Refl
572 | corePkgRoundTrip Papers = Refl
573 | corePkgRoundTrip IdrisApi = Refl