|
13 | 13 | #include "simplecpp.h"
|
14 | 14 |
|
15 | 15 | #include <algorithm>
|
| 16 | +#include <array> |
16 | 17 | #include <cassert>
|
17 | 18 | #include <cctype>
|
18 | 19 | #include <climits>
|
@@ -2432,16 +2433,18 @@ static bool isAbsolutePath(const std::string &path)
|
2432 | 2433 | #endif
|
2433 | 2434 |
|
2434 | 2435 | namespace {
|
2435 |
| - // "<Pkg/Hdr.h>" -> "<Pkg.framework/Headers/Hdr.h>" |
2436 |
| - static inline std::string |
2437 |
| - toAppleFrameworkRelative(const std::string& header) |
| 2436 | + // "<Pkg/Hdr.h>" -> "<Pkg.framework/Headers/Hdr.h>" (and PrivateHeaders variant). |
| 2437 | + // Returns candidates in priority order (Headers, then PrivateHeaders). |
| 2438 | + static inline std::array<std::string,2> |
| 2439 | + toAppleFrameworkRelatives(const std::string& header) |
2438 | 2440 | {
|
2439 | 2441 | const std::size_t slash = header.find('/');
|
2440 | 2442 | if (slash == std::string::npos)
|
2441 |
| - return header; // no transformation applicable |
| 2443 | + return { header, header }; // no transformation applicable |
2442 | 2444 | const std::string pkg = header.substr(0, slash);
|
2443 | 2445 | const std::string tail = header.substr(slash); // includes '/'
|
2444 |
| - return pkg + ".framework/Headers" + tail; |
| 2446 | + return { pkg + ".framework/Headers" + tail, |
| 2447 | + pkg + ".framework/PrivateHeaders" + tail }; |
2445 | 2448 | }
|
2446 | 2449 | }
|
2447 | 2450 |
|
@@ -3015,23 +3018,34 @@ static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const
|
3015 | 3018 | }
|
3016 | 3019 | }
|
3017 | 3020 |
|
3018 |
| - // search the header on the include paths (provided by the flags "-I...") |
3019 |
| - for (const auto &includePath : dui.includePaths) { |
3020 |
| - std::string path = openHeaderDirect(f, simplecpp::simplifyPath(includePath + "/" + header)); |
3021 |
| - if (!path.empty()) |
3022 |
| - return path; |
| 3021 | + // Build an ordered, typed path list: |
| 3022 | + // - Prefer DUI::searchPaths when provided (interleaved -I/-F/-iframework). |
| 3023 | + // - Otherwise mirror legacy includePaths into Include entries (back-compat). |
| 3024 | + std::vector<simplecpp::DUI::SearchPath> searchPaths; |
| 3025 | + if (!dui.searchPaths.empty()) { |
| 3026 | + searchPaths = dui.searchPaths; |
| 3027 | + } else { |
| 3028 | + searchPaths.reserve(dui.includePaths.size()); |
| 3029 | + for (const auto &includePath : dui.includePaths) |
| 3030 | + searchPaths.push_back({includePath, simplecpp::DUI::PathKind::Include}); |
3023 | 3031 | }
|
3024 | 3032 |
|
3025 |
| - // on Apple, try to find the header in the framework path |
3026 |
| - // Convert <includePath>/PKGNAME/myHeader -> <includePath>/PKGNAME.framework/Headers/myHeader |
3027 |
| - // Works on any platform, but only relevant when compiling against Apple SDKs. |
3028 |
| - const std::string appleFrameworkHeader = toAppleFrameworkRelative(header); |
3029 |
| - if (appleFrameworkHeader != header) { |
3030 |
| - for (const auto & includePath: dui.includePaths) { |
3031 |
| - const std::string frameworkCandidatePath = includePath + '/' + appleFrameworkHeader; |
3032 |
| - std::string simplePath = openHeaderDirect(f, simplecpp::simplifyPath(frameworkCandidatePath)); |
3033 |
| - if (!simplePath.empty()) |
3034 |
| - return simplePath; |
| 3033 | + // Search left-to-right, honoring path kinds. |
| 3034 | + for (const auto &searchPath : searchPaths) { |
| 3035 | + if (searchPath.kind == simplecpp::DUI::PathKind::Include) { |
| 3036 | + const std::string path = openHeaderDirect(f, simplecpp::simplifyPath(searchPath.path + "/" + header)); |
| 3037 | + if (!path.empty()) |
| 3038 | + return path; |
| 3039 | + } else { |
| 3040 | + // Framework & SystemFramework: try Headers then PrivateHeaders |
| 3041 | + const auto relatives = toAppleFrameworkRelatives(header); |
| 3042 | + if (relatives[0] != header) { // Skip if no framework rewrite was applied. |
| 3043 | + for (const auto &rel : relatives) { |
| 3044 | + const std::string frameworkPath = openHeaderDirect(f, simplecpp::simplifyPath(searchPath.path + "/" + rel)); |
| 3045 | + if (!frameworkPath.empty()) |
| 3046 | + return frameworkPath; |
| 3047 | + } |
| 3048 | + } |
3035 | 3049 | }
|
3036 | 3050 | }
|
3037 | 3051 |
|
|
0 commit comments