Blame SOURCES/0112-Add-a-version-command.patch

8e15ce
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8e15ce
From: Peter Jones <pjones@redhat.com>
8e15ce
Date: Tue, 11 Sep 2018 14:20:37 -0400
8e15ce
Subject: [PATCH] Add a "version" command.
8e15ce
8e15ce
This adds a command that shows you info about grub's version, the grub target
8e15ce
platform, the compiler version, and if you built with
8e15ce
--with-rpm-version=<string>, the rpm package version.
8e15ce
8e15ce
Signed-off-by: Peter Jones <pjones@redhat.com>
8e15ce
---
8e15ce
 configure.ac                 | 13 ++++++++++
8e15ce
 grub-core/Makefile.core.def  |  5 ++++
8e15ce
 grub-core/commands/version.c | 56 ++++++++++++++++++++++++++++++++++++++++++++
8e15ce
 config.h.in                  |  1 +
8e15ce
 4 files changed, 75 insertions(+)
8e15ce
 create mode 100644 grub-core/commands/version.c
8e15ce
8e15ce
diff --git a/configure.ac b/configure.ac
8e15ce
index 152e7dba652..cfdac6bed5a 100644
8e15ce
--- a/configure.ac
8e15ce
+++ b/configure.ac
8e15ce
@@ -312,6 +312,19 @@ AC_SUBST(target_cpu)
8e15ce
 AC_SUBST(platform)
8e15ce
 
8e15ce
 # Define default variables
8e15ce
+have_with_rpm_version=n
8e15ce
+AC_ARG_WITH([rpm_version],
8e15ce
+	    AS_HELP_STRING([--with-rpm-version=VERSION],
8e15ce
+			   [set the rpm package version [[guessed]]]),
8e15ce
+	    [have_with_rpm_version=y],
8e15ce
+	    [have_with_rpm_version=n])
8e15ce
+if test x$have_with_rpm_version = xy; then
8e15ce
+  rpm_version="$with_rpm_version"
8e15ce
+else
8e15ce
+  rpm_version=""
8e15ce
+fi
8e15ce
+GRUB_RPM_VERSION="$rpm_version"
8e15ce
+AC_SUBST(GRUB_RPM_VERSION)
8e15ce
 
8e15ce
 have_with_bootdir=n
8e15ce
 AC_ARG_WITH([bootdir],
8e15ce
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
8e15ce
index 84a3d89de9a..498ca11762a 100644
8e15ce
--- a/grub-core/Makefile.core.def
8e15ce
+++ b/grub-core/Makefile.core.def
8e15ce
@@ -579,6 +579,11 @@ image = {
8e15ce
   enable = mips_loongson;
8e15ce
 };
8e15ce
 
8e15ce
+module = {
8e15ce
+  name = version;
8e15ce
+  common = commands/version.c;
8e15ce
+};
8e15ce
+
8e15ce
 module = {
8e15ce
   name = disk;
8e15ce
   common = lib/disk.c;
8e15ce
diff --git a/grub-core/commands/version.c b/grub-core/commands/version.c
8e15ce
new file mode 100644
8e15ce
index 00000000000..f0966a518f7
8e15ce
--- /dev/null
8e15ce
+++ b/grub-core/commands/version.c
8e15ce
@@ -0,0 +1,56 @@
8e15ce
+/* version.c - Command to print the grub version and build info. */
8e15ce
+/*
8e15ce
+ *  GRUB  --  GRand Unified Bootloader
8e15ce
+ *  Copyright (C) 2006,2007,2008  Free Software Foundation, Inc.
8e15ce
+ *
8e15ce
+ *  GRUB is free software: you can redistribute it and/or modify
8e15ce
+ *  it under the terms of the GNU General Public License as published by
8e15ce
+ *  the Free Software Foundation, either version 3 of the License, or
8e15ce
+ *  (at your option) any later version.
8e15ce
+ *
8e15ce
+ *  GRUB is distributed in the hope that it will be useful,
8e15ce
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
8e15ce
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8e15ce
+ *  GNU General Public License for more details.
8e15ce
+ *
8e15ce
+ *  You should have received a copy of the GNU General Public License
8e15ce
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
8e15ce
+ */
8e15ce
+
8e15ce
+#include <grub/dl.h>
8e15ce
+#include <grub/term.h>
8e15ce
+#include <grub/time.h>
8e15ce
+#include <grub/types.h>
8e15ce
+#include <grub/misc.h>
8e15ce
+#include <grub/extcmd.h>
8e15ce
+#include <grub/i18n.h>
8e15ce
+
8e15ce
+GRUB_MOD_LICENSE ("GPLv3+");
8e15ce
+
8e15ce
+static grub_err_t
8e15ce
+grub_cmd_version (grub_command_t cmd UNUSED, int argc, char **args UNUSED)
8e15ce
+{
8e15ce
+  if (argc != 0)
8e15ce
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("no arguments expected"));
8e15ce
+
8e15ce
+  grub_printf (_("GNU GRUB  version %s\n"), PACKAGE_VERSION);
8e15ce
+  grub_printf (_("Platform %s-%s\n"), GRUB_TARGET_CPU, GRUB_PLATFORM);
8e15ce
+  if (grub_strlen(GRUB_RPM_VERSION) != 0)
8e15ce
+    grub_printf (_("RPM package version %s\n"), GRUB_RPM_VERSION);
8e15ce
+  grub_printf (_("Compiler version %s\n"), __VERSION__);
8e15ce
+
8e15ce
+  return 0;
8e15ce
+}
8e15ce
+
8e15ce
+static grub_command_t cmd;
8e15ce
+
8e15ce
+GRUB_MOD_INIT(version)
8e15ce
+{
8e15ce
+  cmd = grub_register_command ("version", grub_cmd_version, NULL,
8e15ce
+			       N_("Print version and build information."));
8e15ce
+}
8e15ce
+
8e15ce
+GRUB_MOD_FINI(version)
8e15ce
+{
8e15ce
+  grub_unregister_command (cmd);
8e15ce
+}
8e15ce
diff --git a/config.h.in b/config.h.in
8e15ce
index 9e8f9911b18..c7e316f0f1f 100644
8e15ce
--- a/config.h.in
8e15ce
+++ b/config.h.in
8e15ce
@@ -59,6 +59,7 @@
8e15ce
 
8e15ce
 #define GRUB_TARGET_CPU "@GRUB_TARGET_CPU@"
8e15ce
 #define GRUB_PLATFORM "@GRUB_PLATFORM@"
8e15ce
+#define GRUB_RPM_VERSION "@GRUB_RPM_VERSION@"
8e15ce
 
8e15ce
 #define RE_ENABLE_I18N 1
8e15ce