summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-04-14 00:00:56 +0800
committerGitHub <noreply@github.com>2023-04-14 00:00:56 +0800
commit59a603593f06ca2935a376b17a91ec42657f1ef8 (patch)
tree16147c6952e526c536597c816bf7ccc4f40f94cd /source
parentc7e5601bb67d2a5ebadb7f84c6968b5912e7566d (diff)
Set the executable bit on Executable artifact files (#2796)
* Set the executable bit on Executable artifact files * Don't zero out other permission bits in makeExecutable
Diffstat (limited to 'source')
-rw-r--r--source/compiler-core/slang-artifact-handler-impl.cpp4
-rw-r--r--source/core/slang-io.cpp18
-rw-r--r--source/slang/slang-artifact-output-util.cpp13
3 files changed, 27 insertions, 8 deletions
diff --git a/source/compiler-core/slang-artifact-handler-impl.cpp b/source/compiler-core/slang-artifact-handler-impl.cpp
index eb5bfc64a..985aa2337 100644
--- a/source/compiler-core/slang-artifact-handler-impl.cpp
+++ b/source/compiler-core/slang-artifact-handler-impl.cpp
@@ -238,6 +238,10 @@ SlangResult DefaultArtifactHandler::_createOSFile(IArtifact* artifact, ArtifactK
// Write the contents
SLANG_RETURN_ON_FAIL(File::writeAllBytes(path, blob->getBufferPointer(), blob->getBufferSize()));
+ if(artifact->getDesc().kind == ArtifactKind::Executable)
+ {
+ SLANG_RETURN_ON_FAIL(File::makeExecutable(path));
+ }
ComPtr<IOSFileArtifactRepresentation> fileRep;
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp
index 6f97ef45d..5c57a4b3a 100644
--- a/source/core/slang-io.cpp
+++ b/source/core/slang-io.cpp
@@ -154,8 +154,22 @@ namespace Slang
// As long as file extension is executable, it can be executed
return SLANG_OK;
#else
- const int ret = ::chmod(fileName.getBuffer(), S_IXUSR);
- return (ret == 0) ? SLANG_OK : SLANG_FAIL;
+ struct stat st;
+ if(::stat(fileName.getBuffer(), &st) != 0)
+ {
+ return SLANG_FAIL;
+ }
+ if(st.st_mode & S_IXUSR)
+ {
+ return SLANG_OK;
+ }
+ // It would probably be slightly neater to set all executable bits
+ // aside from those in umask..
+ if(::chmod(fileName.getBuffer(), st.st_mode & 07777 | S_IXUSR) != 0)
+ {
+ return SLANG_FAIL;
+ }
+ return SLANG_OK;
#endif
}
diff --git a/source/slang/slang-artifact-output-util.cpp b/source/slang/slang-artifact-output-util.cpp
index bcf145420..80c11a466 100644
--- a/source/slang/slang-artifact-output-util.cpp
+++ b/source/slang/slang-artifact-output-util.cpp
@@ -174,14 +174,15 @@ static SlangResult _requireBlob(IArtifact* artifact, DiagnosticSink* sink, ComPt
/* static */SlangResult ArtifactOutputUtil::writeToFile(const ArtifactDesc& desc, const void* data, size_t size, const String& path)
{
- if (ArtifactDescUtil::isText(desc))
+ const SlangResult res = ArtifactDescUtil::isText(desc)
+ ? File::writeAllTextIfChanged(path, UnownedStringSlice((const char*)data, size))
+ : File::writeAllBytes(path, data, size);
+ if(desc.kind == ArtifactKind::Executable)
{
- return File::writeAllTextIfChanged(path, UnownedStringSlice((const char*)data, size));
- }
- else
- {
- return File::writeAllBytes(path, data, size);
+ // Ignore any success code here, assume the one from the actual write is more important.
+ SLANG_RETURN_ON_FAIL(File::makeExecutable(path));
}
+ return res;
}
/* static */SlangResult ArtifactOutputUtil::writeToFile(const ArtifactDesc& desc, ISlangBlob* blob, const String& path)