Fix version header rewrite (happened too often)

This commit also simplifies the rewrite logic slightly, removing the
regex parsing.

Bug introduced in:

    commit 47772e7ae3
    Author: Chris Pavlina <pavlina.chris@gmail.com>
    Date:   Sun Sep 25 10:28:50 2016 -0400

        cmake: rewrite version header when branch changes

        Before, only KICAD_BUILD_VERSION, which includes the hash but not the
        branch, was compared when deciding whether to regenerate
        kicad_build_version.h. This header also contains the branch name though,
        so we should compare both to address the case of two branches pointing
        at the same commit.
This commit is contained in:
Chris Pavlina 2016-09-27 11:40:12 -04:00
parent 91479bebf8
commit 245607d05c
1 changed files with 18 additions and 22 deletions

View File

@ -41,26 +41,7 @@ else()
set( _wvh_version_str ${KICAD_BUILD_VERSION} )
endif()
set( _wvh_write_version_file ON )
# Compare the version argument against the version in the existing header file for a mismatch.
if( EXISTS ${OUTPUT_FILE} )
file( STRINGS ${OUTPUT_FILE} _current_version_str
REGEX "^#define[\t ]+KICAD_FULL_VERSION[\t ]+.*" )
string( REGEX REPLACE "^#define KICAD_FULL_VERSION \"([()a-zA-Z0-9 -.]+)\".*"
"\\1" _wvh_last_version "${_current_version_str}" )
# No change, do not write version.h
if( _wvh_version_str STREQUAL _wvh_last_version )
message( STATUS "Not updating ${OUTPUT_FILE}" )
set( _wvh_write_version_file OFF )
endif()
endif()
if( _wvh_write_version_file )
message( STATUS "Writing ${OUTPUT_FILE} file with version: ${_wvh_version_str}" )
file( WRITE ${OUTPUT_FILE}
set( _wvh_new_version_text
"/* Do not modify this file, it was automatically generated by CMake. */
/*
@ -74,8 +55,23 @@ if( _wvh_write_version_file )
#define KICAD_FULL_VERSION \"${KICAD_FULL_VERSION}\"
#endif /* __KICAD_VERSION_H__ */
"
)
" )
set( _wvh_write_version_file ON )
# Only write the header if it has changed, to avoid rebuilds
if( EXISTS ${OUTPUT_FILE} )
file( READ ${OUTPUT_FILE} _wvh_old_version_text )
if( _wvh_old_version_text STREQUAL _wvh_new_version_text )
message( STATUS "Not updating ${OUTPUT_FILE}" )
set( _wvh_write_version_file OFF )
endif()
endif()
if( _wvh_write_version_file )
message( STATUS "Writing ${OUTPUT_FILE} file with version: ${_wvh_version_str}" )
file( WRITE ${OUTPUT_FILE} ${_wvh_new_version_text} )
endif()