Browse Source

Don't hard-code the license string in the source

Read it at compile-time from the LICENSE file.
coverity_scan
Daniel Scharrer 13 years ago
parent
commit
bb50bffde2
  1. 3
      CMakeLists.txt
  2. 2
      LICENSE
  3. 1
      VERSION
  4. 102
      cmake/VersionScript.cmake
  5. 47
      cmake/VersionString.cmake
  6. 26
      src/cli/main.cpp
  7. 18
      src/release.cpp.in
  8. 3
      src/release.hpp

3
CMakeLists.txt

@ -199,7 +199,8 @@ include_directories(src ${CMAKE_CURRENT_BINARY_DIR})
configure_file("src/configure.hpp.in" "configure.hpp")
set(VERSION_FILE "${CMAKE_BINARY_DIR}/release.cpp")
version_file("src/release.cpp.in" "${VERSION_FILE}" "VERSION" ".git")
set(VERSION_SOURCES VERSION "VERSION" LICENSE "LICENSE")
version_file("src/release.cpp.in" "${VERSION_FILE}" "${VERSION_SOURCES}" ".git")
list(APPEND INNOEXTRACT_SOURCES "${VERSION_FILE}")

2
LICENSE

@ -1,5 +1,5 @@
Copyright (C) 2011-2012 Daniel Scharrer
Copyright (C) 2011-2012 Daniel Scharrer <daniel@constexpr.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the author(s) be held liable for any damages

1
VERSION

@ -1,3 +1,2 @@
innoextract 1.3-git
Inno Setup 1.2.10 to 5.5.2
(C) 2011-2012 Daniel Scharrer <daniel@constexpr.org>

102
cmake/VersionScript.cmake

@ -22,45 +22,83 @@ cmake_minimum_required(VERSION 2.8)
# CMake script that reads a VERSION file and the current git history and the calls configure_file().
# This is used by version_file() in VersionString.cmake
if((NOT DEFINED INPUT) OR (NOT DEFINED OUTPUT) OR (NOT DEFINED VERSION_FILE) OR (NOT DEFINED GIT_DIR))
if((NOT DEFINED INPUT) OR (NOT DEFINED OUTPUT) OR (NOT DEFINED VERSION_SOURCES) OR (NOT DEFINED GIT_DIR))
message(SEND_ERROR "Invalid arguments.")
endif()
file(READ "${VERSION_FILE}" BASE_VERSION)
string(STRIP "${BASE_VERSION}" BASE_VERSION)
# Split the version file into lines.
string(REGEX MATCHALL "[^\r\n]+" version_lines "${BASE_VERSION}")
set(BASE_VERSION_COUNT 0)
foreach(version_line IN LISTS version_lines)
set(BASE_VERSION_${BASE_VERSION_COUNT} "${version_line}")
set(var "")
foreach(arg IN LISTS VERSION_SOURCES)
# Find the last space
string(STRIP "${version_line}" version_line)
string(LENGTH "${version_line}" version_line_length)
set(version_line_split ${version_line_length})
foreach(i RANGE ${version_line_length})
if(${i} LESS ${version_line_length})
string(SUBSTRING "${version_line}" ${i} 1 version_line_char)
if(version_line_char STREQUAL " ")
set(version_line_split ${i})
if(var STREQUAL "")
set(var ${arg})
else()
file(READ "${arg}" ${var})
string(STRIP "${${var}}" ${var})
string(REGEX REPLACE "\r\n" "\n" ${var} "${${var}}")
string(REGEX REPLACE "\r" "\n" ${var} "${${var}}")
# Split the version file into lines.
string(REGEX MATCHALL "[^\r\n]+" lines "${${var}}")
set(${var}_COUNT 0)
foreach(line IN LISTS lines)
set(${var}_${${var}_COUNT} "${line}")
# Find the first and last spaces
string(STRIP "${line}" line)
string(LENGTH "${line}" line_length)
set(first_space -1)
set(last_space ${line_length})
foreach(i RANGE ${line_length})
if(${i} LESS ${line_length})
string(SUBSTRING "${line}" ${i} 1 line_char)
if(line_char STREQUAL " ")
set(last_space ${i})
if(first_space EQUAL -1)
set(first_space ${i})
endif()
endif()
endif()
endforeach()
# Get everything before the first space
if(${first_space} GREATER -1)
string(SUBSTRING "${line}" 0 ${first_space} line_name)
string(STRIP "${line_name}" ${var}_${${var}_COUNT}_SHORTNAME)
endif()
endif()
endforeach()
# Get everything before the last space
string(SUBSTRING "${version_line}" 0 ${version_line_split} version_line_name)
string(STRIP "${version_line_name}" BASE_NAME_${BASE_VERSION_COUNT})
# Get everything after the last space
if(${version_line_split} LESS ${version_line_length})
math(EXPR num_length "${version_line_length} - ${version_line_split}")
string(SUBSTRING "${version_line}" ${version_line_split} ${num_length} version_line_num)
string(STRIP "${version_line_num}" BASE_NUMBER_${BASE_VERSION_COUNT})
# Get everything after the first space
math(EXPR num_length "${line_length} - ${first_space}")
string(SUBSTRING "${line}" ${first_space} ${num_length} line_num)
string(STRIP "${line_num}" ${var}_${${var}_COUNT}_STRING)
# Get everything before the last space
string(SUBSTRING "${line}" 0 ${last_space} line_name)
string(STRIP "${line_name}" ${var}_${${var}_COUNT}_NAME)
# Get everything after the last space
if(${last_space} LESS ${line_length})
math(EXPR num_length "${line_length} - ${last_space}")
string(SUBSTRING "${line}" ${last_space} ${num_length} line_num)
string(STRIP "${line_num}" ${var}_${${var}_COUNT}_NUMBER)
endif()
math(EXPR ${var}_COUNT "${${var}_COUNT} + 1")
endforeach()
string(REGEX REPLACE "\n\n.*$" "" ${var}_HEAD "${${var}}")
string(STRIP "${${var}_HEAD}" ${var}_HEAD)
string(REGEX MATCH "\n\n.*" ${var}_TAIL "${${var}}")
string(STRIP "${${var}_TAIL}" ${var}_TAIL)
string(REGEX REPLACE "\n" "\\\\n" ${var} "${${var}}")
string(REGEX REPLACE "\n" "\\\\n" ${var}_HEAD "${${var}_HEAD}")
string(REGEX REPLACE "\n" "\\\\n" ${var}_TAIL "${${var}_TAIL}")
set(var "")
endif()
math(EXPR BASE_VERSION_COUNT "${BASE_VERSION_COUNT} + 1")
endforeach()
# Check for a git directory and fill in the git commit hash if one exists.

47
cmake/VersionString.cmake

@ -24,20 +24,47 @@
# SRC is processed using the configure_file() cmake command
# at build to produce DST with the following variable available:
#
# - BASE_VERSION: The contents of the file specified by VERSION_FILE
# - BASE_VERSION_COUNT: Number of lines in the VERSION file
# - BASE_VERSION_i: The i-th line of the VERSION file
# - BASE_NAME_i: Everything except the last component of the i-th line of the VERSION file
# - BASE_NUMBER_i: The last component of the i-th line of the VERSION file
# VERSION_SOURCES:
# List of (${var} ${file}) pairs.
#
# for each variable ${var}
# - ${var}: The contents of the associated file
# - ${var}_COUNT: Number of lines in the associated file
# - ${var}_${i}: The ${i}-th line of the associated file
# - ${var}_${i}_SHORTNAME: The first component of the ${i}-th line of the associated file
# - ${var}_${i}_STRING: Everything except the first component of the ${i}-th line of the associated file
# - ${var}_${i}_NAME: Everything except the last component of the ${i}-th line of the associated file
# - ${var}_${i}_NUMBER: The last component of the ${i}-th line of the associated file
# - ${var}_HEAD: The first paragraph of the associated file
# - ${var}_TAIL: The remaining paragraphs of the associated file
#
# - GIT_COMMIT: The current git commit. (not defined if there is no GIT_DIR directory)
# - GIT_COMMIT_PREFIX_i: The first i characters of GIT_COMMIT (i=0..39)
# - GIT_COMMIT_PREFIX_${i}: The first ${i} characters of GIT_COMMIT (i=0..39)
# For the exact syntax of SRC see the documentation of the configure_file() cmake command.
# The version file is regenerated whenever VERSION_FILE or the current commit changes.
function(version_file SRC DST VERSION_FILE GIT_DIR)
function(version_file SRC DST VERSION_SOURCES GIT_DIR)
set(mode "variable")
set(args)
set(dependencies "${CMAKE_MODULE_PATH}/VersionScript.cmake")
foreach(arg IN LISTS VERSION_SOURCES)
if(mode STREQUAL "variable")
set(mode "file")
else()
get_filename_component(arg "${arg}" ABSOLUTE)
list(APPEND dependencies ${abs_file})
set(mode "variable")
endif()
list(APPEND args ${arg})
endforeach()
get_filename_component(abs_src "${SRC}" ABSOLUTE)
get_filename_component(abs_dst "${DST}" ABSOLUTE)
get_filename_component(abs_version_file "${VERSION_FILE}" ABSOLUTE)
get_filename_component(abs_git_dir "${GIT_DIR}" ABSOLUTE)
set(defines)
@ -45,8 +72,6 @@ function(version_file SRC DST VERSION_FILE GIT_DIR)
set(defines ${ARGV4})
endif()
set(dependencies "${abs_version_file}" "${CMAKE_MODULE_PATH}/VersionScript.cmake")
if(EXISTS "${abs_git_dir}/HEAD")
list(APPEND dependencies "${abs_git_dir}/HEAD")
endif()
@ -62,7 +87,7 @@ function(version_file SRC DST VERSION_FILE GIT_DIR)
${CMAKE_COMMAND}
"-DINPUT=${abs_src}"
"-DOUTPUT=${abs_dst}"
"-DVERSION_FILE=${abs_version_file}"
"-DVERSION_SOURCES=${args}"
"-DGIT_DIR=${abs_git_dir}"
${defines}
-P "${CMAKE_MODULE_PATH}/VersionScript.cmake"

26
src/cli/main.cpp

@ -71,7 +71,8 @@ namespace fs = boost::filesystem;
namespace po = boost::program_options;
static void print_version() {
std::cout << color::white << innoextract_version << color::reset
std::cout << color::white << innoextract_name
<< ' ' << innoextract_version << color::reset
#ifdef DEBUG
<< " (with debug output)"
#endif
@ -89,31 +90,18 @@ static void print_help(const char * name, const po::options_description & visibl
std::cout << "Extracts installers created by " << color::cyan
<< innosetup_versions << color::reset << '\n';
std::cout << '\n';
std::cout << color::white << innoextract_version << color::reset
std::cout << color::white << innoextract_name
<< ' ' << innoextract_version << color::reset
<< ' ' << innoextract_copyright << '\n';
std::cout << "This is free software with absolutely no warranty.\n";
}
static void print_license() {
std::cout << color::white << innoextract_version << color::reset
std::cout << color::white << innoextract_name
<< ' ' << innoextract_version << color::reset
<< ' ' << innoextract_copyright << '\n';
std::cout << '\n';
std::cout << "This software is provided 'as-is', without any express or implied\n"
"warranty. In no event will the author(s) be held liable for any damages\n"
"arising from the use of this software.\n"
"\n"
"Permission is granted to anyone to use this software for any purpose,\n"
"including commercial applications, and to alter it and redistribute it\n"
"freely, subject to the following restrictions:\n"
"\n"
"1. The origin of this software must not be misrepresented; you must not\n"
" claim that you wrote the original software. If you use this software\n"
" in a product, an acknowledgment in the product documentation would be\n"
" appreciated but is not required.\n"
"2. Altered source versions must be plainly marked as such, and must not be\n"
" misrepresented as being the original software.\n"
"3. This notice may not be removed or altered from any source distribution.\n"
std::cout << '\n'<< innoextract_license << '\n';
;
}

18
src/release.cpp.in

@ -26,14 +26,20 @@
* For available variables see cmake/VersionString.cmake.
*/
#if ${BASE_VERSION_COUNT} != 3
#error "Configure error - the VERSION file should specify exactly three lines!"
#if ${VERSION_COUNT} != 2
#error "Configure error - the VERSION file should specify exactly two lines!"
#endif
const char innoextract_name[] = "${BASE_NAME_0}";
#if ${LICENSE_COUNT} < 3
#error "Configure error - the LICENSE file should specify at least three lines!"
#endif
const char innoextract_name[] = "${VERSION_0_NAME}";
const char innoextract_version[] = "${VERSION_0_NUMBER}${GIT_SUFFIX_5}";
const char innoextract_version[] = "${BASE_VERSION_0}${GIT_SUFFIX_5}";
const char innosetup_versions[] = "${VERSION_1}";
const char innosetup_versions[] = "${BASE_VERSION_1}";
const char innoextract_copyright[] = "${LICENSE_0_STRING}";
const char innoextract_copyright[] = "${BASE_VERSION_2}";
const char innoextract_license[] = "${LICENSE_TAIL}";

3
src/release.hpp

@ -33,4 +33,7 @@ extern const char innosetup_versions[];
//! Copyright line for the current program
extern const char innoextract_copyright[];
//! License text for the current program
extern const char innoextract_license[];
#endif // INNOEXTRACT_VERSION_HPP

Loading…
Cancel
Save