summaryrefslogtreecommitdiffhomepage
path: root/ios/build.sh
blob: 8a48a5d17c552f54cc4e6f98af9185bf3c1e869c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env bash

# This script is used to build and ship the iOS app
set -eu
shopt -s nullglob

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

###########################################
# Verify environment configuration
###########################################


# Provisioning profiles directory
if [[ -z ${IOS_PROVISIONING_PROFILES_DIR-} ]]; then
    IOS_PROVISIONING_PROFILES_DIR="$SCRIPT_DIR/iOS Provisioning Profiles"

    echo "The variable IOS_PROVISIONING_PROFILES_DIR is not set."
    echo "Default: $IOS_PROVISIONING_PROFILES_DIR"

    export IOS_PROVISIONING_PROFILES_DIR
fi

###########################################
# Build configuration
###########################################

# The Xcode project name without file extension
# The folder with all sources is expected to hold the same name
PROJECT_NAME="MullvadVPN"

# Xcode project directory
XCODE_PROJECT_DIR="$SCRIPT_DIR/$PROJECT_NAME.xcodeproj"

# Build output directory without trailing slash
BUILD_OUTPUT_DIR="$SCRIPT_DIR/Build"

# Xcode archive output
XCODE_ARCHIVE_DIR="$BUILD_OUTPUT_DIR/$PROJECT_NAME.xcarchive"

# Export options file used for producing .xcarchive
EXPORT_OPTIONS_PATH="$SCRIPT_DIR/ExportOptions.plist"

# Xcodebuild intermediate files directory
DERIVED_DATA_DIR="$BUILD_OUTPUT_DIR/DerivedData"

# System provisioning profiles directory
SYSTEM_PROVISIONING_PROFILES_DIR="$HOME/Library/MobileDevice/Provisioning Profiles"


###########################################
# Install provisioning profiles
###########################################

get_mobile_provisioning_uuid() {
  security cms -D -i "$1" | grep -aA1 UUID | grep -o "[-a-zA-Z0-9]\{36\}"
}

install_mobile_provisioning() {
    echo "Install system provisioning profiles into $SYSTEM_PROVISIONING_PROFILES_DIR"

    if [[ ! -d "$SYSTEM_PROVISIONING_PROFILES_DIR" ]]; then
        echo "Missing system provisioning profiles directory. Creating one."
        mkdir -p "$SYSTEM_PROVISIONING_PROFILES_DIR"
    fi

    for mobile_provisioning_path in "$IOS_PROVISIONING_PROFILES_DIR"/*.mobileprovision; do
        local profile_uuid
        profile_uuid=$(get_mobile_provisioning_uuid "$mobile_provisioning_path")
        local target_path="$SYSTEM_PROVISIONING_PROFILES_DIR/$profile_uuid.mobileprovision"

        if [[ -f "$target_path" ]]; then
            echo "Skip installing $mobile_provisioning_path"
        else
            echo "Install $mobile_provisioning_path -> $target_path"

            cp "$mobile_provisioning_path" "$target_path"
        fi
    done
}

install_mobile_provisioning


###########################################
# Build Xcode project
###########################################

release_build() {
  xcodebuild \
    -project "$XCODE_PROJECT_DIR" \
    -scheme "$PROJECT_NAME" \
    -sdk iphoneos \
    -configuration Release \
    -derivedDataPath "$DERIVED_DATA_DIR" \
    -disableAutomaticPackageResolution \
    "$@"
}

# Clean build directory
release_build clean

# Archive project
release_build archive -archivePath "$XCODE_ARCHIVE_DIR"

# Export IPA for distribution
xcodebuild \
    -exportArchive \
    -archivePath "$XCODE_ARCHIVE_DIR" \
    -exportOptionsPlist "$EXPORT_OPTIONS_PATH" \
    -exportPath "$BUILD_OUTPUT_DIR" \
    -disableAutomaticPackageResolution