From 99b79e541053afe6bfb4e5ea558e299a53372a31 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Fri, 2 Oct 2015 20:02:55 -0400 Subject: [PATCH] Generate verstub.cpp through raw cmake. There is no need for an extra program. As a bonus, generate a consistent windows vdi file. There is still an issue with actually *reading* the vdi, but that's for someone else to tackle. --- StepmaniaCore.cmake | 1 + src/CMakeLists.txt | 36 +-------- src/CommandLineActions.cpp | 2 +- src/NetworkSyncManager.cpp | 12 +-- src/StepMania.cpp | 3 +- src/archutils/Win32/CrashHandlerChild.cpp | 8 +- src/archutils/Win32/mapconv.cpp | 10 +-- src/ver.h | 9 ++- src/version_updater/CMakeLists.txt | 22 ------ src/version_updater/Main.cpp | 73 ------------------- src/version_updater/version.hpp.in | 15 ---- .../verstub.cpp.in => verstub.in.cpp} | 11 +-- 12 files changed, 24 insertions(+), 178 deletions(-) delete mode 100644 src/version_updater/CMakeLists.txt delete mode 100644 src/version_updater/Main.cpp delete mode 100644 src/version_updater/version.hpp.in rename src/{version_updater/verstub.cpp.in => verstub.in.cpp} (50%) diff --git a/StepmaniaCore.cmake b/StepmaniaCore.cmake index 231ad3e1a7..9f214d6ed0 100644 --- a/StepmaniaCore.cmake +++ b/StepmaniaCore.cmake @@ -419,6 +419,7 @@ elseif(LINUX) endif() configure_file("${SM_SRC_DIR}/config.in.hpp" "${SM_SRC_DIR}/generated/config.hpp") +configure_file("${SM_SRC_DIR}/verstub.in.cpp" "${SM_SRC_DIR}/generated/verstub.cpp") # Define installer based items for cpack. include("${CMAKE_CURRENT_LIST_DIR}/CMake/CPackSetup.cmake") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6b96e8eff0..3f32c77074 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,35 +1,8 @@ file(MAKE_DIRECTORY "${SM_SRC_DIR}/generated") if(MSVC) -# Version Updater library. -add_subdirectory(version_updater) - -# This part may move to a different file: it's the SM Data project. -add_custom_command( - OUTPUT ${SM_SRC_DIR}/generated/verstub.cpp - COMMAND VersionUpdater ${SM_SRC_DIR}/generated/verstub.cpp - DEPENDS VersionUpdater -) - -# Add the mapconv program of the past to allow for debugging information. -include("CMakeProject-mapconv.cmake") - -else() -# Version Stub generation. Needs fixing on Windows. -add_custom_command( - OUTPUT ${SM_SRC_DIR}/generated/verstub.cpp - COMMAND ${CMAKE_COMMAND} - ARGS -DSM_SRC_DIR=${SM_SRC_DIR} -P ${SM_SRC_DIR}/../CMake/VerStubUtil.cmake - WORKING_DIRECTORY "${SM_ROOT_DIR}" - DEPENDS ${SM_SRC_DIR}/generated/delete -) - -add_custom_command( - OUTPUT ${SM_SRC_DIR}/generated/delete - COMMAND rm - ARGS -f ${SM_SRC_DIR}/generated/ver* - WORKING_DIRECTORY "${SM_ROOT_DIR}" -) + # Add the mapconv program of the past to allow for debugging information. + include("CMakeProject-mapconv.cmake") endif() # Main project is below. @@ -39,6 +12,7 @@ list(APPEND SMDATA_GLOBAL_FILES_SRC "global.cpp" "SpecialFiles.cpp" "StepMania.cpp" # TODO: Refactor into separate main project. + "${SM_SRC_DIR}/generated/verstub.cpp" ) list(APPEND SMDATA_GLOBAL_FILES_HPP @@ -148,7 +122,6 @@ list(APPEND SMDATA_FILE_TYPES_HPP source_group("File Types" FILES ${SMDATA_FILE_TYPES_SRC} ${SMDATA_FILE_TYPES_HPP}) list(APPEND SMDATA_ALL_FILES_SRC - ${SM_SRC_DIR}/generated/verstub.cpp ${SMDATA_GLOBAL_FILES_SRC} ${SMDATA_GLOBAL_SINGLETON_SRC} ${SMDATA_ALL_ACTORS_SRC} @@ -306,8 +279,7 @@ if(WIN32) ) if(MSVC) - # Allow for getting a virtualdub stack trace. - + # Allow for getting a virtualdub stack trace. add_custom_command(TARGET "${SM_EXE_NAME}" POST_BUILD COMMAND "mapconv" "${SM_PROGRAM_DIR}/$<$:${SM_NAME_DEBUG}>$<$:${SM_NAME_MINSIZEREL}>$<$:${SM_NAME_RELWITHDEBINFO}>$<$:${SM_NAME_RELEASE}>.map" "${SM_PROGRAM_DIR}/$<$:${SM_NAME_DEBUG}>$<$:${SM_NAME_MINSIZEREL}>$<$:${SM_NAME_RELWITHDEBINFO}>$<$:${SM_NAME_RELEASE}>.vdi" diff --git a/src/CommandLineActions.cpp b/src/CommandLineActions.cpp index 3aac6f784e..95cd4f53e3 100644 --- a/src/CommandLineActions.cpp +++ b/src/CommandLineActions.cpp @@ -90,7 +90,7 @@ static void Version() RString sProductID = ssprintf("%s", (string(PRODUCT_FAMILY) + product_version).c_str() ); RString sVersion = "(StepMania was built without HAVE_VERSION_INFO)"; #if defined(HAVE_VERSION_INFO) - sVersion = ssprintf("build %lu\nCompile Date: %s @ %s", version_num, version_date, version_time); + sVersion = ssprintf("build %s\nCompile Date: %s @ %s", ::sm_version_git_hash, version_date, version_time); #endif // HAVE_VERSION_INFO AllocConsole(); diff --git a/src/NetworkSyncManager.cpp b/src/NetworkSyncManager.cpp index 047eda4332..8c3ffe491b 100644 --- a/src/NetworkSyncManager.cpp +++ b/src/NetworkSyncManager.cpp @@ -32,11 +32,7 @@ void NetworkSyncManager::SelectUserSong() { } RString NetworkSyncManager::MD5Hex( const RString &sInput ) { return RString(); } int NetworkSyncManager::GetSMOnlineSalt() { return 0; } void NetworkSyncManager::GetListOfLANServers( vector& AllServers ) { } - #if defined(HAVE_VERSION_INFO) - unsigned long NetworkSyncManager::GetCurrentSMBuild( LoadingWindow* ld ) { return version_num; } - #else - unsigned long NetworkSyncManager::GetCurrentSMBuild( LoadingWindow* ld ) { return 0; } - #endif +unsigned long NetworkSyncManager::GetCurrentSMBuild( LoadingWindow* ld ) { return 0; } #else #include "ezsockets.h" #include "ProfileManager.h" @@ -849,7 +845,7 @@ void NetworkSyncManager::GetListOfLANServers( vector& AllServers // Aldo: Please move this method to a new class, I didn't want to create new files because I don't know how to properly update the files for each platform. // I preferred to misplace code rather than cause unneeded headaches to non-windows users, although it would be nice to have in the wiki which files to // update when adding new files and how (Xcode/stepmania_xcode4.3.xcodeproj has a really crazy structure :/). -#if !defined(HAVE_VERSION_INFO) +#if !defined(HAVE_VERSION_INFO) || defined(CMAKE_POWERED) unsigned long NetworkSyncManager::GetCurrentSMBuild( LoadingWindow* ld ) { return 0; } #else unsigned long NetworkSyncManager::GetCurrentSMBuild( LoadingWindow* ld ) @@ -867,7 +863,7 @@ unsigned long NetworkSyncManager::GetCurrentSMBuild( LoadingWindow* ld ) ld->SetText("Checking for updates..."); } - unsigned long uCurrentSMBuild = version_num; + unsigned long uCurrentSMBuild = 0; bool bSuccess = false; EzSockets* socket = new EzSockets(); socket->create(); @@ -885,7 +881,7 @@ unsigned long NetworkSyncManager::GetCurrentSMBuild( LoadingWindow* ld ) "\r\n", sResource.c_str(), sHost.c_str(), sUserAgent.c_str(), sReferer.c_str(), - version_num + 0 ); socket->SendData(sHTTPRequest); diff --git a/src/StepMania.cpp b/src/StepMania.cpp index 7553eeca1f..d0b87ec70a 100644 --- a/src/StepMania.cpp +++ b/src/StepMania.cpp @@ -919,13 +919,12 @@ static void MountTreeOfZips( const RString &dir ) } } - static void WriteLogHeader() { LOG->Info("%s%s", PRODUCT_FAMILY, product_version); #if defined(HAVE_VERSION_INFO) - LOG->Info( "Compiled %s @ %s (build %lu)", version_date, version_time, version_num ); + LOG->Info( "Compiled %s @ %s (build %s)", version_date, version_time, ::sm_version_git_hash); #endif time_t cur_time; diff --git a/src/archutils/Win32/CrashHandlerChild.cpp b/src/archutils/Win32/CrashHandlerChild.cpp index 1a1c580c1c..57a4a35bf8 100644 --- a/src/archutils/Win32/CrashHandlerChild.cpp +++ b/src/archutils/Win32/CrashHandlerChild.cpp @@ -412,13 +412,13 @@ namespace { if( !g_debugInfo.Loaded() ) return ssprintf( "debug resource file '%s': %s.\n", g_debugInfo.sFilename, g_debugInfo.sError.c_str() ); - + /* if( g_debugInfo.nBuildNumber != int(version_num) ) { return ssprintf( "Incorrect %s file (build %d, expected %d) for this version of " PRODUCT_FAMILY " -- call stack unavailable.\n", g_debugInfo.sFilename, g_debugInfo.nBuildNumber, int(version_num) ); } - + */ RString sRet; for( int i = 0; Backtrace[i]; ++i ) { @@ -444,9 +444,9 @@ struct CompleteCrashData static void MakeCrashReport( const CompleteCrashData &Data, RString &sOut ) { sOut += ssprintf( - "%s crash report (build %d, %s @ %s)\n" + "%s crash report (build %s, %s @ %s)\n" "--------------------------------------\n\n", - (string(PRODUCT_FAMILY) + product_version).c_str(), version_num, version_date, version_time ); + (string(PRODUCT_FAMILY) + product_version).c_str(), ::sm_version_git_hash, version_date, version_time ); sOut += ssprintf( "Crash reason: %s\n", Data.m_CrashInfo.m_CrashReason ); sOut += ssprintf( "\n" ); diff --git a/src/archutils/Win32/mapconv.cpp b/src/archutils/Win32/mapconv.cpp index 137b6a464f..e24ab7ed7f 100644 --- a/src/archutils/Win32/mapconv.cpp +++ b/src/archutils/Win32/mapconv.cpp @@ -106,7 +106,6 @@ struct RVASorter { }; int main(int argc, char **argv) { - int ver=0; int i; long load_addr; @@ -115,13 +114,8 @@ int main(int argc, char **argv) { return 0; } - if (f=fopen("version.bin", "rb")) { - fread(&ver,4,1,f); - fclose(f); - } else { - printf("can't read version file\n"); - return 20; - } + // TODO: Choose a better default for the vdi file. + int ver = 20151002; if (!(f=fopen(argv[1], "r"))) { printf("can't open listing file \"%s\"\n", argv[1]); diff --git a/src/ver.h b/src/ver.h index 1df651bd5f..69c7aad7cc 100644 --- a/src/ver.h +++ b/src/ver.h @@ -4,13 +4,14 @@ #if !defined(CMAKE_POWERED) && ( defined(_MSC_VER) || defined(__MACOSX__) ) #define product_version "5.0-UNKNOWN" #else -extern const char *const product_version; +extern char const * const product_version; #endif // XXX: These names are misnomers. This is actually the BUILD number, time and date. // NOTE: In GNU toolchain these are defined in ver.cpp. In MSVC these are defined in archutils/Win32/verinc.c I think. Why? I don't know and I don't have MSVC. --root -extern const unsigned long version_num; -extern const char *const version_time; -extern const char *const version_date; +extern unsigned long const version_num; +extern char const * const version_time; +extern char const * const version_date; +extern char const * const sm_version_git_hash; #endif \ No newline at end of file diff --git a/src/version_updater/CMakeLists.txt b/src/version_updater/CMakeLists.txt deleted file mode 100644 index 09e0947141..0000000000 --- a/src/version_updater/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -source_group("" FILES Main.cpp) - -configure_file( - "version.hpp.in" - "${PROJECT_BINARY_DIR}/version.hpp" -) - -include_directories(${PROJECT_BINARY_DIR}) - -add_executable("VersionUpdater" Main.cpp "${PROJECT_BINARY_DIR}/version.hpp") - -if (WITH_FULL_RELEASE) - sm_add_compile_definition("VersionUpdater" IS_FULL_RELEASE) - message(STATUS "Full release mode engaged.") -endif() - -set_property(TARGET "VersionUpdater" PROPERTY FOLDER "Internal Libraries") - -if(MSVC) - sm_add_compile_definition("VersionUpdater" _CRT_SECURE_NO_WARNINGS) -endif() - diff --git a/src/version_updater/Main.cpp b/src/version_updater/Main.cpp deleted file mode 100644 index a0a586b04a..0000000000 --- a/src/version_updater/Main.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This program was placed in the public domain by Avery, - * with some ideas implemented by AJ. Any C++ improvements - * are made by others. - */ - -#include -#include -#include -#include -#include -#include -#include "version.hpp" - -int main(int argc, char *argv[]) { - if (argc < 2) { - return 1; - } - - std::ifstream versionReadFile("version.bin", std::ios::in); - - unsigned long build = 0; - - // try to read the last version seen. - if (versionReadFile.is_open()) { - std::string line; - std::getline(versionReadFile, line); - if (!line.empty()) { - // TODO: Use stoul when C++11 is utilized. - build = std::atol(line.c_str()); - } - - versionReadFile.close(); - } - - // increment the build number and write it. - ++build; - - std::ofstream versionWriteFile("version.bin", std::ios::out); - - if (versionWriteFile.is_open()) { - versionWriteFile << build; - versionWriteFile.close(); - } - - char strdate[10]; - char strtime[64]; - time_t tm; - - std::time(&tm); - - std::strftime(strdate, 15, "%Y%m%d", std::localtime(&tm)); - std::strftime(strtime, 64, "%H:%M:%S %Z", std::localtime(&tm)); - - // zero out the newline. - strtime[sizeof(strtime) - 1] = 0; - - std::ofstream versionDataFile(argv[1], std::ios::out); - if (versionDataFile.is_open()) { - versionDataFile << "extern unsigned long const version_num = " << build << ";" << std::endl; - versionDataFile << "extern int const sm_version_major = " << smVersionMajor << ";" << std::endl; - versionDataFile << "extern int const sm_version_minor = " << smVersionMinor << ";" << std::endl; - versionDataFile << "extern int const sm_version_patch = " << smVersionPatch << ";" << std::endl; - versionDataFile << "extern char const * const sm_version_git_hash = \"" << smVersionGitHash << "\";" << std::endl; - versionDataFile << "extern char const * const sm_version_traditional = \"" << smVersionTraditional << "\";" << std::endl; - versionDataFile << "extern char const * const version_date = \"" << strdate << "\";" << std::endl; - versionDataFile << "extern char const * const version_time = \"" << strtime << "\";" << std::endl; - versionDataFile << "extern char const * const product_version = \"" << smVersionFull << "\";" << std::endl; - versionDataFile.close(); - } - - return 0; -} diff --git a/src/version_updater/version.hpp.in b/src/version_updater/version.hpp.in deleted file mode 100644 index 4c50f75a43..0000000000 --- a/src/version_updater/version.hpp.in +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef VERSION_UPDATER_HPP_ -#define VERSION_UPDATER_HPP_ - -int smVersionMajor = @SM_VERSION_MAJOR@; -int smVersionMinor = @SM_VERSION_MINOR@; -int smVersionPatch = @SM_VERSION_PATCH@; -char const * const smVersionGitHash = "@SM_VERSION_GIT_HASH@"; -#if defined(IS_FULL_RELEASE) -char const * const smVersionFull = "@SM_VERSION_TRADITIONAL@"; -#else -char const * const smVersionFull = "@SM_VERSION_FULL@"; -#endif -char const * const smVersionTraditional = "@SM_VERSION_TRADITIONAL@"; - -#endif \ No newline at end of file diff --git a/src/version_updater/verstub.cpp.in b/src/verstub.in.cpp similarity index 50% rename from src/version_updater/verstub.cpp.in rename to src/verstub.in.cpp index 3db81a1f3f..fde207ae2a 100644 --- a/src/version_updater/verstub.cpp.in +++ b/src/verstub.in.cpp @@ -2,14 +2,7 @@ extern int const sm_version_major = @SM_VERSION_MAJOR@; extern int const sm_version_minor = @SM_VERSION_MINOR@; extern int const sm_version_patch = @SM_VERSION_PATCH@; extern char const * const sm_version_git_hash = "@SM_VERSION_GIT_HASH@"; -extern char const * const smVersionTraditional = "@SM_VERSION_TRADITIONAL@"; -extern char const * const smVersionFull = "@SM_VERSION_FULL@"; +extern char const * const sm_version_traditional = "@SM_VERSION_TRADITIONAL@"; extern char const * const version_date = "@SM_TIMESTAMP_DATE@"; extern char const * const version_time = "@SM_TIMESTAMP_TIME@"; -#if defined(IS_FULL_RELEASE) -extern char const * const product_version = smVersionFull; -#else -extern char const * const product_version = smVersionTraditional; -#endif - -extern int const version_num = 0; // will change \ No newline at end of file +extern char const * const product_version = "@SM_VERSION_GIT@";