diff --git a/lib/PrintAsClang/PrintAsClang.cpp b/lib/PrintAsClang/PrintAsClang.cpp index bb2ebc32ca3..31897d370a1 100644 --- a/lib/PrintAsClang/PrintAsClang.cpp +++ b/lib/PrintAsClang/PrintAsClang.cpp @@ -450,6 +450,11 @@ writeImports(raw_ostream &out, llvm::SmallPtrSetImpl &imports, for (auto searchDir = clangHeaderSearchInfo.search_dir_begin(); searchDir != clangHeaderSearchInfo.search_dir_end(); ++searchDir) { + // Header map lookup is not supported for now, so don't add the hmap + // paths to the search list. + if (searchDir->isHeaderMap()) + continue; + // Ensure search directories end in / so that we don't prefix match // against a folder that starts with the same substring. auto path = normalizePath(searchDir->getName()); diff --git a/test/PrintAsObjC/emit-clang-header-nonmodular-includes-skip-header-maps.swift b/test/PrintAsObjC/emit-clang-header-nonmodular-includes-skip-header-maps.swift new file mode 100644 index 00000000000..a3f4e0d8afd --- /dev/null +++ b/test/PrintAsObjC/emit-clang-header-nonmodular-includes-skip-header-maps.swift @@ -0,0 +1,26 @@ +// REQUIRES: objc_interop + +// RUN: %empty-directory(%t) + +// Create a header map that maps header-regular.h to its real path. +// RUN: echo '{"mappings": {"header-regular.h": "%/S/Inputs/custom-modules/header_subdirectory/header-regular.h"}}' > %t/hmap.json +// RUN: %hmaptool write %t/hmap.json %t/headers.hmap + +// Compile with the header map as a search directory alongside a regular +// include directory. The header map should be skipped when collecting include +// paths for nonmodular includes. +// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -emit-objc-header-path %t/textual-imports.h -Xcc -fmodule-map-file=%S/Inputs/custom-modules/module.modulemap -Xcc -I%t/headers.hmap -Xcc -I%S/Inputs/custom-modules/header_subdirectory/ -emit-clang-header-nonmodular-includes %s +// RUN: %FileCheck %s < %t/textual-imports.h + +import EmitClangHeaderNonmodularIncludesStressTest + +public class Bar : Baz {} + +// CHECK: @import EmitClangHeaderNonmodularIncludesStressTest; +// CHECK-NEXT: #elif defined(__OBJC__) +// CHECK-NEXT: #import +// CHECK-NEXT: #import +// CHECK-NEXT: #else +// CHECK-NEXT: #include +// CHECK-NEXT: #include +// CHECK-NEXT: #endif