Skip to content

Commit

Permalink
feat: lake: add name to manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
tydeu authored and kim-em committed Sep 26, 2023
1 parent 94f3ec8 commit a832f39
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/lake/Lake/Load/Main.lean
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def buildUpdatedManifest (ws : Workspace)
return {pkg with opaqueDeps := ← deps.mapM (.mk <$> resolve ·)}
match res with
| (.ok root, deps) =>
let manifest : Manifest := {packagesDir? := ws.relPkgsDir}
let manifest : Manifest := {name? := ws.root.name, packagesDir? := ws.relPkgsDir}
let manifest := deps.foldl (fun m d => m.addPackage d.manifestEntry) manifest
return ({ws with root}, manifest)
| (.error cycle, _) =>
Expand Down
19 changes: 11 additions & 8 deletions src/lake/Lake/Load/Manifest.lean
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ instance [FromJson α] : FromJson (NameMap α) where
return m.insert k (← fromJson? v)

/-- Current version of the manifest format. -/
def Manifest.version : Nat := 5
def Manifest.version : Nat := 6

/-- An entry for a package stored in the manifest. -/
inductive PackageEntry
Expand Down Expand Up @@ -60,6 +60,7 @@ end PackageEntry

/-- Manifest data structure that is serialized to the file. -/
structure Manifest where
name? : Option Name := none
packagesDir? : Option FilePath := none
packages : Array PackageEntry := #[]

Expand All @@ -77,10 +78,11 @@ instance : ForIn m Manifest PackageEntry where
forIn self init f := self.packages.forIn init f

protected def toJson (self : Manifest) : Json :=
Json.mkObj [
("version", version),
("packagesDir", toJson self.packagesDir?),
("packages", toJson self.packages)
Json.mkObj <| .join [
[("version", version)],
Json.opt "name" self.name?,
[("packagesDir", toJson self.packagesDir?)],
[("packages", toJson self.packages)]
]

instance : ToJson Manifest := ⟨Manifest.toJson⟩
Expand All @@ -90,16 +92,17 @@ protected def fromJson? (json : Json) : Except String Manifest := do
let .ok ver := ver.getNat? | throw s!"unknown manifest version `{ver}`"
if ver < 5 then
throw s!"incompatible manifest version `{ver}`"
else if ver = 5 then
else if ver ≤ 6 then
let name? ← json.getObjValAs? _ "name"
let packagesDir? ← do
match json.getObjVal? "packagesDir" with
| .ok path => fromJson? path
| .error _ => pure none
let packages : Array PackageEntry ← fromJson? (← json.getObjVal? "packages")
return {packagesDir?, packages}
return {name?, packagesDir?, packages}
else
throw <|
s!"manifest version `{ver}` is higher than this Lake's '{Manifest.version}';" ++
s!"manifest version `{ver}` is higher than this Lake's '{Manifest.version}'; " ++
"you may need to update your `lean-toolchain`"

instance : FromJson Manifest := ⟨Manifest.fromJson?⟩
Expand Down

0 comments on commit a832f39

Please sign in to comment.