I usually build swift-corelibs-foundation on macos with Xcode. It's easy to edit and test. Now, I want to build and run the Foundation test on Linux (Ubuntu 18.04). I followed the guide GettingStarted.md, On Linux section.
It's not working.
I spent server days reading docs, searching on google and swift forums, then try on the Linux. However, I failed.
It's there anyone could tell how to do it? I would like to help to create a PR, so it will not block new beginners.
Update the repositories with ./swift-source/swift/utils/update-checkout
Build with release mode: ./swift-source/swift/utils/build-script -R
Build Foundation ./swift-source/swift/utils/build-script --foundation --xctest -R
All the above steps works. Then
cd swift-corelibs-foundation
ninja
It failed, raise an error ninja: error: loading 'build.ninja': No such file or directory
I though the GettingStarted.md is outdated, so I cd to the build directory, run ninja and ninja test
root@swift:/data/swift-source/build/Ninja-ReleaseAssert/foundation-linux-x86_64# ninja
[5/5] Running utility command for FoundationNetworking
root@swift:/data/swift-source/build/Ninja-ReleaseAssert/foundation-linux-x86_64# ninja test
[0/1] Running tests...
Test project /data/swift-source/build/Ninja-ReleaseAssert/foundation-linux-x86_64
No tests were found!!!
Replace SOME_DIRECTORY and SOMEWHERE with paths that will contain installed files for this copy of Swift — I generally use directories beside my build directory. The CI preset is the only one guaranteed to behave like our testing does (and then, only in Ubuntu — if you’re not on a supported Ubuntu version, use the Swift docker images for best results.)
@millenomi It's still not working(Ubuntu 18.04).
I think I can ask in an alternative way: How do you test on the Linux when you make some changes of foundation framework?
@dannliu: I don’t know if this will be helpful, but the build-script builds Foundation twice for the test to work: it has to build Foundation because XCTest depends on Foundation, and then it builds it again with test which depend on XCTest. If you are running ninja manually in between those steps, it might be that the tests haven't been configured, and so the target is failing.
BTW, in my opinion it might be better to invoke cmake --build . -- and cmake --build . -- test instead of ninja and ninja test. The former will take care of re-running CMake in case the scripts have changed, while the later will not (the former invokes the later internally).
If you post the output of the error you are getting now, maybe we can see what's wrong. Good luck!
@millenomi I built with the command you provided. And then got the ./build/buildbot_linux/foundation-linux-x86_64 run ninja test. It still shows No tests were found!!!
@dannliu: I think there's nothing in the install_destdir because the build script tries to build and test all the projects before installing (except for a couple of exception, but they are not your case).
It definitely looks as if the test haven't been configured yet. I would recommend checking if XCTest is around (it should be to build the Foundation tests). Check for a directory ./build/buildbot_linux/xctest-linux-x86_64 (or something similar, I'm typing from memory). In the directory is there, I would recommend doing a cmake --build . -- in that directory to make sure XCTest has been built. If the directory is not there, or the CMake invocation fails, it would be great to know the error there.
Once XCTest is built, you can go back to foundation-linux-x86_64 and try to do cmake -DENABLE_TESTING:BOOL=YES -DFOUNDATION_PATH_TO_XCTEST_BUILD:PATH=<absolute path to your build of XCTest>. That would hopefully configure Foundation for testing (hopefully it finishes without failures). Then a final cmake --build -- test should do the trick.
Also, rerunning the build script invocation should go very fast through the steps that have already finished, so you should try that too. If that fails, maybe use some system like gist.github.com to paste the full output of the build-script invocation, to give us more clues of what's failing.
What's the command you use to run the foundation test?
Also, could you provide more detail about such a scenario:
We fix a bug for swift-corelibs-foundation (for example 3 lines changed). How do you verify whether the bug is fixed quickly?
The process on Linux seems so hard (or I did something wrong). I think the developer or swift lover deserve a better README. It should not spend us so much time on how to build and test. @John_McCall
Thanks
Danny
The tests should run once as part of that command. After that, I iterate using (cd build/buildbot_linux/foundation-*; ninja). I often run the test binary (build/buildbot_linux/foundation-*/TestFoundation/TestFoundation) manually after setting up the environment as described in the CTest* file because I run it under lldb rather than using ninja test.
Note that if compilation fails earlier, Foundation won’t be built. Without more detail (say, logs) I’m not sure how to help further.
Hey, I've been building and testing on linux since earlier this year, specifically on Arch linux. This is the command I use to build and run the Foundation tests:
Note that only the --xctest -T are required- as others have noted XCTest has to be built first, because the Foundation tests run with it- everything else is optional. Take a look at ./swift/utils/build-test --help to get a better idea, I came up with this command after looking at that help info and experimenting a bit.
-R --no-assertions means a Release build without assertions, you may prefer otherwise. I don't bother building several uncommon targets in the LLVM backend, just to save some time on the interminable LLVM build. I skip the Swift tests after the first build, you can find more ways to just run the tests you want in the build-script flags.
This will run the entire test suite, you can iterate on a particular function or test after running this once, by going to the build directory and running ninja and ninja test or invoking the TestFoundation binary directly.