-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
Fix for grpc.tools #17995 & protobuf #7474 (handle UTF-8 paths in argumentfile) #10200
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
@acozzette can you please review? This is an important fix for gRPC's codegen support and you seems to be the author of the argumentFile parsing logic in protoc. |
@tonydnewell just to clarify:
|
CC @jskeet |
|
||
// Create the process. | ||
PROCESS_INFORMATION process_info; | ||
|
||
if (CreateProcessA((search_mode == SEARCH_PATH) ? nullptr : program.c_str(), | ||
(search_mode == SEARCH_PATH) ? command_line : nullptr, | ||
if (CreateProcessW((search_mode == SEARCH_PATH) ? NULL : wprogram.c_str(), |
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.
nit: change NULL -> nullptr everywhere in the diff (as that seems to be the current codestyle requirement in protobuf codebase?)
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.
Updated the code to use nullptr
It is just the plugin path that is an issue (these are the paths used in subprocess.cc). All other paths/names seem to work ok as they use the functions in io_win32.cc which do the utf-8 to wide string conversion correctly. I've tested with non-ASCII proto_path and non-ASCII .proto file name. Here is one of my test input rsp files: --plugin=protoc-gen-grpc=E:\work\grpc\protoctest\test-Dré\tools\grpc_csharp_plugin.exe
The reported problem was with using an utf-8 encoding in an argument file and this is what I've tested and is what Grpc.Tools uses. In theory it should be the same with command line arguments as all that reading the argument file does (in ExpandArgumentFile) is push the lines read onto the same vector of command line arguments before the arguments are interpreted. However this does not seem to work - I think the arguments are getting changed before passing to If we want to fix that too then may need to change to using |
As I said above to handle non-ascii arguments on the command line (for Windows) then wmain needs to be used. The code would need to be something like below. I've not included that in the fix as it is probably outside the scope of the issue being fixed: In main.cc: #ifndef _WIN32
int main(int argc, char* argv[]) {
return PROTOBUF_NAMESPACE_ID::compiler::ProtobufMain(argc, argv);
}
#else
int wmain( int argc, wchar_t *wargv[ ]) {
// convert all arguments to utf-8
char **argv = (char **)malloc(sizeof(char *) * argc);
for (int i = 0; i < argc; ++i) {
std::string utf8str;
if (!google::protobuf::io::win32::strings::wcs_to_utf8(wargv[i], &utf8str)) {
//GOOGLE_LOG(FATAL) << "wcs_to_utf8: " << Win32ErrorMessage(GetLastError());
}
argv[i] = _strdup(utf8str.c_str());
}
// call ProtobufMain with the utf-8 arguments
int sts = PROTOBUF_NAMESPACE_ID::compiler::ProtobufMain(argc, argv);
// free memory allocated for arguments
for (int i = 0; i < argc; ++i)
free(argv[i]);
free(argv);
return sts;
}
#endif |
Thanks for the explanation, the fix makes sense to me. Looks like after this fix, all the command line arguments would work correctly with accents when passed via an argument file (e.g. What's still a bit puzzling to me is why the command line argument don't seem to work with accents when regular command line arguments (not argument files) are used. Perhaps relevant:
|
// Using a malloc'ed string because CreateProcess() can mutate its second | ||
// parameter. | ||
char* command_line = | ||
portable_strdup(("cmd.exe /c \"" + program + "\"").c_str()); |
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.
There is another call to portable_strdup
in SubProccess::Start
. Does that need to be updated as well?
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.
I don't think so. It is used in the non-Windows code and this is a Windows specific fix.
Looks like this change didn't make it to protobuf's 21.x release. I'd therefore expect it to become available as part of 22.x release (AFAIKT that release cycle hasn't started yet). |
If you would like to include this in the next 21.x repease, please send a PR that cherry picks this back |
…obuf-7474 Fix for grpc.tools protocolbuffers#17995 & protobuf protocolbuffers#7474 (handle UTF-8 paths in argumentfile)
Merge pull request #10200 from tonydnewell/bugfix/protobuf-7474
* Force uninstall protobuf in python macos builds We are seeing failures in brew uninstall protobuf due to no package. Change this to a force install to avoid the error. * Fix spelling errors (#10717) * Merge pull request #10200 from tonydnewell/bugfix/protobuf-7474 Fix for grpc.tools #17995 & protobuf #7474 (handle UTF-8 paths in argumentfile) * Upgrade to kotlin 1.6 * 21.x No longer define no_threadlocal on OpenBSD * Upgrade kokoro to Xcode 14 (#10732) * Upgrade kokoro to Xcode 14 * Fix osx errors * Merge pull request #10770 from protocolbuffers/googleberg-cl-480629524 Mark default instance as immutable first to avoid race during static initialization of default instances. * Auto capitalize enums name in Ruby (#10454) (#10763) This closes #1965. * Edit toolchain to work with absl dep * Bump upb to latest version after fixes applied (#10783) * 21.x 202210180838 (#10785) * Updating version.json and repo version numbers to: 21.8 * Update changelog Co-authored-by: Protobuf Team Bot <[email protected]> * Update generated protos Co-authored-by: deannagarcia <[email protected]> Co-authored-by: Matt Fowles Kulukundis <[email protected]> Co-authored-by: Deanna Garcia <[email protected]> Co-authored-by: Brad Smith <[email protected]> Co-authored-by: Jerry Berg <[email protected]> Co-authored-by: tison <[email protected]> Co-authored-by: Protobuf Team Bot <[email protected]>
Fix for #7474 (and grpc/grpc#17995)
When calling the plugins in subprocess.cc
Subprocess::Start()
fix to use CreateProcessW instead of CreateProcessA to handle non-ascii paths.See grpc/grpc#17995 (comment) for a summary of what the actual problem is and why the fix looks like the way it does.