From eda9dd33647b271dd5ea5256e87cb23ad269b19f Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 12 Apr 2023 12:06:41 -0400 Subject: Artifact Container (#2783) * #include an absolute path didn't work - because paths were taken to always be relative. * WIP simplifying artifact interface. * Use ContainedKind. * Remove LazyCastableList. Use ContainedKind for find. * Remove ICastableList. * Remove need for ICastableList. * Remove IArtifactContainer. * Small fixes. * Small improvements around Artifact. * Make explicit find is for *representations* that can cast. Fix bug in handling casting in lookup. * Made associated items artifacts too. * Small fixes. * Small improvements around writing a container. * WIP artifact container format. * Make the root a special case. * Special case if the artifact doesn't have children/associated. --- source/slang/slang-compiler.cpp | 67 ++--------------------------------------- 1 file changed, 2 insertions(+), 65 deletions(-) (limited to 'source/slang/slang-compiler.cpp') diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 497cf3d94..1a4a12dfe 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -24,6 +24,7 @@ #include "../compiler-core/slang-artifact-util.h" #include "../compiler-core/slang-artifact-associated.h" #include "../compiler-core/slang-artifact-diagnostic-util.h" +#include "../compiler-core/slang-artifact-container-util.h" // Artifact output #include "slang-artifact-output-util.h" @@ -1957,71 +1958,7 @@ namespace Slang { return SLANG_OK; } - - ComPtr containerBlob; - SLANG_RETURN_ON_FAIL(m_containerArtifact->loadBlob(ArtifactKeep::Yes, containerBlob.writeRef())); - - { - FileStream stream; - SLANG_RETURN_ON_FAIL(stream.init(fileName, FileMode::Create, FileAccess::Write, FileShare::ReadWrite)); - SLANG_RETURN_ON_FAIL(stream.write(containerBlob->getBufferPointer(), containerBlob->getBufferSize())); - } - - auto parentPath = Path::getParentDirectory(fileName); - - // Lets look to see if we have any maps - { - Index nameCount = 0; - - for (auto associatedArtifact : m_containerArtifact->getAssociated()) - { - auto desc = associatedArtifact->getDesc(); - - if (isDerivedFrom(desc.payload, ArtifactPayload::SourceMap)) - { - StringBuilder artifactFilename; - - // Dump out - const char* artifactName = associatedArtifact->getName(); - if (artifactName && artifactName[0] != 0) - { - SLANG_RETURN_ON_FAIL(ArtifactUtil::calcName(associatedArtifact, UnownedStringSlice(artifactName), artifactFilename)); - } - else - { - // Perhaps we can generate the name from the output basename - StringBuilder baseName; - - baseName << Path::getFileNameWithoutExt(m_containerOutputPath); - - if (nameCount != 0) - { - baseName.appendChar('-'); - baseName.append(nameCount); - } - - SLANG_RETURN_ON_FAIL(ArtifactUtil::calcName(associatedArtifact, baseName.getUnownedSlice(), artifactFilename)); - - nameCount ++; - } - - ComPtr blob; - SLANG_RETURN_ON_FAIL(associatedArtifact->loadBlob(ArtifactKeep::No, blob.writeRef())); - - // Try to write it out - { - // Work out the path to the artifact - auto artifactPath = Path::combine(parentPath, artifactFilename); - - // Write out the map - FileStream stream; - SLANG_RETURN_ON_FAIL(stream.init(artifactPath, FileMode::Create, FileAccess::Write, FileShare::ReadWrite)); - SLANG_RETURN_ON_FAIL(stream.write(blob->getBufferPointer(), blob->getBufferSize())); - } - } - } - } - + SLANG_RETURN_ON_FAIL(ArtifactContainerUtil::writeContainer(m_containerArtifact, fileName)); return SLANG_OK; } -- cgit v1.2.3