Added Get version and available features feature

This commit is contained in:
Sleepy Flower Girl
2019-01-29 01:46:34 -05:00
parent ac62cfed4c
commit 6cab141734
10 changed files with 223 additions and 11 deletions

3
.gitignore vendored
View File

@@ -264,4 +264,5 @@ ModelManifest.xml
#my files
deps/
/discord token.txt
/discord token.txt
include/sleepy_discord/version.h

View File

@@ -121,6 +121,51 @@ if(USE_LIBSODIUM)
)
endif()
# Get Version Info
find_package(Git)
if(Git_FOUND)
execute_process(
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD
OUTPUT_VARIABLE SLEEPY_DISCORD_VERSION_BUILD
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE SLEEPY_DISCORD_VERSION_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_VARIABLE SLEEPY_DISCORD_VERSION_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (SLEEPY_DISCORD_VERSION_BRANCH STREQUAL "master")
set(SLEEPY_DISCORD_VERSION_IS_MASTER "1")
else()
set(SLEEPY_DISCORD_VERSION_IS_MASTER "0")
endif()
execute_process(
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND ${GIT_EXECUTABLE} describe --always --long --dirty
OUTPUT_VARIABLE SLEEPY_DISCORD_VERSION_DESCRIPTION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(
NOT SLEEPY_DISCORD_VERSION_DESCRIPTION STREQUAL ""
)
set(SLEEPY_DISCORD_VERSION_DESCRIPTION_CONCAT " ")
else()
set(SLEEPY_DISCORD_VERSION_DESCRIPTION_CONCAT "")
endif()
configure_file(
"${PROJECT_SOURCE_DIR}/include/sleepy_discord/version.h.in"
"${PROJECT_SOURCE_DIR}/include/sleepy_discord/version.h"
)
endif()
# Add Subdirectories
add_subdirectory(sleepy_discord)
if (BUILD_SLEEPY_DISCORD_EXAMPLES)

View File

@@ -0,0 +1,2 @@
#pragma once
#define NONEXISTANT_VERSION_H

View File

@@ -1,10 +0,0 @@
#pragma once
#include <string>
namespace SleepyDiscord {
extern const unsigned int& revisionNum;
extern const std::string& description;
extern const std::string& branch;
extern const std::string& revision;
}

View File

@@ -0,0 +1,14 @@
/*
!!!!!! WARNING !!!!!!
version.h is an auto generated file. Any changes in version.h while be replaced.
However, version.h.in, not be confused with version.h, is ok to make changes to.
*/
#pragma once
#define SLEEPY_DISCORD_VERSION_BUILD ${SLEEPY_DISCORD_VERSION_BUILD}
#define SLEEPY_DISCORD_VERSION_BRANCH "${SLEEPY_DISCORD_VERSION_BRANCH}"
#define SLEEPY_DISCORD_VERSION_HASH "${SLEEPY_DISCORD_VERSION_HASH}"
#define SLEEPY_DISCORD_VERSION_IS_MASTER ${SLEEPY_DISCORD_VERSION_IS_MASTER}
#define SLEEPY_DISCORD_VERSION_DESCRIPTION_CONCAT "${SLEEPY_DISCORD_VERSION_DESCRIPTION_CONCAT}"
#define SLEEPY_DISCORD_VERSION_DESCRIPTION "${SLEEPY_DISCORD_VERSION_DESCRIPTION}"

View File

@@ -0,0 +1,56 @@
#pragma once
#include "version.h"
#include <unordered_set>
namespace SleepyDiscord {
//thanks https://stackoverflow.com/a/5459929
//convert preprocessor number into a string
//for example:
//#define SLEEPY_DISCORD_VERSION_BUILD 540
//SLEEPY_DISCORD_VERSION_STR(BUILD) gives us "540"
#define SLEEPY_STR_HELPER(x) #x
#define SLEEPY_STR_HELPER2(x) SLEEPY_STR_HELPER(x)
#define SLEEPY_STR_HELPER3(x, y) x##y
#define SLEEPY_DISCORD_VERSION_STR(x) \
SLEEPY_STR_HELPER2(SLEEPY_STR_HELPER3(SLEEPY_DISCORD_VERSION_ , x))
//please only use defines when you want to check version via preprocessors
//uses xxxxyyyyyy format, which can be converted to xxxx.yyyyyy
#define SLEEPY_DISCORD_VERSION_NUM 0
#if defined NONEXISTANT_VERSION_H || defined NONEXISTANT_GIT_INFO
#define SLEEPY_DISCORD_VERSION_BUILD 0
#define SLEEPY_DISCORD_VERSION_BRANCH "unknown branch"
#define SLEEPY_DISCORD_VERSION_HASH "unknown revision"
#define SLEEPY_DISCORD_VERSION_IS_MASTER 0
//letter to use for concat description
#define SLEEPY_DISCORD_VERSION_DESCRIPTION_CONCAT " "
#define SLEEPY_DISCORD_VERSION_DESCRIPTION "unknown"
#endif
#define SLEEPY_DISCORD_VERSION \
SLEEPY_DISCORD_VERSION_STR(NUM) "-"\
SLEEPY_DISCORD_VERSION_STR(BUILD) " "\
SLEEPY_DISCORD_VERSION_BRANCH \
SLEEPY_DISCORD_VERSION_DESCRIPTION_CONCAT \
SLEEPY_DISCORD_VERSION_DESCRIPTION
constexpr unsigned int versionNum = SLEEPY_DISCORD_VERSION_NUM;
constexpr unsigned int revisionNum = SLEEPY_DISCORD_VERSION_BUILD;
//for some reason const fixes a warning about convering a char* to a const char*
constexpr const char* description = SLEEPY_DISCORD_VERSION_DESCRIPTION;
constexpr const char* branch = SLEEPY_DISCORD_VERSION_BRANCH;
constexpr const char* revision = SLEEPY_DISCORD_VERSION_HASH;
constexpr const char* version = SLEEPY_DISCORD_VERSION;
constexpr bool isMaster = SLEEPY_DISCORD_VERSION_IS_MASTER;
//Features
//Remember to list features in both preprocessers and unordered_set
#define SLEEPY_FEATURE_AVAILABLE_FEATURE_LIST
std::unordered_set<std::string> availableFeatures{
"Available Feature List"
};
inline bool isFeatureAvaiable(std::string& featureName) {
return availableFeatures.find(featureName) != availableFeatures.end();
}
}

View File

@@ -88,6 +88,10 @@ if(USE_LIBSODIUM)
target_link_libraries(sleepy-discord ${LIB_SODIUM})
endif()
if(NOT Git_FOUND)
target_compile_definitions(sleepy-discord PRIVATE NONEXISTANT_GIT_INFO)
endif()
target_include_directories(sleepy-discord
PUBLIC
${PROJECT_SOURCE_DIR}/include/sleepy_discord/IncludeNonexistent

View File

@@ -0,0 +1,78 @@
/*
!!! NOTE !!!
This is not a noramal javascript script. You much use this using Windows Script Host.
*/
var wscriptShell = new ActiveXObject("WScript.Shell");
var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
// Get git
var git = "git";
function testGit() {
try {
wscriptShell.Exec(git + " --version");
} catch (error) {
return false;
}
return true;
}
if (!testGit()) {
try {
git = wscriptShell.RegRead("HKLM\\SOFTWARE\\GitForWindows\\InstallPath") + "\\bin\\git.exe";
} catch (error) { /*do notthing*/ }
if (!testGit()) {
WScript.Echo("Could not find git for windows values in windows registry. Try installing git for windows\n");
WScript.Quit(1);
}
}
function readCommandLine(command) {
try {
return wscriptShell.Exec(command).StdOut.ReadLine();
} catch (error) {
WScript.Echo("Failed to exec " + command);
WScript.Quit(1);
}
}
var isInGitRepo = readCommandLine(git + " rev-parse --is-inside-work-tree");
if (isInGitRepo !== "true") {
WScript.Echo("Not in a git repo");
WScript.Quit(0);
}
var build = readCommandLine(git + " rev-list --count HEAD");
var branch = readCommandLine(git + " rev-parse --abbrev-ref HEAD");
var hash = readCommandLine(git + " rev-parse HEAD");
var isMaster = branch === "master" ? "1" : "0";
var description = readCommandLine(git + " describe --always --long --dirty");
var descriptionConcat = description === "" ? "" : " ";
var outputContent = "/*\n\
!!!!!!WARNING!!!!!!\n\
version.h is an auto generated file.Any changes in version.h while be replaced.\n\
However, version.h.in, not be confused with version.h, is ok to make changes to.\n\
*/\n\
\n\
#pragma once\n\
\n\
#define SLEEPY_DISCORD_VERSION_BUILD " + build + "\n\
#define SLEEPY_DISCORD_VERSION_BRANCH \"" + branch + "\"\n\
#define SLEEPY_DISCORD_VERSION_HASH \"" + hash + "\"\n\
#define SLEEPY_DISCORD_VERSION_IS_MASTER " + isMaster + "\n\
#define SLEEPY_DISCORD_VERSION_DESCRIPTION_CONCAT \"" + descriptionConcat + "\"\n\
#define SLEEPY_DISCORD_VERSION_DESCRIPTION \"" + description + "\"";
var outputFile = "../include/sleepy_discord/version.h";
var outputFileContent;
try {
outputFileContent = fileSystem.OpenTextFile(outputFile).ReadAll();
} catch (error) {
outputFileContent = ""; //file doesn't exist
}
if (outputContent === outputFileContent) {
WScript.Echo(outputFile + " doesn't need to be updated. " + description);
} else {
fileSystem.CreateTextFile(outputFile, true).Write(outputContent);
WScript.Echo(outputFile + " updated to " + description);
}

View File

@@ -252,6 +252,9 @@ xcopy ..\include C:\devkitPro\portlibs\3ds\include /y /e</NMakeBuildCommandLine>
<Lib>
<AdditionalOptions> /machine:X86 %(AdditionalOptions)</AdditionalOptions>
</Lib>
<PreBuildEvent>
<Command>cscript /nologo /e:JScript "make_version.h.js"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
@@ -285,6 +288,9 @@ xcopy ..\include C:\devkitPro\portlibs\3ds\include /y /e</NMakeBuildCommandLine>
<Lib>
<AdditionalOptions>/machine:X64 %(AdditionalOptions)</AdditionalOptions>
</Lib>
<PreBuildEvent>
<Command>cscript /nologo /e:JScript "make_version.h.js"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
<ClCompile>
@@ -318,6 +324,9 @@ xcopy ..\include C:\devkitPro\portlibs\3ds\include /y /e</NMakeBuildCommandLine>
<Lib>
<AdditionalOptions> /machine:X86 %(AdditionalOptions)</AdditionalOptions>
</Lib>
<PreBuildEvent>
<Command>cscript /nologo /e:JScript "make_version.h.js"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Make|Win32'">
<ClCompile>
@@ -450,6 +459,9 @@ xcopy ..\include C:\devkitPro\portlibs\3ds\include /y /e</NMakeBuildCommandLine>
</Lib>
<ProjectReference />
<ProjectReference />
<PreBuildEvent>
<Command>cscript /nologo /e:JScript "make_version.h.js"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
@@ -483,6 +495,9 @@ xcopy ..\include C:\devkitPro\portlibs\3ds\include /y /e</NMakeBuildCommandLine>
</Lib>
<ProjectReference />
<ProjectReference />
<PreBuildEvent>
<Command>cscript /nologo /e:JScript "make_version.h.js"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
<ClCompile>
@@ -516,6 +531,9 @@ xcopy ..\include C:\devkitPro\portlibs\3ds\include /y /e</NMakeBuildCommandLine>
</Lib>
<ProjectReference />
<ProjectReference />
<PreBuildEvent>
<Command>cscript /nologo /e:JScript "make_version.h.js"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Make|Win32'">
<ClCompile>
@@ -890,6 +908,7 @@ xcopy ..\include C:\devkitPro\portlibs\3ds\include /y /e</NMakeBuildCommandLine>
<ClInclude Include="..\include\sleepy_discord\user.h" />
<ClInclude Include="..\include\sleepy_discord\uwebsockets_connection.h" />
<ClInclude Include="..\include\sleepy_discord\uwebsockets_websocket.h" />
<ClInclude Include="..\include\sleepy_discord\version_helper.h" />
<ClInclude Include="..\include\sleepy_discord\voice.h" />
<ClInclude Include="..\include\sleepy_discord\voice_connection.h" />
<ClInclude Include="..\include\sleepy_discord\webhook.h" />
@@ -903,6 +922,7 @@ xcopy ..\include C:\devkitPro\portlibs\3ds\include /y /e</NMakeBuildCommandLine>
<None Include="..\buildtools\Makefile" />
<None Include="..\buildtools\Makefile.3ds" />
<None Include="..\include\sleepy_discord\sleepy_discord.h" />
<None Include="make_version.h.js" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@@ -218,6 +218,7 @@
<ClInclude Include="..\include\sleepy_discord\custom_connection.h">
<Filter>websocket</Filter>
</ClInclude>
<ClInclude Include="..\include\sleepy_discord\version_helper.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\include\sleepy_discord\sleepy_discord.h" />
@@ -227,6 +228,7 @@
<None Include="..\buildtools\Makefile">
<Filter>buildtools</Filter>
</None>
<None Include="make_version.h.js" />
</ItemGroup>
<ItemGroup>
<Filter Include="websocket">