← Back to team overview

kicad-developers team mailing list archive

[PATCH] Update version string formatting after git migration

 

Now that we've migrated from bzr, there isn't much reason to keep
attaching a (now fake) bzr revision number to the version string.
Additionally, we can choose a sensible default branch name if one isn't
specified on the cmake line, rather than "product". This patch reformats
the version strings to:

(2016-08-26 revision 67230ac)-master
 |                   |        |
 |                   |        custom branch name if set. Otherwise,
 |                   |        branch name, "HEAD" if not on a branch,
 |                   |          or "unknown" if no .git present
 |                   |
 |                   abbreviated commit hash, or no-git if no .git
 |                     present
 |
 date of commit, or date of build if no .git present

-- 
Chris
>From 1ff0b4d0de8b56c7bb59bcf18f04c6c0b275c77e Mon Sep 17 00:00:00 2001
From: Chris Pavlina <pavlina.chris@xxxxxxxxx>
Date: Sat, 27 Aug 2016 11:08:07 -0400
Subject: [PATCH] Update version string formatting after git migration

It is no longer necessary (or sensible) to include a simulated bzr
revision number, and we can reliably get a branch name now. Therefore,
the new version strings look like:

(2016-08-26 revision 67230ac)-master
 |                   |        |
 |                   |        branch name, "HEAD" if not on a branch,
 |                   |          or "unknown" if no .git present
 |                   |
 |                   abbreviated commit hash, or no-git if no .git
 |                     present
 |
 date of commit, or date of build if no .git present

Signed-off-by: Chris Pavlina <pavlina.chris@xxxxxxxxx>
---
 CMakeLists.txt                            | 24 +++++++++++++++++++++++-
 CMakeModules/CreateGitVersionHeader.cmake | 19 ++++++++++++-------
 CMakeModules/WriteVersionHeader.cmake     |  3 ++-
 common/build_version.cpp                  |  4 ++--
 4 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 484a365..a849798 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,3 +1,25 @@
+#
+#  This program source code file is part of KICAD, a free EDA CAD application.
+#
+#  Copyright (C) 2007-2016 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 2
+#  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, you may find one here:
+#  http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+#  or you may search the http://www.gnu.org website for the version 2 license,
+#  or you may write to the Free Software Foundation, Inc.,
+#  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+#
 
 # Default to CMAKE_BUILD_TYPE = Release unless overridden on command line
 # http://www.cmake.org/pipermail/cmake/2008-September/023808.html
@@ -62,7 +84,7 @@ option( BUILD_GITHUB_PLUGIN "Build the GITHUB_PLUGIN for pcbnew." ON )
 option( KICAD_SPICE "Build Kicad with internal Spice simulator." OFF )
 
 # This can be set to a custom name to brag about a particular branch in the "About" dialog:
-set( KICAD_REPO_NAME "product" CACHE STRING "Name of the tree from which this build came." )
+set( KICAD_REPO_NAME "unknown" CACHE STRING "Name of the tree from which this build came." )
 
 
 # Global setting: exports are explicit
diff --git a/CMakeModules/CreateGitVersionHeader.cmake b/CMakeModules/CreateGitVersionHeader.cmake
index 42cf4b4..b9bfdf9 100644
--- a/CMakeModules/CreateGitVersionHeader.cmake
+++ b/CMakeModules/CreateGitVersionHeader.cmake
@@ -2,7 +2,7 @@
 #  This program source code file is part of KICAD, a free EDA CAD application.
 #
 #  Copyright (C) 2010 Wayne Stambaugh <stambaughw@xxxxxxxxxxx>
-#  Copyright (C) 2010-2015 Kicad Developers, see AUTHORS.txt for contributors.
+#  Copyright (C) 2010-2016 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
@@ -23,9 +23,11 @@
 #
 
 macro( create_git_version_header _git_src_path )
-    # If bzr is not found or an error occurs using the git commands to determine the repo
-    # version, set the build version string to "no-git"
+    # If an error occurs using the git commands to determine the repo
+    # version, set the build version string to "no-git" and the default
+    # branch name to unknown
     set( KICAD_BUILD_VERSION "no-git" )
+    set( KICAD_BRANCH_NAME ${KICAD_REPO_NAME} )
 
     # Include Git support to automagically create version header file.
     find_package( Git )
@@ -72,17 +74,17 @@ macro( create_git_version_header _git_src_path )
 
             execute_process(
             COMMAND
-            ${GIT_EXECUTABLE} rev-list HEAD --count
-            --first-parent
+            ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
             WORKING_DIRECTORY ${_git_src_path}
-            OUTPUT_VARIABLE _git_SERIAL
+            OUTPUT_VARIABLE _git_BRANCH
             OUTPUT_STRIP_TRAILING_WHITESPACE)
 
             message(STATUS "Git hash: ${_git_LONG_HASH}")
+            message(STATUS "Git branch: ${_git_BRANCH}")
 
             if( ${_git_log_result} EQUAL 0 )
                 string( REGEX REPLACE "^(.*\n)?revno: ([^ \n]+).*"
-                        "\\2" Kicad_REPO_REVISION "BZR ${_git_SERIAL}, Git ${_git_SHORT_HASH}" )
+                        "\\2" Kicad_REPO_REVISION "revision ${_git_SHORT_HASH}" )
                 string( REGEX REPLACE "^(.*\n)?committer: ([^\n]+).*"
                         "\\2" Kicad_REPO_LAST_CHANGED_AUTHOR "${_git_LAST_COMITTER}")
                 string( REGEX REPLACE "^(.*\n)?timestamp: [a-zA-Z]+ ([^ \n]+).*"
@@ -99,6 +101,9 @@ macro( create_git_version_header _git_src_path )
         string( REGEX REPLACE "^([0-9]+)\\-([0-9]+)\\-([0-9]+)" "\\1-\\2-\\3"
                 _kicad_git_date ${Kicad_REPO_LAST_CHANGED_DATE} )
         set( KICAD_BUILD_VERSION "(${_kicad_git_date} ${Kicad_REPO_REVISION})" )
+        if( NOT "${KICAD_REPO_NAME}" STREQUAL "unknown" )
+            set( KICAD_BRANCH_NAME ${_git_BRANCH} )
+        endif()
     endif()
 
     set( KICAD_BUILD_VERSION ${KICAD_BUILD_VERSION} )
diff --git a/CMakeModules/WriteVersionHeader.cmake b/CMakeModules/WriteVersionHeader.cmake
index 0adf6af..da1b9a4 100644
--- a/CMakeModules/WriteVersionHeader.cmake
+++ b/CMakeModules/WriteVersionHeader.cmake
@@ -2,7 +2,7 @@
 #  This program source code file is part of KICAD, a free EDA CAD application.
 #
 #  Copyright (C) 2015 Wayne Stambaugh <stambaughw@xxxxxxxxxxx>
-#  Copyright (C) 2015 KiCad Developers, see AUTHORS.txt for contributors.
+#  Copyright (C) 2015-2016 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
@@ -74,6 +74,7 @@ if( _wvh_write_version_file )
 #define __KICAD_VERSION_H__
 
 #define KICAD_BUILD_VERSION \"${_wvh_version_str}\"
+#define KICAD_BRANCH_NAME \"${KICAD_BRANCH_NAME}\"
 
 #endif  /* __KICAD_VERSION_H__ */
 "
diff --git a/common/build_version.cpp b/common/build_version.cpp
index d8bd538..47d25cb 100644
--- a/common/build_version.cpp
+++ b/common/build_version.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
- * Copyright (C) 2015 KiCad Developers, see CHANGELOG.TXT for contributors.
+ * Copyright (C) 2015-2016 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
@@ -39,7 +39,7 @@ wxString GetBuildVersion()
     wxString msg = wxString::Format(
         wxT( "%s-%s" ),
         wxT( KICAD_BUILD_VERSION ),
-        wxT( KICAD_REPO_NAME )
+        wxT( KICAD_BRANCH_NAME )
         );
 
     return msg;
-- 
2.9.2


Follow ups