Skip to content

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

Merged
merged 4 commits into from
Jul 9, 2021
Merged

Conversation

elsh
Copy link
Contributor

@elsh elsh commented Jul 1, 2021

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.

var isDirectory: Bool {
var isDir: ObjCBool = false
let exists = FileManager.default.fileExists(atPath: self.pathString, isDirectory: &isDir)
return exists && isDir.boolValue
Copy link
Contributor

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.

Copy link
Contributor Author

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

@@ -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)")
Copy link
Contributor

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.

Copy link
Contributor Author

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

@elsh elsh force-pushed the es-assert branch 2 times, most recently from 7d37ffb to 5722c8e Compare July 1, 2021 21:24
@@ -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) {
Copy link
Contributor Author

@elsh elsh Jul 1, 2021

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.

@elsh
Copy link
Contributor Author

elsh commented Jul 1, 2021

@swift-ci smoke test

@elsh elsh changed the title Assert include directory exists in Clang target Check for an include directory for a library Clang target Jul 7, 2021
@elsh elsh changed the title Check for an include directory for a library Clang target Check for the include directory for a library Clang target Jul 7, 2021
@elsh
Copy link
Contributor Author

elsh commented Jul 7, 2021

@swift-ci smoke test

@elsh
Copy link
Contributor Author

elsh commented Jul 7, 2021

@swift-ci smoke test

@elsh
Copy link
Contributor Author

elsh commented Jul 8, 2021

@swift-ci smoke test

@abertelrud
Copy link
Contributor

Thanks @elsh, this looks good to me.

@elsh
Copy link
Contributor Author

elsh commented Jul 9, 2021

@swift-ci smoke test

@elsh elsh merged commit ae1cb55 into main Jul 9, 2021
@elsh elsh deleted the es-assert branch July 9, 2021 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants