|
15 | 15 | //===----------------------------------------------------------------------===//
|
16 | 16 | #include "swift/ClangImporter/ClangImporter.h"
|
17 | 17 | #include "ClangDiagnosticConsumer.h"
|
| 18 | +#include "ClangIncludePaths.h" |
18 | 19 | #include "ImporterImpl.h"
|
19 | 20 | #include "swift/AST/ASTContext.h"
|
20 | 21 | #include "swift/AST/Builtins.h"
|
|
38 | 39 | #include "swift/Basic/Version.h"
|
39 | 40 | #include "swift/ClangImporter/ClangImporterRequests.h"
|
40 | 41 | #include "swift/ClangImporter/ClangModule.h"
|
41 |
| -#include "swift/Config.h" |
42 |
| -#include "swift/Demangling/Demangle.h" |
43 | 42 | #include "swift/Parse/Lexer.h"
|
44 | 43 | #include "swift/Parse/Parser.h"
|
45 | 44 | #include "swift/Strings.h"
|
46 | 45 | #include "swift/Subsystems.h"
|
47 | 46 | #include "clang/AST/ASTContext.h"
|
48 | 47 | #include "clang/AST/Mangle.h"
|
49 |
| -#include "clang/Basic/CharInfo.h" |
50 | 48 | #include "clang/Basic/IdentifierTable.h"
|
51 | 49 | #include "clang/Basic/Module.h"
|
52 | 50 | #include "clang/Basic/TargetInfo.h"
|
53 | 51 | #include "clang/Basic/Version.h"
|
54 | 52 | #include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
|
55 |
| -#include "clang/Driver/Driver.h" |
56 | 53 | #include "clang/Frontend/FrontendActions.h"
|
57 | 54 | #include "clang/Frontend/Utils.h"
|
58 | 55 | #include "clang/Index/IndexingAction.h"
|
|
74 | 71 | #include "llvm/Support/Path.h"
|
75 | 72 | #include "llvm/Support/VirtualFileSystem.h"
|
76 | 73 | #include "llvm/Support/YAMLParser.h"
|
77 |
| -#include "llvm/Support/YAMLTraits.h" |
78 | 74 | #include <algorithm>
|
79 | 75 | #include <string>
|
80 | 76 | #include <memory>
|
@@ -444,60 +440,6 @@ ClangImporter::~ClangImporter() {
|
444 | 440 |
|
445 | 441 | #pragma mark Module loading
|
446 | 442 |
|
447 |
| -static Optional<StringRef> getModuleMapFilePath(StringRef name, |
448 |
| - SearchPathOptions &Opts, |
449 |
| - llvm::Triple triple, |
450 |
| - SmallVectorImpl<char> &buffer) { |
451 |
| - StringRef platform = swift::getPlatformNameForTriple(triple); |
452 |
| - StringRef arch = swift::getMajorArchitectureName(triple); |
453 |
| - |
454 |
| - StringRef SDKPath = Opts.getSDKPath(); |
455 |
| - if (!SDKPath.empty()) { |
456 |
| - buffer.clear(); |
457 |
| - buffer.append(SDKPath.begin(), SDKPath.end()); |
458 |
| - llvm::sys::path::append(buffer, "usr", "lib", "swift"); |
459 |
| - llvm::sys::path::append(buffer, platform, arch, name); |
460 |
| - |
461 |
| - // Only specify the module map if that file actually exists. It may not; |
462 |
| - // for example in the case that `swiftc -target x86_64-unknown-linux-gnu |
463 |
| - // -emit-ir` is invoked using a Swift compiler not built for Linux targets. |
464 |
| - if (llvm::sys::fs::exists(buffer)) |
465 |
| - return StringRef(buffer.data(), buffer.size()); |
466 |
| - } |
467 |
| - |
468 |
| - if (!Opts.RuntimeResourcePath.empty()) { |
469 |
| - buffer.clear(); |
470 |
| - buffer.append(Opts.RuntimeResourcePath.begin(), |
471 |
| - Opts.RuntimeResourcePath.end()); |
472 |
| - llvm::sys::path::append(buffer, platform, arch, name); |
473 |
| - |
474 |
| - // Only specify the module map if that file actually exists. It may not; |
475 |
| - // for example in the case that `swiftc -target x86_64-unknown-linux-gnu |
476 |
| - // -emit-ir` is invoked using a Swift compiler not built for Linux targets. |
477 |
| - if (llvm::sys::fs::exists(buffer)) |
478 |
| - return StringRef(buffer.data(), buffer.size()); |
479 |
| - } |
480 |
| - |
481 |
| - return None; |
482 |
| -} |
483 |
| - |
484 |
| -/// Finds the glibc.modulemap file relative to the provided resource dir. |
485 |
| -/// |
486 |
| -/// Note that the module map used for Glibc depends on the target we're |
487 |
| -/// compiling for, and is not included in the resource directory with the other |
488 |
| -/// implicit module maps. It's at {freebsd|linux}/{arch}/glibc.modulemap. |
489 |
| -static Optional<StringRef> |
490 |
| -getGlibcModuleMapPath(SearchPathOptions &Opts, llvm::Triple triple, |
491 |
| - SmallVectorImpl<char> &buffer) { |
492 |
| - return getModuleMapFilePath("glibc.modulemap", Opts, triple, buffer); |
493 |
| -} |
494 |
| - |
495 |
| -static Optional<StringRef> |
496 |
| -getLibStdCxxModuleMapPath(SearchPathOptions &opts, llvm::Triple triple, |
497 |
| - SmallVectorImpl<char> &buffer) { |
498 |
| - return getModuleMapFilePath("libstdcxx.modulemap", opts, triple, buffer); |
499 |
| -} |
500 |
| - |
501 | 443 | static bool clangSupportsPragmaAttributeWithSwiftAttr() {
|
502 | 444 | clang::AttributeCommonInfo swiftAttrInfo(clang::SourceRange(),
|
503 | 445 | clang::AttributeCommonInfo::AT_SwiftAttr,
|
@@ -882,99 +824,6 @@ importer::addCommonInvocationArguments(
|
882 | 824 | }
|
883 | 825 | }
|
884 | 826 |
|
885 |
| -/// On Linux, some platform libraries (glibc, libstdc++) are not modularized. |
886 |
| -/// We inject modulemaps for those libraries into their include directories |
887 |
| -/// to allow using them from Swift. |
888 |
| -static SmallVector<std::pair<std::string, std::string>, 16> |
889 |
| -getClangInvocationFileMapping(ASTContext &ctx) { |
890 |
| - using Path = SmallString<128>; |
891 |
| - |
892 |
| - const llvm::Triple &triple = ctx.LangOpts.Target; |
893 |
| - // We currently only need this when building for Linux. |
894 |
| - if (!triple.isOSLinux()) |
895 |
| - return {}; |
896 |
| - // Android uses libc++. |
897 |
| - if (triple.isAndroid()) |
898 |
| - return {}; |
899 |
| - |
900 |
| - // Extract the libstdc++ installation path from Clang driver. |
901 |
| - auto clangDiags = clang::CompilerInstance::createDiagnostics( |
902 |
| - new clang::DiagnosticOptions()); |
903 |
| - clang::driver::Driver clangDriver(ctx.ClangImporterOpts.clangPath, |
904 |
| - triple.str(), *clangDiags); |
905 |
| - // Flags passed to Swift with `-Xcc` might affect include paths. |
906 |
| - unsigned unused1, unused2; |
907 |
| - std::vector<const char *> clangArgs; |
908 |
| - for (const auto &each : ctx.ClangImporterOpts.ExtraArgs) { |
909 |
| - clangArgs.push_back(each.c_str()); |
910 |
| - } |
911 |
| - llvm::opt::InputArgList clangDriverArgs = |
912 |
| - clangDriver.getOpts().ParseArgs(clangArgs, unused1, unused2); |
913 |
| - // If an SDK path was explicitly passed to Swift, make sure to pass it to |
914 |
| - // Clang driver as well. It affects the resulting include paths. |
915 |
| - auto sdkPath = ctx.SearchPathOpts.getSDKPath(); |
916 |
| - if (!sdkPath.empty()) { |
917 |
| - unsigned argIndex = clangDriverArgs.MakeIndex("--sysroot", sdkPath); |
918 |
| - clangDriverArgs.append(new llvm::opt::Arg( |
919 |
| - clangDriver.getOpts().getOption(clang::driver::options::OPT__sysroot), |
920 |
| - sdkPath, argIndex)); |
921 |
| - } |
922 |
| - auto cxxStdlibDirs = |
923 |
| - clangDriver.getLibStdCxxIncludePaths(clangDriverArgs, triple); |
924 |
| - if (cxxStdlibDirs.empty()) { |
925 |
| - ctx.Diags.diagnose(SourceLoc(), diag::libstdcxx_not_found, triple.str()); |
926 |
| - return {}; |
927 |
| - } |
928 |
| - Path cxxStdlibDir(cxxStdlibDirs.front()); |
929 |
| - // VFS does not allow mapping paths that contain `../` or `./`. |
930 |
| - llvm::sys::path::remove_dots(cxxStdlibDir, /*remove_dot_dot=*/true); |
931 |
| - |
932 |
| - // Currently only a modulemap for libstdc++ is injected. |
933 |
| - if (!ctx.LangOpts.EnableCXXInterop) |
934 |
| - return {}; |
935 |
| - |
936 |
| - Path actualModuleMapPath; |
937 |
| - Path buffer; |
938 |
| - if (auto path = getLibStdCxxModuleMapPath(ctx.SearchPathOpts, triple, buffer)) |
939 |
| - actualModuleMapPath = path.getValue(); |
940 |
| - else |
941 |
| - return {}; |
942 |
| - |
943 |
| - // Only inject the module map if it actually exists. It may not, for example |
944 |
| - // if `swiftc -target x86_64-unknown-linux-gnu -emit-ir` is invoked using |
945 |
| - // a Swift compiler not built for Linux targets. |
946 |
| - if (!llvm::sys::fs::exists(actualModuleMapPath)) |
947 |
| - // FIXME: emit a warning of some kind. |
948 |
| - return {}; |
949 |
| - |
950 |
| - // TODO: remove the libstdcxx.h header and reference all libstdc++ headers |
951 |
| - // directly from the modulemap. |
952 |
| - Path actualHeaderPath = actualModuleMapPath; |
953 |
| - llvm::sys::path::remove_filename(actualHeaderPath); |
954 |
| - llvm::sys::path::append(actualHeaderPath, "libstdcxx.h"); |
955 |
| - |
956 |
| - // Inject a modulemap into VFS for the libstdc++ directory. |
957 |
| - // Only inject the module map if the module does not already exist at |
958 |
| - // {sysroot}/usr/include/module.{map,modulemap}. |
959 |
| - Path injectedModuleMapLegacyPath(cxxStdlibDir); |
960 |
| - llvm::sys::path::append(injectedModuleMapLegacyPath, "module.map"); |
961 |
| - if (llvm::sys::fs::exists(injectedModuleMapLegacyPath)) |
962 |
| - return {}; |
963 |
| - |
964 |
| - Path injectedModuleMapPath(cxxStdlibDir); |
965 |
| - llvm::sys::path::append(injectedModuleMapPath, "module.modulemap"); |
966 |
| - if (llvm::sys::fs::exists(injectedModuleMapPath)) |
967 |
| - return {}; |
968 |
| - |
969 |
| - Path injectedHeaderPath(cxxStdlibDir); |
970 |
| - llvm::sys::path::append(injectedHeaderPath, "libstdcxx.h"); |
971 |
| - |
972 |
| - return { |
973 |
| - {std::string(injectedModuleMapPath), std::string(actualModuleMapPath)}, |
974 |
| - {std::string(injectedHeaderPath), std::string(actualHeaderPath)}, |
975 |
| - }; |
976 |
| -} |
977 |
| - |
978 | 827 | bool ClangImporter::canReadPCH(StringRef PCHFilename) {
|
979 | 828 | if (!llvm::sys::fs::exists(PCHFilename))
|
980 | 829 | return false;
|
|
0 commit comments