diff options
author | Joe George <joe@zeroc.com> | 2015-03-06 15:56:04 +0000 |
---|---|---|
committer | Joe George <joe@zeroc.com> | 2015-05-12 11:39:22 -0400 |
commit | af56dba8f887b822965778c32f29eca3a20d85d4 (patch) | |
tree | df33f433f407e81239d20e6c9497b78f1cd9f287 | |
parent | Patch 6 - Fix Ice for .NET thread pool serialization issue (diff) | |
download | ice-af56dba8f887b822965778c32f29eca3a20d85d4.tar.bz2 ice-af56dba8f887b822965778c32f29eca3a20d85d4.tar.xz ice-af56dba8f887b822965778c32f29eca3a20d85d4.zip |
Patch 7 - Fix slice2cpp and symbolic links
-rw-r--r-- | cpp/include/Slice/Util.h | 2 | ||||
-rw-r--r-- | cpp/src/Slice/Parser.cpp | 64 | ||||
-rw-r--r-- | cpp/src/Slice/Util.cpp | 53 |
3 files changed, 67 insertions, 52 deletions
diff --git a/cpp/include/Slice/Util.h b/cpp/include/Slice/Util.h index 45f7b0c8daa..06c1b325b67 100644 --- a/cpp/include/Slice/Util.h +++ b/cpp/include/Slice/Util.h @@ -27,7 +27,7 @@ SLICE_API void emitWarning(const std::string&, const std::string&, const std::st SLICE_API void emitRaw(const char*); SLICE_API std::vector<std::string> filterMcppWarnings(const std::string&); SLICE_API void printGeneratedHeader(IceUtilInternal::Output& out, const std::string&, const std::string& commentStyle = "//"); - +SLICE_API std::string normalizePath(const std::string&); } #endif diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp index abdffefb7e1..b8980cec70e 100644 --- a/cpp/src/Slice/Parser.cpp +++ b/cpp/src/Slice/Parser.cpp @@ -9,6 +9,7 @@ #include <IceUtil/Functional.h> #include <IceUtil/InputUtil.h> +#include <IceUtil/FileUtil.h> #include <IceUtil/StringUtil.h> #include <IceUtil/Unicode.h> #include <Slice/Parser.h> @@ -19,6 +20,9 @@ #ifdef _WIN32 # include <io.h> +#else +# include <climits> // For PATH_MAX +# include <unistd.h> // For readlink() #endif using namespace std; @@ -5657,6 +5661,56 @@ Slice::Unit::nextLine() _currentLine++; } +#ifndef _WIN32 +namespace +{ +string +readLink(const string& orig) +{ + string result = orig; + string::size_type beg = 0; + string::size_type next = string::npos; + do + { + string subpath; + next = result.find('/', beg + 1); + if(next == string::npos) + { + subpath = result; + } + else + { + subpath = result.substr(0, next); + } + + char buf[PATH_MAX + 1]; + int len = static_cast<int>(readlink(subpath.c_str(), buf, sizeof(buf))); + if(len > 0) + { + buf[len] = '\0'; + string linkpath = buf; + if(!IceUtilInternal::isAbsolutePath(linkpath)) // Path relative to the location of the link + { + string::size_type pos = subpath.rfind('/'); + assert(pos != string::npos); + linkpath = subpath.substr(0, pos + 1) + linkpath; + } + result = normalizePath(linkpath) + (next != string::npos ? result.substr(next) : string()); + beg = 0; + next = 0; + } + else + { + beg = next; + } + } + while(next != string::npos); + return result; +} + +} +#endif + bool Slice::Unit::scanPosition(const char* s) { @@ -5702,6 +5756,16 @@ Slice::Unit::scanPosition(const char* s) LineType type = File; + // + // We need to compare the file targets as one could be a symbolic link. + // +#ifndef _WIN32 + if(readLink(currentFile) == readLink(_topLevelFile)) + { + currentFile = _topLevelFile; + } +#endif + if(_currentLine == 0) { if(_currentIncludeLevel > 0 || currentFile != _topLevelFile) diff --git a/cpp/src/Slice/Util.cpp b/cpp/src/Slice/Util.cpp index 97b9e7c9844..5973da2b627 100644 --- a/cpp/src/Slice/Util.cpp +++ b/cpp/src/Slice/Util.cpp @@ -18,11 +18,8 @@ using namespace std; using namespace Slice; -namespace -{ - string -normalizePath(const string& path) +Slice::normalizePath(const string& path) { string result = path; @@ -78,8 +75,6 @@ normalizePath(const string& path) return result; } -} - string Slice::fullPath(const string& path) { @@ -93,51 +88,7 @@ Slice::fullPath(const string& path) } } - result = normalizePath(result); - -#ifdef _WIN32 - return result; -#else - - string::size_type beg = 0; - string::size_type next; - do - { - string subpath; - next = result.find('/', beg + 1); - if(next == string::npos) - { - subpath = result; - } - else - { - subpath = result.substr(0, next); - } - - char buf[PATH_MAX + 1]; - int len = static_cast<int>(readlink(subpath.c_str(), buf, sizeof(buf))); - if(len > 0) - { - buf[len] = '\0'; - string linkpath = buf; - if(!IceUtilInternal::isAbsolutePath(linkpath)) // Path relative to the location of the link - { - string::size_type pos = subpath.rfind('/'); - assert(pos != string::npos); - linkpath = subpath.substr(0, pos + 1) + linkpath; - } - result = normalizePath(linkpath) + (next != string::npos ? result.substr(next) : string()); - beg = 0; - next = 0; - } - else - { - beg = next; - } - } - while(next != string::npos); - return result; -#endif + return normalizePath(result); } string |