-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·235 lines (211 loc) · 8.9 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·235 lines (211 loc) · 8.9 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env bash
#
# build.sh — build every artifact a working codegraph install needs.
#
# TypeScript : pnpm -r build -> packages/*/dist (incl. the viz bundle
# `codegraph city --serve` looks for) and
# extractors/typescript/dist/cli.js (bin/codegraph-typescript)
# Java : ./mvnw package -> extractors/java/target/codegraph-java.jar
# --native -> extractors/java/dist/<rid>/codegraph-java
# (GraalVM native image; HOST platform only —
# native-image drives the host linker and
# cannot cross-compile, so the per-OS matrix
# is one CI job per runner, not one job)
# C# : dotnet publish -> extractors/csharp/dist/<rid>/codegraph-csharp
# (self-contained single file; --publish-all
# builds the five-RID matrix from this host)
#
# Wraps both with the toolchain checks that a bare `pnpm`/`mvnw` invocation
# skips: Node's floor, the pinned pnpm, and a JDK that non-interactive shells
# cannot see because they never source sdkman.
#
# Tests are NOT run here — that is test.sh. `--skip-tests` on the Maven side is
# therefore deliberate, not a shortcut.
SCRIPT_NAME="build.sh"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/scripts/lib.sh"
trap on_error ERR
CLEAN="no"
NATIVE="no"
PUBLISH_ALL="no"
PUBLISH_RID=""
usage() {
cat <<'USAGE'
Usage: ./build.sh [options]
Builds the TypeScript workspace and the Java extractor.
Options:
--ts, --ts-only only packages/* (pnpm -r build)
--java, --java-only only extractors/java (./mvnw package)
--csharp, --csharp-only
only extractors/csharp (dotnet publish, host RID)
--native Java: also build the GraalVM native binary for THIS
platform (extractors/java/dist/<rid>/codegraph-java)
--publish-all C#: publish linux-x64, linux-arm64, osx-x64, osx-arm64, win-x64
--rid <rid> C#: publish exactly this RID (what the CI matrix calls, one per job)
--all everything (default)
--clean discard previous output first (dist/, target/)
--skip-install do not run pnpm install (requires an existing node_modules)
--no-frozen allow pnpm install to update pnpm-lock.yaml
--no-auto-install never provision pnpm via corepack; fail with instructions
-h, --help this text
Examples:
./build.sh # everything, lockfile frozen
./build.sh --ts --skip-install
./build.sh --java --clean
./build.sh --java --native # jar + the native binary for this OS/arch
USAGE
}
while [ $# -gt 0 ]; do
if parse_common_flag "$1"; then shift; continue; fi
case "$1" in
--clean) CLEAN="yes" ;;
--native) NATIVE="yes" ;;
--publish-all) PUBLISH_ALL="yes" ;;
--rid)
[ $# -ge 2 ] || usage_error "--rid needs a value"
PUBLISH_RID="$2"; shift ;;
-h|--help) usage; exit 0 ;;
*) usage_error "unknown option: $1" ;;
esac
shift
done
printf '%scodegraph build%s %s(%s)%s\n' "$C_BOLD" "$C_RESET" "$C_DIM" "$ROOT" "$C_RESET"
# ---------------------------------------------------------------- checks ----
step "toolchain"
if wants_ts; then check_node; ensure_pnpm; fi
SKIP_JAVA="no"; SKIP_CSHARP="no"
if wants_java; then
if have_java_extractor; then
ensure_jdk; ensure_mvnw
if [ "$NATIVE" = "yes" ]; then ensure_native_image; fi
else warn "no extractors/java in this checkout — skipping the Java build"; SKIP_JAVA="yes"; fi
fi
if wants_csharp; then
if have_csharp_extractor; then ensure_dotnet
else warn "no extractors/csharp in this checkout — skipping the C# build"; SKIP_CSHARP="yes"; fi
fi
step_done
# ------------------------------------------------------------ typescript ----
if wants_ts; then
pnpm_install
if [ "$CLEAN" = "yes" ]; then
step "clean (typescript)"
run rm -rf "$ROOT"/packages/*/dist
step_done
fi
step "build typescript (pnpm -r build)"
run pnpm --dir "$ROOT" -r build
step_done
fi
# ------------------------------------------------------------------ java ----
if wants_java && [ "$SKIP_JAVA" = "no" ]; then
if [ "$CLEAN" = "yes" ] && [ "$NATIVE" = "yes" ]; then
step "clean (java native)"
run rm -rf "$JAVA_DIR/dist"
step_done
fi
step "build java extractor (./mvnw package)"
# -B: batch mode, no ANSI progress spam in logs. Tests belong to test.sh.
( cd "$JAVA_DIR" && run ./mvnw -B -DskipTests package )
step_done
# One native executable for the HOST platform, ahead-of-time compiled from the
# shaded jar — which is deliberately the same artifact `java -jar` runs, so the
# two cannot drift apart. Reachability metadata travels inside that jar
# (META-INF/native-image/…), as does the embedded Java API reference the image
# resolves java.* against, since a native image has no JVM to borrow one from.
#
# --no-fallback refuse to emit an image that secretly needs a JVM;
# a missing reflection entry must fail the BUILD
# -march=compatibility target the baseline ISA, not this builder's CPU —
# a released binary must run on the machine that
# downloads it, not only on the one that built it
if [ "$NATIVE" = "yes" ]; then
rid="$(host_rid)"
step "build java native image ($rid)"
run mkdir -p "$JAVA_DIR/dist/$rid"
( cd "$JAVA_DIR" && run "$NATIVE_IMAGE" \
-jar target/codegraph-java.jar \
-o "dist/$rid/codegraph-java" \
--no-fallback \
-march=compatibility )
step_done
fi
fi
# ---------------------------------------------------------------- csharp ----
# One self-contained single-file binary per RID (PLAN.md §13.7): the runtime,
# Roslyn and the embedded BCL reference pack travel inside it, so the machine
# that runs it needs no SDK. ReadyToRun for startup; never trimmed (Roslyn is
# not trim-clean). Every RID cross-publishes from any host.
publish_csharp() {
local rid="$1"
( cd "$CSHARP_DIR" && run dotnet publish src/Codegraph.CSharp -c Release -r "$rid" --self-contained \
-p:PublishSingleFile=true -p:EnableCompressionInSingleFile=true -p:PublishReadyToRun=true \
-p:IncludeNativeLibrariesForSelfExtract=true -p:DebugType=none \
-o "dist/$rid" --nologo -v quiet )
}
if wants_csharp && [ "$SKIP_CSHARP" = "no" ]; then
if [ "$CLEAN" = "yes" ]; then
step "clean (csharp)"
run rm -rf "$CSHARP_DIR/dist" "$CSHARP_DIR"/src/*/bin "$CSHARP_DIR"/src/*/obj "$CSHARP_DIR"/tests/*/bin "$CSHARP_DIR"/tests/*/obj
step_done
fi
if [ -n "$PUBLISH_RID" ]; then
step "publish csharp extractor ($PUBLISH_RID)"
publish_csharp "$PUBLISH_RID"
step_done
elif [ "$PUBLISH_ALL" = "yes" ]; then
for rid in linux-x64 linux-arm64 osx-x64 osx-arm64 win-x64; do
step "publish csharp extractor ($rid)"
publish_csharp "$rid"
step_done
done
else
step "publish csharp extractor ($(host_rid))"
publish_csharp "$(host_rid)"
step_done
fi
fi
# -------------------------------------------------------------- artifacts ---
step "artifacts"
missing=0
report() {
if [ -e "$1" ]; then
printf ' %s✓%s %-46s %s\n' "$C_GREEN" "$C_RESET" "${1#$ROOT/}" "$(du -h "$1" | cut -f1)"
else
printf ' %s✗%s %-46s %smissing%s\n' "$C_RED" "$C_RESET" "${1#$ROOT/}" "$C_RED" "$C_RESET"
missing=$(( missing + 1 ))
fi
}
if wants_ts; then
for pkg in core analyzer city navigator cli; do report "$ROOT/packages/$pkg/dist/index.js"; done
# viz and navigator-ui ship Vite apps, not modules: their entry point is the
# HTML the CLI serves. Their absence is what breaks `--serve`, so name them.
report "$ROOT/packages/viz/dist/index.html"
report "$ROOT/packages/navigator-ui/dist/index.html"
# The TypeScript extractor is a workspace package: built by the same pnpm -r build.
report "$ROOT/extractors/typescript/dist/cli.js"
fi
if wants_java && [ "$SKIP_JAVA" = "no" ]; then
report "$JAVA_DIR/target/codegraph-java.jar"
if [ "$NATIVE" = "yes" ]; then
case "$(host_rid)" in
win-*) report "$JAVA_DIR/dist/$(host_rid)/codegraph-java.exe" ;;
*) report "$JAVA_DIR/dist/$(host_rid)/codegraph-java" ;;
esac
fi
fi
report_rid() {
case "$1" in
win-*) report "$CSHARP_DIR/dist/$1/codegraph-csharp.exe" ;;
*) report "$CSHARP_DIR/dist/$1/codegraph-csharp" ;;
esac
}
if wants_csharp && [ "$SKIP_CSHARP" = "no" ]; then
if [ -n "$PUBLISH_RID" ]; then report_rid "$PUBLISH_RID"
elif [ "$PUBLISH_ALL" = "yes" ]; then
for rid in linux-x64 linux-arm64 osx-x64 osx-arm64 win-x64; do report_rid "$rid"; done
else report_rid "$(host_rid)"; fi
fi
[ "$missing" -eq 0 ] || die "$missing expected artifact(s) missing — the build did not produce a usable tree"
step_done
summary
printf '\nRun it: %s./bin/codegraph --version%s\n' "$C_BOLD" "$C_RESET"