summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-file-system.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-11-01 15:57:51 -0400
committerGitHub <noreply@github.com>2019-11-01 15:57:51 -0400
commit608b7fba5411f9de2193ac604d38363463807410 (patch)
treec2f34e81b6fe137b59c2cc99064fd6ed3d2a33f3 /source/slang/slang-file-system.cpp
parent068f2a2552ba49335a8a1e72e1731d047335fe82 (diff)
Using repro as a file system (#1104)
* Added RiffReadHelper * Move type to fourCC in Chunk simplifies some code. * Make MemoryArena able to track external blocks. Allow ownership of Data to vary. Changed IR serialization to use moved allocations to avoid copies. As it turns out all of the array writes could use unowned data, but doing so requires the IRData to stay in scope longer than IRSerialData, which it does at the moment - but perhaps needs better naming or a control for the feature. * Write out slang-module container. * WIP on -r option. Loading modules - with -r. * Making the serialized-module run (without using imported module). * Split compiling module from the test. * Separate module compilation with a function working. * Remove serialization test as not used. * Fix warning on gcc. * Updated test to have types across module boundary. * Allow entry point declaration. A test that tries to build with just an entry point declaration and a module. * Try to make link work with multiple modules. * Multi module linking first pass working. * Multi module test working with -module-name option * Added feature to repro manifest of approximation of command line that was used. * Use isDefinition - for determining to add decorations to entry point lowering. * Added support for repo-file-system.h More precise control of CacheFileSystem. Allow RelativeFileSystem to strip paths optionally. Use canonical paths in PathInfo cache. Fix bug in -D options for command line output of StateSerailizeUtil * Add missing slang-options.h * Fix bug in bit slang-state-serialize.cpp with bit removal. * Added documentation around -repro-file-system Added spLoadReproAsFileSystem function. * Fix warning.
Diffstat (limited to 'source/slang/slang-file-system.cpp')
-rw-r--r--source/slang/slang-file-system.cpp110
1 files changed, 63 insertions, 47 deletions
diff --git a/source/slang/slang-file-system.cpp b/source/slang/slang-file-system.cpp
index 7d6d6df66..c6bee28e1 100644
--- a/source/slang/slang-file-system.cpp
+++ b/source/slang/slang-file-system.cpp
@@ -203,18 +203,35 @@ SLANG_NO_THROW SlangResult SLANG_MCALL CacheFileSystem::queryInterface(SlangUUID
}
-CacheFileSystem::CacheFileSystem(ISlangFileSystem* fileSystem, UniqueIdentityMode uniqueIdentityMode, PathStyle pathStyle) :
- m_fileSystem(fileSystem),
- m_uniqueIdentityMode(uniqueIdentityMode),
- m_pathStyle(pathStyle)
+CacheFileSystem::CacheFileSystem(ISlangFileSystem* fileSystem, UniqueIdentityMode uniqueIdentityMode, PathStyle pathStyle)
{
+ setInnerFileSystem(fileSystem, uniqueIdentityMode, pathStyle);
+}
+
+CacheFileSystem::~CacheFileSystem()
+{
+ for (const auto& pair : m_uniqueIdentityMap)
+ {
+ delete pair.Value;
+ }
+}
+
+void CacheFileSystem::setInnerFileSystem(ISlangFileSystem* fileSystem, UniqueIdentityMode uniqueIdentityMode, PathStyle pathStyle)
+{
+ m_fileSystem = fileSystem;
+
+ m_uniqueIdentityMode = uniqueIdentityMode;
+ m_pathStyle = pathStyle;
+
+ m_fileSystemExt.setNull();
+
if (fileSystem)
{
// Try to get the more sophisticated interface
fileSystem->queryInterface(IID_ISlangFileSystemExt, (void**)m_fileSystemExt.writeRef());
}
- switch (uniqueIdentityMode)
+ switch (m_uniqueIdentityMode)
{
case UniqueIdentityMode::Default:
case UniqueIdentityMode::FileSystemExt:
@@ -226,29 +243,22 @@ CacheFileSystem::CacheFileSystem(ISlangFileSystem* fileSystem, UniqueIdentityMod
default: break;
}
- if (m_fileSystemExt)
- {
- // We just defer to the m_fileSystem, so we mark as unknown
- m_pathStyle = PathStyle::Unknown;
- }
- else if (m_pathStyle == PathStyle::Default)
+ if (pathStyle == PathStyle::Default)
{
// We'll assume it's simplify-able
m_pathStyle = PathStyle::Simplifiable;
+ // If we have fileSystemExt, we defer to that
+ if (m_fileSystemExt)
+ {
+ // We just defer to the m_fileSystem
+ m_pathStyle = PathStyle::FileSystemExt;
+ }
}
// It can't be default
SLANG_ASSERT(m_uniqueIdentityMode != UniqueIdentityMode::Default);
}
-CacheFileSystem::~CacheFileSystem()
-{
- for (const auto& pair : m_uniqueIdentityMap)
- {
- delete pair.Value;
- }
-}
-
void CacheFileSystem::clearCache()
{
for (const auto& pair : m_uniqueIdentityMap)
@@ -450,14 +460,17 @@ SlangResult CacheFileSystem::getFileUniqueIdentity(const char* path, ISlangBlob*
SlangResult CacheFileSystem::calcCombinedPath(SlangPathType fromPathType, const char* fromPath, const char* path, ISlangBlob** pathOut)
{
// Just defer to contained implementation
- if (m_fileSystemExt)
- {
- return m_fileSystemExt->calcCombinedPath(fromPathType, fromPath, path, pathOut);
- }
- else
+ switch (m_pathStyle)
{
- // Just use the default implementation
- return _calcCombinedPath(fromPathType, fromPath, path, pathOut);
+ case PathStyle::FileSystemExt:
+ {
+ return m_fileSystemExt->calcCombinedPath(fromPathType, fromPath, path, pathOut);
+ }
+ default:
+ {
+ // Just use the default implementation
+ return _calcCombinedPath(fromPathType, fromPath, path, pathOut);
+ }
}
}
@@ -498,34 +511,24 @@ SlangResult CacheFileSystem::getPathType(const char* pathIn, SlangPathType* path
SlangResult CacheFileSystem::getSimplifiedPath(const char* path, ISlangBlob** outSimplifiedPath)
{
// If we have a ISlangFileSystemExt we can just pass on the request to it
- if (m_fileSystemExt)
+ switch (m_pathStyle)
{
- return m_fileSystemExt->getSimplifiedPath(path, outSimplifiedPath);
- }
- else
- {
- // Use the path style to see what we can do with it
- switch (m_pathStyle)
+ case PathStyle::FileSystemExt:
{
- case PathStyle::Simplifiable:
- {
- String simplifiedPath = Path::simplify(_fixPathDelimiters(path));
- *outSimplifiedPath = StringUtil::createStringBlob(simplifiedPath).detach();
- return SLANG_OK;
- }
- default: return SLANG_E_NOT_IMPLEMENTED;
+ return m_fileSystemExt->getSimplifiedPath(path, outSimplifiedPath);
}
+ case PathStyle::Simplifiable:
+ {
+ String simplifiedPath = Path::simplify(_fixPathDelimiters(path));
+ *outSimplifiedPath = StringUtil::createStringBlob(simplifiedPath).detach();
+ return SLANG_OK;
+ }
+ default: return SLANG_E_NOT_IMPLEMENTED;
}
}
SlangResult CacheFileSystem::getCanonicalPath(const char* path, ISlangBlob** outCanonicalPath)
{
- // If we don't have a backing full file system, we can't produce a canonical path with just ISlangFileSystem::loadFile
- if (!m_fileSystemExt)
- {
- return SLANG_E_NOT_IMPLEMENTED;
- }
-
// A file must exist to get a canonical path...
PathInfo* info = _resolvePathCacheInfo(path);
if (!info)
@@ -536,6 +539,11 @@ SlangResult CacheFileSystem::getCanonicalPath(const char* path, ISlangBlob** out
// We don't have this -> so read it ...
if (info->m_getCanonicalPathResult == CompressedResult::Uninitialized)
{
+ if (!m_fileSystemExt)
+ {
+ return SLANG_E_NOT_IMPLEMENTED;
+ }
+
// Try getting the canonicalPath by asking underlying file system
ComPtr<ISlangBlob> canonicalPathBlob;
SlangResult res = m_fileSystemExt->getCanonicalPath(path, canonicalPathBlob.writeRef());
@@ -576,7 +584,15 @@ ISlangUnknown* RelativeFileSystem::getInterface(const Guid& guid)
SlangResult RelativeFileSystem::_getFixedPath(const char* path, String& outPath)
{
ComPtr<ISlangBlob> blob;
- SLANG_RETURN_ON_FAIL(m_fileSystem->calcCombinedPath(SLANG_PATH_TYPE_DIRECTORY, m_relativePath.getBuffer(), path, blob.writeRef()));
+ if (m_stripPath)
+ {
+ String strippedPath = Path::getFileName(path);
+ SLANG_RETURN_ON_FAIL(m_fileSystem->calcCombinedPath(SLANG_PATH_TYPE_DIRECTORY, m_relativePath.getBuffer(), strippedPath.getBuffer(), blob.writeRef()));
+ }
+ else
+ {
+ SLANG_RETURN_ON_FAIL(m_fileSystem->calcCombinedPath(SLANG_PATH_TYPE_DIRECTORY, m_relativePath.getBuffer(), path, blob.writeRef()));
+ }
outPath = StringUtil::getString(blob);
return SLANG_OK;