changeset 21608:80258bb3a14b

store hg id info in libgui and main exe and check for consistency (bug #45659) * libgui/src/liboctgui-build-info.h, libgui/src/liboctgui-build-info.in.cc, src/octave-build-info.h, src/octave-build-info.in.cc: New files. * libgui/src/module.mk, src/module.mk: Update. * main-cli.cc (check_hg_versions): New function. * main-gui.cc (check_hg_versions): New function. * toplev.cc (F__octave_config_info__): Only keep one hg_id field since all libraries and the main executable file are required to match.
author John W. Eaton <jwe@octave.org>
date Mon, 11 Apr 2016 13:53:17 -0400
parents 37f6ed8a6f1b
children 46f059de4dce
files libgui/src/liboctgui-build-info.h libgui/src/liboctgui-build-info.in.cc libgui/src/module.mk libinterp/corefcn/toplev.cc src/main-cli.cc src/main-gui.cc src/module.mk src/octave-build-info.h src/octave-build-info.in.cc
diffstat 9 files changed, 287 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgui/src/liboctgui-build-info.h	Mon Apr 11 13:53:17 2016 -0400
@@ -0,0 +1,34 @@
+/*
+
+Copyright (C) 2016 M. Muetzel
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#if ! defined (octave_liboctgui_build_info_h)
+#define octave_liboctgui_build_info_h 1
+
+#include "octave-config.h"
+
+#include <ctime>
+
+#include <string>
+
+extern std::string liboctgui_hg_id (void);
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgui/src/liboctgui-build-info.in.cc	Mon Apr 11 13:53:17 2016 -0400
@@ -0,0 +1,34 @@
+// %NO_EDIT_WARNING%
+/*
+
+Copyright (C) 2016 M. Muetzel
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "liboctgui-build-info.h"
+
+std::string
+liboctgui_hg_id (void)
+{
+  return "%OCTAVE_HG_ID%";
+}
--- a/libgui/src/module.mk	Mon Apr 11 12:16:19 2016 -0400
+++ b/libgui/src/module.mk	Mon Apr 11 13:53:17 2016 -0400
@@ -130,6 +130,7 @@
   libgui/src/documentation-dock-widget.h \
   libgui/src/files-dock-widget.h \
   libgui/src/history-dock-widget.h \
+  libgui/src/liboctgui-build-info.h \
   libgui/src/m-editor/file-editor-interface.h \
   libgui/src/m-editor/file-editor-tab.h \
   libgui/src/m-editor/file-editor.h \
@@ -187,7 +188,10 @@
   libgui/src/workspace-model.cc \
   libgui/src/workspace-view.cc
 
-nodist_libgui_src_libgui_src_la_SOURCES = $(octave_gui_MOC) $(octave_gui_RC)
+nodist_libgui_src_libgui_src_la_SOURCES = \
+  libgui/src/liboctgui-build-info.cc \
+  $(octave_gui_MOC) \
+  $(octave_gui_RC)
 
 libgui_src_libgui_src_la_CPPFLAGS = \
   $(AM_CPPFLAGS) \
@@ -219,12 +223,22 @@
 noinst_LTLIBRARIES += libgui/src/libgui-src.la
 
 libgui_EXTRA_DIST += \
+  libgui/src/liboctgui-build-info.in.cc \
   libgui/src/resource.qrc \
   $(octave_gui_UI) \
   $(octave_gui_ICONS)
 
+libgui_DISTCLEANFILES += \
+  libgui/src/liboctgui-build-info.cc
+
 libgui_CLEANFILES += \
   $(octave_gui_MOC) \
   $(octave_gui_UI_H) \
   $(octave_gui_RC)
 
+libgui/src/liboctgui-build-info.cc: libgui/src/liboctgui-build-info.in.cc HG-ID | libgui/src/$(octave-dirstamp)
+	$(AM_V_GEN)rm -f $@-t && \
+	$(SED) \
+	  -e "s|%NO_EDIT_WARNING%|DO NOT EDIT!  Generated automatically by Makefile|" \
+	  -e "s|%OCTAVE_HG_ID%|`cat $(builddir)/HG-ID`|" $< > $@-t && \
+	$(simple_move_if_change_rule)
--- a/libinterp/corefcn/toplev.cc	Mon Apr 11 12:16:19 2016 -0400
+++ b/libinterp/corefcn/toplev.cc	Mon Apr 11 13:53:17 2016 -0400
@@ -52,7 +52,6 @@
 #include "str-vec.h"
 
 #include "build-env.h"
-#include "liboctave-build-info.h"
 #include "liboctinterp-build-info.h"
 #include "defaults.h"
 #include "defun.h"
@@ -1438,12 +1437,10 @@
       { "infofile", subst_octave_home (OCTAVE_INFOFILE) },
       { "libdir", subst_octave_home (OCTAVE_LIBDIR) },
       { "libexecdir", subst_octave_home (OCTAVE_LIBEXECDIR) },
-      // The liboctave and liboctinterp hg ids should always be the
-      // same, but it is possible for someone to accidentally have a
-      // mismatched pair so we record both separately so that we can
-      // ensure that they are consistent.
-      { "liboctave_hg_id", liboctave_hg_id () },
-      { "liboctinterp_hg_id", liboctinterp_hg_id () },
+      // Each library and executable has its own definition of the hg
+      // id.  We check for consistency when Octave starts so we just
+      // store and report one of them here.
+      { "hg_id", liboctinterp_hg_id () },
       { "localapiarchlibdir", subst_octave_home (OCTAVE_LOCALAPIARCHLIBDIR) },
       { "localapifcnfiledir", subst_octave_home (OCTAVE_LOCALAPIFCNFILEDIR) },
       { "localapioctfiledir", subst_octave_home (OCTAVE_LOCALAPIOCTFILEDIR) },
--- a/src/main-cli.cc	Mon Apr 11 12:16:19 2016 -0400
+++ b/src/main-cli.cc	Mon Apr 11 13:53:17 2016 -0400
@@ -24,13 +24,63 @@
 #  include "config.h"
 #endif
 
+#include <cstdlib>
+
+#include <iostream>
+#include <string>
+
+#include "liboctave-build-info.h"
+
+#include "liboctinterp-build-info.h"
+
 #include "defaults.h"
 #include "octave.h"
+#include "octave-build-info.h"
 #include "sysdep.h"
 
+static void
+check_hg_versions (void)
+{
+  bool ok = true;
+
+  // Each library and executable has its own definition of the hg
+  // id.  They should always match but may be different because of a
+  // botched installation or incorrect LD_LIBRARY_PATH or some other
+  // unusual problem.
+
+  std::string octave_id = octave_hg_id ();
+  std::string liboctave_id = liboctave_hg_id ();
+  std::string liboctinterp_id = liboctinterp_hg_id ();
+
+  if (octave_id != liboctave_id)
+    {
+      std::cerr << "octave hg id ("
+                << octave_id
+                << ") does not match liboctave hg id ("
+                << liboctave_id
+                << ")" << std::endl;
+      ok = false;
+    }
+
+  if (octave_id != liboctinterp_id)
+    {
+      std::cerr << "octave hg id ("
+                << octave_id
+                << ") does not match liboctinterp hg id ("
+                << liboctinterp_id
+                << ")" << std::endl;
+      ok = false;
+    }
+
+  if (! ok)
+    exit (1);
+}
+
 int
 main (int argc, char **argv)
 {
+  check_hg_versions ();
+
   octave_process_command_line (argc, argv);
 
   sysdep_init ();
--- a/src/main-gui.cc	Mon Apr 11 12:16:19 2016 -0400
+++ b/src/main-gui.cc	Mon Apr 11 13:53:17 2016 -0400
@@ -24,14 +24,77 @@
 #  include "config.h"
 #endif
 
+#include <cstdlib>
+
+#include <iostream>
+#include <string>
+
+#include "liboctave-build-info.h"
+
+#include "liboctinterp-build-info.h"
+
+#include "liboctgui-build-info.h"
+
 #include "defaults.h"
 #include "octave.h"
+#include "octave-build-info.h"
 #include "octave-gui.h"
 #include "sysdep.h"
 
+static void
+check_hg_versions (void)
+{
+  bool ok = true;
+
+  // Each library and executable has its own definition of the hg
+  // id.  They should always match but may be different because of a
+  // botched installation or incorrect LD_LIBRARY_PATH or some other
+  // unusual problem.
+
+  std::string octave_id = octave_hg_id ();
+  std::string liboctave_id = liboctave_hg_id ();
+  std::string liboctinterp_id = liboctinterp_hg_id ();
+  std::string liboctgui_id = liboctgui_hg_id ();
+
+  if (octave_id != liboctave_id)
+    {
+      std::cerr << "octave hg id ("
+                << octave_id
+                << ") does not match liboctave hg id ("
+                << liboctave_id
+                << ")" << std::endl;
+      ok = false;
+    }
+
+  if (octave_id != liboctinterp_id)
+    {
+      std::cerr << "octave hg id ("
+                << octave_id
+                << ") does not match liboctinterp hg id ("
+                << liboctinterp_id
+                << ")" << std::endl;
+      ok = false;
+    }
+
+  if (octave_id != liboctgui_id)
+    {
+      std::cerr << "octave hg id ("
+                << octave_id
+                << ") does not match liboctgui hg id ("
+                << liboctgui_id
+                << ")" << std::endl;
+      ok = false;
+    }
+
+  if (! ok)
+    exit (1);
+}
+
 int
 main (int argc, char **argv)
 {
+  check_hg_versions ();
+
   octave_process_command_line (argc, argv);
 
   sysdep_init ();
--- a/src/module.mk	Mon Apr 11 12:16:19 2016 -0400
+++ b/src/module.mk	Mon Apr 11 13:53:17 2016 -0400
@@ -7,12 +7,13 @@
 ## Search local directories before those specified by the user.
 
 SRC_DIR_CPPFLAGS = \
+  -Iliboctave -I$(srcdir)/liboctave \
   -I$(srcdir)/liboctave/array \
   -I$(srcdir)/liboctave/cruft/misc \
   -I$(srcdir)/liboctave/numeric \
   -I$(srcdir)/liboctave/system \
   -I$(srcdir)/liboctave/util \
-  -I$(srcdir)/libinterp \
+  -Ilibinterp -I$(srcdir)/libinterp \
   -Ilibinterp/corefcn -I$(srcdir)/libinterp/corefcn \
   -I$(srcdir)/src \
   -Ilibgnu -I$(srcdir)/libgnu
@@ -20,6 +21,7 @@
 EXTRA_DIST += \
   src/main.in.cc \
   src/mkoctfile.in.cc \
+  src/octave-build-info.in.cc \
   src/octave-config.in.cc
 
 DISTCLEANFILES += \
@@ -37,8 +39,11 @@
   $(bin_PROGRAMS) \
   $(OCTAVE_VERSION_LINKS)
 
+octinclude_HEADERS += \
+  src/octave-build-info.h
+
 noinst_HEADERS += \
-  src/display-available.h	\
+  src/display-available.h \
   src/shared-fcns.h
 
 OCTAVE_VERSION_LINKS += src/octave-cli-$(version)$(EXEEXT)
@@ -55,6 +60,7 @@
   liboctave/liboctave.la
 
 nodist_src_octave_SOURCES = src/main.cc
+
 src_octave_SOURCES = src/display-available.c
 
 src_octave_LDADD = \
@@ -81,6 +87,7 @@
   $(WARN_CXXFLAGS)
 
 src_octave_cli_SOURCES = src/main-cli.cc
+nodist_src_octave_cli_SOURCES = src/octave-build-info.cc
 
 src_octave_cli_LDADD = \
   $(OCTAVE_CORE_LIBS) \
@@ -101,8 +108,9 @@
 
 if AMCOND_BUILD_QT_GUI
   src_octave_gui_SOURCES = src/main-gui.cc
+  nodist_src_octave_gui_SOURCES = src/octave-build-info.cc
   OCTAVE_GUI_LIBS = libgui/liboctgui.la
-  OCTAVE_GUI_CPPFLAGS = -I$(srcdir)/libgui/src
+  OCTAVE_GUI_CPPFLAGS = -Ilibgui/src -I$(srcdir)/libgui/src
 endif
 
 src_octave_gui_CPPFLAGS = \
@@ -199,6 +207,13 @@
 src/main.cc: src/main.in.cc build-aux/subst-default-vals.sh | src/$(octave_dirstamp)
 	$(AM_V_GEN)$(call simple-filter-rule,build-aux/subst-default-vals.sh)
 
+src/octave-build-info.cc: src/octave-build-info.in.cc HG-ID | src/$(octave-dirstamp)
+	$(AM_V_GEN)rm -f $@-t && \
+	$(SED) \
+	  -e "s|%NO_EDIT_WARNING%|DO NOT EDIT!  Generated automatically by Makefile|" \
+	  -e "s|%OCTAVE_HG_ID%|`cat $(builddir)/HG-ID`|" $< > $@-t && \
+	$(simple_move_if_change_rule)
+
 ALL_LOCAL_TARGETS += $(OCTAVE_VERSION_LINKS) $(OCTAVE_CROSS_TOOLS)
 
 install-exec-hook: make-version-links
@@ -231,6 +246,7 @@
 	cd $(@D) && $(LN_S) $(<F) $(@F)
 
 src_CLEANFILES += $(OCTAVE_VERSION_LINKS)
+src_DISTCLEANFILES += src/octave-build-info.cc
 
 CLEANFILES += $(src_CLEANFILES)
 DISTCLEANFILES += $(src_DISTCLEANFILES)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/octave-build-info.h	Mon Apr 11 13:53:17 2016 -0400
@@ -0,0 +1,34 @@
+/*
+
+Copyright (C) 2016 M. Muetzel
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#if ! defined (octave_octave_build_info_h)
+#define octave_octave_build_info_h 1
+
+#include "octave-config.h"
+
+#include <ctime>
+
+#include <string>
+
+extern std::string octave_hg_id (void);
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/octave-build-info.in.cc	Mon Apr 11 13:53:17 2016 -0400
@@ -0,0 +1,34 @@
+// %NO_EDIT_WARNING%
+/*
+
+Copyright (C) 2016 M. Muetzel
+
+This file is part of Octave.
+
+Octave is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+Octave is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "octave-build-info.h"
+
+std::string
+octave_hg_id (void)
+{
+  return "%OCTAVE_HG_ID%";
+}