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-util.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-util.cpp')
| -rw-r--r-- | source/compiler-core/slang-artifact-util.cpp | 119 |
1 files changed, 25 insertions, 94 deletions
diff --git a/source/compiler-core/slang-artifact-util.cpp b/source/compiler-core/slang-artifact-util.cpp index 047e87db0..413bd5efe 100644 --- a/source/compiler-core/slang-artifact-util.cpp +++ b/source/compiler-core/slang-artifact-util.cpp @@ -95,124 +95,55 @@ namespace Slang { return artifact->findArtifactByPredicate(IArtifact::FindStyle::SelfOrChildren, &ArtifactUtil::isSignificant, nullptr); } -/* static */String ArtifactUtil::getBaseName(IArtifact* artifact) -{ - if (auto fileRep = findRepresentation<IFileArtifactRepresentation>(artifact)) - { - return ArtifactDescUtil::getBaseName(artifact->getDesc(), fileRep); - } - // Else use the name - return artifact->getName(); -} - -/* static */String ArtifactUtil::getParentPath(IFileArtifactRepresentation* fileRep) -{ - UnownedStringSlice path(fileRep->getPath()); - return Path::getParentDirectory(path); -} - -/* static */String ArtifactUtil::getParentPath(IArtifact* artifact) -{ - if (auto fileRep = findRepresentation<IFileArtifactRepresentation>(artifact)) - { - return getParentPath(fileRep); - } - return String(); -} - -/* static */IFileArtifactRepresentation* ArtifactUtil::findFileSystemTemporaryFile(IArtifact* artifact) -{ - if (auto fileRep = findFileSystemFile(artifact)) - { - return fileRep->getLockFile() ? fileRep : nullptr; - } - return nullptr; -} - -/* static */IFileArtifactRepresentation* ArtifactUtil::findFileSystemFile(IArtifact* artifact) +UnownedStringSlice ArtifactUtil::findPath(IArtifact* artifact) { - for (auto rep : artifact->getRepresentations()) + // If a name is set we'll just use that { - if (auto fileSystemRep = as<IFileArtifactRepresentation>(rep)) + const UnownedStringSlice name(artifact->getName()); + if (name.getLength()) { - if (fileSystemRep->getFileSystem() == nullptr) - { - return fileSystemRep; - } + return name; } } - return nullptr; -} -/* static */IFileArtifactRepresentation* ArtifactUtil::findFileSystemPrimaryFile(IArtifact* artifact) -{ + IPathArtifactRepresentation* bestRep = nullptr; + + // Look for a rep with a path. Prefer IExtFile because a IOSFile might be a temporary file for (auto rep : artifact->getRepresentations()) { - if (auto fileRep = as<IFileArtifactRepresentation>(rep)) + if (auto pathRep = as<IPathArtifactRepresentation>(rep)) { - // If it has a file system it's not on OS - // If it has a lock file it can be assumed to be temporary - if (fileRep->getFileSystem() != nullptr || - fileRep->getLockFile()) - { - continue; - } - - // If it's a file that is persistant it will just be a reference to a pre-existing file - const auto kind = fileRep->getKind(); - if (kind != IFileArtifactRepresentation::Kind::Reference) + if (pathRep->getPathType() == SLANG_PATH_TYPE_FILE && + (bestRep == nullptr || as<IExtFileArtifactRepresentation>(rep))) { - continue; + bestRep = pathRep; } - - return fileRep; } } - return nullptr; + + const UnownedStringSlice name = bestRep ? UnownedStringSlice(bestRep->getPath()) : UnownedStringSlice(); + return name.getLength() ? name : UnownedStringSlice(); } -UnownedStringSlice ArtifactUtil::findPath(IArtifact* artifact) +/* static */UnownedStringSlice ArtifactUtil::inferExtension(IArtifact* artifact) { - // If a name is set we'll just use that - { - const char* name = artifact->getName(); - if (name && name[0] != 0) - { - return UnownedStringSlice(name); - } - } - - // Find the *first* file rep and use it's path. - // This may not be the file on the file system - but is probably the path/name the user most associated with the artifact - if (auto fileRep = findRepresentation<IFileArtifactRepresentation>(artifact)) + const UnownedStringSlice path = findPath(artifact); + if (path.getLength()) { - // If there isn't a lock file it is - if (fileRep->getLockFile() == nullptr) + auto ext = Path::getPathExt(UnownedStringSlice(path)); + if (ext.getLength()) { - return UnownedStringSlice(fileRep->getPath()); + return ext; } } - return UnownedStringSlice(); } -/* static */UnownedStringSlice ArtifactUtil::inferExtension(IArtifact* artifact) +/* static */UnownedStringSlice ArtifactUtil::findName(IArtifact* artifact) { - for (auto rep :artifact->getRepresentations()) - { - if (auto fileRep = as<IFileArtifactRepresentation>(rep)) - { - const char* path = fileRep->getPath(); - auto ext = Path::getPathExt(UnownedStringSlice(path)); - if (ext.getLength()) - { - return ext; - } - } - } - - // Okay lets see if the name has an extension - return Path::getPathExt(UnownedStringSlice(artifact->getName())); + const UnownedStringSlice path = findPath(artifact); + const Index pos = Path::findLastSeparatorIndex(path); + return (pos >= 0) ? path.tail(pos + 1) : path; } static SlangResult _calcInferred(IArtifact* artifact, const UnownedStringSlice& basePath, StringBuilder& outPath) |
