summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2015-02-25 11:39:02 +0100
committerJose <jose@zeroc.com>2015-02-25 11:39:02 +0100
commite0f3bf0c78952ecc0ae8c0cb02bb33c13448d094 (patch)
tree0379cebf670b8833d056e31ed9c963e2a29146b0 /cpp
parentFix (ICE-5833) - shorten paths when include file is not a canonical path (diff)
downloadice-e0f3bf0c78952ecc0ae8c0cb02bb33c13448d094.tar.bz2
ice-e0f3bf0c78952ecc0ae8c0cb02bb33c13448d094.tar.xz
ice-e0f3bf0c78952ecc0ae8c0cb02bb33c13448d094.zip
(ICE-5833) - related fixes:
* Update test/Slice/headers to check this * Canonical path must be only used when attempts to shorten the actual path fails.
Diffstat (limited to 'cpp')
-rw-r--r--cpp/src/Slice/Util.cpp25
-rwxr-xr-xcpp/test/Slice/headers/run.py66
2 files changed, 83 insertions, 8 deletions
diff --git a/cpp/src/Slice/Util.cpp b/cpp/src/Slice/Util.cpp
index 1961ef34e03..5ddd8c6c8b9 100644
--- a/cpp/src/Slice/Util.cpp
+++ b/cpp/src/Slice/Util.cpp
@@ -161,18 +161,22 @@ Slice::changeInclude(const string& path, const vector<string>& includePaths)
// the path that produces the shortest relative filename.
//
string result = path;
- set<string> paths;
- paths.insert(path);
+ vector<string> paths;
+ paths.push_back(path);
//
// if path is not a canonical path we also test with its canonical
// path
//
- paths.insert(fullPath(path));
-
- for(set<string>::const_iterator i = paths.begin(); i != paths.end(); ++i)
+ string canonicalPath = fullPath(path);
+ if(canonicalPath != path)
+ {
+ paths.push_back(canonicalPath);
+ }
+
+ for(vector<string>::const_iterator i = paths.begin(); i != paths.end(); ++i)
{
for(vector<string>::const_iterator j = includePaths.begin(); j != includePaths.end(); ++j)
- {
+ {
if(i->compare(0, j->length(), *j) == 0)
{
string s = i->substr(j->length() + 1); // + 1 for the '/'
@@ -182,6 +186,15 @@ Slice::changeInclude(const string& path, const vector<string>& includePaths)
}
}
}
+
+ //
+ // If the path has been already shortened no need to test
+ // with canonical path.
+ //
+ if(result != path)
+ {
+ break;
+ }
}
result = normalizePath(result); // Normalize the result.
diff --git a/cpp/test/Slice/headers/run.py b/cpp/test/Slice/headers/run.py
index 18096f51f09..803901b61d8 100755
--- a/cpp/test/Slice/headers/run.py
+++ b/cpp/test/Slice/headers/run.py
@@ -28,7 +28,8 @@ def clean():
os.path.join("slices", "dir1", "linktoa3.ice")]:
if os.path.exists(f):
os.unlink(f)
-
+ os.system("rm -rf project1 tmp")
+
clean()
os.symlink("slices", "linktoslices")
os.symlink("dir1", os.path.join("slices", "linktodir1"))
@@ -37,6 +38,7 @@ os.symlink("dir2", os.path.join("slices", "linktodir2"))
slice2cpp = TestUtil.getSliceTranslator()
+basedir = os.path.dirname(os.path.abspath(__file__))
slicedir = os.path.join(TestUtil.getIceDir(), "slice")
os.symlink(slicedir, "iceslices")
@@ -65,7 +67,67 @@ runTest("%s -I%s -Ilinktoslices linktoslices/linktodir2/b.ice" % (slice2cpp, sli
if os.path.exists("SLICES"):
runTest("%s -IICESLICES -ISLICES SLICES/DIR2/B.ice" % (slice2cpp))
runTest("%s -IICESLICES -ILINKTOSLICES LINKTOSLICES/LINKTODIR2/B.ice" % (slice2cpp))
+
+#
+# Slice files are symlinks, include dir is a regular directory
+#
+os.system("mkdir -p project1/git/services.settings.slices")
+os.system("mkdir -p project1/src/services/settings")
+os.system("cd project1/src/services/settings && ln -s ../../../git/services.settings.slices slices")
-print("ok")
+f = open("project1/git/services.settings.slices/A.ice", "w")
+f.write("// dumy file")
+f.close()
+f = open("project1/git/services.settings.slices/B.ice", "w")
+f.write("#include <services/settings/slices/A.ice>")
+f.close()
+
+os.system("cd project1 && %s -Isrc src/services/settings/slices/B.ice" % slice2cpp)
+f = open("project1/B.h")
+
+if not re.search(re.escape('#include <services/settings/slices/A.h>'), f.read()):
+ print("failed!")
+ sys.exit(1)
+
+clean()
+
+#
+# Slice file is regular file, include dir is a symlink to a second symlink
+#
+os.system("mkdir -p tmp/Ice-x.y.z/share")
+os.system("cd tmp/Ice-x.y.z/share && ln -s %s" % TestUtil.getIceDir("slice"))
+
+
+os.system("mkdir -p project1/share")
+os.system("cd project1/share && ln -s %s/tmp/Ice-x.y.z/share/slice" % basedir)
+f = open("project1/A.ice", "w")
+f.write("#include <Ice/Identity.ice>")
+f.close()
+os.system("cd project1 && %s -Ishare/slice A.ice" % slice2cpp)
+f = open("project1/A.h")
+if not re.search(re.escape('#include <Ice/Identity.h>'), f.read()):
+ print("failed!")
+ sys.exit(1)
+
+clean()
+#
+# Typical Ice install with symlink Ice-x.y -> Ice-x.y.z
+#
+os.system("mkdir -p tmp/Ice-x.y.z/slice/Ice")
+os.system("cd tmp && ln -s Ice-x.y.z Ice-x.y")
+f = open("tmp/Ice-x.y.z/slice/Ice/Identity.ice", "w")
+f.write("// dumy file")
+
+os.system("mkdir -p project1")
+f = open("project1/A.ice", "w")
+f.write("#include <Ice/Identity.ice>")
+f.close()
+os.system("cd project1 && %s -I%s/tmp/Ice-x.y/slice A.ice" % (slice2cpp, basedir))
+f = open("project1/A.h")
+if not re.search(re.escape('#include <Ice/Identity.h>'), f.read()):
+ print("failed!")
+ sys.exit(1)
+
+print("ok")
clean()