From f24a3232a59ec6e2806230f643ba550bbd24d912 Mon Sep 17 00:00:00 2001 From: Doug Ilijev Date: Tue, 7 Feb 2017 18:30:25 -0800 Subject: [PATCH 1/4] Add -v and --version flags to ch to print ChakraCore version. Partially addresses #109 and #2472 ``` ch /v ch /version ch -v ch --v ch -version ch --version ``` The above all display the version in a simple `..` format, e.g.: ``` 1.4.1 ``` This flag is available in all flavors (including Release). --- bin/ch/ch.cpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/bin/ch/ch.cpp b/bin/ch/ch.cpp index 2bf6b33954f..56f50924aff 100644 --- a/bin/ch/ch.cpp +++ b/bin/ch/ch.cpp @@ -78,6 +78,11 @@ void __stdcall PrintUsage() #endif } +void __stdcall PrintVersion() +{ + wprintf(_u("%d.%d.%d\n"), CHAKRA_CORE_MAJOR_VERSION, CHAKRA_CORE_MINOR_VERSION, CHAKRA_CORE_PATCH_VERSION); +} + // On success the param byteCodeBuffer will be allocated in the function. HRESULT GetSerializedBuffer(LPCSTR fileContents, JsValueRef *byteCodeBuffer) { @@ -770,7 +775,36 @@ int _cdecl wmain(int argc, __in_ecount(argc) LPWSTR argv[]) int cpos = 1; for(int i = 1; i < argc; ++i) { - if(wcsstr(argv[i], _u("-TTRecord=")) == argv[i]) + wchar *arg = argv[i]; + size_t arglen = wcsnlen(arg, 2); // just look for prefixes for now + + // support - or / prefix for flags + if (arglen >= 1 && (arg[0] == _u('-') +#ifdef _WIN32 + || arg[0] == _u('/') // '/' prefix for legacy (Windows-only because it starts a path on Unix) +#endif + )) + { + // support -- prefix for flags + if (arglen >= 2 && arg[0] == _u('-') && arg[1] == _u('-')) + { + arg += 2; // advance past -- prefix + } + else + { + arg += 1; // advance past - or / prefix + } + } + + arglen = wcsnlen(arg, 8); // ensure that we get the entirety of "version" so we don't match e.g. "versions" + if (arglen == 1 && wcsncmp(arg, _u("v"), arglen) == 0 || + arglen == 7 && wcsncmp(arg, _u("version"), arglen) == 0) + { + PrintVersion(); + PAL_Shutdown(); + return EXIT_SUCCESS; + } + else if(wcsstr(argv[i], _u("-TTRecord=")) == argv[i]) { doTTRecord = true; wchar* ruri = argv[i] + wcslen(_u("-TTRecord=")); From 10f53b4b0b220430c67c88f062353f437c9089e4 Mon Sep 17 00:00:00 2001 From: Doug Ilijev Date: Wed, 8 Feb 2017 15:24:10 -0800 Subject: [PATCH 2/4] Fix up xplat build. --- bin/ch/ch.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/ch/ch.cpp b/bin/ch/ch.cpp index 56f50924aff..e30c82cf1bd 100644 --- a/bin/ch/ch.cpp +++ b/bin/ch/ch.cpp @@ -4,6 +4,7 @@ //------------------------------------------------------------------------------------------------------- #include "stdafx.h" #include "Core/AtomLockGuids.h" +#include #ifdef _WIN32 #include #endif @@ -775,8 +776,8 @@ int _cdecl wmain(int argc, __in_ecount(argc) LPWSTR argv[]) int cpos = 1; for(int i = 1; i < argc; ++i) { - wchar *arg = argv[i]; - size_t arglen = wcsnlen(arg, 2); // just look for prefixes for now + const wchar *arg = argv[i]; + size_t arglen = wcslen(arg); // support - or / prefix for flags if (arglen >= 1 && (arg[0] == _u('-') @@ -796,9 +797,9 @@ int _cdecl wmain(int argc, __in_ecount(argc) LPWSTR argv[]) } } - arglen = wcsnlen(arg, 8); // ensure that we get the entirety of "version" so we don't match e.g. "versions" - if (arglen == 1 && wcsncmp(arg, _u("v"), arglen) == 0 || - arglen == 7 && wcsncmp(arg, _u("version"), arglen) == 0) + arglen = wcslen(arg); // get length of flag after prefix + if ((arglen == 1 && wcsncmp(arg, _u("v"), arglen) == 0) || + (arglen == 7 && wcsncmp(arg, _u("version"), arglen) == 0)) { PrintVersion(); PAL_Shutdown(); From 9f391c2f31684b9371a7ba785a5a8d64715392b8 Mon Sep 17 00:00:00 2001 From: Doug Ilijev Date: Wed, 8 Feb 2017 18:23:19 -0800 Subject: [PATCH 3/4] Updating the help message. Also enable `-h` and `-help` as per request in #2472. Enables `-h` and `-help` for non-release builds, and `-?`, `-h`, and `-help` for release builds. Messages will look as follows. debug/test builds: ``` Usage: ch.exe [-v|-version] [-h|-help] [-?] [flaglist] -v|-version Displays version info -h|-help Displays this help message -? Displays this help message with complete [flaglist] info ``` release builds: ``` Usage: ch.exe [-v|-version] [-h|-help|-?] Note: [flaglist] is not supported in Release builds; try a Debug or Test build to enable these flags. -v|-version Displays version info -h|-help|-? Displays this help message ``` The distinction is that `-?` is already implemented in debug/test builds to display full information about the `[flaglist]` options. This is a minimal change here that will result in guiding the user more accurately in all build flavors, the effect of which is that `-?` in debug/test builds is still the only way to get information about the `[flaglist]` options. --- bin/ch/HostConfigFlags.cpp | 2 +- bin/ch/ch.cpp | 31 +++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/bin/ch/HostConfigFlags.cpp b/bin/ch/HostConfigFlags.cpp index cfa4058f60c..1bc2514bddf 100644 --- a/bin/ch/HostConfigFlags.cpp +++ b/bin/ch/HostConfigFlags.cpp @@ -78,7 +78,7 @@ void HostConfigFlags::PrintUsage() pfnPrintUsage(); } - wprintf(_u("\nFlag List : \n")); + wprintf(_u("\nHost Config Flags: \n\n")); HostConfigFlags::PrintUsageString(); ChakraRTInterface::PrintConfigFlagsUsageString(); } diff --git a/bin/ch/ch.cpp b/bin/ch/ch.cpp index e30c82cf1bd..38a88b5525b 100644 --- a/bin/ch/ch.cpp +++ b/bin/ch/ch.cpp @@ -65,17 +65,28 @@ int HostExceptionFilter(int exceptionCode, _EXCEPTION_POINTERS *ep) void __stdcall PrintUsageFormat() { - wprintf(_u("\nUsage: %s [flaglist] \n"), hostName); + wprintf(_u("\nUsage: %s [-v|-version] [-h|-help] [-?] [flaglist] \n"), hostName); + wprintf(_u("\t-v|-version\t\tDisplays version info\n")); + wprintf(_u("\t-h|-help\t\tDisplays this help message\n")); + wprintf(_u("\t-?\t\t\tDisplays this help message with complete [flaglist] info\n")); } +#if !defined(ENABLE_DEBUG_CONFIG_OPTIONS) +void __stdcall PrintReleaseUsage() +{ + wprintf(_u("\nUsage: %s [-v|-version] [-h|-help|-?] %s"), hostName, + _u("\nNote: [flaglist] is not supported in Release builds; try a Debug or Test build to enable these flags.\n")); + wprintf(_u("\t-v|-version\t\tDisplays version info\n")); + wprintf(_u("\t-h|-help|-?\t\tDisplays this help message\n")); +} +#endif + void __stdcall PrintUsage() { #if !defined(ENABLE_DEBUG_CONFIG_OPTIONS) - wprintf(_u("\nUsage: %s %s"), hostName, - _u("\n[flaglist] is not supported for Release mode\n")); + PrintReleaseUsage(); #else PrintUsageFormat(); - wprintf(_u("Try '%s -?' for help\n"), hostName); #endif } @@ -805,6 +816,18 @@ int _cdecl wmain(int argc, __in_ecount(argc) LPWSTR argv[]) PAL_Shutdown(); return EXIT_SUCCESS; } + else if ( +#if !defined(ENABLE_DEBUG_CONFIG_OPTIONS) // release builds can display some kind of help message + (arglen == 1 && wcsncmp(arg, _u("?"), arglen) == 0) || +#endif + (arglen == 1 && wcsncmp(arg, _u("h"), arglen) == 0) || + (arglen == 4 && wcsncmp(arg, _u("help"), arglen) == 0) + ) + { + PrintUsage(); + PAL_Shutdown(); + return EXIT_SUCCESS; + } else if(wcsstr(argv[i], _u("-TTRecord=")) == argv[i]) { doTTRecord = true; From beb522dcbe2bb30391aa6366a7d21a908db7b005 Mon Sep 17 00:00:00 2001 From: Doug Ilijev Date: Wed, 8 Feb 2017 20:03:44 -0800 Subject: [PATCH 4/4] Read version information from ChakraCore library. --- bin/ch/ChakraRtInterface.cpp | 5 ++++ bin/ch/ChakraRtInterface.h | 2 ++ bin/ch/ch.cpp | 58 +++++++++++++++++++++++++++++++++++- bin/ch/ch.vcxproj | 3 +- 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/bin/ch/ChakraRtInterface.cpp b/bin/ch/ChakraRtInterface.cpp index aefd08c101b..f9c5a057d6c 100644 --- a/bin/ch/ChakraRtInterface.cpp +++ b/bin/ch/ChakraRtInterface.cpp @@ -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 diff --git a/bin/ch/ChakraRtInterface.h b/bin/ch/ChakraRtInterface.h index 9657a4db78c..d5e1cd5426c 100644 --- a/bin/ch/ChakraRtInterface.h +++ b/bin/ch/ChakraRtInterface.h @@ -188,6 +188,8 @@ struct JsAPIHooks JsrtTTDReplayExecutionPtr pfJsrtTTDReplayExecution; }; +LPCSTR GetChakraDllName(); + class ChakraRTInterface { public: diff --git a/bin/ch/ch.cpp b/bin/ch/ch.cpp index 38a88b5525b..917911afe58 100644 --- a/bin/ch/ch.cpp +++ b/bin/ch/ch.cpp @@ -6,6 +6,7 @@ #include "Core/AtomLockGuids.h" #include #ifdef _WIN32 +#include #include #endif @@ -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. diff --git a/bin/ch/ch.vcxproj b/bin/ch/ch.vcxproj index 46358a4f39b..ecdc0f7f0dd 100644 --- a/bin/ch/ch.vcxproj +++ b/bin/ch/ch.vcxproj @@ -37,6 +37,7 @@ ole32.lib; kernel32.lib; Rpcrt4.lib; + version.lib; @@ -102,4 +103,4 @@ - \ No newline at end of file +