Skip to content

Conversation

@artemcm
Copy link
Contributor

@artemcm artemcm commented Sep 9, 2022

The Swift compiler does not have a concept of a working directory. It is instead handled by the Swift driver by resolving relative paths according to the driver's working directory argument. On the other hand, Clang does have a concept working directory which may be specified on this Clang invocation with '-working-directory'. If so, it is crucial that we use this directory as an argument to the Clang scanner API. Otherwiswe, we risk having a mismatch between the working directory specified on the scanner's Clang invocation and the one use from the scanner API entry-points, which leads to downstream inconsistencies and errors.

@artemcm
Copy link
Contributor Author

artemcm commented Sep 9, 2022

@swift-ci test

Copy link
Contributor

@jansvoboda11 jansvoboda11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for this?

…ctory matches the invocation.

The Swift compiler does not have a concept of a working directory. It is instead handled by the Swift driver by resolving relative paths according to the driver's working directory argument. On the other hand, Clang does have a concept working directory which may be specified on this Clang invocation with '-working-directory'. If so, it is crucial that we use this directory as an argument to the Clang scanner API. Otherwiswe, we risk having a mismatch between the working directory specified on the scanner's Clang invocation and the one use from the scanner API entry-points, which leads to downstream inconsistencies and errors.
@artemcm artemcm force-pushed the ClangScannerWorkDir branch from ca75c9e to 03136e0 Compare September 9, 2022 20:32
@artemcm
Copy link
Contributor Author

artemcm commented Sep 9, 2022

Can you add a test for this?

Without this change, #60807 fails all driver tests that perform dependency scanning (and explicit builds). This is because the driver runs tests in a different directory than where the compiler is located. So merging it will ensure we don't regress the correct behavior introduced by this change.

Otherwise it is a tricky thing to test without introducing the above change.

@artemcm
Copy link
Contributor Author

artemcm commented Sep 9, 2022

@swift-ci test

Copy link
Contributor

@jansvoboda11 jansvoboda11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM.

@artemcm artemcm merged commit 9a28ae0 into swiftlang:main Sep 12, 2022
@artemcm artemcm deleted the ClangScannerWorkDir branch September 12, 2022 16:32
artemcm added a commit to artemcm/swift that referenced this pull request Apr 26, 2023
…ctory matches the invocation when querying bridging header dependencies

The Swift compiler does not have a concept of a working directory. It is instead handled by the Swift driver by resolving relative paths according to the driver's working directory argument. On the other hand, Clang does have a concept working directory which may be specified on this Clang invocation with '-working-directory'. If so, it is crucial that we use this directory as an argument to the Clang scanner API. Otherwiswe, we risk having a mismatch between the working directory specified on the scanner's Clang invocation and the one use from the scanner API entry-points, which leads to downstream inconsistencies and errors.

This was originally fixed for the main by-name module dependencies query in swiftlang#61025 (03136e0), but the Bridging Header dependencies code has continued to incorrectly expect the Swift ASTContext to both have the working directory set *and* be consistent with that of the Clang scanner instance.

Resolves rdar://108464467
artemcm added a commit to artemcm/swift that referenced this pull request Apr 26, 2023
…ctory matches the invocation when querying bridging header dependencies

The Swift compiler does not have a concept of a working directory. It is instead handled by the Swift driver by resolving relative paths according to the driver's working directory argument. On the other hand, Clang does have a concept working directory which may be specified on this Clang invocation with '-working-directory'. If so, it is crucial that we use this directory as an argument to the Clang scanner API. Otherwiswe, we risk having a mismatch between the working directory specified on the scanner's Clang invocation and the one use from the scanner API entry-points, which leads to downstream inconsistencies and errors.

This was originally fixed for the main by-name module dependencies query in swiftlang#61025 (03136e0), but the Bridging Header dependencies code has continued to incorrectly expect the Swift ASTContext to both have the working directory set *and* be consistent with that of the Clang scanner instance.

Resolves rdar://108464467
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.

2 participants