Skip to content

Commit 7d37ffb

Browse files
committed
Throw an error for a library clang target if include dir is not found
1 parent 81e4399 commit 7d37ffb

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,10 @@ public final class PackageBuilder {
916916
// First determine the type of module map that will be appropriate for the target based on its header layout.
917917
// FIXME: We should really be checking the target type to see whether it is one that can vend headers, not just check for the existence of the public headers path. But right now we have now way of distinguishing between, for example, a library and an executable. The semantics here should be to only try to detect the header layout of targets that can vend public headers.
918918
let moduleMapType: ModuleMapType
919+
920+
if targetType == .library, !fileSystem.exists(publicHeadersPath) {
921+
throw ModuleError.invalidPublicHeadersDirectory(potentialModule.name)
922+
}
919923
if fileSystem.exists(publicHeadersPath) {
920924
let moduleMapGenerator = ModuleMapGenerator(targetName: potentialModule.name, moduleName: potentialModule.name.spm_mangledToC99ExtendedIdentifier(), publicHeadersDir: publicHeadersPath, fileSystem: fileSystem)
921925
moduleMapType = moduleMapGenerator.determineModuleMapType(diagnostics: diagnostics)

Sources/PackageModel/Target.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import TSCBasic
1212
import TSCUtility
13-
import Foundation
1413

1514
public class Target: ObjectIdentifierProtocol, PolymorphicCodableProtocol {
1615
public static var implementations: [PolymorphicCodableProtocol.Type] = [
@@ -429,7 +428,7 @@ public final class ClangTarget: Target {
429428
buildSettings: BuildSettings.AssignmentTable = .init()
430429
) {
431430

432-
assert(includeDir.isDirectory && includeDir.contains(sources.root), "\(includeDir) should be contained in the source root \(sources.root)")
431+
assert(includeDir.contains(sources.root), "\(includeDir) should be contained in the source root \(sources.root)")
433432
self.isCXX = sources.containsCXXFiles
434433
self.cLanguageStandard = cLanguageStandard
435434
self.cxxLanguageStandard = cxxLanguageStandard
@@ -668,12 +667,3 @@ public enum PluginCapability: Equatable, Codable {
668667
}
669668
}
670669
}
671-
672-
673-
fileprivate extension AbsolutePath {
674-
var isDirectory: Bool {
675-
var isDir: ObjCBool = false
676-
let exists = FileManager.default.fileExists(atPath: self.pathString, isDirectory: &isDir)
677-
return exists && isDir.boolValue
678-
}
679-
}

0 commit comments

Comments
 (0)