Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reapply changes to use posix_spawn_file_actions_addchdir_np on macOS #876

Merged
merged 3 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/Basic/Subprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ int pthread_fchdir_np(int fd)

#ifndef HAVE_POSIX_SPAWN_CHDIR
#if defined(__sun) || \
(defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) || \
__GLIBC_PREREQ(2, 29)
#define HAVE_POSIX_SPAWN_CHDIR 1
#else
Expand All @@ -90,6 +91,12 @@ static int posix_spawn_file_actions_addchdir(posix_spawn_file_actions_t * __rest
#if HAVE_POSIX_SPAWN_CHDIR
return ::posix_spawn_file_actions_addchdir_np(file_actions, path);
#else
#if defined(__APPLE__) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500
if (__builtin_available(macOS 10.15, *)) {
return ::posix_spawn_file_actions_addchdir_np(file_actions, path);
}
#endif

// Any other POSIX platform returns ENOSYS (Function not implemented),
// to simplify the fallback logic around the call site.
return ENOSYS;
Expand Down
10 changes: 9 additions & 1 deletion lib/BuildSystem/ShellCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ bool ShellCommand::processDiscoveredDependencies(BuildSystem& system,

for (const auto& depsPath: depsPaths) {
// Read the dependencies file.
auto input = system.getFileSystem().getFileContents(depsPath);
std::unique_ptr<llvm::MemoryBuffer> input;
if (llvm::sys::path::is_absolute(depsPath)) {
input = system.getFileSystem().getFileContents(depsPath);
} else {
SmallString<PATH_MAX> absPath = StringRef(workingDirectory);
llvm::sys::path::append(absPath, depsPath);
llvm::sys::fs::make_absolute(absPath);
input = system.getFileSystem().getFileContents(StringRef(absPath));
}
if (!input) {
system.getDelegate().commandHadError(
this, "unable to open dependencies file (" + depsPath + ")");
Expand Down
20 changes: 18 additions & 2 deletions products/libllbuild/BuildSystem-C-API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,15 @@ class CAPIExternalCommand : public ExternalCommand {
QueueJobContext* context,
std::string depsPath) {
// Read the dependencies file.
auto input = system.getFileSystem().getFileContents(depsPath);
std::unique_ptr<llvm::MemoryBuffer> input;
if (llvm::sys::path::is_absolute(depsPath)) {
input = system.getFileSystem().getFileContents(depsPath);
} else {
SmallString<PATH_MAX> absPath = StringRef(workingDirectory);
llvm::sys::path::append(absPath, depsPath);
llvm::sys::fs::make_absolute(absPath);
input = system.getFileSystem().getFileContents(StringRef(absPath));
}
if (!input) {
system.getDelegate().commandHadError(this, "unable to open dependencies file (" + depsPath + ")");
return false;
Expand Down Expand Up @@ -778,7 +786,15 @@ class CAPIExternalCommand : public ExternalCommand {
QueueJobContext* context,
std::string depsPath) {
// Read the dependencies file.
auto input = system.getFileSystem().getFileContents(depsPath);
std::unique_ptr<llvm::MemoryBuffer> input;
if (llvm::sys::path::is_absolute(depsPath)) {
input = system.getFileSystem().getFileContents(depsPath);
} else {
SmallString<PATH_MAX> absPath = StringRef(workingDirectory);
llvm::sys::path::append(absPath, depsPath);
llvm::sys::fs::make_absolute(absPath);
input = system.getFileSystem().getFileContents(StringRef(absPath));
}
if (!input) {
system.getDelegate().commandHadError(this, "unable to open dependencies file (" + depsPath + ")");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

# Check a build that modifies the header.
#
# RUN: echo "mod" >> %t.build/header-1
# RUN: echo "mod" >> %t.build/wd/header-1
# RUN: %{llbuild} buildsystem build --serial --chdir %t.build &> %t2.out
# RUN: %{FileCheck} --check-prefix=CHECK-AFTER-MOD --input-file=%t2.out %s
#
Expand Down