-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[SR-3033] Poor diagnostic when importing executable target module in a test #5190
Comments
Is the package which reproduces this public? |
It looks like you're trying to import an executable target via XCTest which is not supported |
Comment by Sam Liu (JIRA) @ddunbar Yes they are here: https://github.com/thinkswift/SR-3033/releases |
ontouchstart (JIRA User) Both of the packages tests fine for me, the logs suggest you're linking a main.swift file with tests however that is not the case in the packages you provided. The logs also suggest that you're probably using the same build directory for linux and macOS. Make sure you delete the build dir (rm -r .build) if you're mounting and building on Linux |
Comment by Sam Liu (JIRA) @aciidb0mb3r I think you are right, it is duplicated by SR-1503 Per @ddunbar's suggestion via twitter, I made some change in version 0.0.1 and it works. I wonder if this is a short term hack before it if fixed in Linux or a recommended best practice for the future packages with cli. https://gist.github.com/ontouchstart/37d70553c95c626db7c3ddf47bcf6156 https://gist.github.com/ontouchstart/06a272456d7a56cfff8bba012625c40e Thanks for the hard work. |
Comment by Sam Liu (JIRA) @aciidb0mb3r I wrapped test_main package with an empty SR-3033 for easy version control. both test_main-0.0.0 and test_main-0.0.1 work in macOS for sure. For Linux. My gists above test them in fresh docker containers without any macOS build. You should be able to reproduce them. I put Makefile back in the gists: https://gist.github.com/ed8b21af4ad67b3e9352c0a0018222d8 |
Comment by Sam Liu (JIRA) I noticed that in my 0.0.0 test, there is a mismatch of file name and module name. I renamed it in version 0.0.3 https://github.com/thinkswift/test_main/releases/tag/0.0.3 The result is the same: |
FWIW, you wouldn't get these errors now since we don't link executables anymore and consider them only as build order dependencies |
Comment by Sam Liu (JIRA) What do you mean "now"? Here is a test in swift-DEVELOPMENT-SNAPSHOT-2016-10-21-a-ubuntu16.04 |
Comment by Sam Liu (JIRA) SR-3033 combined test for 0.0.3 swift-DEVELOPMENT-SNAPSHOT-2016-10-21-a-ubuntu16.04 and macox |
/SR-3033/Packages/test_main-0.0.3/Tests/test_mainTests/test_mainTests.swift:8: error: undefined reference to 'TFV9test_main9test_mainCfT_S0' Yup, This is expected now since you can't "import" executable modules however it is guaranteed to be built before your test module (i.e. executables are build order dependencies) so you can popen and test your executables functionally (we do this in SwiftPM). TL;DR We need to have a better error message if someone tries to import executables but I don't know if its possible to do that at this stage. |
Comment by Sam Liu (JIRA) Tests on test_main package directly instead of as a sub package. https://gist.github.com/9b9b4d60673ceb2f92f239d236160ec3 (0.0.3 failed) |
Ah, I see now. This probably requires SR-1393 (linked). |
Comment by Sam Liu (JIRA) @ddunbar @aciidb0mb3r Do you think this test might be related ? https://gist.github.com/103babaa6710c4b92be613237622d1d3 |
Comment by Sam Liu (JIRA) More test in https://gist.github.com/846d355429e7676e87197ee3928bb7a9 A few observations: 1. test_main-0.0.4 (https://github.com/thinkswift/test_main/tree/0.0.4) has no exported public interface but an executable .build/debug/test_main . Although useless as a module, it is an example of package as a utility. 2. SR-3033-0.0.4 (https://github.com/thinkswift/SR-3033/blob/0.0.4/Package.swift) includes test_main-0.0.4 as the dependency only for the utility purpose 3. The first run of swift build failed to build on both Linux and macOS https://gist.github.com/ontouchstart/846d355429e7676e87197ee3928bb7a9#file-linux_stdout-log-L41 (Linux) 4. Second run of swift build was successful. Although the test_main module has not public interface to be used in SR-3033, there is no compiler/linker error either. The binary .build/debug/test_main works https://gist.github.com/ontouchstart/846d355429e7676e87197ee3928bb7a9#file-linux_stdout-log-L196 (Linux) and test works on both Linux and macOS. I am not raising this issue from technical but user experience standpoint . In integrated interactive development environment like xcode, packages are mostly used as library provider, not utilities. In non-integrated development environment like Linux/UNIX, standalone utilities become powerful and flexible tools in the development toolchain. Reliable support of swift package as utility might be very helpful for backend developers down the road. |
Comment by Sam Liu (JIRA) Without better solutions, I set two targets and only test non-executable target lib_test_main with XCTest targets: [ Version 0.0.10 https://github.com/thinkswift/test_main/tree/0.0.10 https://github.com/thinkswift/SR-3033/tree/0.0.10 https://gist.github.com/6eab3b8e04bc486eafe344e90fcc1430 Can I use this as the template for future projects? |
Attachment: Download
Environment
Swift version 3.0 (swift-3.0-RELEASE)
Target: x86_64-unknown-linux-gnu
Swift Package Manager - Swift 3.0.0
Test repo:
https://github.com/thinkswift/test_main/tree/907a62c40321209f8d60e835ee58c10e999d17e4
Additional Detail from JIRA
md5: 9e3dfc420909e57213129976258c15f0
duplicates:
relates to:
Issue Description:
swift test -v
/swift-3.0-RELEASE-ubuntu15.10/usr/bin/swiftc --driver-mode=swift -I /swift-3.0-RELEASE-ubuntu15.10/usr/lib/swift/pm -L /swift-3.0-RELEASE-ubuntu15.10/usr/lib/swift/pm -lPackageDescription /home/test_main/Package.swift -fileno 4
/swift-3.0-RELEASE-ubuntu15.10/usr/bin/swift-build-tool -f /home/test_main/.build/debug.yaml test -v
'/swift-3.0-RELEASE-ubuntu15.10/usr/bin/swiftc' -Xlinker '-rpath=$ORIGIN' -g -L/home/test_main/.build/debug -o /home/test_main/.build/debug/test_mainPackageTests.xctest -module-name test_mainPackageTests /home/test_main/Tests/LinuxMain.swift -emit-executable -I /home/test_main/.build/debug /home/test_main/.build/debug/test_mainTests.build/test_mainTests.swift.o /home/test_main/.build/debug/test_main.build/main.swift.o /home/test_main/.build/debug/test_main.build/test_no_main.swift.o
/usr/bin/ld.gold: error: /home/test_main/.build/debug/test_main.build/main.swift.o: multiple definition of 'main'
/usr/bin/ld.gold: /tmp/LinuxMain-41188c.o: previous definition here
/usr/bin/ld.gold: fatal error: /home/test_main/.build/debug/test_mainPackageTests.xctest: open: Is a directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): /swift-3.0-RELEASE-ubuntu15.10/usr/bin/swift-build-tool -f /home/test_main/.build/debug.yaml test -v
The text was updated successfully, but these errors were encountered: