From a832f398b80a5ebb820d27b9e55ec949759043ff Mon Sep 17 00:00:00 2001 From: tydeu Date: Wed, 20 Sep 2023 12:15:33 -0400 Subject: [PATCH] feat: lake: add name to manifest --- src/lake/Lake/Load/Main.lean | 2 +- src/lake/Lake/Load/Manifest.lean | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/lake/Lake/Load/Main.lean b/src/lake/Lake/Load/Main.lean index f3c5401e9e92..65166d64541e 100644 --- a/src/lake/Lake/Load/Main.lean +++ b/src/lake/Lake/Load/Main.lean @@ -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, _) => diff --git a/src/lake/Lake/Load/Manifest.lean b/src/lake/Lake/Load/Manifest.lean index 99fc9bf1acdc..2f454203f761 100644 --- a/src/lake/Lake/Load/Manifest.lean +++ b/src/lake/Lake/Load/Manifest.lean @@ -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 @@ -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 := #[] @@ -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⟩ @@ -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?⟩