Skip to content

Osx build script #34

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ install XCTest in your active version of Swift:
--test
```

To run the tests on OS X, build and run the `SwiftXCTestFunctionalTests` target in the Xcode project. You may also run them via the command line:

```
xcodebuild -project XCTest.xcodeproj -scheme SwiftXCTestFunctionalTests
Building and installing on OSX:
```sh
sudo ./build_script.py \
--swiftc="/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swiftc" \
--build-dir="/tmp/XCTest_build" \
--swift-build-dir="/Library/Developer/Toolchains/swift-latest.xctoolchain/usr" \
--library-install-path="/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/lib/swift/macosx" \
--module-install-path="/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/lib/swift/macosx/x86_64"
```

To run the tests on OS X, build and run the `SwiftXCTestFunctionalTests` target in the Xcode project, the `--test` parameter for the build script will not work.

You may add tests for XCTest by including them in the `Tests/Functional/` directory. For an example, see `Tests/Functional/SingleFailingTestCase`.

### Additional Considerations for Swift on Linux
Expand Down
27 changes: 22 additions & 5 deletions build_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Here is a nice way to invoke this script if you are building locally, and Swift is installed at /, and you want to install XCTest back there
# sudo ./build_script.py --swiftc="/usr/bin/swiftc" --build-dir="/tmp/XCTest_build" --swift-build-dir="/usr" --library-install-path="/usr/lib/swift/linux" --module-install-path="/usr/lib/swift/linux/x86_64"

import os, subprocess, argparse
import os, shlex, subprocess, argparse, platform

SOURCE_DIR = os.path.dirname(os.path.abspath(__file__))

Expand Down Expand Up @@ -109,10 +109,27 @@ def main():

# Not incremental..
# Build library
run("{0} -c {1} -emit-object {2} -module-name XCTest -parse-as-library -emit-module "
"-emit-module-path {3}/XCTest.swiftmodule -o {3}/XCTest.o -force-single-frontend-invocation "
"-module-link-name XCTest".format(swiftc, style_options, " ".join(sourcePaths), build_dir))
run("clang {0}/XCTest.o -shared -o {0}/libXCTest.so -Wl,--no-undefined -Wl,-soname,libXCTest.so -L{1}/lib/swift/linux/ -lswiftGlibc -lswiftCore -lm".format(build_dir, swift_build_dir))
if platform.system() == "Darwin":
sdkpath_cmd = shlex.split("xcrun --show-sdk-path --sdk macosx")
sdk, err = subprocess.Popen(sdkpath_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
run("{swiftc} -sdk {sdkpath} -c {style_options} -emit-object {obj} -module-name XCTest -parse-as-library -emit-module "
"-emit-module-path {build_dir}/XCTest.swiftmodule -o {build_dir}/XCTest.o -force-single-frontend-invocation "
"-module-link-name XCTest".format(
swiftc=swiftc,
sdkpath=sdk.strip(),
style_options=style_options,
obj=" ".join(sourcePaths),
build_dir=build_dir)
)
run("clang {build_dir}/XCTest.o -shared -o {build_dir}/libXCTest.so -L{swift_build_dir}/lib/swift/macosx/ -lswiftCore -lm".format(
build_dir=build_dir,
swift_build_dir=swift_build_dir)
)
else:
run("{0} -c {1} -emit-object {2} -module-name XCTest -parse-as-library -emit-module "
"-emit-module-path {3}/XCTest.swiftmodule -o {3}/XCTest.o -force-single-frontend-invocation "
"-module-link-name XCTest".format(swiftc, style_options, " ".join(sourcePaths), build_dir))
run("clang {0}/XCTest.o -shared -o {0}/libXCTest.so -Wl,--no-undefined -Wl,-soname,libXCTest.so -L{1}/lib/swift/linux/ -lswiftGlibc -lswiftCore -lm".format(build_dir, swift_build_dir))

# If we were given an install directive, perform installation
if args.module_path is not None and args.lib_path is not None:
Expand Down