-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Check for the include directory for a library Clang target #3583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Sources/PackageModel/Target.swift
Outdated
var isDirectory: Bool { | ||
var isDir: ObjCBool = false | ||
let exists = FileManager.default.fileExists(atPath: self.pathString, isDirectory: &isDir) | ||
return exists && isDir.boolValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to go through the FileSystem
abstraction here instead of checking the local file system directly. It might be a bit awkward to get a handle to the currently used file system object here, one option could be moving the check to TargetSourcesBuilder
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved a check out of this
Sources/PackageModel/Target.swift
Outdated
@@ -427,7 +428,8 @@ public final class ClangTarget: Target { | |||
dependencies: [Target.Dependency] = [], | |||
buildSettings: BuildSettings.AssignmentTable = .init() | |||
) { | |||
assert(includeDir.contains(sources.root), "\(includeDir) should be contained in the source root \(sources.root)") | |||
|
|||
assert(includeDir.isDirectory && includeDir.contains(sources.root), "\(includeDir) should be contained in the source root \(sources.root)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be an assertion or is this a user error? Assertions are for programming errors, and are compiled out in release builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved a check out of this and throw an error per below
7d37ffb
to
5722c8e
Compare
@@ -916,6 +916,10 @@ public final class PackageBuilder { | |||
// First determine the type of module map that will be appropriate for the target based on its header layout. | |||
// 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. | |||
let moduleMapType: ModuleMapType | |||
|
|||
if targetType == .library, !fileSystem.exists(publicHeadersPath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abertelrud @neonichu Is this target type check enough here? A quick sanity check shows it is but the comment above seems to suggest otherwise.
@swift-ci smoke test |
@swift-ci smoke test |
@swift-ci smoke test |
@swift-ci smoke test |
Thanks @elsh, this looks good to me. |
@swift-ci smoke test |
Motivation:
Resolves rdar://52162539 ([SR-10975]: Improve the error message when a C target is missing the include directory).
Modifications:
Added a check to verify the include dir exists for a library clang target if toolchain is 5.5+.
Result:
With the change, it now properly throws an error indicating missing include directory.