summaryrefslogtreecommitdiffstats
path: root/source/compiler-core
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-04-24 12:43:48 -0400
committerGitHub <noreply@github.com>2023-04-24 12:43:48 -0400
commitfbe37ea6d90f7bfe18506b042657c6e533eaf9b2 (patch)
tree3ba92ecef38e5e4518bfb31e982573fbfe5fa661 /source/compiler-core
parentcef7a478de583cdd4825d642f055a90948b833bc (diff)
Fix issue with Obfuscated hash (#2834)
* #include an absolute path didn't work - because paths were taken to always be relative. * Remove legacy container writing. Test using module without source map. * Change hashing for obfuscated source map such that takes into account different line endings.
Diffstat (limited to 'source/compiler-core')
-rw-r--r--source/compiler-core/slang-artifact-container-util.cpp89
-rw-r--r--source/compiler-core/slang-artifact-container-util.h3
2 files changed, 13 insertions, 79 deletions
diff --git a/source/compiler-core/slang-artifact-container-util.cpp b/source/compiler-core/slang-artifact-container-util.cpp
index dfc385f9a..94ea792c2 100644
--- a/source/compiler-core/slang-artifact-container-util.cpp
+++ b/source/compiler-core/slang-artifact-container-util.cpp
@@ -462,75 +462,6 @@ SlangResult FileSystemContents::find(ISlangFileSystemExt* fileSystem, const Unow
return SLANG_OK;
}
-/* static */SlangResult ArtifactContainerUtil::writeLegacy(IArtifact* artifact, const String& fileName)
-{
- ComPtr<ISlangBlob> containerBlob;
- SLANG_RETURN_ON_FAIL(artifact->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 : artifact->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(fileName);
-
- if (nameCount != 0)
- {
- baseName.appendChar('-');
- baseName.append(nameCount);
- }
-
- SLANG_RETURN_ON_FAIL(ArtifactUtil::calcName(associatedArtifact, baseName.getUnownedSlice(), artifactFilename));
-
- nameCount ++;
- }
-
- ComPtr<ISlangBlob> 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()));
- }
- }
- }
- }
-
- return SLANG_OK;
-}
-
static SlangResult _remove(ISlangMutableFileSystem* fileSystem, const String& path)
{
SlangPathType pathType;
@@ -547,11 +478,11 @@ static SlangResult _remove(ISlangMutableFileSystem* fileSystem, const String& pa
const auto ext = Path::getPathExt(fileName);
- if (ext == "zip")
+ if (ext == toSlice("zip"))
{
SLANG_RETURN_ON_FAIL(_remove(osFileSystem, fileName));
- // Create the zip
+ // Create the zip
ComPtr<ISlangMutableFileSystem> fileSystem;
SLANG_RETURN_ON_FAIL(ZipFileSystem::create(fileSystem));
@@ -567,13 +498,12 @@ static SlangResult _remove(ISlangMutableFileSystem* fileSystem, const String& pa
// Okay we can now write out the zip
SLANG_RETURN_ON_FAIL(osFileSystem->saveFileBlob(fileName.getBuffer(), blob));
-
return SLANG_OK;
}
else if (ext == toSlice("dir"))
{
// We use the special extension "dir" to write out to a directory.
- // This is a little hokey, but at list is consistent
+ // This is a little hokey arguably...
auto path = Path::getPathWithoutExt(fileName);
SLANG_RETURN_ON_FAIL(_remove(osFileSystem, path));
@@ -583,11 +513,18 @@ static SlangResult _remove(ISlangMutableFileSystem* fileSystem, const String& pa
ComPtr<ISlangMutableFileSystem> fileSystem(new RelativeFileSystem(osFileSystem, path));
SLANG_RETURN_ON_FAIL(writeContainer(artifact, fileName, fileSystem));
+ return SLANG_OK;
}
- else
+
+ // In order to write out as a artifact hierarchy we need a file system. If we don't have that
+ // we only write out the "main" (or root) artifact. All associated/children are typically ignored.
{
- // This is the legacy way to write out the container artifact
- SLANG_RETURN_ON_FAIL(ArtifactContainerUtil::writeLegacy(artifact, fileName));
+ // Get the artifact as a blob
+ ComPtr<ISlangBlob> containerBlob;
+ SLANG_RETURN_ON_FAIL(artifact->loadBlob(ArtifactKeep::Yes, containerBlob.writeRef()));
+
+ // Write out the blob
+ SLANG_RETURN_ON_FAIL(osFileSystem->saveFileBlob(fileName.getBuffer(), containerBlob));
}
return SLANG_OK;
diff --git a/source/compiler-core/slang-artifact-container-util.h b/source/compiler-core/slang-artifact-container-util.h
index 0ee99de26..68c1f11f5 100644
--- a/source/compiler-core/slang-artifact-container-util.h
+++ b/source/compiler-core/slang-artifact-container-util.h
@@ -21,9 +21,6 @@ or other file like representations
*/
struct ArtifactContainerUtil
{
- /// Writes using the legacy mechanism
- static SlangResult writeLegacy(IArtifact* artifact, const String& filename);
-
/// Write the container using the specified path.
/// Uses the extension of the path to determine how to write
static SlangResult writeContainer(IArtifact* artifact, const String& path);