Repository navigation
Expand file tree
/
Copy pathsync-harness.sh
More file actions
executable file
·165 lines (140 loc) · 6.94 KB
/
Copy pathsync-harness.sh
File metadata and controls
executable file
·165 lines (140 loc) · 6.94 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env bash
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
HARNESS_DIR="${SCRIPT_DIR}/antigravity-sdk-harness"
BIN_DIR="${HARNESS_DIR}/src/main/resources/google/antigravity/bin"
DOWNLOADER_JAVA="${SCRIPT_DIR}/antigravity-sdk-wrapper/src/main/java/io/github/glaforge/antigravity/HarnessDownloader.java"
SLICES=("linux-x86_64" "osx-aarch64" "osx-x86_64" "linux-aarch64" "windows-x86_64" "windows-aarch64")
sync_version_references() {
local ver="$1"
if [ -n "$ver" ] && [ "$ver" != "unknown" ] && [ -f "$DOWNLOADER_JAVA" ]; then
python3 -c "
import re, pathlib
p = pathlib.Path('$DOWNLOADER_JAVA')
text = p.read_text()
updated = re.sub(r'(public static final String DEFAULT_UPSTREAM_VERSION = \")[^\"]+(\";)', r'\g<1>${ver}\g<2>', text)
if updated != text:
p.write_text(updated)
print('Updated HarnessDownloader.DEFAULT_UPSTREAM_VERSION to v${ver}')
"
fi
local os_name="$(uname -s | tr '[:upper:]' '[:lower:]')"
local arch_name="$(uname -m | tr '[:upper:]' '[:lower:]')"
local host_os=""
local host_arch=""
if [[ "$os_name" == *linux* ]]; then host_os="linux"; elif [[ "$os_name" == *darwin* ]] || [[ "$os_name" == *mac* ]]; then host_os="osx"; fi
if [[ "$arch_name" == *x86_64* ]] || [[ "$arch_name" == *amd64* ]]; then host_arch="x86_64"; elif [[ "$arch_name" == *arm64* ]] || [[ "$arch_name" == *aarch64* ]]; then host_arch="aarch64"; fi
if [ -n "$host_os" ] && [ -n "$host_arch" ]; then
local host_slice="${host_os}-${host_arch}"
local src_bin="${BIN_DIR}/${host_slice}/localharness"
local cache_dir="${HOME}/.antigravity/bin/${host_slice}"
if [ -f "$src_bin" ] && [ -d "${HOME}/.antigravity/bin" ]; then
local cache_ver=""
if [ -f "${cache_dir}/.version" ]; then
cache_ver=$(tr -d '[:space:]' < "${cache_dir}/.version")
fi
if [ "$cache_ver" != "$ver" ] || [ ! -f "${cache_dir}/localharness" ]; then
mkdir -p "$cache_dir"
cp "$src_bin" "${cache_dir}/localharness"
chmod +x "${cache_dir}/localharness"
echo "$ver" > "${cache_dir}/.version"
echo "Updated local cache in ${cache_dir} to v${ver}"
fi
fi
fi
}
# Check if binaries exist in legacy wrapper dir locally, copy them over
LEGACY_WRAPPER_BIN="${SCRIPT_DIR}/antigravity-sdk-wrapper/src/main/resources/google/antigravity/bin"
if [ -d "$LEGACY_WRAPPER_BIN" ] && [ -n "$(ls -A "$LEGACY_WRAPPER_BIN" 2>/dev/null)" ] && [ ! -d "$BIN_DIR" ]; then
echo "Migrating binaries from wrapper to harness module..."
mkdir -p "$BIN_DIR"
cp -R "$LEGACY_WRAPPER_BIN"/* "$BIN_DIR"/
fi
# If running inside a nested checkout (e.g. target/checkout during maven-release-plugin),
# check if the parent project already downloaded the binaries
PARENT_BIN_DIR="${SCRIPT_DIR}/../../antigravity-sdk-harness/src/main/resources/google/antigravity/bin"
if [ -d "$PARENT_BIN_DIR" ] && [ -n "$(ls -A "$PARENT_BIN_DIR" 2>/dev/null)" ]; then
echo "Found pre-synced binaries in parent directory: $PARENT_BIN_DIR"
echo "Copying binaries from parent..."
mkdir -p "$BIN_DIR"
cp -R "$PARENT_BIN_DIR"/* "$BIN_DIR"/
echo "Binaries successfully copied from parent."
exit 0
fi
CURL_OPTS=(-sSfL --retry 5 --retry-all-errors --retry-delay 2 --connect-timeout 15)
PACKAGE_INFO=$(curl "${CURL_OPTS[@]}" https://pypi.org/pypi/google-antigravity/json)
UPSTREAM_VERSION=$(echo "$PACKAGE_INFO" | jq -r '.info.version // "unknown"')
echo "Detected upstream google-antigravity version: v${UPSTREAM_VERSION}"
VERSION_FILE="${BIN_DIR}/.version"
CURRENT_VERSION=""
if [ -f "$VERSION_FILE" ]; then
CURRENT_VERSION=$(cat "$VERSION_FILE" | tr -d '[:space:]')
fi
# Check if all slices already exist locally, are non-empty, and match upstream version
ALL_EXIST=true
for SLICE in "${SLICES[@]}"; do
BINARY_PATH="$BIN_DIR/$SLICE/localharness"
if [[ "$SLICE" == windows* ]]; then
BINARY_PATH="$BIN_DIR/$SLICE/localharness.exe"
fi
if [ ! -f "$BINARY_PATH" ] || [ ! -s "$BINARY_PATH" ]; then
ALL_EXIST=false
break
fi
done
if [ "$ALL_EXIST" = true ] && [ "$CURRENT_VERSION" = "$UPSTREAM_VERSION" ] && [ "${FORCE_SYNC:-false}" != "true" ]; then
sync_version_references "$UPSTREAM_VERSION"
echo "All Go harness binaries are already present and up-to-date (v${CURRENT_VERSION}) in $BIN_DIR. (Set FORCE_SYNC=true to re-download and unpack Python source)"
exit 0
fi
echo "Syncing Go harness binaries from upstream PyPI wheels (current: '${CURRENT_VERSION:-none}', target: 'v${UPSTREAM_VERSION}')..."
PLATFORMS=("manylinux" "macosx" "macosx" "manylinux" "win" "win")
ARCHS=("x86_64" "arm64" "x86_64" "aarch64" "amd64" "arm64")
EXTRACTED_PYTHON=false
for i in "${!PLATFORMS[@]}"; do
PLATFORM="${PLATFORMS[$i]}"
ARCH="${ARCHS[$i]}"
SLICE="${SLICES[$i]}"
echo "Searching wheel for: $SLICE"
WHEEL_URL=$(echo "$PACKAGE_INFO" | jq -r --arg plt "$PLATFORM" --arg arc "$ARCH" '.urls[] | select(.filename | contains($plt) and contains($arc)) | .url' | head -n 1)
if [ -n "$WHEEL_URL" ] && [ "$WHEEL_URL" != "null" ]; then
WHEEL_FILE="wheel_${SLICE}.whl"
echo "Downloading $SLICE from $WHEEL_URL"
curl "${CURL_OPTS[@]}" -o "$WHEEL_FILE" "$WHEEL_URL"
# Extract Python package source from the first downloaded wheel for systematic diffing and API audit
if [ "$EXTRACTED_PYTHON" = false ]; then
UPSTREAM_PYTHON_DIR="${SCRIPT_DIR}/target/upstream-python"
echo "Extracting Python SDK source to $UPSTREAM_PYTHON_DIR and /tmp/antigravity_upstream/ for API audit..."
rm -rf "$UPSTREAM_PYTHON_DIR" /tmp/antigravity_upstream
mkdir -p "$UPSTREAM_PYTHON_DIR" /tmp/antigravity_upstream
unzip -q -o "$WHEEL_FILE" "google/antigravity/*" -d "$UPSTREAM_PYTHON_DIR" 2>/dev/null || true
if [ -d "$UPSTREAM_PYTHON_DIR/google/antigravity" ]; then
cp -R "$UPSTREAM_PYTHON_DIR"/google/antigravity/* /tmp/antigravity_upstream/ 2>/dev/null || true
echo "Python SDK source successfully unpacked."
fi
EXTRACTED_PYTHON=true
fi
TARGET_DIR="$BIN_DIR/$SLICE"
mkdir -p "$TARGET_DIR"
if [[ "$PLATFORM" == "win" ]]; then
unzip -p "$WHEEL_FILE" "google/antigravity/bin/localharness.exe" > "$TARGET_DIR/localharness.exe"
chmod +x "$TARGET_DIR/localharness.exe"
else
unzip -p "$WHEEL_FILE" "google/antigravity/bin/localharness" > "$TARGET_DIR/localharness"
chmod +x "$TARGET_DIR/localharness"
fi
rm -f "$WHEEL_FILE"
else
echo "Warning: No matching upstream wheel found for platform slice: $SLICE"
fi
done
# Write version stamp and synchronize version references
echo "$UPSTREAM_VERSION" > "$BIN_DIR/.version"
sync_version_references "$UPSTREAM_VERSION"
echo "================================================================="
echo "Go harness synchronization complete (upstream v${UPSTREAM_VERSION})."
if [ "$EXTRACTED_PYTHON" = true ]; then
echo "Python SDK source unpacked at: /tmp/antigravity_upstream/"
echo "Audit step: diff -r <previous_source_dir> /tmp/antigravity_upstream/"
fi
echo "================================================================="