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-6743] SwiftPM: Skipping the build of tests #4845
Comments
swift build and swift run should never build tests by default. You can pass --build-tests to swift build to build them. I think you might be running into a bug, can you attach a sample package where you're seeing this behavior? |
Sure, look here (clone branch SR-6743) to reproduce try with swift run -c release error: could not find target(s): ApplicationTests; use the 'path' property in the Swift 4 manifest to set a custom target path |
Ah, this happens because we create the build plan regardless of what will be actually compiled. If you fix the error by adding the ApplicationTests target, running `swift run` will not compile it. |
I don't understand hm... I already have the test target in place: What is the fix exactly? |
Can you please check it again for me? this is the file from the branch in question. It has the test target in Package.swift https://github.com/krzyzanowskim/OnlineSwiftPlayground/blob/SR-6743/Package.swift |
Yes but that test target directory does not exist in that branch. https://github.com/krzyzanowskim/OnlineSwiftPlayground/tree/SR-6743 doesn't have a Tests/ApplicationTests directory. |
Thanks. This is intentional though. As I don't expect the test being built in the first place, the test target directory is missing and expectancy is that testTarget is just skipped for any operation. |
The same goes to gave reverse option, to build all the products for swift run --build-all I'd love to re-open the issue. I can work on PR to make it happen. |
SwiftPM roughly works in the following way:
`swift build` will by default build everything except test targets unless you pass the option to build them (`- These options are meant to control how llbuild is invoked. The manifest will always have complete list of tasks (including tests). The error you were running into was at the 2nd stage because there was a target defined in the manifest which wasn't present on the disk. Even though you were not trying building it, SwiftPM still has to load it. This is important because it needs to form the correct internal representation in order to perform rest of the operations. Another advantage of this approach is that we can cache the build manifest and re-contruct it only if something changes. This is experimentally implemented on master using `--enable-build-manifest-caching` option. The suggested `- |
exactly. While `swift build` does build all targets, the `swift run` is not (atm). That needs two calls to build and run it all: swift build && swift run since `swift run` already builds the executables, it could build the other products too (not tests). Let's say I have two products: executable and library. |
Oh you're right, we only build the executable that you're running. Ok, --build-all makes sense for swift run! |
Additional Detail from JIRA
md5: 46f992b1ff478959aad8050f968c2ee5
Issue Description:
When running the project with swift run it is desirable to skip tests at all. Tests are useful for development, but not necessarily for release. eg. if I deploy sources and want to build and run, I don't really need to build tests.
More general swift build and swift run should allow skipping building test targets.
-As of today, it is possible using build flags "*swift run -Xswiftc
DNOTESTS*" and adding a condition in the Package.swiftActually this is not possible, the flag is not used to build Packages.swiftsomething like:
swift run --skip-tests
swift build --skip-tests
would build/run without tests.
The text was updated successfully, but these errors were encountered: