File size: 4,571 Bytes
41dfd8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
113
114
115
116
117
118
#!/usr/bin/env bash
#
# Standalone, reproducible build script for the "tmpNote" macOS app
# (repo: macos-buddax2-tmpnote).
#
# It is fully self-contained: on a fresh `git clone` into which only this
# script (and launch.sh) has been copied, `bash build.sh` produces
# ./tmpNote.app.
#
#   * The CocoaPods dependencies (MASShortcut, SwiftyMarkdown) are committed
#     to the repo under Pods/, so a normal clone already has them. pod install
#     is therefore only run as a fallback when the Pods sandbox is missing or
#     out of sync with Podfile.lock.
#   * The project's original deployment targets (10.6 / 10.12 for the Pods)
#     are too low for Xcode 15, whose toolchain no longer ships libarclite.
#     We override MACOSX_DEPLOYMENT_TARGET=10.15 for the whole build. 10.15 is
#     required anyway by the app sources (they use Combine), and it is >= the
#     value that avoids the libarclite link error for the Objective-C pod.
#   * Code signing is fully disabled, as required for CI builds.
#
# No source-code changes are needed, so this script applies no patches.

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"

# CocoaPods needs a UTF-8 locale.
export LANG="${LANG:-en_US.UTF-8}"
export LC_ALL="${LC_ALL:-en_US.UTF-8}"

# ----------------------------------------------------------------------------
# Configuration
# ----------------------------------------------------------------------------
WORKSPACE="tmpNote.xcworkspace"
SCHEME="tmpNote"
CONFIGURATION="Release"
DERIVED_DATA="$SCRIPT_DIR/build_dd"
DEPLOYMENT_TARGET="10.15"
APP_NAME="tmpNote.app"
OUTPUT_DIR="${APP_OUTPUT_DIR:-$SCRIPT_DIR}"

# ----------------------------------------------------------------------------
# 1. Dependencies
# ----------------------------------------------------------------------------
# CocoaPods is only required if we have to (re)generate the Pods sandbox.
# The Pods/ directory is committed to the repo, so on a normal clone this is a
# no-op. We still ensure the tool is available for the fallback path below.
if ! command -v pod >/dev/null 2>&1; then
    if command -v brew >/dev/null 2>&1; then
        echo "==> CocoaPods not found; installing via Homebrew"
        brew list cocoapods >/dev/null 2>&1 || brew install cocoapods
    else
        echo "WARNING: CocoaPods not found and Homebrew is unavailable." >&2
    fi
fi

# Regenerate the Pods sandbox ONLY when it is missing or out of sync with
# Podfile.lock. In the normal (committed Pods) case the two lock files match
# and we keep the vendored, known-good sandbox untouched.
need_pod_install=0
if [ ! -d "$SCRIPT_DIR/Pods" ] || [ ! -f "$SCRIPT_DIR/Pods/Manifest.lock" ]; then
    need_pod_install=1
elif ! diff -q "$SCRIPT_DIR/Podfile.lock" "$SCRIPT_DIR/Pods/Manifest.lock" >/dev/null 2>&1; then
    need_pod_install=1
fi

if [ "$need_pod_install" -eq 1 ]; then
    echo "==> Pods sandbox missing or out of sync -> running pod install"
    if command -v pod >/dev/null 2>&1; then
        pod install --repo-update || pod install
    else
        echo "ERROR: pod install is required but CocoaPods is not installed." >&2
        exit 1
    fi
else
    echo "==> Pods sandbox is in sync with Podfile.lock; skipping pod install"
fi

# ----------------------------------------------------------------------------
# 2. Build
# ----------------------------------------------------------------------------
echo "==> Building $SCHEME ($CONFIGURATION) with deployment target $DEPLOYMENT_TARGET"
rm -rf "$DERIVED_DATA"

xcodebuild \
    -workspace "$WORKSPACE" \
    -scheme "$SCHEME" \
    -configuration "$CONFIGURATION" \
    -derivedDataPath "$DERIVED_DATA" \
    MACOSX_DEPLOYMENT_TARGET="$DEPLOYMENT_TARGET" \
    CODE_SIGN_IDENTITY="" \
    CODE_SIGNING_ALLOWED=NO \
    CODE_SIGN_STYLE=Manual \
    DEVELOPMENT_TEAM="" \
    PROVISIONING_PROFILE_SPECIFIER="" \
    clean build

# ----------------------------------------------------------------------------
# 3. Collect the result
# ----------------------------------------------------------------------------
BUILT_APP="$DERIVED_DATA/Build/Products/$CONFIGURATION/$APP_NAME"
if [ ! -d "$BUILT_APP" ]; then
    echo "ERROR: expected app not found at $BUILT_APP" >&2
    exit 1
fi

mkdir -p "$OUTPUT_DIR"
# Only copy if the destination differs from the freshly built location.
if [ "$(cd "$OUTPUT_DIR" && pwd)" != "$(cd "$(dirname "$BUILT_APP")" && pwd)" ]; then
    rm -rf "$OUTPUT_DIR/$APP_NAME"
    cp -R "$BUILT_APP" "$OUTPUT_DIR/"
fi

echo ""
echo "==> BUILD SUCCEEDED"
echo "    App bundle: $OUTPUT_DIR/$APP_NAME"