From a479aa1366734f80360a00e3020f5b148cb3c060 Mon Sep 17 00:00:00 2001 From: "zachr@google.com" Date: Fri, 2 Aug 2013 15:54:30 +0000 Subject: [PATCH] fix skpdiff viewer bug when using relative paths BUG=skia:1463 R=djsollen@google.com Review URL: https://codereview.chromium.org/21601002 git-svn-id: http://skia.googlecode.com/svn/trunk@10515 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tools/skpdiff/SkDiffContext.cpp | 7 +++++-- tools/skpdiff/skpdiff_util.cpp | 23 +++++++++++++++++++++++ tools/skpdiff/skpdiff_util.h | 7 +++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/tools/skpdiff/SkDiffContext.cpp b/tools/skpdiff/SkDiffContext.cpp index cf2654ac05..f551ff3508 100644 --- a/tools/skpdiff/SkDiffContext.cpp +++ b/tools/skpdiff/SkDiffContext.cpp @@ -164,12 +164,15 @@ void SkDiffContext::outputRecords(SkWStream& stream, bool useJSONP) { while (NULL != currentRecord) { stream.writeText(" {\n"); + SkString baselineAbsPath = get_absolute_path(currentRecord->fBaselinePath); + SkString testAbsPath = get_absolute_path(currentRecord->fTestPath); + stream.writeText(" \"baselinePath\": \""); - stream.writeText(currentRecord->fBaselinePath.c_str()); + stream.writeText(baselineAbsPath.c_str()); stream.writeText("\",\n"); stream.writeText(" \"testPath\": \""); - stream.writeText(currentRecord->fTestPath.c_str()); + stream.writeText(testAbsPath.c_str()); stream.writeText("\",\n"); stream.writeText(" \"diffs\": [\n"); diff --git a/tools/skpdiff/skpdiff_util.cpp b/tools/skpdiff/skpdiff_util.cpp index 0047959b60..5b19c7311d 100644 --- a/tools/skpdiff/skpdiff_util.cpp +++ b/tools/skpdiff/skpdiff_util.cpp @@ -15,10 +15,15 @@ # include #endif +#if SK_BUILD_FOR_MAC +# include // PATH_MAX is here for Macs +#endif + #if SK_BUILD_FOR_WIN32 # include #endif +#include #include #include "SkOSFile.h" #include "skpdiff_util.h" @@ -181,3 +186,21 @@ bool glob_files(const char globPattern[], SkTArray* entries) { return false; #endif } + +SkString get_absolute_path(const SkString& path) { +#if SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX || SK_BUILD_FOR_ANDROID + SkString fullPath(PATH_MAX + 1); + if (realpath(path.c_str(), fullPath.writable_str()) == NULL) { + fullPath.reset(); + } + return fullPath; +#elif SK_BUILD_FOR_WIN32 + SkString fullPath(MAX_PATH); + if (_fullpath(fullPath.writable_str(), path.c_str(), MAX_PATH) == NULL) { + fullPath.reset(); + } + return fullPath; +#else + return SkString(); +#endif +} diff --git a/tools/skpdiff/skpdiff_util.h b/tools/skpdiff/skpdiff_util.h index 9df1bc0b2a..8750bf6b54 100644 --- a/tools/skpdiff/skpdiff_util.h +++ b/tools/skpdiff/skpdiff_util.h @@ -49,5 +49,12 @@ bool get_directory(const char path[], SkTArray* entries); */ bool glob_files(const char globPattern[], SkTArray* entries); +/** + * Gets the absolute version of the given path. + * @param path The absolute or relative path to expand + * @return The absolute path of the given path on success, or an empty string on failure. + */ +SkString get_absolute_path(const SkString& path); + #endif -- 2.34.1