summaryrefslogtreecommitdiff
path: root/source/compiler-core/slang-artifact.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-06-24 16:08:08 -0400
committerGitHub <noreply@github.com>2022-06-24 16:08:08 -0400
commitf1b41a71be938b8711ee0fff0130185f512d2336 (patch)
tree29ad602a61968e1aacdf8424afc0c89defdb4330 /source/compiler-core/slang-artifact.cpp
parentc12c0ad7fbb0272283f224493dbc28d9d60e7b91 (diff)
Handling of temporary files (#2299)
* #include an absolute path didn't work - because paths were taken to always be relative. * Work around windows issue with temporary file clash. * Handle the temporary file path actually creates a file. * Fix typo. * Fix typo in linux for temporary file. * Add unit test for io. Tests generateTemporary operation.
Diffstat (limited to 'source/compiler-core/slang-artifact.cpp')
-rw-r--r--source/compiler-core/slang-artifact.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/source/compiler-core/slang-artifact.cpp b/source/compiler-core/slang-artifact.cpp
index 5e5b93578..bf61763c8 100644
--- a/source/compiler-core/slang-artifact.cpp
+++ b/source/compiler-core/slang-artifact.cpp
@@ -58,10 +58,16 @@ void* Artifact::getInterface(const Guid& uuid)
Artifact::~Artifact()
{
+ // Remove the temporary
if (m_pathType == PathType::Temporary)
{
File::remove(m_path);
}
+ // If there is a temporary lock path, remove that
+ if (m_temporaryLockPath.getLength())
+ {
+ File::remove(m_temporaryLockPath);
+ }
}
bool Artifact::exists()
@@ -192,8 +198,10 @@ SlangResult Artifact::requireFile(Keep keep)
// TODO(JS): NOTE! This isn't strictly correct, as the generated filename is not guarenteed to be unique
// if we change it with an extension (or prefix).
// This doesn't change the previous behavior though.
- String path;
- SLANG_RETURN_ON_FAIL(File::generateTemporary(nameBase, path));
+ String temporaryLockPath;
+ SLANG_RETURN_ON_FAIL(File::generateTemporary(nameBase, temporaryLockPath));
+
+ String path = temporaryLockPath;
if (ArtifactInfoUtil::isCpuBinary(m_desc) &&
(m_desc.kind == ArtifactKind::SharedLibrary ||
@@ -221,7 +229,6 @@ SlangResult Artifact::requireFile(Keep keep)
}
// If there is an extension append it
-
const UnownedStringSlice ext = ArtifactInfoUtil::getDefaultExtension(m_desc);
if (ext.getLength())
@@ -230,6 +237,13 @@ SlangResult Artifact::requireFile(Keep keep)
path.append(ext);
}
+ // If the final path is different from the lock path save that path
+ if (path != temporaryLockPath)
+ {
+ m_temporaryLockPath = temporaryLockPath;
+ }
+
+ // Write the contents
SLANG_RETURN_ON_FAIL(File::writeAllBytes(path, blob->getBufferPointer(), blob->getBufferSize()));
// Okay we can now add this as temporary path too
@@ -244,9 +258,6 @@ SlangResult Artifact::loadBlob(Keep keep, ISlangBlob** outBlob)
if (!blob)
{
- // TODO(JS):
- // Strictly speaking we could *potentially* convert some other representation into
- // a blob by serializing it, but we don't worry about any of that here
if (m_pathType != PathType::None)
{
// Read into a blob
@@ -258,6 +269,7 @@ SlangResult Artifact::loadBlob(Keep keep, ISlangBlob** outBlob)
}
else
{
+ // Look for a representation that we can serialize into a blob
for (const auto& element : m_elements)
{
ISlangUnknown* intf = element.value;
@@ -275,7 +287,6 @@ SlangResult Artifact::loadBlob(Keep keep, ISlangBlob** outBlob)
}
// Wasn't able to construct
-
if (!blob)
{
return SLANG_E_NOT_FOUND;