From cd8715a7760189c54b36c0c250efbe1db5b8635c Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 1 Sep 2022 09:35:18 -0400 Subject: Passing source to Downstream compilation as artifacts (#2382) * #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. --- source/compiler-core/slang-source-loc.cpp | 88 +++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) (limited to 'source/compiler-core/slang-source-loc.cpp') diff --git a/source/compiler-core/slang-source-loc.cpp b/source/compiler-core/slang-source-loc.cpp index f245d1e0c..c82636248 100644 --- a/source/compiler-core/slang-source-loc.cpp +++ b/source/compiler-core/slang-source-loc.cpp @@ -4,6 +4,9 @@ #include "../core/slang-string-util.h" #include "../core/slang-string-escape-util.h" +#include "slang-artifact-representation-impl.h" +#include "slang-artifact-impl.h" + namespace Slang { /* !!!!!!!!!!!!!!!!!!!!!!!!! SourceView !!!!!!!!!!!!!!!!!!!!!!!!!!!! */ @@ -22,6 +25,20 @@ const String PathInfo::getMostUniqueIdentity() const } } +String PathInfo::getName() const +{ + switch (type) + { + case Type::Normal: + case Type::FromString: + case Type::FoundPath: + { + return foundPath; + } + } + return String(); +} + bool PathInfo::operator==(const ThisType& rhs) const { // They must be the same type @@ -415,6 +432,77 @@ String SourceFile::calcVerbosePath() const return m_pathInfo.foundPath; } +void SourceFile::maybeAddArtifact(ISlangFileSystemExt* ext) +{ + if (!m_contentBlob) + { + return; + } + + // If there already is an artifact, or we are not using OSFile system then + if (m_artifact) + { + // TODO(JS): + // Check if it has the blob or not + SLANG_ASSERT(m_contentBlob == findRepresentation(m_artifact)); + return; + } + + // We don't know how the source will be used + m_artifact = Artifact::create(ArtifactDesc::make(ArtifactKind::Source, ArtifactPayload::Unknown, ArtifactStyle::Unknown)); + + // Add the blob as a representation. + m_artifact->addRepresentationUnknown(m_contentBlob); + + // If we have the file system see if we can set up a path too + if (ext) + { + const auto osPathKind = ext->getOSPathKind(); + + if (osPathKind != OSPathKind::None) + { + String path; + switch (osPathKind) + { + case OSPathKind::Canonical: + { + // Get the canonical path + ComPtr canonicalPath; + if (SLANG_SUCCEEDED(ext->getCanonicalPath(getPathInfo().foundPath.getBuffer(), canonicalPath.writeRef()))) + { + path = StringUtil::getString(canonicalPath); + } + break; + } + case OSPathKind::Direct: + { + path = getPathInfo().foundPath; + break; + } + } + + if (path.getLength()) + { + // We can sanity check that this works + SlangPathType pathType; + if (SLANG_SUCCEEDED(ext->getPathType(path.getBuffer(), &pathType))) + { + // We can add a file representation + FileArtifactRepresentation* fileRep = new FileArtifactRepresentation(IFileArtifactRepresentation::Kind::Reference, path.getUnownedSlice(), nullptr, nullptr); + m_artifact->addRepresentation(fileRep); + } + } + } + } + + // Get the name + auto name = getPathInfo().getName(); + if (name.getLength()) + { + m_artifact->setName(name.getBuffer()); + } +} + /* !!!!!!!!!!!!!!!!!!!!!!!!! SourceManager !!!!!!!!!!!!!!!!!!!!!!!!!!!! */ void SourceManager::initialize( -- cgit v1.2.3