|
1 | 1 | #!/bin/sh
|
2 | 2 |
|
| 3 | +# Skip this script when running SwiftUI previews |
| 4 | +if [ "$XCODE_RUNNING_FOR_PREVIEWS" == "1" ]; then |
| 5 | + echo "Skipping WireGuardTunnel for SwiftUI Previews" |
| 6 | + exit 0 |
| 7 | +fi |
| 8 | + |
3 | 9 | # build_wireguard_go_bridge.sh - Builds WireGuardKitGo
|
4 | 10 | #
|
5 | 11 | # Figures out the directory where the wireguard-apple SPM package
|
@@ -35,21 +41,31 @@ install_go() {
|
35 | 41 | export PATH="${TEMP_DIR}/go/bin:$PATH"
|
36 | 42 |
|
37 | 43 | # Verify the Go installation
|
38 |
| - go version |
| 44 | + go version || { |
| 45 | + echo "Error: Failed to install Go." |
| 46 | + exit 1 |
| 47 | + } |
39 | 48 |
|
40 | 49 | # Clean up by removing the downloaded tarball
|
41 | 50 | rm -rf "${TEMP_DIR}/go.tar.gz"
|
42 | 51 | }
|
43 | 52 |
|
44 |
| -# Check if Go is installed |
45 |
| -goPath=$(which go) |
| 53 | +# Check if Go is installed and has the correct version |
| 54 | +current_go_version=$(go version 2>/dev/null | awk '{print $3}' | sed 's/go//') |
46 | 55 |
|
47 |
| -# If Go is not installed, install it |
48 |
| -if [ -z "$goPath" ]; then |
49 |
| - echo "Go is not installed. Installing version ${GO_VERSION}..." |
50 |
| - install_go |
| 56 | +if [ "$current_go_version" == "$GO_VERSION" ]; then |
| 57 | + echo "Correct Go version (${GO_VERSION}) is already installed. Skipping installation." |
51 | 58 | else
|
52 |
| - echo "Go is already installed at ${goPath}." |
| 59 | + echo "Go version mismatch (found: $current_go_version, expected: $GO_VERSION). Installing correct version..." |
| 60 | + install_go |
| 61 | +fi |
| 62 | + |
| 63 | +# Prevent redundant builds by adding a caching marker |
| 64 | +BUILD_ARTIFACT="$BUILD_DIR/WireGuardGoBridge.artifact" |
| 65 | + |
| 66 | +if [ -f "$BUILD_ARTIFACT" ]; then |
| 67 | + echo "WireGuardGoBridge already built. Skipping build step..." |
| 68 | + exit 0 |
53 | 69 | fi
|
54 | 70 |
|
55 | 71 | # Proceed with the WireGuard build process
|
@@ -87,3 +103,8 @@ cd "$wireguard_go_dir" && /usr/bin/make || {
|
87 | 103 | echo "Error: Make failed in $wireguard_go_dir"
|
88 | 104 | exit 1
|
89 | 105 | }
|
| 106 | + |
| 107 | +# Create marker file to prevent redundant builds |
| 108 | +touch "$BUILD_ARTIFACT" |
| 109 | + |
| 110 | +echo "WireGuardGoBridge successfully built." |
0 commit comments