From 0a13f15a9d283522ac1f3af6f528934cdc305eb7 Mon Sep 17 00:00:00 2001
From: Seth Hillbrand <seth@kipro-pcb.com>
Date: Thu, 3 Feb 2022 15:53:12 -0800
Subject: [PATCH] Ensure we can version scripting properly

Adds Version() and FullVersion() calls to support reporting version to
scripts and scripting window

Fixes https://gitlab.com/kicad/code/kicad/issues/10079
---
 pcbnew/CMakeLists.txt               |  2 ++
 pcbnew/python/swig/pcbnew.i         |  1 +
 pcbnew/python/swig/version.i        | 35 +++++++++++++++++++++++++++++
 scripting/kicad_pyshell/__init__.py |  3 ++-
 4 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 pcbnew/python/swig/version.i

diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt
index ad3a138ae0..58a3b0e13f 100644
--- a/pcbnew/CMakeLists.txt
+++ b/pcbnew/CMakeLists.txt
@@ -407,6 +407,7 @@ set( SWIG_FLAGS
     -I${CMAKE_SOURCE_DIR}/pcbnew/python/scripting
     -I${CMAKE_SOURCE_DIR}/common/swig
     -I${CMAKE_SOURCE_DIR}/libs/kimath/include
+    -I${CMAKE_BINARY_DIR}
     )
 
 if( DEBUG )
@@ -468,6 +469,7 @@ add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/pcbnew_wrap.cxx
     DEPENDS python/swig/track.i
     DEPENDS python/swig/units.i
     DEPENDS python/swig/typeinfo.i
+    DEPENDS python/swig/version.i
     DEPENDS python/swig/zone.i
     DEPENDS python/swig/zone_settings.i
 
diff --git a/pcbnew/python/swig/pcbnew.i b/pcbnew/python/swig/pcbnew.i
index 0be856d90e..8610acf385 100644
--- a/pcbnew/python/swig/pcbnew.i
+++ b/pcbnew/python/swig/pcbnew.i
@@ -135,5 +135,6 @@ HANDLE_EXCEPTIONS(WriteDRCReport)
 %include footprint.i
 %include plugins.i
 %include units.i
+%include version.i
 
 
diff --git a/pcbnew/python/swig/version.i b/pcbnew/python/swig/version.i
new file mode 100644
index 0000000000..34678065a2
--- /dev/null
+++ b/pcbnew/python/swig/version.i
@@ -0,0 +1,35 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <https://www.gnu.org/licenses/>
+ */
+
+/**
+ * @file version.i
+ * @brief KiCad version routine
+ */
+%include kicad_build_version.h
+
+%pythoncode
+%{
+    def Version():
+        """Return the semantic version of KiCad"""
+        return KICAD_SEMANTIC_VERSION
+    
+    def FullVersion():
+        """Return the full, git-based version of KiCad"""
+        return KICAD_VERSION_FULL
+%}
\ No newline at end of file
diff --git a/scripting/kicad_pyshell/__init__.py b/scripting/kicad_pyshell/__init__.py
index 927a3e48b6..4b0f27b343 100644
--- a/scripting/kicad_pyshell/__init__.py
+++ b/scripting/kicad_pyshell/__init__.py
@@ -20,6 +20,7 @@ Pgm() returns a nullptr and Kicad crashes when Pgm is invoked.
 import wx
 import sys
 import os
+import pcbnew
 
 from wx.py import crust, version, dispatcher
 
@@ -136,7 +137,7 @@ class KiCadPyShell(KiCadEditorNotebookFrame):
         """Display an About window."""
         title = 'About : KiCad - Python Shell'
         text = "Enhanced Python Shell for KiCad\n\n" + \
-               "KiCad Revision: %s\n" % "??.??" + \
+               "KiCad Revision: %s\n" % pcbnew.FullVersion() + \
                "Platform: %s\n" % sys.platform + \
                "Python Version: %s\n" % sys.version.split()[0] + \
                "wxPython Version: %s\n" % wx.VERSION_STRING + \