diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-09-01 10:06:19 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-01 10:06:19 -0400 |
| commit | 3c0177134d126956336865623ea3d6861be59cfa (patch) | |
| tree | 920ba158afe75edde6f5254617dfa22ffeb98403 /source/compiler-core/slang-artifact-handler-impl.cpp | |
| parent | cd8715a7760189c54b36c0c250efbe1db5b8635c (diff) | |
Make FileSystem files and OS files distinct (#2383)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Make DownstreamCompileOptions use POD types.
* CharSliceAllocator -> SliceAllocator
Added SliceConverter
CharSliceCaster -> SliceCaster
* First attempt at zero terminating around blobs.
* Fix clang warning.
* Add SlangTerminatedChars
Make Blob implementations support it.
Make most blobs 'terminated'.
* Fix bug setting up sourceFiles for CommandLineDownstreamCompiler.
* Traffic in TerminatedCharSlice for sourceFiles.
Use ArtifactDesc to generate temporary file names for source.
* Fix typo in testing for shared library/C++.
* Working with source being passed as artifacts to DownstreamCompiler.
* Use artifacts in SourceManager/SourceFile.
* Support infering extension from the original file extension.
* * Infer extension if can't determine from the artifact type
* Split IOSFile/IExtFile representations
* Move responsibility for creating OS file to the handler.
* Disable the check memory path.
Diffstat (limited to 'source/compiler-core/slang-artifact-handler-impl.cpp')
| -rw-r--r-- | source/compiler-core/slang-artifact-handler-impl.cpp | 87 |
1 files changed, 56 insertions, 31 deletions
diff --git a/source/compiler-core/slang-artifact-handler-impl.cpp b/source/compiler-core/slang-artifact-handler-impl.cpp index 94e6fb6f7..d7c3f02b6 100644 --- a/source/compiler-core/slang-artifact-handler-impl.cpp +++ b/source/compiler-core/slang-artifact-handler-impl.cpp @@ -7,9 +7,12 @@ #include "slang-artifact-desc-util.h" #include "slang-artifact-helper.h" +#include "slang-artifact-util.h" #include "../core/slang-castable-util.h" +#include "slang-slice-allocator.h" + #include "../core/slang-file-system.h" #include "../core/slang-io.h" #include "../core/slang-shared-library.h" @@ -148,42 +151,72 @@ SlangResult DefaultArtifactHandler::getOrCreateRepresentation(IArtifact* artifac SLANG_RETURN_ON_FAIL(_loadSharedLibrary(artifact, sharedLib.writeRef())); return _addRepresentation(artifact, keep, sharedLib, outCastable); } + else if (guid == IOSFileArtifactRepresentation::getTypeGuid()) + { + ComPtr<IOSFileArtifactRepresentation> fileRep; + SLANG_RETURN_ON_FAIL(_createOSFile(artifact, getIntermediateKeep(keep), fileRep.writeRef())); + return _addRepresentation(artifact, keep, fileRep, outCastable); + } return SLANG_E_NOT_AVAILABLE; } -static bool _isFileSystemFile(ICastable* castable, void* data) +SlangResult DefaultArtifactHandler::_createOSFile(IArtifact* artifact, ArtifactKeep keep, IOSFileArtifactRepresentation** outFileRep) { - if (auto fileRep = as<IFileArtifactRepresentation>(castable)) + // Look if we have an IExtFile representation, as we might already have a OS file associated with that + if (auto extRep = findRepresentation<IExtFileArtifactRepresentation>(artifact)) { - ISlangMutableFileSystem* fileSystem = (ISlangMutableFileSystem*)data; - if (fileRep->getFileSystem() == fileSystem) + auto system = extRep->getFileSystem(); + + String path; + switch (system->getOSPathKind()) { - return true; + case OSPathKind::Direct: + { + path = UnownedStringSlice(extRep->getPath()); + break; + } + case OSPathKind::Canonical: + { + ComPtr<ISlangBlob> canonicalPathBlob; + if (SLANG_SUCCEEDED(system->getCanonicalPath(extRep->getPath(), canonicalPathBlob.writeRef()))) + { + path = StringUtil::getString(canonicalPathBlob); + } + break; + } + default: break; } - } - return false; -} -SlangResult DefaultArtifactHandler::getOrCreateFileRepresentation(IArtifact* artifact, ArtifactKeep keep, ISlangMutableFileSystem* fileSystem, IFileArtifactRepresentation** outFileRep) -{ - // See if we already have it - if (auto fileRep = as<IFileArtifactRepresentation>(artifact->findRepresentationWithPredicate(&_isFileSystemFile, fileSystem))) - { - fileRep->addRef(); - *outFileRep = fileRep; - return SLANG_OK; + if (path.getLength()) + { + auto fileRep = OSFileArtifactRepresentation::create(IOSFileArtifactRepresentation::Kind::Reference, path.getUnownedSlice() , nullptr); + // As a sanity check make sure it exists! + if (fileRep->exists()) + { + *outFileRep = fileRep.detach(); + return SLANG_OK; + } + } } + // Okay looks like we will need to generate a temporary file auto helper = DefaultArtifactHelper::getSingleton(); // If we are going to access as a file we need to be able to write it, and to do that we need a blob ComPtr<ISlangBlob> blob; SLANG_RETURN_ON_FAIL(artifact->loadBlob(getIntermediateKeep(keep), blob.writeRef())); + // Find some name associated + auto name = ArtifactUtil::findName(artifact); + if (name.getLength() == 0) + { + name = toSlice("unknown"); + } + // Okay we need to store as a temporary. Get a lock file. - ComPtr<IFileArtifactRepresentation> lockFile; - SLANG_RETURN_ON_FAIL(helper->createLockFile(artifact->getName(), fileSystem, lockFile.writeRef())); + ComPtr<IOSFileArtifactRepresentation> lockFile; + SLANG_RETURN_ON_FAIL(helper->createLockFile(asCharSlice(name), lockFile.writeRef())); // Now we need the appropriate name for this item ComPtr<ISlangBlob> pathBlob; @@ -194,7 +227,7 @@ SlangResult DefaultArtifactHandler::getOrCreateFileRepresentation(IArtifact* art // Write the contents SLANG_RETURN_ON_FAIL(File::writeAllBytes(path, blob->getBufferPointer(), blob->getBufferSize())); - ComPtr<IFileArtifactRepresentation> fileRep; + ComPtr<IOSFileArtifactRepresentation> fileRep; // TODO(JS): This path comparison is perhaps not perfect, in that it assumes the path is not changed // in any way. For example an impl of calcArtifactPath that changed slashes or used a canonical path @@ -209,13 +242,7 @@ SlangResult DefaultArtifactHandler::getOrCreateFileRepresentation(IArtifact* art else { // Create a new rep that references the lock file - fileRep = new FileArtifactRepresentation(IFileArtifactRepresentation::Kind::Owned, path, lockFile, lockFile->getFileSystem()); - } - - // Create the rep - if (canKeep(keep)) - { - artifact->addRepresentation(fileRep); + fileRep = new OSFileArtifactRepresentation(IOSFileArtifactRepresentation::Kind::Owned, path, lockFile); } // Return the file @@ -232,14 +259,11 @@ SlangResult DefaultArtifactHandler::_loadSharedLibrary(IArtifact* artifact, ISla isDerivedFrom(desc.payload, ArtifactPayload::CPULike)) { // Get as a file represenation on the OS file system - ComPtr<IFileArtifactRepresentation> fileRep; + ComPtr<IOSFileArtifactRepresentation> fileRep; // We want to keep the file representation, otherwise every request, could produce a new file // and that seems like a bad idea. - SLANG_RETURN_ON_FAIL(artifact->requireFile(ArtifactKeep::Yes, nullptr, fileRep.writeRef())); - - // We requested on the OS file system, just check that's what we got... - SLANG_ASSERT(fileRep->getFileSystem() == nullptr); + SLANG_RETURN_ON_FAIL(artifact->requireFile(ArtifactKeep::Yes, fileRep.writeRef())); // Try loading the shared library SharedLibrary::Handle handle; @@ -247,6 +271,7 @@ SlangResult DefaultArtifactHandler::_loadSharedLibrary(IArtifact* artifact, ISla { return SLANG_FAIL; } + // Output *outSharedLibrary = ScopeSharedLibrary::create(handle, fileRep).detach(); return SLANG_OK; |
