<div dir="ltr">From aa14ce529df826e6ddbb29987cc7f13d0d74f744 Mon Sep 17 00:00:00 2001<br>From: Srikanth Kurapati <<a href="mailto:srikanth.kurapati@multicorewareinc.com">srikanth.kurapati@multicorewareinc.com</a>><br>Date: Tue, 13 Oct 2020 20:46:56 +0530<br>Subject: [PATCH 1/2] Fix incorrect version display issue on console for<br> archived repositories.<br><br>1. adds a new file x265version.txt to maintain version information across releases.<br>2. adds functionality to process the same & updates documentation.<br>---<br> doc/reST/cli.rst           |  17 +++-<br> source/CMakeLists.txt      |   2 +-<br> source/cmake/Version.cmake | 193 +++++++++++++++++++++++++++++++++++++<br> source/cmake/version.cmake |  97 -------------------<br> x265Version.txt            |   5 +<br> 5 files changed, 214 insertions(+), 100 deletions(-)<br> create mode 100644 source/cmake/Version.cmake<br> delete mode 100644 source/cmake/version.cmake<br> create mode 100644 x265Version.txt<br><br>diff --git a/doc/reST/cli.rst b/doc/reST/cli.rst<br>index c449a5d36..6fcf2b028 100644<br>--- a/doc/reST/cli.rst<br>+++ b/doc/reST/cli.rst<br>@@ -36,13 +36,26 @@ Executable Options<br> <br> .. option:: --help, -h<br> <br>-     Display help text<br>+    Displays help text<br> <br>       **CLI ONLY**<br> <br> .. option:: --version, -V<br> <br>-    Display version details<br>+      Displays version details in the following manner *[Version Name]+/-[Number of commits from the release changeset]-/+[repository's head changeset  SHA-1 paraphrase identifier]*<br>+ along with the compilation platform, build information and supported cpu capabilities.<br>+<br>+    In case of release tar balls version information is partly derived from configuration file *x265Version.txt*<br>+ .. seeAlso::  For more information on how to configure the version file please refer to `<<a href="https://bitbucket.org/multicoreware/x265_git/wiki/Home">https://bitbucket.org/multicoreware/x265_git/wiki/Home</a>>`_  and Contribute pages for updates specific<br>+    release and version control management.<br>+<br>+   **Example:**<br>+<br>+      *x265 [info]: HEVC encoder version 3.4+27-'d9217cf00'*<br>+<br>+    *x265 [info]: build info [Windows][MSVC 1916][64 bit] 10bit*<br>+<br>+      *x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2*<br> <br>       **CLI ONLY**<br> <br>diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt<br>index 518fec98f..2481e7a3c 100644<br>--- a/source/CMakeLists.txt<br>+++ b/source/CMakeLists.txt<br>@@ -467,7 +467,7 @@ if(POWER)<br>     endif()<br> endif()<br> <br>-include(version) # determine X265_VERSION and X265_LATEST_TAG<br>+include(Version) # determine X265_VERSION and X265_LATEST_TAG<br> include_directories(. common encoder "${PROJECT_BINARY_DIR}")<br> <br> option(ENABLE_PPA "Enable PPA profiling instrumentation" OFF)<br>diff --git a/source/cmake/Version.cmake b/source/cmake/Version.cmake<br>new file mode 100644<br>index 000000000..37c759268<br>--- /dev/null<br>+++ b/source/cmake/Version.cmake<br>@@ -0,0 +1,193 @@<br>+ #################################################################################################################<br>+ #<br>+ #    Copyright (C) 2013-2020 MulticoreWare, Inc<br>+ #<br>+ # This program is free software; you can redistribute it and/or modify<br>+ # it under the terms of the GNU General Public License as published by<br>+ # the Free Software Foundation; either version 2 of the License, or<br>+ # (at your option) any later version.<br>+ #<br>+ # This program is distributed in the hope that it will be useful,<br>+ # but WITHOUT ANY WARRANTY; without even the implied warranty of<br>+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>+ # GNU General Public License for more details.<br>+ #<br>+ # You should have received a copy of the GNU General Public License<br>+ # along with this program; if not, write to the Free Software<br>+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.<br>+ #<br>+ # This program is also available under a commercial proprietary license.<br>+ # For more information, contact us at license @ <a href="http://x265.com">x265.com</a><br>+ #<br>+ # Authors: Janani T.E <<a href="mailto:janani.te@multicorewareinc.com">janani.te@multicorewareinc.com</a>>, Srikanth Kurapati <<a href="mailto:srikanthkurapati@multicorewareinc.com">srikanthkurapati@multicorewareinc.com</a>><br>+ #<br>+ #################################################################################################################<br>+ # PURPOSE: Identity version control software version display, also read version files to present x265 version.<br>+ #################################################################################################################<br>+ #Default Settings, for user to be vigilant about x265 version being reported during product build.<br>+set(X265_VERSION "unknown")<br>+set(X265_LATEST_TAG "0.0")<br>+set(X265_TAG_DISTANCE "0")<br>+set(HG_ARCHETYPE "0")<br>+set(GIT_ARCHETYPE "0")<br>+<br>+#Find version control software to be used for live and extracted repositories from compressed tarballs<br>+if(CMAKE_VERSION VERSION_LESS "2.8.10")<br>+    find_program(HG_EXECUTABLE hg)<br>+    if(EXISTS "${HG_EXECUTABLE}.bat")<br>+        set(HG_EXECUTABLE "${HG_EXECUTABLE}.bat")<br>+    endif()<br>+    message(STATUS "hg found at ${HG_EXECUTABLE}")<br>+else()<br>+    find_package(Hg QUIET)<br>+endif()<br>+if(HG_EXECUTABLE)<br>+    #Set Version Control binary for source code kind<br>+    if(EXISTS CMAKE_CURRENT_SOURCE_DIR}/../.hg_archival.txt)<br>+        set(HG_ARCHETYPE "1")<br>+    elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.hg)<br>+        set(HG_ARCHETYPE "2")<br>+    endif()<br>+endif(HG_EXECUTABLE)<br>+find_package(Git QUIET) #No restrictions on Git versions used, any versions from 1.8.x to 2.2.x or later should do.<br>+if(Git_FOUND)<br>+    find_program(GIT_EXECUTABLE git)<br>+    message(STATUS "GIT_EXECUTABLE ${GIT_EXECUTABLE}")<br>+    if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git)<br>+        set(GIT_ARCHETYPE "2")<br>+    elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../x265Version.txt)<br>+        set(GIT_ARCHETYPE "1")<br>+    endif()<br>+endif(Git_FOUND)<br>+if(HG_ARCHETYPE STREQUAL "1")<br>+    #Read the lines of the archive summary file to extract the version<br>+    message(STATUS "SOURCE CODE IS FROM x265 ARCHIVED ZIP OR TAR BALL")<br>+    file(READ ${CMAKE_CURRENT_SOURCE_DIR}/../.hg_archival.txt archive)<br>+    STRING(REGEX REPLACE "\n" ";" archive "${archive}")<br>+    foreach(f ${archive})<br>+        string(FIND "${f}" ": " pos)<br>+        string(SUBSTRING "${f}" 0 ${pos} key)<br>+        string(SUBSTRING "${f}" ${pos} -1 value)<br>+        string(SUBSTRING "${value}" 2 -1 value)<br>+        set(hg_${key} ${value})<br>+    endforeach()<br>+    if(DEFINED hg_tag)<br>+        set(X265_LATEST_TAG ${hg_tag})<br>+    elseif(DEFINED hg_node)<br>+        set(X265_LATEST_TAG ${hg_latesttag})<br>+        set(X265_TAG_DISTANCE ${hg_latesttagdistance})<br>+        string(SUBSTRING "${hg_node}" 0 12 X265_REVISION_ID)<br>+    endif()<br>+    message(STATUS "HG ARCHIVAL INFORMATION PROCESSED")<br>+elseif(HG_ARCHETYPE STREQUAL "2")<br>+    execute_process(COMMAND<br>+        ${HG_EXECUTABLE} log -r. --template "{latesttag}"<br>+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}<br>+        OUTPUT_VARIABLE X265_LATEST_TAG<br>+        ERROR_QUIET<br>+        OUTPUT_STRIP_TRAILING_WHITESPACE<br>+        )<br>+    execute_process(COMMAND<br>+        ${HG_EXECUTABLE} log -r. --template "{latesttagdistance}"<br>+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}<br>+        OUTPUT_VARIABLE X265_TAG_DISTANCE<br>+        ERROR_QUIET<br>+        OUTPUT_STRIP_TRAILING_WHITESPACE<br>+        )<br>+    execute_process(<br>+        COMMAND<br>+        ${HG_EXECUTABLE} log -r. --template "{node}"<br>+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}<br>+        OUTPUT_VARIABLE X265_REVISION_ID<br>+        ERROR_QUIET<br>+        OUTPUT_STRIP_TRAILING_WHITESPACE<br>+        )<br>+    string(SUBSTRING "${X265_REVISION_ID}" 0 12 X265_REVISION_ID)<br>+    if(X265_LATEST_TAG MATCHES "^r")<br>+        string(SUBSTRING ${X265_LATEST_TAG} 1 -1 X265_LATEST_TAG)<br>+    endif()<br>+    message(STATUS "HG LIVE REPO STATUS CHECK DONE")<br>+elseif(GIT_ARCHETYPE STREQUAL "2")<br>+    execute_process(<br>+        COMMAND<br>+        ${GIT_EXECUTABLE} describe --abbrev=0 --tags<br>+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}<br>+        OUTPUT_VARIABLE X265_LATEST_TAG<br>+        ERROR_QUIET<br>+        OUTPUT_STRIP_TRAILING_WHITESPACE<br>+        )<br>+    execute_process(<br>+        COMMAND<br>+        ${GIT_EXECUTABLE} rev-list ${X265_LATEST_TAG}.. --count --first-parent<br>+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}<br>+        OUTPUT_VARIABLE X265_TAG_DISTANCE<br>+        ERROR_QUIET<br>+        OUTPUT_STRIP_TRAILING_WHITESPACE<br>+        )<br>+    execute_process(<br>+        COMMAND<br>+        ${GIT_EXECUTABLE} log --pretty=format:%h -n 1<br>+        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}<br>+        OUTPUT_VARIABLE X265_REVISION_ID<br>+        ERROR_QUIET<br>+        OUTPUT_STRIP_TRAILING_WHITESPACE<br>+        )<br>+elseif(GIT_ARCHETYPE STREQUAL "1")<br>+    message(STATUS "X265 GIT ARCHIVE EXTRACT VERSION INFORMATION PROCESSING")<br>+    #Read the lines of the archive summary file to extract the version<br>+    file(READ ${CMAKE_CURRENT_SOURCE_DIR}/../x265Version.txt filebuf)<br>+    STRING(REGEX REPLACE "\n" ";" filebuf "${filebuf}")<br>+    foreach(line ${filebuf})<br>+        string(FIND "${line}" ": " pos)<br>+        string(SUBSTRING "${line}" 0 ${pos} key)<br>+        string(SUBSTRING "${line}" ${pos} -1 value)<br>+        string(SUBSTRING "${value}" 2 -1 value)<br>+        set(git_${key} ${value})<br>+    endforeach()<br>+    if(DEFINED git_releasetag)<br>+        set(X265_LATEST_TAG ${git_releasetag})<br>+        if(DEFINED git_releasetagcommitid)<br>+            string(SUBSTRING "${git_releasetagcommitid}" 0 9 X265_REVISION_ID)<br>+        else()<br>+            message(WARNING "RELEASE CHANGESET INFO NOT PRESENT IN VERSION FILE")<br>+        endif()<br>+        if(DEFINED git_repositorychangeset)<br>+           string(SUBSTRING "${git_repositorychangeset}" 0 9 X265_REPO_ID)<br>+        else()<br>+           message(STATUS "X265 LATEST COMMIT TIP INFORMATION NOT AVAILABLE")<br>+        endif()<br>+        if(DEFINED git_releasetagdistance)<br>+           set(X265_TAG_DISTANCE ${git_releasetagdistance})<br>+        else()<br>+           message(WARNING "COMMIT INFORMATION AFTER LATEST REVISION UNAVAILABLE")<br>+        endif()<br>+    else()<br>+        message(WARNING "X265 RELEASE VERSION LABEL MISSING: ${X265_LATEST_TAG}")<br>+    endif()<br>+endif()<br>+<br>+# formatting based on positive or negative distance from tag<br>+if(X265_TAG_DISTANCE STREQUAL "0")<br>+    if(X265_REVISION_ID STREQUAL X265_REPO_ID)<br>+        set(X265_VERSION "${X265_LATEST_TAG}")<br>+    else()<br>+        message(WARNING "REPO AND RELEASE CHANGESETS NOT MATCHING")<br>+    endif()<br>+elseif(X265_TAG_DISTANCE STRGREATER "0")<br>+    if(X265_REVISION_ID STRLESS X265_REPO_ID)<br>+        set(X265_VERSION "${X265_LATEST_TAG}+${X265_TAG_DISTANCE}-${X265_REVISION_ID}")<br>+    else()<br>+        message(WARNING "ARCCHIVE TIP CHANGESET TO BE GREATER THAN REVISION ID")<br>+    endif()<br>+elseif(X265_TAG_DISTANCE STRLESS "0")<br>+    if(X265_REVISION_ID STRGREATER X265_REPO_ID)<br>+       set(X265_VERSION "${X265_LATEST_TAG}${X265_TAG_DISTANCE}+${X265_REPO_ID}")<br>+    else()<br>+        message(WARNING "REVISION ID EXPECTED TO BE LARGER THAN ARCHIVE TIP CHANGESET")<br>+    endif()<br>+else()<br>+    message(ERROR "Inappropriate set of version information")<br>+endif()<br>+<br>+#will always be printed in its entirety based on version file configuration to avail revision monitoring by repo owners<br>+message(STATUS "x265 RELEASE VERSION ${X265_VERSION}")<br>diff --git a/source/cmake/version.cmake b/source/cmake/version.cmake<br>deleted file mode 100644<br>index 35302249a..000000000<br>--- a/source/cmake/version.cmake<br>+++ /dev/null<br>@@ -1,97 +0,0 @@<br>-if(CMAKE_VERSION VERSION_LESS "2.8.10")<br>-    find_program(HG_EXECUTABLE hg)<br>-else()<br>-    find_package(Hg QUIET)<br>-endif()<br>-find_package(Git QUIET) # present in 2.8.8<br>-<br>-# defaults, in case everything below fails<br>-set(X265_VERSION "unknown")<br>-set(X265_LATEST_TAG "0.0")<br>-set(X265_TAG_DISTANCE "0")<br>-<br>-if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.hg_archival.txt)<br>-    # read the lines of the archive summary file to extract the version<br>-    file(READ ${CMAKE_CURRENT_SOURCE_DIR}/../.hg_archival.txt archive)<br>-    STRING(REGEX REPLACE "\n" ";" archive "${archive}")<br>-    foreach(f ${archive})<br>-        string(FIND "${f}" ": " pos)<br>-        string(SUBSTRING "${f}" 0 ${pos} key)<br>-        string(SUBSTRING "${f}" ${pos} -1 value)<br>-        string(SUBSTRING "${value}" 2 -1 value)<br>-        set(hg_${key} ${value})<br>-    endforeach()<br>-    if(DEFINED hg_tag)<br>-        set(X265_LATEST_TAG ${hg_tag})<br>-    elseif(DEFINED hg_node)<br>-        set(X265_LATEST_TAG ${hg_latesttag})<br>-        set(X265_TAG_DISTANCE ${hg_latesttagdistance})<br>-        string(SUBSTRING "${hg_node}" 0 12 X265_REVISION_ID)<br>-    endif()<br>-elseif(HG_EXECUTABLE AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.hg)<br>-    if(EXISTS "${HG_EXECUTABLE}.bat")<br>-        # mercurial source installs on Windows require .bat extension<br>-        set(HG_EXECUTABLE "${HG_EXECUTABLE}.bat")<br>-    endif()<br>-    message(STATUS "hg found at ${HG_EXECUTABLE}")<br>-<br>-    execute_process(COMMAND<br>-        ${HG_EXECUTABLE} log -r. --template "{latesttag}"<br>-        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}<br>-        OUTPUT_VARIABLE X265_LATEST_TAG<br>-        ERROR_QUIET<br>-        OUTPUT_STRIP_TRAILING_WHITESPACE<br>-        )<br>-    execute_process(COMMAND<br>-        ${HG_EXECUTABLE} log -r. --template "{latesttagdistance}"<br>-        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}<br>-        OUTPUT_VARIABLE X265_TAG_DISTANCE<br>-        ERROR_QUIET<br>-        OUTPUT_STRIP_TRAILING_WHITESPACE<br>-        )<br>-    execute_process(<br>-        COMMAND<br>-        ${HG_EXECUTABLE} log -r. --template "{node}"<br>-        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}<br>-        OUTPUT_VARIABLE X265_REVISION_ID<br>-        ERROR_QUIET<br>-        OUTPUT_STRIP_TRAILING_WHITESPACE<br>-        )<br>-    string(SUBSTRING "${X265_REVISION_ID}" 0 12 X265_REVISION_ID)<br>-<br>-    if(X265_LATEST_TAG MATCHES "^r")<br>-        string(SUBSTRING ${X265_LATEST_TAG} 1 -1 X265_LATEST_TAG)<br>-    endif()<br>-elseif(GIT_EXECUTABLE AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git)<br>-    execute_process(<br>-        COMMAND<br>-        ${GIT_EXECUTABLE} describe --abbrev=0 --tags<br>-        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}<br>-        OUTPUT_VARIABLE X265_LATEST_TAG<br>-        ERROR_QUIET<br>-        OUTPUT_STRIP_TRAILING_WHITESPACE<br>-        )<br>-    execute_process(<br>-        COMMAND<br>-        ${GIT_EXECUTABLE} rev-list ${X265_LATEST_TAG}.. --count --first-parent<br>-        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}<br>-        OUTPUT_VARIABLE X265_TAG_DISTANCE<br>-        ERROR_QUIET<br>-        OUTPUT_STRIP_TRAILING_WHITESPACE<br>-        )<br>-    execute_process(<br>-        COMMAND<br>-        ${GIT_EXECUTABLE} log -1 --format=g%h<br>-        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}<br>-        OUTPUT_VARIABLE X265_REVISION_ID<br>-        ERROR_QUIET<br>-        OUTPUT_STRIP_TRAILING_WHITESPACE<br>-        )<br>-endif()<br>-if(X265_TAG_DISTANCE STREQUAL "0")<br>-    set(X265_VERSION "${X265_LATEST_TAG}")<br>-else()<br>-    set(X265_VERSION "${X265_LATEST_TAG}+${X265_TAG_DISTANCE}-${X265_REVISION_ID}")<br>-endif()<br>-<br>-message(STATUS "x265 version ${X265_VERSION}")<br>diff --git a/x265Version.txt b/x265Version.txt<br>new file mode 100644<br>index 000000000..e20c8c0a1<br>--- /dev/null<br>+++ b/x265Version.txt<br>@@ -0,0 +1,5 @@<br>+#Attribute:           Values<br>+repositorychangeset: f4fa0303e<br>+releasetagcommitid: a4f320054<br>+releasetagdistance: 28<br>+releasetag: 3.4<br>-- <br>2.20.1.windows.1<br><br><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><b style="background-color:rgb(255,255,255)"><font color="#0b5394">With Regards,</font></b><div><b style="background-color:rgb(255,255,255)"><font color="#0b5394">Srikanth Kurapati.</font></b></div></div></div></div>