Skip to content

Commit 0726267

Browse files
Make goto-gcc generate executables with execute permissions set on OSX
1 parent 9701c54 commit 0726267

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/goto-cc/hybrid_binary.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Author: Michael Tautschnig, 2018
1616

1717
#include <cstring>
1818

19+
#if defined(__APPLE__)
20+
# include <sys/stat.h>
21+
#endif
22+
1923
int hybrid_binary(
2024
const std::string &compiler_or_linker,
2125
const std::string &goto_binary_file,
@@ -85,6 +89,23 @@ int hybrid_binary(
8589
"-output", output_file };
8690

8791
result = run(lipo_argv[0], lipo_argv);
92+
93+
if(result == 0)
94+
{
95+
// lipo creates an output file, but it does not set execute permissions,
96+
// so the user is unable to directly execute the output file until its
97+
// chmod +x
98+
mode_t current_umask = umask(0);
99+
umask(current_umask);
100+
int chmod_result = chmod(
101+
output_file.c_str(), (S_IRWXU | S_IRWXG | S_IRWXO) & ~current_umask);
102+
if(chmod_result != 0)
103+
{
104+
message.error() << "Setting execute permissions failed: "
105+
<< std::strerror(errno) << messaget::eom;
106+
result = chmod_result;
107+
}
108+
}
88109
}
89110
else
90111
{

src/goto-cc/module_dependencies.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ jsil
66
json
77
langapi # should go away
88
linking
9+
sys # system
910
util

0 commit comments

Comments
 (0)