From 682173d7c084de77bd948b458ef9a7bf48bcb34e Mon Sep 17 00:00:00 2001 From: Kyle Miller Date: Fri, 18 Oct 2024 13:17:52 -0700 Subject: [PATCH] feat: `#version` command (#5768) Prints `Lean.versionString` and target/platform information. Example: ``` Lean 4.12.0, commit 82189401520b7902eea618745e443c1909e2c3c8 Target: arm64-apple-darwin23.5.0 macOS ``` --- src/Lean/Elab/BuiltinCommand.lean | 11 +++++++++++ src/Lean/Parser/Command.lean | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/Lean/Elab/BuiltinCommand.lean b/src/Lean/Elab/BuiltinCommand.lean index 64ab21f3b9..66d21a068f 100644 --- a/src/Lean/Elab/BuiltinCommand.lean +++ b/src/Lean/Elab/BuiltinCommand.lean @@ -12,6 +12,7 @@ import Lean.Elab.Eval import Lean.Elab.Command import Lean.Elab.Open import Lean.Elab.SetOption +import Init.System.Platform namespace Lean.Elab.Command @@ -404,6 +405,16 @@ def failIfSucceeds (x : CommandElabM Unit) : CommandElabM Unit := do includedVars := sc.includedVars.filter (!omittedVars.contains ·) } | _ => throwUnsupportedSyntax +@[builtin_command_elab version] def elabVersion : CommandElab := fun _ => do + let mut target := System.Platform.target + if target.isEmpty then target := "unknown" + -- Only one should be set, but good to know if multiple are set in error. + let platforms := + (if System.Platform.isWindows then [" Windows"] else []) + ++ (if System.Platform.isOSX then [" macOS"] else []) + ++ (if System.Platform.isEmscripten then [" Emscripten"] else []) + logInfo m!"Lean {Lean.versionString}\nTarget: {target}{String.join platforms}" + @[builtin_command_elab Parser.Command.exit] def elabExit : CommandElab := fun _ => logWarning "using 'exit' to interrupt Lean" diff --git a/src/Lean/Parser/Command.lean b/src/Lean/Parser/Command.lean index f409144336..322ad18653 100644 --- a/src/Lean/Parser/Command.lean +++ b/src/Lean/Parser/Command.lean @@ -505,6 +505,9 @@ Displays all available tactic tags, with documentation. -/ @[builtin_command_parser] def printTacTags := leading_parser "#print " >> nonReservedSymbol "tactic " >> nonReservedSymbol "tags" +/-- Shows the current Lean version. Prints `Lean.versionString`. -/ +@[builtin_command_parser] def version := leading_parser + "#version" @[builtin_command_parser] def «init_quot» := leading_parser "init_quot" def optionValue := nonReservedSymbol "true" <|> nonReservedSymbol "false" <|> strLit <|> numLit