| #!/bin/bash |
| # |
| # Licensed to the Apache Software Foundation (ASF) under one or more |
| # contributor license agreements. See the NOTICE file distributed with |
| # this work for additional information regarding copyright ownership. |
| # The ASF licenses this file to You under the Apache License, Version 2.0 |
| # (the "License"); you may not use this file except in compliance with |
| # the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| |
| set -ex |
| |
| if [ -z "$1" ] ; then |
| echo 'Error: Missing action name' |
| exit 1 |
| fi |
| if [ -z "$2" ] ; then |
| echo 'Error: Missing kind, for example swift:4.1' |
| exit 2 |
| fi |
| OUTPUT_DIR="build" |
| if [ ${2} == "swift:3.1.1" ]; then |
| BASE_PATH="/swift3Action" |
| DEST_SOURCE="$BASE_PATH/spm-build" |
| RUNTIME="openwhisk/action-swift-v3.1.1" |
| elif [ ${2} == "swift:4.1" ]; then |
| RUNTIME="openwhisk/action-swift-v4.1" |
| BASE_PATH="/swift4Action" |
| DEST_SOURCE="/$BASE_PATH/spm-build/Sources/Action" |
| else |
| echo "Error: Kind $2 not recognize" |
| exit 3 |
| fi |
| DEST_PACKAGE_SWIFT="$BASE_PATH/spm-build/Package.swift" |
| |
| BUILD_FLAGS="" |
| if [ -n "$3" ] ; then |
| BUILD_FLAGS=${3} |
| fi |
| |
| echo "Using runtime $RUNTIME to compile swift" |
| docker run --rm --name=compile-ow-swift -it -v "$(pwd):/owexec" $RUNTIME bash -ex -c " |
| |
| if [ -f \"/owexec/$OUTPUT_DIR/$1.zip\" ] ; then |
| rm \"/owexec/$OUTPUT_DIR/$1.zip\" |
| fi |
| |
| echo 'Setting up build...' |
| cp /owexec/actions/$1/Sources/*.swift $DEST_SOURCE/ |
| |
| # action file can be either {action name}.swift or main.swift |
| if [ -f \"$DEST_SOURCE/$1.swift\" ] ; then |
| echo 'renaming $DEST_SOURCE/$1.swift $DEST_SOURCE/main.swift' |
| mv \"$DEST_SOURCE/$1.swift\" $DEST_SOURCE/main.swift |
| fi |
| # Add in the OW specific bits |
| cat $BASE_PATH/epilogue.swift >> $DEST_SOURCE/main.swift |
| echo '_run_main(mainFunction:main)' >> $DEST_SOURCE/main.swift |
| |
| # Only for Swift4 |
| if [ ${2} != "swift:3.1.1" ]; then |
| echo 'Adding wait to deal with escaping' |
| echo '_ = _whisk_semaphore.wait(timeout: .distantFuture)' >> $DEST_SOURCE/main.swift |
| fi |
| |
| echo \"Compiling $1...\" |
| cd /$BASE_PATH/spm-build |
| cp /owexec/actions/$1/Package.swift $DEST_PACKAGE_SWIFT |
| # we have our own Package.swift, do a full compile |
| swift build ${BUILD_FLAGS} -c release |
| |
| echo 'Creating archive $1.zip...' |
| #.build/release/Action |
| mkdir -p /owexec/$OUTPUT_DIR |
| zip \"/owexec/$OUTPUT_DIR/$1.zip\" .build/release/Action |
| |
| " |