summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-03-27 18:39:44 -0700
committerGitHub <noreply@github.com>2023-03-28 09:39:44 +0800
commit84dc318576e19ef1f86f6b012ba911c4b63f788d (patch)
treed7c70603509eebfeeb203ec527b71ce92eae59c1 /source
parentca1f93a916ce6b984cba402c8d3710988f2b618f (diff)
Don't touch output file if content did not change. (#2738)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source')
-rw-r--r--source/core/slang-io.cpp11
-rw-r--r--source/core/slang-io.h2
-rw-r--r--source/slang/slang-artifact-output-util.cpp2
3 files changed, 14 insertions, 1 deletions
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp
index 12cbb9ba8..6f97ef45d 100644
--- a/source/core/slang-io.cpp
+++ b/source/core/slang-io.cpp
@@ -993,6 +993,17 @@ namespace Slang
return SLANG_OK;
}
+ SlangResult File::writeAllTextIfChanged(const String& fileName, UnownedStringSlice text)
+ {
+ String existingContent;
+ auto result = File::readAllText(fileName, existingContent);
+ if (SLANG_FAILED(result) || existingContent != text)
+ {
+ return File::writeNativeText(fileName, text.begin(), text.getLength());
+ }
+ return SLANG_OK;
+ }
+
/* static */SlangResult File::writeNativeText(const String& path, const void* data, size_t size)
{
FILE* file = fopen(path.getBuffer(), "w");
diff --git a/source/core/slang-io.h b/source/core/slang-io.h
index 60487e6af..30c477730 100644
--- a/source/core/slang-io.h
+++ b/source/core/slang-io.h
@@ -21,6 +21,8 @@ namespace Slang
static SlangResult writeAllText(const String& fileName, const String& text);
+ static SlangResult writeAllTextIfChanged(const String& fileName, UnownedStringSlice text);
+
/// Write as text in native form for the target (so typically may change line endings )
static SlangResult writeNativeText(const String& filename, const void* data, size_t size);
diff --git a/source/slang/slang-artifact-output-util.cpp b/source/slang/slang-artifact-output-util.cpp
index e9cfe6615..bcf145420 100644
--- a/source/slang/slang-artifact-output-util.cpp
+++ b/source/slang/slang-artifact-output-util.cpp
@@ -176,7 +176,7 @@ static SlangResult _requireBlob(IArtifact* artifact, DiagnosticSink* sink, ComPt
{
if (ArtifactDescUtil::isText(desc))
{
- return File::writeNativeText(path, data, size);
+ return File::writeAllTextIfChanged(path, UnownedStringSlice((const char*)data, size));
}
else
{