summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-04-25 08:51:12 -0400
committerGitHub <noreply@github.com>2019-04-25 08:51:12 -0400
commitc84e7c0fa526de51f380227a6667f723af36aea2 (patch)
tree755c034fab30a2d0dfe7f8f6027d892b46d19f87 /source/core
parent1004f50bd7d0032411a564ad4625055e982902ea (diff)
Fixed building on CygWin with clang gcc (#953)
* * Make Path:: use lowerCamel method names as per coding standard * Small improvements to make closer to standard * GetDirectoryName -> getParentDirectory - previous method name's action was somewhat unclear, hopefully this is better * * Can build on clang and gcc on CygWin * Fix problem on cygwin loading shared libraries * Renamed Path::isRelative to ::hasRelativeElement because isRelative implies the path is 'relative to the current path' and which isn't quite what it does * Documented how to build for CygWin * * Fix small bug creating platform shared library name. * Small typo fixes in building.md
Diffstat (limited to 'source/core')
-rw-r--r--source/core/platform.cpp5
-rw-r--r--source/core/slang-io.cpp68
-rw-r--r--source/core/slang-io.h15
3 files changed, 83 insertions, 5 deletions
diff --git a/source/core/platform.cpp b/source/core/platform.cpp
index ff7d8e231..e7575d21e 100644
--- a/source/core/platform.cpp
+++ b/source/core/platform.cpp
@@ -150,9 +150,14 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY);
/* static */void SharedLibrary::appendPlatformFileName(const UnownedStringSlice& name, StringBuilder& dst)
{
+#if __CYGWIN__
+ dst.Append(name);
+ dst.Append(".dll");
+#else
dst.Append("lib");
dst.Append(name);
dst.Append(".so");
+#endif
}
#endif // _WIN32
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp
index 7385934c3..332718cea 100644
--- a/source/core/slang-io.cpp
+++ b/source/core/slang-io.cpp
@@ -1,6 +1,8 @@
#include "slang-io.h"
#include "exception.h"
+#include "../../slang-com-helper.h"
+
#ifndef __STDC__
# define __STDC__ 1
#endif
@@ -152,7 +154,39 @@ namespace Slang
}
default: return false;
}
-
+ }
+
+ UnownedStringSlice Path::getFirstElement(const UnownedStringSlice& in)
+ {
+ const char* end = in.end();
+ const char* cur = in.begin();
+ // Find delimiter or the end
+ while (cur < end && !Path::isDelimiter(*cur)) ++cur;
+ return UnownedStringSlice(in.begin(), cur);
+ }
+
+ /* static */bool Path::isAbsolute(const UnownedStringSlice& path)
+ {
+ if (path.size() > 0 && isDelimiter(path[0]))
+ {
+ return true;
+ }
+
+#if SLANG_WINDOWS_FAMILY
+ // Check for the \\ network drive style
+ if (path.size() >= 2 && path[0] == '\\' && path[1] == '\\')
+ {
+ return true;
+ }
+
+ // Check for drive
+ if (isDriveSpecification(getFirstElement(path)))
+ {
+ return true;
+ }
+#endif
+
+ return false;
}
/* static */void Path::split(const UnownedStringSlice& path, List<UnownedStringSlice>& splitOut)
@@ -186,7 +220,7 @@ namespace Slang
}
}
- /* static */bool Path::isRelative(const UnownedStringSlice& path)
+ /* static */bool Path::hasRelativeElement(const UnownedStringSlice& path)
{
List<UnownedStringSlice> splitPath;
split(path, splitPath);
@@ -316,6 +350,8 @@ namespace Slang
::free(absPath);
return SLANG_OK;
#else
+# if 1
+
// http://man7.org/linux/man-pages/man3/realpath.3.html
char* canonicalPath = ::realpath(path.begin(), nullptr);
if (canonicalPath)
@@ -325,6 +361,34 @@ namespace Slang
return SLANG_OK;
}
return SLANG_FAIL;
+# else
+ // This is a mechanism to get an approximation of canonical path if we don't have 'realpath'
+ // We only can get if the file exists. This checks that the ../. etc are really valid
+ SlangPathType pathType;
+ SLANG_RETURN_ON_FAIL(getPathType(path, &pathType));
+ if (isAbsolute(path))
+ {
+ // If it's absolute, we can just simplify as is
+ canonicalPathOut = Path::simplify(path);
+ return SLANG_OK;
+ }
+ else
+ {
+ char buffer[PATH_MAX];
+ // https://linux.die.net/man/3/getcwd
+ const char* getCwdPath = getcwd(buffer, SLANG_COUNT_OF(buffer));
+ if (!getCwdPath)
+ {
+ return SLANG_FAIL;
+ }
+
+ // Okay combine the paths
+ String combinedPaths = Path::combine(String(getCwdPath), path);
+ // Simplify
+ canonicalPathOut = Path::simplify(combinedPaths);
+ return SLANG_OK;
+ }
+# endif
#endif
}
diff --git a/source/core/slang-io.h b/source/core/slang-io.h
index a982b7adc..9df8d8d57 100644
--- a/source/core/slang-io.h
+++ b/source/core/slang-io.h
@@ -45,9 +45,13 @@ namespace Slang
static String simplify(const UnownedStringSlice& path);
static String simplify(const String& path) { return simplify(path.getUnownedSlice()); }
- /// Returns true if a path contains a . or ..
- static bool isRelative(const UnownedStringSlice& path);
- static bool isRelative(const String& path) { return isRelative(path.getUnownedSlice()); }
+ /// Returns true if the path is absolute
+ static bool isAbsolute(const UnownedStringSlice& path);
+ static bool isAbsolute(const String& path) { return isAbsolute(path.getUnownedSlice()); }
+
+ /// Returns true if path contains contains an element of . or ..
+ static bool hasRelativeElement(const UnownedStringSlice& path);
+ static bool hasRelativeElement(const String& path) { return hasRelativeElement(path.getUnownedSlice()); }
/// Determines the type of file at the path
/// @param path The path to test
@@ -66,6 +70,11 @@ namespace Slang
/// @return The path in platform native format. Returns empty string if failed.
static String getExecutablePath();
+ /// Returns the first element of the path or an empty slice if there is none
+ /// This broadly equivalent to returning the first element of split
+ /// @param path Path to extract first element from
+ /// @return The first element of the path, or empty
+ static UnownedStringSlice getFirstElement(const UnownedStringSlice& path);
};
}