Files
nixpkgs/pkgs/by-name/xc/xcbuild/patches/Use-system-toolchain-for-usr-bin.patch
Dark Steveneq 646b892680
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s
push sheeet
2025-10-09 14:15:47 +02:00

89 lines
3.5 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
diff -Naur a/Libraries/xcsdk/Tools/xcrun.cpp b/Libraries/xcsdk/Tools/xcrun.cpp
--- a/Libraries/xcsdk/Tools/xcrun.cpp 1970-01-01 09:00:01
+++ b/Libraries/xcsdk/Tools/xcrun.cpp 2024-11-19 01:44:38
@@ -23,10 +23,19 @@
#include <process/DefaultUser.h>
#include <pbxsetting/Type.h>
+#include <algorithm>
+
using libutil::DefaultFilesystem;
using libutil::Filesystem;
using libutil::FSUtil;
+namespace {
+ const std::vector<std::string> kSystemDeveloperDirs = {
+ "/private/var/select/developer_dir",
+ "/private/var/db/xcode_select_link"
+ };
+}
+
class Options {
private:
ext::optional<bool> _help;
@@ -398,6 +407,8 @@
fprintf(stderr, "\n");
}
+ std::unordered_map<std::string, std::string> environment = processContext->environmentVariables();
+
/*
* Collect search paths for the tool.
* Can be in toolchains, target (if one is provided), developer root,
@@ -408,10 +419,46 @@
executablePaths.insert(executablePaths.end(), defaultExecutablePaths.begin(), defaultExecutablePaths.end());
/*
+ * Remove `/usr/bin` from the search paths to avoid infinite recursions from stubs that try to invoke `xcrun`.
+ */
+ const auto originalSize = executablePaths.size();
+ auto result = executablePaths.erase(
+ std::remove(executablePaths.begin(), executablePaths.end(), "/usr/bin"),
+ executablePaths.end()
+ );
+
+ /*
* Find the tool to execute.
*/
ext::optional<std::string> executable = filesystem->findExecutable(*options.tool(), executablePaths);
if (!executable) {
+ /*
+ * However, check for the system developer dir and look there if the binaries cant be found in the store.
+ * This is done only if a binary is not found in the store to ensure those always take priority.
+ * Fixes https://github.com/NixOS/nixpkgs/issues/353875.
+ */
+ std::vector<std::string> toolchainPaths = { };
+ if (executablePaths.size() < originalSize) {
+ for (const auto& dir : kSystemDeveloperDirs) {
+ if (filesystem->exists(dir)) {
+ auto linkTarget = filesystem->readSymbolicLinkCanonical(dir);
+ if (linkTarget) {
+ auto usrBinPath = FSUtil::NormalizePath(*linkTarget + "/usr/bin");
+ if (filesystem->exists(usrBinPath)) {
+ toolchainPaths.push_back(usrBinPath);
+ }
+ auto toolchainUsrBinPath = FSUtil::NormalizePath(*linkTarget + "/Toolchains/XcodeDefault.xctoolchain/usr/bin");
+ if (filesystem->exists(toolchainUsrBinPath)) {
+ toolchainPaths.push_back(toolchainUsrBinPath);
+ }
+ }
+ }
+ }
+ }
+ executable = filesystem->findExecutable(*options.tool(), toolchainPaths);
+ }
+
+ if (!executable) {
fprintf(stderr, "error: tool '%s' not found\n", options.tool()->c_str());
return 1;
}
@@ -427,8 +474,6 @@
return 0;
} else {
/* Run is the default. */
-
- std::unordered_map<std::string, std::string> environment = processContext->environmentVariables();
if (target != nullptr) {
/*