Repository navigation
Expand file tree
/
Copy pathupdate_libgit2
More file actions
executable file
·86 lines (70 loc) · 2.47 KB
/
Copy pathupdate_libgit2
File metadata and controls
executable file
·86 lines (70 loc) · 2.47 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
#!/bin/sh
set -e
# Resolve the repository root so the script behaves identically whether CI runs
# it from the root or Xcode runs it from $SRCROOT.
script_dir=$(cd "$(dirname "$0")" && pwd)
script_path="$script_dir/$(basename "$0")"
root=$(cd "$script_dir/.." && pwd)
cd "$root"
submodule="$root/External/libgit2"
archive="$root/External/libgit2.a"
stamp="$root/External/libgit2.a.stamp"
# A key identifying the archive we would produce. It covers the submodule
# revision, so switching revisions invalidates the archive even when the new
# revision only deletes or renames sources; the submodule working tree, so
# local edits and deletions invalidate it; the host architecture, since the
# archive is built for the host only; and this script, so changing the cmake
# flags invalidates it. If any part of the key cannot be computed we rebuild
# rather than trust an archive we cannot account for.
build_key() {
git -C "$submodule" rev-parse HEAD || return 1
git -C "$submodule" status --porcelain --untracked-files=all \
-- . ':(exclude)build' || return 1
uname -m || return 1
git hash-object "$script_path" || return 1
}
key=$(build_key) || key=''
if [ -n "$key" ] && [ -f "$archive" ] && [ -f "$stamp" ] &&
[ "$key" = "$(cat "$stamp")" ]; then
echo "libgit2 is up to date."
exit 0
fi
# Drop the stamp before building: if the build fails or is interrupted, the
# archive left behind must not look up to date on the next run.
rm -f "$stamp"
cd "$submodule"
if [ -d "build" ]; then
rm -rf "build"
fi
mkdir build
cd build
# OpenSSL is keg-only, so add its pkgconfig location manually
if [ "$(uname -m)" = 'arm64' ]; then
echo "Running on a Apple Silicon M1"
export ARCH_PREFIX=/opt/homebrew
else
echo "Running on a Apple x86"
export ARCH_PREFIX=/usr/local
fi
export PKG_CONFIG_PATH=$ARCH_PREFIX/opt/openssl/lib/pkgconfig:$ARCH_PREFIX/lib/pkgconfig
# augment path to help it find cmake installed in /usr/local/bin,
# e.g. via brew. Xcode's Run Script phase doesn't seem to honor
# ~/.MacOSX/environment.plist
PATH="$ARCH_PREFIX/bin:$PATH"
cmake --version
cmake -DBUILD_SHARED_LIBS:BOOL=OFF \
-DBUILD_TESTS:BOOL=OFF \
-DTHREADSAFE:BOOL=ON \
-DUSE_SSH=libssh2 \
-DUSE_GSSAPI:BOOL=OFF \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
..
cmake --build .
rm -f "$archive"
cp -v "libgit2.a" "$archive"
if [ -n "$key" ]; then
printf '%s\n' "$key" > "$stamp"
else
echo "Could not record a libgit2 build stamp; libgit2 will be rebuilt next time." >&2
fi
echo "libgit2 has been updated."