From 0af3ed5189182985573dbea30e173aca0f9a1685 Mon Sep 17 00:00:00 2001 From: Dan Barry Date: Tue, 2 Jun 2015 17:00:40 -0700 Subject: [PATCH] Add protoc path detection for Mac OS --- .../protobuf/compiler/command_line_interface.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 667b2b637c..c57cfd3d86 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -53,6 +53,10 @@ #include #endif +#ifdef __APPLE__ +#include +#endif + #include #include #include @@ -186,6 +190,16 @@ bool GetProtocAbsolutePath(string* path) { #ifdef _WIN32 char buffer[MAX_PATH]; int len = GetModuleFileName(NULL, buffer, MAX_PATH); +#elif __APPLE__ + char buffer[PATH_MAX]; + int len = 0; + + char dirtybuffer[PATH_MAX]; + uint32_t size = sizeof(dirtybuffer); + if (_NSGetExecutablePath(dirtybuffer, &size) == 0) { + realpath(dirtybuffer, buffer); + len = strlen(buffer); + } #else char buffer[PATH_MAX]; int len = readlink("/proc/self/exe", buffer, PATH_MAX);