Skip to content

Commit d6b5c68

Browse files
authored
[tools] Fix not utility to work on iOS (#73)
* [tools] Fix not utility to work on iOS This addresses issue #77137. The implementation uses posix_spawn on iOS but std::system elsewhere.
1 parent be6bd27 commit d6b5c68

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

tools/CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,4 @@ else()
4040
llvm_add_host_executable(build-timeit timeit timeit.c)
4141
endif()
4242

43-
# FIXME: the iOS buildbots can't build this since it uses `std::system`, but
44-
# since we don't support Fortram on the iOS bots and this utility is only used
45-
# by Fortran tests, it effectively "reverts to green", without entirely
46-
# reverting the patch.
47-
#
48-
# See: https://github.com/llvm/llvm-project/issues/77137
49-
if(TEST_SUITE_FORTRAN)
50-
add_executable(not ${CMAKE_CURRENT_SOURCE_DIR}/not.cpp)
51-
endif()
43+
add_executable(not ${CMAKE_CURRENT_SOURCE_DIR}/not.cpp)

tools/not.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@
2424
#include <windows.h>
2525
#endif
2626

27-
int main(int argc, const char **argv) {
27+
#ifdef __APPLE__
28+
#include <spawn.h>
29+
#include <sys/wait.h>
30+
#include <TargetConditionals.h>
31+
#endif
32+
33+
int main(int argc, char* const* argv) {
2834
bool expectCrash = false;
2935

3036
++argv;
@@ -49,13 +55,21 @@ int main(int argc, const char **argv) {
4955
if (argc == 0)
5056
return 1;
5157

58+
int result;
59+
#if !defined(TARGET_OS_IPHONE)
5260
std::stringstream ss;
5361
ss << argv[0];
5462
for (int i = 1; i < argc; ++i)
5563
ss << " " << argv[i];
5664
std::string cmd = ss.str();
57-
58-
int result = std::system(cmd.c_str());
65+
result = std::system(cmd.c_str());
66+
#else
67+
pid_t pid;
68+
if (posix_spawn(&pid, argv[0], NULL, NULL, argv, NULL))
69+
return EXIT_FAILURE;
70+
if (waitpid(pid, &result, WUNTRACED | WCONTINUED) == -1)
71+
return EXIT_FAILURE;
72+
#endif
5973
int retcode = 0;
6074
int signal = 0;
6175

0 commit comments

Comments
 (0)