Skip to content

[.xcodeproj] Share SwiftXCTest scheme #47

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 1 commit into from
Feb 8, 2016

Conversation

modocache
Copy link
Contributor

What's in this pull request?

Currently, running the Swift build script /path/to/swift/utils/build-script --xctest on OS X fails because it attempts to use the Linux-only build_script.py.

We should make it possible for swift-corelibs-xctest to be built via the --xctest switch on OS X, which means making the project buildable via the command line.

To make the project buildable via the command line, share the "SwiftXCTest" scheme. This allows the project to be built via:

$ xcodebuild -project SwiftXCTest.xcodeproj -scheme SwiftXCTest

Why merge this pull request?

After merging these changes and #46, I plan on allowing swift-corelibs-xctest to be built and tested via the Swift build script. This could be accomplished via the following changes to apple/swift:

diff --git a/utils/build-script-impl b/utils/build-script-impl
index eebeef7..7b176f5 100755
--- a/utils/build-script-impl
+++ b/utils/build-script-impl
@@ -1797,11 +1797,18 @@ for deployment_target in "${HOST_TARGET}" "${CROSS_TOOLS_DEPLOYMENT_TARGETS[@]}"
                 continue
                 ;;
             xctest)
-                SWIFTC_BIN="$(build_directory_bin ${deployment_target} swift)/swiftc"
-                SWIFT_BUILD_PATH="$(build_directory ${deployment_target} swift)"
-                set -x
-                "${XCTEST_SOURCE_DIR}"/build_script.py --swiftc="${SWIFTC_BIN}" --build-dir="${build_dir}" --swift-build-dir="${SWIFT_BUILD_PATH}"
-                { set +x; } 2>/dev/null
+                if [[ "$(uname -s)" == "Darwin" ]] ; then
+                    set -x
+                    # FIXME: When built on Darwin, the '$build_dir' is ignored.
+                    xcodebuild -project "${XCTEST_SOURCE_DIR}"/XCTest.xcodeproj -scheme SwiftXCTest
+                    { set +x; } 2>/dev/null
+                else
+                    SWIFTC_BIN="$(build_directory_bin ${deployment_target} swift)/swiftc"
+                    SWIFT_BUILD_PATH="$(build_directory ${deployment_target} swift)"
+                    set -x
+                    "${XCTEST_SOURCE_DIR}"/build_script.py --swiftc="${SWIFTC_BIN}" --build-dir="${build_dir}" --swift-build-dir="${SWIFT_BUILD_PATH}"
+                    { set +x; } 2>/dev/null
+                fi

                 # XCTest builds itself and doesn't rely on cmake
                 continue
@@ -2021,7 +2028,21 @@ for deployment_target in "${STDLIB_DEPLOYMENT_TARGETS[@]}"; do
                 if [[ "${SKIP_TEST_XCTEST}" ]]; then
                     continue
                 fi
-                # FIXME: We don't test xctest, yet...
+                echo "--- Running tests for ${product} ---"
+                if [[ "$(uname -s)" == "Darwin" ]] ; then
+                    set -x
+                    xcodebuild -project "${XCTEST_SOURCE_DIR}"/XCTest.xcodeproj -scheme SwiftXCTestFunctionalTests
+                    { set +x; } 2>/dev/null
+                else
+                    SWIFTC_BIN="$(build_directory_bin ${deployment_target} swift)/swiftc"
+                    SWIFT_BUILD_PATH="$(build_directory ${deployment_target} swift)"
+                    set -x
+                    # FIXME: This re-builds swift-corelibs-xctest. Instead, 'build_script.py' should take
+                    # a top-level 'test' command that only tests an already built XCTest.
+                    "${XCTEST_SOURCE_DIR}"/build_script.py --swiftc="${SWIFTC_BIN}" --build-dir="${build_dir}" --swift-build-dir="${SWIFT_BUILD_PATH}" --test
+                    { set +x; } 2>/dev/null
+                fi
+                echo "--- Finished tests for ${product} ---"
                 continue
                 ;;
             foundation)

We haven't traditionally been quick to notice when swift-corelibs-xctest is broken; the failures introduced by #33 and #44 took several days to even discover. Adding swift-corelibs-xctest to the Swift test suite will allow us to discover failures quicker.

What downsides are there to merging this pull request?

We probably want a shared scheme in any case, but one could argue that adding swift-corelibs-xctest tests to the Swift build script is premature. After all, the changes I suggest above already have two FIXMEs in them. Still, I think this is forward progress--the FIXMEs can be addressed in turn.

Currently, running the Swift build script
`swift/utils/build-script --xctest` on OS X fails because it attempts
to use the Linux-only `build_script.py`.

We should make it possible for swift-corelibs-xctest to be built via
the `--xctest` switch on OS X, which means making the project
build-able via the command line.

To make the project build-able via the command line, share the
"SwiftXCTest" scheme. This allows the project to be built via:

```
$ xcodebuild -project SwiftXCTest.xcodeproj -scheme SwiftXCTest
```
@briancroom
Copy link
Contributor

LGTM, as far as the contents of this PR itself are concerned. I'm not very familiar with the overall build script and can't really speak to the other proposed changes. Thanks a lot for taking on all this infrastructure effort @modocache!

@modocache
Copy link
Contributor Author

Thanks for the review! I'm sure my proposed changes to the build script will undergo a bit of revision when I submit the pull request to apple/swift, but I think we'll need the SwiftXCTest scheme exposed either way.

Now that I think about it, with regards to the first FIXME above: I wonder if the directory where built products are placed can be specified using an environment variable when invoking xcodebuild? That is, something like the following: BUILT_PRODUCTS_DIR=/some/path xcodebuild -project XCTest.xcodeproj -scheme SwiftXCTest?

mike-ferris pushed a commit that referenced this pull request Feb 8, 2016
[.xcodeproj] Share SwiftXCTest scheme
@mike-ferris mike-ferris merged commit 3314ff2 into swiftlang:master Feb 8, 2016
@modocache modocache deleted the share-swiftxctest-scheme branch February 8, 2016 15:39
modocache added a commit to modocache/swift that referenced this pull request Feb 19, 2016
Allow swift-corelibs-xctest to be built and tested on Linux and OS X,
via `utils/build-script --xctest --test`.

On OS X, XCTest is built via `xcodebuild`, which has been possible since
swiftlang/swift-corelibs-xctest#47. It's tested via
the "SwiftXCTestFunctionalTests" Xcode target. Keep in mind that
`xcodebuild` must be configured on the host machine to use a Swift
toolchain that can build XCTest--as of
swiftlang/swift-corelibs-xctest#48, that would be
`swift-DEVELOPMENT-SNAPSHOT-2016-02-08` or later.

On Linux, XCTest is built and tested via the project's
`build_script.py`, which has been possible since
swiftlang/swift-corelibs-xctest#46.
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.

3 participants