Skip to content

[cmake] [unittests] removing scripts for Xcode project test targets #36971

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 2 commits into from
Jun 14, 2021

Conversation

oozoofrog
Copy link
Contributor

@oozoofrog oozoofrog commented Apr 20, 2021

Some scripts in the add_swift_unittest function modifies LINK_LIBRARIES for include gtest, gtest_main libs. as a result lose link information that receving from add_unittest.
This PR removes that script, so the test target no longer throws a "fatal error: 'gtest/gtest.h' file not found" from build test targets.

it had been affected by after https://reviews.llvm.org/D86616

…r search paths

add target include directories on AddSwiftUnittests.cmake module.
currently generated Xcode project doesn't include googletest headers after https://reviews.llvm.org/D86616
@oozoofrog
Copy link
Contributor Author

oozoofrog commented Apr 20, 2021

@varungandhi-apple I am not sure hundred percent this is right method. but this solved my problem that not included gtest header on unittests of generated xcode project.

@LucianoPAlmeida
Copy link
Contributor

Hum, interesting ... this could potentially fix the problem people were having https://forums.swift.org/t/gtest-gtest-h-not-found-in-typeref-cpp-while-compiling-the-compiler/44399 ?

@@ -10,6 +10,9 @@ function(add_swift_unittest test_dirname)
# function defined by AddLLVM.cmake.
add_unittest(SwiftUnitTests ${test_dirname} ${ARGN})

target_include_directories(${test_dirname} PUBLIC ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
target_include_directories(${test_dirname} PUBLIC ${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include)

Copy link
Member

Choose a reason for hiding this comment

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

This is incorrect: https://github.com/llvm/llvm-project/blob/main/llvm/cmake/modules/AddLLVM.cmake#L1471

add_unittest already links against the library, which should have the public include directories specified, so that would already setup the include paths properly.

Copy link
Contributor Author

@oozoofrog oozoofrog Apr 21, 2021

Choose a reason for hiding this comment

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

@compnerd thank you.
now I know this should be include header paths too, some reason Xcode project of llvm-project include header but not swift Xcode project. i'm continuing to figure out the script.

ps. include_directories is working well too, but want to find more elegant way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suspect this is only issue for generating Xcode project so now testing some conditional options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@compnerd now, i understand cmake build dependencies from this area. so removing some codes more.

Comment on lines 13 to 14
target_include_directories(${test_dirname} PUBLIC ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
target_include_directories(${test_dirname} PUBLIC ${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include)
Copy link
Member

Choose a reason for hiding this comment

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

PUBLIC is definitely not the right thing here. The unit tests do not define the interfaces for gtest or gmock.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@compnerd Obviously this script was unnecessary.

@abdulajet
Copy link

Hum, interesting ... this could potentially fix the problem people were having https://forums.swift.org/t/gtest-gtest-h-not-found-in-typeref-cpp-while-compiling-the-compiler/44399 ?

FYI, I ran into this issue with a fresh install of macOS 10.15.7 and Xcode 12.3

@oozoofrog
Copy link
Contributor Author

Hum, interesting ... this could potentially fix the problem people were having https://forums.swift.org/t/gtest-gtest-h-not-found-in-typeref-cpp-while-compiling-the-compiler/44399 ?

FYI, I ran into this issue with a fresh install of macOS 10.15.7 and Xcode 12.3

sadly, build with Xcode 12.2 not working too.

gtest, gtest_main LINK_LIBRARIES dependencies changed by that removed scripts to absolute library file path. as a result losing necessary include path dirs.
Copy link
Contributor Author

@oozoofrog oozoofrog left a comment

Choose a reason for hiding this comment

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

@compnerd remove target_include_directories and unnecessary scripts. @varungandhi-apple @shahmishal @LucianoPAlmeida @abdulajet

@oozoofrog oozoofrog requested a review from compnerd April 30, 2021 15:45
@compnerd
Copy link
Member

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 87e3453

@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2021

Build failed
Swift Test OS X Platform
Git Sha - 87e3453

@compnerd
Copy link
Member

compnerd commented May 1, 2021

@swift-ci please test Linux platform

@compnerd
Copy link
Member

compnerd commented May 1, 2021

@swift-ci please test macOS platform

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

LGTM

@LucianoPAlmeida
Copy link
Contributor

@compnerd remove target_include_directories and unnecessary scripts. @varungandhi-apple @shahmishal @LucianoPAlmeida @abdulajet

@rollmind Perhaps the PR title and description should be updated to reflect the new changes :)

@oozoofrog oozoofrog changed the title [cmake] [unittests] include googletest headers to Xcode project header search paths [cmake] [unittests] removing scripts for Xcode project test targets May 2, 2021
@oozoofrog
Copy link
Contributor Author

@compnerd remove target_include_directories and unnecessary scripts. @varungandhi-apple @shahmishal @LucianoPAlmeida @abdulajet

@rollmind Perhaps the PR title and description should be updated to reflect the new changes :)

I see, how about that changed title and description.

@oozoofrog
Copy link
Contributor Author

@compnerd Thanks

@oozoofrog
Copy link
Contributor Author

oozoofrog commented Jun 14, 2021

@varungandhi-apple @shahmishal
Can I ask test and merge please?

@varungandhi-apple
Copy link
Contributor

@swift-ci test and merge

@swift-ci swift-ci merged commit 8687e61 into swiftlang:main Jun 14, 2021
@oozoofrog
Copy link
Contributor Author

@varungandhi-apple Thnx! :)

@kbongort
Copy link

Can we cherry-pick this into the 5.5 branch so that people trying to build from that branch have a better time?

oozoofrog pushed a commit to oozoofrog/swift that referenced this pull request Nov 11, 2021
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.

7 participants