-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add -v and --version flags to ch to print ChakraCore version. #2490
Conversation
Partially addresses chakra-core#109 and chakra-core#2472 ``` ch /v ch /version ch -v ch --v ch -version ch --version ``` The above all display the version in a simple `<major>.<minor>.<patch>` format, e.g.: ``` 1.4.1 ``` This flag is available in all flavors (including Release).
@bterlson @liminzhu We could probably merge this before the 1.4.1 release, so at a minimum 1.4.1 and 2.0.0 binaries can be distinguished at this point. |
Problems building on xplat. What is an xplat alternative for |
Linux has wcslen. The build problem is probably about const conversion. In reply to: 278212465 [](ancestors = 278212465) |
bin/ch/ch.cpp
Outdated
@@ -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]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const?
🎉 |
should we include this into |
This sounds pretty useful. Is there a way for any embedder (not just ch) to programmatically know ChakraCore version #? |
We intend to ship "ChakraCoreVersion.h" file, and embedder knows it by including that header. |
Yes, additionally, the file info of the compiled binaries already contains information about the version (that's how these macros were being consumed before): Here's the info for some binaries I built locally:
And from the preview package I recently published to myget:
|
It looks like the problem is that the signature of main for xplat specifies the following and converts so that #ifndef _WIN32
static char16** argv = nullptr;
int main(int argc, char** c_argv)
{
PAL_InitializeChakraCore(argc, c_argv);
argv = new char16*[argc]; Instead of the Windows version which uses: int _cdecl wmain(int argc, __in_ecount(argc) LPWSTR argv[]) Note Additionally, I confused things initially by using
|
Apparently we have On the other hand @jianchun suggests that since security is not a concern in |
I'm going to look into using |
We shouldn't use |
LGTM. Thanks @dilijev for taking care of this! |
@jianchun re: shipping ChakraCoreVersion.h -- the NuGet packages do not include this file since it's so minor. Would it be worth including it? Even so, that only solves the problem for Native projects. For .NET projects which might want to report the ChakraCore version without hardcoding it, is there any kind of solution that would work that doesn't involve exposing a new API that reports the version info? Should we consider implementing such an API for the benefit of hosting? Is there some other approach that could work? /cc @liminzhu |
From my investigation so far, this seems like a bit of a rabbit hole. There seems to be good reason (at least, it was thought about before) not to initialize the I agree that taking a dependency on PAL for this may be a bit extreme. One workaround is to copy a definition of @jianchun @obastemur Think it's safe to merge this as-is and follow-up later if the dependency becomes a problem? |
Updating the help message. Also enable Enables Messages will look as follows. debug/test builds:
release builds:
The distinction is that |
…t in chakra-core#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] <source file> -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|-?] <source file> 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.
@tcare Believes that this is potentially misleading as the version being reported is really just the version of At a minimum, we should report the following at this time:
We could read the Assuming that in the common case Will discuss with others on the team for opinions about how to proceed before merging this. |
https://stackoverflow.com/questions/940707/how-do-i-programatically-get-the-version-of-a-dll-or-exe-file/940743#940743 shows how to read file information from a binary. Output of
Or, because it reads the DLL info, when the DLL built from a different version, that is reflected in the output as well:
Note: At present, this only reports the /cc @tcare |
Windows x86_release error:
DWORD
APIENTRY
GetFileVersionInfoSizeA(
_In_ LPCSTR lptstrFilename, /* Filename of version stamped file */
_Out_opt_ LPDWORD lpdwHandle /* Information for use by GetFileVersionInfo */
); BOOL
APIENTRY
GetFileVersionInfoA(
_In_ LPCSTR lptstrFilename, /* Filename of version stamped file */
_Reserved_ DWORD dwHandle, /* Information from GetFileVersionSize */
_In_ DWORD dwLen, /* Length of buffer for info */
_Out_writes_bytes_(dwLen) LPVOID lpData /* Buffer to place the data structure */
); What? This seems like a warning that should be suppressed because clearly the value of |
dwHandle is reserved and is ignored. Just pass in nullptr. https://msdn.microsoft.com/en-us/library/windows/desktop/ms647003(v=vs.85).aspx |
@tcare Thanks for confirming, I was thinking that might be the right thing to do but I couldn't find info about it. I didn't think to check the API page since I figured the function signature would be enough to tell why the warning happened (clearly the |
bin/ch/ch.cpp
Outdated
DWORD verHandle = NULL; | ||
UINT size = 0; | ||
LPBYTE lpBuffer = NULL; | ||
DWORD verSize = GetFileVersionInfoSizeA(filename, &verHandle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verHandle is optional for this and we don't use it later, so you can also pass nullptr here.
@@ -23,6 +23,11 @@ ChakraRTInterface::ArgInfo* ChakraRTInterface::m_argInfo = nullptr; | |||
TestHooks ChakraRTInterface::m_testHooks = { 0 }; | |||
JsAPIHooks ChakraRTInterface::m_jsApiHooks = { 0 }; | |||
|
|||
LPCSTR GetChakraDllName() | |||
{ | |||
return chakraDllName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Top of the file. Different string for each platform.
bin/ch/ch.vcxproj
Outdated
@@ -37,6 +37,7 @@ | |||
ole32.lib; | |||
kernel32.lib; | |||
Rpcrt4.lib; | |||
$(ChakraCommonLinkDependencies); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to add this link dependency? Is there a more lightweight way to get the Dll name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll just link the specific lib.
93d53e5
to
57eba6b
Compare
bin/ch/ch.cpp
Outdated
(size != 0)) | ||
{ | ||
VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer; | ||
if (verInfo->dwSignature == 0xfeef04bd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number can be VS_FFI_SIGNATURE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah thanks, that was bugging me too.
LGTM, please run by @curtisman. |
…raCore version. Merge pull request #2490 from dilijev:version-r14 Partially addresses #109 and #2472. This is intended as a first pass at the issue to provide some information at this point. Later, we plan to add more information such as whether a binary was produced as a developer build or an official build, what specific commit the binary was built from, which branch, which machine, etc. The specific set of information that we plan to provide is still being discussed in #109. ``` ch /v ch /version ch -v ch --v ch -version ch --version ``` (Supporting `-` and `--` prefixes for short and long flag names is consistent with how we process all behaviors. The logic I used here is a replica of that in `CmdLineArgsParser::Parse`.) The above all display the version information for `ch` and `ChakraCore` as `<major>.<minor>.<patch>.<QFE>` (note: by convention, ChakraCore's `QFE` is always `0`). For example on Windows for ChakraCore 1.4.1 with `ch.exe` and `ChakraCore.dll` from the same build: ``` $ ch -v ch.exe version 1.4.1.0 chakracore.dll version 1.4.1.0 ``` If with the same `ch.exe`, if `ChakraCore.dll` was from, e.g., a 2.0.0 build: ``` $ ch -v ch.exe version 1.4.1.0 chakracore.dll version 2.0.0.0 ``` On Linux: ``` ~/dev/ChakraCore$ ./BuildLinux/Release/ch -v ch version 1.4.1.0 ``` This flag is available in all flavors (including Release). --- 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] <source file> -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|-?] <source file> 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.
…to print ChakraCore version. Merge pull request #2490 from dilijev:version-r14 Partially addresses #109 and #2472. This is intended as a first pass at the issue to provide some information at this point. Later, we plan to add more information such as whether a binary was produced as a developer build or an official build, what specific commit the binary was built from, which branch, which machine, etc. The specific set of information that we plan to provide is still being discussed in #109. ``` ch /v ch /version ch -v ch --v ch -version ch --version ``` (Supporting `-` and `--` prefixes for short and long flag names is consistent with how we process all behaviors. The logic I used here is a replica of that in `CmdLineArgsParser::Parse`.) The above all display the version information for `ch` and `ChakraCore` as `<major>.<minor>.<patch>.<QFE>` (note: by convention, ChakraCore's `QFE` is always `0`). For example on Windows for ChakraCore 1.4.1 with `ch.exe` and `ChakraCore.dll` from the same build: ``` $ ch -v ch.exe version 1.4.1.0 chakracore.dll version 1.4.1.0 ``` If with the same `ch.exe`, if `ChakraCore.dll` was from, e.g., a 2.0.0 build: ``` $ ch -v ch.exe version 1.4.1.0 chakracore.dll version 2.0.0.0 ``` On Linux: ``` ~/dev/ChakraCore$ ./BuildLinux/Release/ch -v ch version 1.4.1.0 ``` This flag is available in all flavors (including Release). --- 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] <source file> -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|-?] <source file> 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.
Partially addresses #109 and #2472.
This is intended as a first pass at the issue to provide some information at this point.
Later, we plan to add more information such as whether a binary was produced as a developer build or an official build, what specific commit the binary was built from, which branch, which machine, etc. The specific set of information that we plan to provide is still being discussed in #109.
(Supporting
-
and--
prefixes for short and long flag names is consistent with how we process all behaviors. The logic I used here is a replica of that inCmdLineArgsParser::Parse
.)The above all display the version information for
ch
andChakraCore
as<major>.<minor>.<patch>.<QFE>
(note: by convention, ChakraCore'sQFE
is always0
).For example on Windows for ChakraCore 1.4.1 with
ch.exe
andChakraCore.dll
from the same build:If with the same
ch.exe
, ifChakraCore.dll
was from, e.g., a 2.0.0 build:On Linux:
This flag is available in all flavors (including Release).
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:
release builds:
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.