diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index cd66952..a16d37c 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -4,6 +4,13 @@ set(SOURCE_FILES # add files here main.cpp) +if(WIN32) +list(APPEND SOURCE_FILES + ${CMAKE_CURRENT_BINARY_DIR}/../lib/Version/VersionResource.rc + ${CMAKE_CURRENT_BINARY_DIR}/../lib/Version/VersionInfo.h +) +endif() + include_directories(${CMAKE_SOURCE_DIR}/src/lib) add_executable(${PROJECT_NAME} ${SOURCE_FILES}) diff --git a/src/cli/main.cpp b/src/cli/main.cpp index 29a81a3..ac2e415 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -6,6 +6,7 @@ #include "Evaluator.h" #include "Symbol/SymbolTableMgr.h" #include "Syntax/SyntaxTree.h" +#include "Version/version.h" #include #include @@ -96,7 +97,7 @@ void evaluate(std::string &line, bool showTree) { } void startRepl(bool showTree) { - std::cout << "warfLang 1.0" << std::endl; + WarfHelper::printVersion(); while (true) { try { std::string line = ""; diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index d5ffd87..fbed7d0 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -26,6 +26,7 @@ add_library (${PROJECT_NAME} STATIC $ $ $ + $ ) target_include_directories(${PROJECT_NAME} @@ -39,4 +40,5 @@ target_include_directories(${PROJECT_NAME} add_subdirectory(Syntax) add_subdirectory(Binding) add_subdirectory(Symbol) -add_subdirectory(Error) \ No newline at end of file +add_subdirectory(Error) +add_subdirectory(Version) \ No newline at end of file diff --git a/src/lib/Version/CMakeLists.txt b/src/lib/Version/CMakeLists.txt new file mode 100644 index 0000000..202fcd0 --- /dev/null +++ b/src/lib/Version/CMakeLists.txt @@ -0,0 +1,74 @@ + + +include ("CMakeListsVersion.cmake") + +set(GIT_EXECUTABLE git) +set(WARF_DESCRIPTION "Warf, An Interpreter for the Warf Language.") + +# the commit's SHA1, and whether the building workspace was dirty or not +execute_process(COMMAND + "${GIT_EXECUTABLE}" rev-parse --short HEAD + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_SHA1 + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + +# the date of the commit +execute_process(COMMAND + "${GIT_EXECUTABLE}" log -1 --format=%ad --date=local + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_DATE + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + +# the subject of the commit +execute_process(COMMAND + "${GIT_EXECUTABLE}" log -1 --format=%s + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_COMMIT_SUBJECT + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + +# the branch of the commit +execute_process(COMMAND + "${GIT_EXECUTABLE}" branch --show-current + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_COMMIT_BRANCH + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + + +# generate version.cpp +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in" + "${CMAKE_CURRENT_BINARY_DIR}/version.cpp" @ONLY) + +set (SourceFiles + ${CMAKE_CURRENT_BINARY_DIR}/version.cpp +) + +if(WIN32) + include(generate_product_version.cmake) + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/icon.ico + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + generate_product_version( + VersionFilesOutputVariable + NAME "${WARF_NAME}" + ICON ${CMAKE_CURRENT_BINARY_DIR}/icon.ico + VERSION_MAJOR ${WARF_MAJOR} + VERSION_MINOR ${WARF_MINOR} + VERSION_PATCH ${WARF_PATCH} + #VERSION_REVISION 0 #could hook this up with the cli + COMPANY_NAME ${WARF_NAME} + FILE_DESCRIPTION ${WARF_DESCRIPTION} + ) +endif() + + +set(HeaderFiles + version.h +) + +add_library (WarfCore.Version OBJECT + ${SourceFiles} ${HeaderFiles} +) +set_target_properties(WarfCore.Version PROPERTIES LINKER_LANGUAGE CXX) + +target_include_directories ( + WarfCore.Version PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} +) diff --git a/src/lib/Version/CMakeListsVersion.cmake b/src/lib/Version/CMakeListsVersion.cmake new file mode 100644 index 0000000..2fba1ad --- /dev/null +++ b/src/lib/Version/CMakeListsVersion.cmake @@ -0,0 +1,19 @@ +# this file is intended to be included by other project CMakeLists.txt files +# in order to make the following Warf version variables available +# WARF_MAJOR : Integer major number (e.g. 0, 1, 2) +# WARF_MINOR : Integer minor number (e.g. 0, 1, 2) +# WARF_PATCH : Integer patch number (e.g. 0, 1, 2) +# WARF_VERSION : Full WARF verion string as MAJOR.MINOR.PATCH+BUILD (e.g. 1.0.5+255) + +file (READ ${CMAKE_CURRENT_LIST_DIR}/version.txt VERSION NEWLINE_CONSUME) +string (REPLACE "." ";" VERSION "${VERSION}") +string (REPLACE "\n" ";" VERSION "${VERSION}") +string (REPLACE "\r" ";" VERSION "${VERSION}") +list (GET VERSION 0 WARF_MAJOR) +list (GET VERSION 1 WARF_MINOR) +list (GET VERSION 2 WARF_PATCH) + +file (READ ${CMAKE_CURRENT_LIST_DIR}/appName.txt WARF_NAME) + + +set (WARF_VERSION "${WARF_MAJOR}.${WARF_MINOR}.${WARF_PATCH}") \ No newline at end of file diff --git a/src/lib/Version/VersionInfo.in b/src/lib/Version/VersionInfo.in new file mode 100644 index 0000000..c77180f --- /dev/null +++ b/src/lib/Version/VersionInfo.in @@ -0,0 +1,82 @@ +#pragma once + +#ifndef PRODUCT_VERSION_MAJOR +#define PRODUCT_VERSION_MAJOR @PRODUCT_VERSION_MAJOR@ +#endif + +#ifndef PRODUCT_VERSION_MINOR +#define PRODUCT_VERSION_MINOR @PRODUCT_VERSION_MINOR@ +#endif + +#ifndef PRODUCT_VERSION_PATCH +#define PRODUCT_VERSION_PATCH @PRODUCT_VERSION_PATCH@ +#endif + +#ifndef PRODUCT_VERSION_BUILD +#define PRODUCT_VERSION_BUILD @PRODUCT_VERSION_REVISION@ +#endif + +#ifndef FILE_VERSION_MAJOR +#define FILE_VERSION_MAJOR @PRODUCT_VERSION_MAJOR@ +#endif + +#ifndef FILE_VERSION_MINOR +#define FILE_VERSION_MINOR @PRODUCT_VERSION_MINOR@ +#endif + +#ifndef FILE_VERSION_PATCH +#define FILE_VERSION_PATCH @PRODUCT_VERSION_PATCH@ +#endif + +#ifndef FILE_VERSION_BUILD +#define FILE_VERSION_BUILD @PRODUCT_VERSION_REVISION@ +#endif + +#ifndef __TO_STRING +#define __TO_STRING_IMPL(x) #x +#define __TO_STRING(x) __TO_STRING_IMPL(x) +#endif + +#define PRODUCT_VERSION_MAJOR_MINOR_STR __TO_STRING(PRODUCT_VERSION_MAJOR) "." __TO_STRING(PRODUCT_VERSION_MINOR) +#define PRODUCT_VERSION_MAJOR_MINOR_PATCH_STR PRODUCT_VERSION_MAJOR_MINOR_STR "." __TO_STRING(PRODUCT_VERSION_PATCH) +#define PRODUCT_VERSION_FULL_STR PRODUCT_VERSION_MAJOR_MINOR_PATCH_STR "." __TO_STRING(PRODUCT_VERSION_BUILD) +#define PRODUCT_VERSION_RESOURCE PRODUCT_VERSION_MAJOR,PRODUCT_VERSION_MINOR,PRODUCT_VERSION_PATCH,PRODUCT_VERSION_BUILD +#define PRODUCT_VERSION_RESOURCE_STR PRODUCT_VERSION_FULL_STR "\0" + +#define FILE_VERSION_MAJOR_MINOR_STR __TO_STRING(FILE_VERSION_MAJOR) "." __TO_STRING(FILE_VERSION_MINOR) +#define FILE_VERSION_MAJOR_MINOR_PATCH_STR FILE_VERSION_MAJOR_MINOR_STR "." __TO_STRING(FILE_VERSION_PATCH) +#define FILE_VERSION_FULL_STR FILE_VERSION_MAJOR_MINOR_PATCH_STR "." __TO_STRING(FILE_VERSION_BUILD) +#define FILE_VERSION_RESOURCE FILE_VERSION_MAJOR,FILE_VERSION_MINOR,FILE_VERSION_PATCH,FILE_VERSION_BUILD +#define FILE_VERSION_RESOURCE_STR FILE_VERSION_FULL_STR "\0" + +#ifndef PRODUCT_ICON +#define PRODUCT_ICON "@PRODUCT_ICON@" +#endif + +#ifndef PRODUCT_COMMENTS +#define PRODUCT_COMMENTS "@PRODUCT_COMMENTS@\0" +#endif + +#ifndef PRODUCT_COMPANY_NAME +#define PRODUCT_COMPANY_NAME "@PRODUCT_COMPANY_NAME@\0" +#endif + +#ifndef PRODUCT_COMPANY_COPYRIGHT +#define PRODUCT_COMPANY_COPYRIGHT "@PRODUCT_COMPANY_COPYRIGHT@\0" +#endif + +#ifndef PRODUCT_FILE_DESCRIPTION +#define PRODUCT_FILE_DESCRIPTION "@PRODUCT_FILE_DESCRIPTION@\0" +#endif + +#ifndef PRODUCT_INTERNAL_NAME +#define PRODUCT_INTERNAL_NAME "@PRODUCT_NAME@\0" +#endif + +#ifndef PRODUCT_ORIGINAL_FILENAME +#define PRODUCT_ORIGINAL_FILENAME "@PRODUCT_ORIGINAL_FILENAME@\0" +#endif + +#ifndef PRODUCT_BUNDLE +#define PRODUCT_BUNDLE "@PRODUCT_BUNDLE@\0" +#endif diff --git a/src/lib/Version/VersionResource.rc b/src/lib/Version/VersionResource.rc new file mode 100644 index 0000000..83147f3 --- /dev/null +++ b/src/lib/Version/VersionResource.rc @@ -0,0 +1,52 @@ +#include "VersionInfo.h" + +#if defined(__MINGW64__) || defined(__MINGW32__) + // MinGW-w64, MinGW + #if defined(__has_include) && __has_include() + #include + #else + #include + #include + #endif +#else + // MSVC, Windows SDK + #include +#endif + +IDI_ICON1 ICON PRODUCT_ICON + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +VS_VERSION_INFO VERSIONINFO + FILEVERSION FILE_VERSION_RESOURCE + PRODUCTVERSION PRODUCT_VERSION_RESOURCE + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000904b0" + BEGIN + VALUE "Comments", PRODUCT_COMMENTS + VALUE "CompanyName", PRODUCT_COMPANY_NAME + VALUE "FileDescription", PRODUCT_FILE_DESCRIPTION + VALUE "FileVersion", FILE_VERSION_RESOURCE_STR + VALUE "InternalName", PRODUCT_INTERNAL_NAME + VALUE "LegalCopyright", PRODUCT_COMPANY_COPYRIGHT + VALUE "OriginalFilename", PRODUCT_ORIGINAL_FILENAME + VALUE "ProductName", PRODUCT_BUNDLE + VALUE "ProductVersion", PRODUCT_VERSION_RESOURCE_STR + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x9, 1200 + END +END diff --git a/src/lib/Version/generate_product_version.cmake b/src/lib/Version/generate_product_version.cmake new file mode 100644 index 0000000..bc395d4 --- /dev/null +++ b/src/lib/Version/generate_product_version.cmake @@ -0,0 +1,107 @@ +include (CMakeParseArguments) + +set (GenerateProductVersionCurrentDir ${CMAKE_CURRENT_LIST_DIR}) + +# generate_product_version() function +# +# This function uses VersionInfo.in template file and VersionResource.rc file +# to generate WIN32 resource with version information and general resource strings. +# +# Usage: +# generate_product_version( +# SomeOutputResourceVariable +# NAME MyGreatProject +# ICON ${PATH_TO_APP_ICON} +# VERSION_MAJOR 2 +# VERSION_MINOR 3 +# VERSION_PATCH ${BUILD_COUNTER} +# VERSION_REVISION ${BUILD_REVISION} +# ) +# where BUILD_COUNTER and BUILD_REVISION could be values from your CI server. +# +# You can use generated resource for your executable targets: +# add_executable(target-name ${target-files} ${SomeOutputResourceVariable}) +# +# You can specify resource strings in arguments: +# NAME - name of executable (no defaults, ex: Microsoft Word) +# BUNDLE - bundle (${NAME} is default, ex: Microsoft Office) +# ICON - path to application icon (${CMAKE_SOURCE_DIR}/product.ico by default) +# VERSION_MAJOR - 1 is default +# VERSION_MINOR - 0 is default +# VERSION_PATCH - 0 is default +# VERSION_REVISION - 0 is default +# COMPANY_NAME - your company name (no defaults) +# COMPANY_COPYRIGHT - ${COMPANY_NAME} (C) Copyright ${CURRENT_YEAR} is default +# COMMENTS - ${NAME} v${VERSION_MAJOR}.${VERSION_MINOR} is default +# ORIGINAL_FILENAME - ${NAME} is default +# INTERNAL_NAME - ${NAME} is default +# FILE_DESCRIPTION - ${NAME} is default +function(generate_product_version outfiles) + set (options) + set (oneValueArgs + NAME + BUNDLE + ICON + VERSION_MAJOR + VERSION_MINOR + VERSION_PATCH + VERSION_REVISION + COMPANY_NAME + COMPANY_COPYRIGHT + COMMENTS + ORIGINAL_FILENAME + INTERNAL_NAME + FILE_DESCRIPTION) + set (multiValueArgs) + cmake_parse_arguments(PRODUCT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if (NOT PRODUCT_BUNDLE OR "${PRODUCT_BUNDLE}" STREQUAL "") + set(PRODUCT_BUNDLE "${PRODUCT_NAME}") + endif() + if (NOT PRODUCT_ICON OR "${PRODUCT_ICON}" STREQUAL "") + set(PRODUCT_ICON "${CMAKE_SOURCE_DIR}/product.ico") + endif() + + if (NOT PRODUCT_VERSION_MAJOR EQUAL 0 AND (NOT PRODUCT_VERSION_MAJOR OR "${PRODUCT_VERSION_MAJOR}" STREQUAL "")) + set(PRODUCT_VERSION_MAJOR 1) + endif() + if (NOT PRODUCT_VERSION_MINOR EQUAL 0 AND (NOT PRODUCT_VERSION_MINOR OR "${PRODUCT_VERSION_MINOR}" STREQUAL "")) + set(PRODUCT_VERSION_MINOR 0) + endif() + if (NOT PRODUCT_VERSION_PATCH EQUAL 0 AND (NOT PRODUCT_VERSION_PATCH OR "${PRODUCT_VERSION_PATCH}" STREQUAL "")) + set(PRODUCT_VERSION_PATCH 0) + endif() + if (NOT PRODUCT_VERSION_REVISION EQUAL 0 AND (NOT PRODUCT_VERSION_REVISION OR "${PRODUCT_VERSION_REVISION}" STREQUAL "")) + set(PRODUCT_VERSION_REVISION 0) + endif() + + if (NOT PRODUCT_COMPANY_COPYRIGHT OR "${PRODUCT_COMPANY_COPYRIGHT}" STREQUAL "") + string(TIMESTAMP PRODUCT_CURRENT_YEAR "%Y") + set(PRODUCT_COMPANY_COPYRIGHT "${PRODUCT_COMPANY_NAME} (C) Copyright ${PRODUCT_CURRENT_YEAR}") + endif() + if (NOT PRODUCT_COMMENTS OR "${PRODUCT_COMMENTS}" STREQUAL "") + set(PRODUCT_COMMENTS "${PRODUCT_NAME} v${PRODUCT_VERSION_MAJOR}.${PRODUCT_VERSION_MINOR}") + endif() + if (NOT PRODUCT_ORIGINAL_FILENAME OR "${PRODUCT_ORIGINAL_FILENAME}" STREQUAL "") + set(PRODUCT_ORIGINAL_FILENAME "${PRODUCT_NAME}") + endif() + if (NOT PRODUCT_INTERNAL_NAME OR "${PRODUCT_INTERNAL_NAME}" STREQUAL "") + set(PRODUCT_INTERNAL_NAME "${PRODUCT_NAME}") + endif() + if (NOT PRODUCT_FILE_DESCRIPTION OR "${PRODUCT_FILE_DESCRIPTION}" STREQUAL "") + set(PRODUCT_FILE_DESCRIPTION "${PRODUCT_NAME}") + endif() + + set (_VersionInfoFile ${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.h) + set (_VersionResourceFile ${CMAKE_CURRENT_BINARY_DIR}/VersionResource.rc) + configure_file( + ${GenerateProductVersionCurrentDir}/VersionInfo.in + ${_VersionInfoFile} + @ONLY) + configure_file( + ${GenerateProductVersionCurrentDir}/VersionResource.rc + ${_VersionResourceFile} + COPYONLY) + list(APPEND ${outfiles} ${_VersionInfoFile} ${_VersionResourceFile}) + set (${outfiles} ${${outfiles}} PARENT_SCOPE) +endfunction() diff --git a/src/lib/Version/icon.ico b/src/lib/Version/icon.ico new file mode 100644 index 0000000..7793b36 Binary files /dev/null and b/src/lib/Version/icon.ico differ diff --git a/src/lib/Version/version.cpp.in b/src/lib/Version/version.cpp.in new file mode 100644 index 0000000..198314a --- /dev/null +++ b/src/lib/Version/version.cpp.in @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021 Farzon Lotfi All rights reserved. + * Use of this source code is governed by a BSD-style + * license that can be found in the LICENSE file. + */ + +#include "version.h" +#include + +const std::string WarfHelper::Version::number = "@WARF_VERSION@"; +const std::string WarfHelper::Version::name = "@WARF_NAME@"; + +const std::string WarfHelper::Git::sha1 = "@GIT_SHA1@"; +const std::string WarfHelper::Git::date = "@GIT_DATE@"; +const std::string WarfHelper::Git::subject = "@GIT_COMMIT_SUBJECT@"; +const std::string WarfHelper::Git::branch = "@GIT_COMMIT_BRANCH@"; + + +void WarfHelper::printVersion() { + std::cout << WarfHelper::Version::name << " version " << WarfHelper::Version::number + << "-" << WarfHelper::Git::branch << " commit " << WarfHelper::Git::sha1 + << std::endl; +} \ No newline at end of file diff --git a/src/lib/Version/version.h b/src/lib/Version/version.h new file mode 100644 index 0000000..9af6a5a --- /dev/null +++ b/src/lib/Version/version.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021 Farzon Lotfi All rights reserved. + * Use of this source code is governed by a BSD-style + * license that can be found in the LICENSE file. + */ + +#ifndef __version_h__ +#define __version_h__ + +#include + +namespace WarfHelper { +struct Version { + static const std::string number; + static const std::string name; + +private: + Version() = delete; +}; +struct Git { + static const std::string sha1; + static const std::string date; + static const std::string subject; + static const std::string branch; + +private: + Git() = delete; +}; + +void printVersion(); + +} // namespace WarfHelper + +#endif //__version_h__ \ No newline at end of file diff --git a/src/lib/Version/version.txt b/src/lib/Version/version.txt index fa3de58..99d85ec 100644 --- a/src/lib/Version/version.txt +++ b/src/lib/Version/version.txt @@ -1 +1 @@ -0.0.5 \ No newline at end of file +0.0.6 \ No newline at end of file