Skip to content

Commit

Permalink
Read version information from ChakraCore library.
Browse files Browse the repository at this point in the history
  • Loading branch information
dilijev committed Feb 9, 2017
1 parent 9f391c2 commit beb522d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
5 changes: 5 additions & 0 deletions bin/ch/ChakraRtInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ ChakraRTInterface::ArgInfo* ChakraRTInterface::m_argInfo = nullptr;
TestHooks ChakraRTInterface::m_testHooks = { 0 };
JsAPIHooks ChakraRTInterface::m_jsApiHooks = { 0 };

LPCSTR GetChakraDllName()
{
return chakraDllName;
}

// Wrapper functions to abstract out loading ChakraCore
// and resolving its symbols
// Currently, these functions resolve to the PAL on Linux
Expand Down
2 changes: 2 additions & 0 deletions bin/ch/ChakraRtInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ struct JsAPIHooks
JsrtTTDReplayExecutionPtr pfJsrtTTDReplayExecution;
};

LPCSTR GetChakraDllName();

class ChakraRTInterface
{
public:
Expand Down
58 changes: 57 additions & 1 deletion bin/ch/ch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Core/AtomLockGuids.h"
#include <CommonPal.h>
#ifdef _WIN32
#include <winver.h>
#include <process.h>
#endif

Expand Down Expand Up @@ -90,9 +91,64 @@ void __stdcall PrintUsage()
#endif
}

void __stdcall PrintChVersion()
{
wprintf(_u("%s version %d.%d.%d.0\n"), hostName, CHAKRA_CORE_MAJOR_VERSION, CHAKRA_CORE_MINOR_VERSION, CHAKRA_CORE_PATCH_VERSION);
}

#ifdef _WIN32
void __stdcall PrintChakraCoreVersion()
{
char filename[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];

LPCSTR chakraDllName = GetChakraDllName();

char modulename[_MAX_PATH];
GetModuleFileNameA(NULL, modulename, _MAX_PATH);
_splitpath_s(modulename, drive, _MAX_DRIVE, dir, _MAX_DIR, nullptr, 0, nullptr, 0);
_makepath_s(filename, drive, dir, chakraDllName, nullptr);

UINT size = 0;
LPBYTE lpBuffer = NULL;
DWORD verSize = GetFileVersionInfoSizeA(filename, NULL);

if (verSize != NULL)
{
LPSTR verData = new char[verSize];

if (GetFileVersionInfoA(filename, NULL, verSize, verData) &&
VerQueryValue(verData, _u("\\"), (VOID FAR * FAR *)&lpBuffer, &size) &&
(size != 0))
{
VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer;
if (verInfo->dwSignature == VS_FFI_SIGNATURE)
{
// Doesn't matter if you are on 32 bit or 64 bit,
// DWORD is always 32 bits, so first two revision numbers
// come from dwFileVersionMS, last two come from dwFileVersionLS
printf("%s version %d.%d.%d.%d\n",
chakraDllName,
(verInfo->dwFileVersionMS >> 16) & 0xffff,
(verInfo->dwFileVersionMS >> 0) & 0xffff,
(verInfo->dwFileVersionLS >> 16) & 0xffff,
(verInfo->dwFileVersionLS >> 0) & 0xffff);
}
}

delete[] verData;
}
}
#endif

void __stdcall PrintVersion()
{
wprintf(_u("%d.%d.%d\n"), CHAKRA_CORE_MAJOR_VERSION, CHAKRA_CORE_MINOR_VERSION, CHAKRA_CORE_PATCH_VERSION);
PrintChVersion();

#ifdef _WIN32
PrintChakraCoreVersion();
#endif
}

// On success the param byteCodeBuffer will be allocated in the function.
Expand Down
3 changes: 2 additions & 1 deletion bin/ch/ch.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
ole32.lib;
kernel32.lib;
Rpcrt4.lib;
version.lib;
</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
Expand Down Expand Up @@ -102,4 +103,4 @@
</ItemGroup>
<Import Project="$(BuildConfigPropsPath)Chakra.Build.targets" Condition="exists('$(BuildConfigPropsPath)Chakra.Build.targets')" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>
</Project>

0 comments on commit beb522d

Please sign in to comment.