Skip to content

Commit 09b9849

Browse files
committed
Read version information from ChakraCore library.
1 parent 9f391c2 commit 09b9849

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

bin/ch/ChakraRtInterface.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ ChakraRTInterface::ArgInfo* ChakraRTInterface::m_argInfo = nullptr;
2323
TestHooks ChakraRTInterface::m_testHooks = { 0 };
2424
JsAPIHooks ChakraRTInterface::m_jsApiHooks = { 0 };
2525

26+
LPCSTR GetChakraDllName()
27+
{
28+
return chakraDllName;
29+
}
30+
2631
// Wrapper functions to abstract out loading ChakraCore
2732
// and resolving its symbols
2833
// Currently, these functions resolve to the PAL on Linux

bin/ch/ChakraRtInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ struct JsAPIHooks
188188
JsrtTTDReplayExecutionPtr pfJsrtTTDReplayExecution;
189189
};
190190

191+
LPCSTR GetChakraDllName();
192+
191193
class ChakraRTInterface
192194
{
193195
public:

bin/ch/ch.cpp

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "Core/AtomLockGuids.h"
77
#include <CommonPal.h>
88
#ifdef _WIN32
9+
#include <winver.h>
910
#include <process.h>
1011
#endif
1112

@@ -90,9 +91,65 @@ void __stdcall PrintUsage()
9091
#endif
9192
}
9293

94+
void __stdcall PrintChVersion()
95+
{
96+
wprintf(_u("%s version %d.%d.%d.0\n"), hostName, CHAKRA_CORE_MAJOR_VERSION, CHAKRA_CORE_MINOR_VERSION, CHAKRA_CORE_PATCH_VERSION);
97+
}
98+
99+
#ifdef _WIN32
100+
void __stdcall PrintChakraCoreVersion()
101+
{
102+
char filename[_MAX_PATH];
103+
char drive[_MAX_DRIVE];
104+
char dir[_MAX_DIR];
105+
106+
LPCSTR chakraDllName = GetChakraDllName();
107+
108+
char modulename[_MAX_PATH];
109+
GetModuleFileNameA(NULL, modulename, _MAX_PATH);
110+
_splitpath_s(modulename, drive, _MAX_DRIVE, dir, _MAX_DIR, nullptr, 0, nullptr, 0);
111+
_makepath_s(filename, drive, dir, chakraDllName, nullptr);
112+
113+
DWORD verHandle = NULL;
114+
UINT size = 0;
115+
LPBYTE lpBuffer = NULL;
116+
DWORD verSize = GetFileVersionInfoSizeA(filename, &verHandle);
117+
118+
if (verSize != NULL)
119+
{
120+
LPSTR verData = new char[verSize];
121+
122+
if (GetFileVersionInfoA(filename, NULL, verSize, verData) &&
123+
VerQueryValue(verData, _u("\\"), (VOID FAR * FAR *)&lpBuffer, &size) &&
124+
(size != 0))
125+
{
126+
VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer;
127+
if (verInfo->dwSignature == 0xfeef04bd)
128+
{
129+
// Doesn't matter if you are on 32 bit or 64 bit,
130+
// DWORD is always 32 bits, so first two revision numbers
131+
// come from dwFileVersionMS, last two come from dwFileVersionLS
132+
printf("%s version %d.%d.%d.%d\n",
133+
chakraDllName,
134+
(verInfo->dwFileVersionMS >> 16) & 0xffff,
135+
(verInfo->dwFileVersionMS >> 0) & 0xffff,
136+
(verInfo->dwFileVersionLS >> 16) & 0xffff,
137+
(verInfo->dwFileVersionLS >> 0) & 0xffff);
138+
}
139+
}
140+
141+
delete[] verData;
142+
}
143+
}
144+
#endif
145+
93146
void __stdcall PrintVersion()
94147
{
95-
wprintf(_u("%d.%d.%d\n"), CHAKRA_CORE_MAJOR_VERSION, CHAKRA_CORE_MINOR_VERSION, CHAKRA_CORE_PATCH_VERSION);
148+
PrintChVersion();
149+
150+
#ifdef _WIN32
151+
PrintChakraCoreVersion();
152+
#endif
96153
}
97154

98155
// On success the param byteCodeBuffer will be allocated in the function.

bin/ch/ch.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
ole32.lib;
3838
kernel32.lib;
3939
Rpcrt4.lib;
40+
$(ChakraCommonLinkDependencies);
4041
</AdditionalDependencies>
4142
</Link>
4243
</ItemDefinitionGroup>
@@ -102,4 +103,4 @@
102103
</ItemGroup>
103104
<Import Project="$(BuildConfigPropsPath)Chakra.Build.targets" Condition="exists('$(BuildConfigPropsPath)Chakra.Build.targets')" />
104105
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
105-
</Project>
106+
</Project>

0 commit comments

Comments
 (0)