Repository: realm/realm-swift
File: build.sh (Shell)

Code before:
        if [ "$OS" != "Darwin" ]; then
	    echo "Framework for iOS can only be generated under Mac OS X"
	    exit 0
	fi
	realm_version="$(sh build.sh get-version)"
	FRAMEWORK=Realm.framework
	rm -rf "$FRAMEWORK" realm-ios*.zip || exit 1
	mkdir -p "$FRAMEWORK/Headers" || exit 1
	cp iphone-lib/librealm-objc-ios.a "$FRAMEWORK/Realm" || exit 1
	cp iphone-lib/include/realm/objc/*.h "$FRAMEWORK/Headers" || exit 1
	(cd "$FRAMEWORK/Headers" && mv realm.h Realm.h) || exit 1
	find "$FRAMEWORK/Headers" -name '*.h' -exec sed -i '' -e 's/import <realm\/objc\/\(.*\)>/import "\1"/g' {} \; || exit 1
	find "$FRAMEWORK/Headers" -name '*.h' -exec sed -i '' -e 's/include <realm\/objc\/\(.*\)>/include "\1"/g' {} \; || exit 1
	zip -r -q realm-ios-$realm_version.zip $FRAMEWORK || exit 1
	echo "Framework for iOS can be found in realm-ios-$realm_version.zip"
	exit 0
	;;

    "test")
        auto_configure || exit 1
        $MAKE check-norun || exit 1
        TEMP_DIR="$(mktemp -d /tmp/tightdb.objc.test.XXXX)" || exit 1
        mkdir -p "$TEMP_DIR/unit-tests.xctest/Contents/MacOS" || exit 1
        cp "src/realm/objc/test/unit-tests" "$TEMP_DIR/unit-tests.xctest/Contents/MacOS/" || exit 1
        XCODE_HOME="$(xcode-select --print-path)" || exit 1
        path_list_prepend DYLD_LIBRARY_PATH "$REALM_OBJC_HOME/src/realm/objc" || exit 1
        export DYLD_LIBRARY_PATH
        OBJC_DISABLE_GC=YES
        "$XCODE_HOME/usr/bin/xctest" -XCTest All "$TEMP_DIR/unit-tests.xctest" || exit 1
        echo "Test passed"
        exit 0
        ;;

    "test-debug")
        auto_configure || exit 1
        $MAKE check-debug-norun || exit 1
        TEMP_DIR="$(mktemp -d /tmp/tightdb.objc.test-debug.XXXX)" || exit 1
        mkdir -p "$TEMP_DIR/unit-tests-dbg.xctest/Contents/MacOS" || exit 1
        cp "src/realm/objc/test/unit-tests-dbg" "$TEMP_DIR/unit-tests-dbg.xctest/Contents/MacOS/" || exit 1
        XCODE_HOME="$(xcode-select --print-path)" || exit 1
        path_list_prepend DYLD_LIBRARY_PATH "$REALM_OBJC_HOME/src/realm/objc" || exit 1
        export DYLD_LIBRARY_PATH
        OBJC_DISABLE_GC=YES
        "$XCODE_HOME/usr/bin/xctest" -XCTest All "$TEMP_DIR/unit-tests-dbg.xctest" || exit 1
        echo "Test passed"
        exit 0
        ;;

    "test-gdb")
        auto_configure || exit 1
        $MAKE check-debug-norun || exit 1

Review comment (suggestion):
Consider quoting `$(...)` in case someone uses space in a folder name.


Code after:
        if [ "$OS" != "Darwin" ]; then
	    echo "Framework for iOS can only be generated under Mac OS X"
	    exit 0
	fi
	realm_version="$(sh build.sh get-version)"
	FRAMEWORK=Realm.framework
	rm -rf "$FRAMEWORK" realm-ios*.zip || exit 1
	mkdir -p "$FRAMEWORK/Headers" || exit 1
	cp iphone-lib/librealm-objc-ios.a "$FRAMEWORK/Realm" || exit 1
	cp iphone-lib/include/realm/objc/*.h "$FRAMEWORK/Headers" || exit 1
	(cd "$FRAMEWORK/Headers" && mv realm.h Realm.h) || exit 1
	find "$FRAMEWORK/Headers" -name '*.h' -exec sed -i '' -e 's/import <realm\/objc\/\(.*\)>/import "\1"/g' {} \; || exit 1
	find "$FRAMEWORK/Headers" -name '*.h' -exec sed -i '' -e 's/include <realm\/objc\/\(.*\)>/include "\1"/g' {} \; || exit 1
	zip -r -q realm-ios-$realm_version.zip $FRAMEWORK || exit 1
	echo "Framework for iOS can be found in realm-ios-$realm_version.zip"
	exit 0
	;;

    "package-examples")
        if [ ! -e "Realm.framework" ]; then
            echo "No Realm.framework found. You run the ios-framework target to generate it."
            exit 0
        fi
        (
            cd examples
            for folder in $(ls -l | grep "^d" | awk '{ print $9 }'); do
                echo "Packaging $folder..."
                cp -Rf ../Realm.framework $folder
                sed -i '.bak' -e "s/\.\.\/\.\.\/Realm\.framework/Realm\.framework/" $folder/*.xcodeproj/project.pbxproj
                echo "The $folder Xcode project file was modified like this:"
                diff $folder/*.xcodeproj/project.pbxproj.bak $folder/*.xcodeproj/project.pbxproj
                zip -rq $folder.zip $folder -x \*.bak
                mv -f $folder/*.xcodeproj/project.pbxproj.bak $folder/*.xcodeproj/project.pbxproj
            done
        ) || exit 1
        echo "The zipped examples are now available in the examples folder"
    ;;

    "test")
        auto_configure || exit 1
        $MAKE check-norun || exit 1
        TEMP_DIR="$(mktemp -d /tmp/tightdb.objc.test.XXXX)" || exit 1
        mkdir -p "$TEMP_DIR/unit-tests.xctest/Contents/MacOS" || exit 1
        cp "src/realm/objc/test/unit-tests" "$TEMP_DIR/unit-tests.xctest/Contents/MacOS/" || exit 1
        XCODE_HOME="$(xcode-select --print-path)" || exit 1
        path_list_prepend DYLD_LIBRARY_PATH "$REALM_OBJC_HOME/src/realm/objc" || exit 1
        export DYLD_LIBRARY_PATH
        OBJC_DISABLE_GC=YES
        "$XCODE_HOME/usr/bin/xctest" -XCTest All "$TEMP_DIR/unit-tests.xctest" || exit 1
        echo "Test passed"
        exit 0