aboutsummaryrefslogtreecommitdiff
path: root/www/code-server/Makefile.build
blob: 96d52ea2acb4e0d5bda81822c4673bd64dadfb17 (plain) (blame)
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
post-extract:
	${RM} -r ${WRKSRC}/lib/vscode
	${MV} ${WRKDIR}/vscode-${VSCODE_VERSION} ${WRKSRC}/lib/vscode
.if !defined(BOOTSTRAP_NODE_MODULES)
	${TAR} -xzf ${DISTDIR}/code-server-node-modules-${DISTVERSION}${EXTRACT_SUFX} \
		-C ${WRKSRC}
.endif
	${TAR} -xzf ${DISTDIR}/vscode-reh-web-linux-x64-${DISTVERSION}${EXTRACT_SUFX} \
		-C ${WRKSRC}
# Provide Copilot CLI SDK so the copilot extension postinstall passes.
# GitHub Copilot is closed-source and not usable on FreeBSD.
	${MKDIR} ${WRKSRC}/lib/vscode/extensions/copilot/node_modules/@github/copilot-freebsd-x64
	${CP} -R ${WRKDIR}/package/ ${WRKSRC}/lib/vscode/extensions/copilot/node_modules/@github/copilot-freebsd-x64
.for dir in ${VSCODE_NODE_MODULES}
	${MKDIR} ${WRKSRC}/lib/vscode/${dir}
	${TAR} -xzf ${WRKDIR}/vscode-${dir:S|/|_|g}-node-modules${EXTRACT_SUFX} \
		-C ${WRKSRC}/lib/vscode/${dir}
.endfor
# Provide @github/copilot-linux-x64 in remote/node_modules so the reh-web build's
# ensureCopilotPlatformPackage() finds it locally instead of running "npm pack"
# (which needs network and fails in poudriere). GitHub Copilot is closed-source
# and not usable on FreeBSD; this only lets the build pass.
	${MKDIR} ${WRKSRC}/lib/vscode/remote/node_modules/@github/copilot-linux-x64
	${CP} -R ${WRKDIR}/package/ ${WRKSRC}/lib/vscode/remote/node_modules/@github/copilot-linux-x64

post-patch:
	cd ${WRKSRC} && while read patchfile; do \
		${PATCH} -p1 < ${WRKSRC}/patches/$${patchfile}; \
	done < ${WRKSRC}/patches/series
	${CP} ${WRKSRC}/lib/vscode/build/.moduleignore.linux \
		${WRKSRC}/lib/vscode/build/.moduleignore.freebsd
	${REINPLACE_CMD} -e '/"typeRoots": \[/,+2d' \
		${WRKSRC}/lib/vscode/extensions/configuration-editing/tsconfig.json
	${LOCALBASE}/bin/jq \
		'.version = "${DISTVERSION}" | .commit = "${DISTVERSION}"' \
		${WRKSRC}/package.json > ${WRKSRC}/package.json.tmp
	${MV} ${WRKSRC}/package.json.tmp ${WRKSRC}/package.json
	${LOCALBASE}/bin/jq --slurp '.[0] * .[1]' \
		${WRKSRC}/lib/vscode/product.json ${FILESDIR}/product.json.extensions \
		> ${WRKSRC}/lib/vscode/product.json.tmp
	${MV} ${WRKSRC}/lib/vscode/product.json.tmp ${WRKSRC}/lib/vscode/product.json

do-build:
	cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} \
		npm run build
	cd ${WRKSRC}/lib/vscode/node_modules/node-pty && \
		${SETENV} ${MAKE_ENV} PYTHON=${PYTHON_CMD} \
		node ${LOCALBASE}/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js \
		rebuild --nodedir=${LOCALBASE}
	${MKDIR} ${WRKSRC}/lib/vscode/node_modules/node-pty/prebuilds/freebsd-x64
	${CP} ${WRKSRC}/lib/vscode/node_modules/node-pty/build/Release/pty.node \
		${WRKSRC}/lib/vscode/node_modules/node-pty/prebuilds/freebsd-x64/pty.node
	cd ${WRKSRC}/lib/vscode/node_modules/@vscode/spdlog && \
		${SETENV} ${MAKE_ENV} PYTHON=${PYTHON_CMD} \
		node ${LOCALBASE}/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js \
		rebuild --nodedir=${LOCALBASE}
	cd ${WRKSRC}/lib/vscode/node_modules/@vscode/native-watchdog && \
		${SETENV} ${MAKE_ENV} PYTHON=${PYTHON_CMD} \
		CXXFLAGS="${CXXFLAGS} -I${LOCALBASE}/include" \
		node ${LOCALBASE}/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js \
		rebuild --nodedir=${LOCALBASE}
	cd ${WRKSRC}/lib/vscode && \
		VSCODE_NODE_VERSION=$$(${AWK} \
			'/node-v[0-9.]+-linux-x64\.tar\.gz/ { \
				sub(/^.*node-v/, "", $$2); \
				sub(/-linux-x64\.tar\.gz$$/, "", $$2); \
				print $$2; \
				exit \
			}' build/checksums/nodejs.txt) && \
		${MKDIR} .build/node/v$${VSCODE_NODE_VERSION}/linux-x64 && \
		${CP} ${LOCALBASE}/bin/node \
			.build/node/v$${VSCODE_NODE_VERSION}/linux-x64/node
	cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} VERSION=${DISTVERSION} \
		npm run build:vscode
# Replace bundled Copilot Linux rg/tgrep binaries with native FreeBSD
# versions from textproc/ripgrep and textproc/tgrep. The linux-x64 path
# names are kept as-is (Copilot resolves them by that label); only the
# binary contents are swapped so no Linux ELF binaries ship in the package.
.for _rg in extensions/copilot/node_modules/@github/copilot/sdk/ripgrep/bin/linux-x64/rg \
		node_modules/@github/copilot-linux-x64/ripgrep/bin/linux-x64/rg \
		node_modules/@vscode/ripgrep-universal/bin/linux-x64/rg
	${CP} ${LOCALBASE}/bin/rg \
		${WRKSRC}/lib/vscode-reh-web-linux-x64/${_rg}
.endfor
.for _tgrep in extensions/copilot/node_modules/@github/copilot/tgrep/bin/linux-x64/tgrep \
		extensions/copilot/node_modules/@github/copilot/sdk/tgrep/bin/linux-x64/tgrep \
		node_modules/@github/copilot-linux-x64/tgrep/bin/linux-x64/tgrep
	${CP} ${LOCALBASE}/bin/tgrep \
		${WRKSRC}/lib/vscode-reh-web-linux-x64/${_tgrep}
.endfor
	${PERL} -0pi \
		-e 's#process\.platform !== "linux"\) \{#process.platform !== "linux" \&\&\n    process.platform !== "freebsd") {#' \
		${WRKSRC}/lib/vscode-reh-web-linux-x64/node_modules/@vscode/deviceid/dist/index.js
	${PERL} -0pi \
		-e 's#process\.platform === "linux"#process.platform === "linux" || process.platform === "freebsd"#' \
		${WRKSRC}/lib/vscode-reh-web-linux-x64/node_modules/@vscode/deviceid/dist/storage.js
	${MKDIR} ${WRKSRC}/lib/vscode-reh-web-linux-x64/node_modules/node-pty/prebuilds/freebsd-x64
	${CP} ${WRKSRC}/lib/vscode/node_modules/node-pty/build/Release/pty.node \
		${WRKSRC}/lib/vscode-reh-web-linux-x64/node_modules/node-pty/prebuilds/freebsd-x64/pty.node
	${MKDIR} ${WRKSRC}/lib/vscode-reh-web-linux-x64/node_modules/@vscode/spdlog/build/Release
	${CP} ${WRKSRC}/lib/vscode/node_modules/@vscode/spdlog/build/Release/spdlog.node \
		${WRKSRC}/lib/vscode-reh-web-linux-x64/node_modules/@vscode/spdlog/build/Release/spdlog.node
	${MKDIR} ${WRKSRC}/lib/vscode-reh-web-linux-x64/node_modules/@vscode/native-watchdog/build/Release
	${CP} ${WRKSRC}/lib/vscode/node_modules/@vscode/native-watchdog/build/Release/watchdog.node \
		${WRKSRC}/lib/vscode-reh-web-linux-x64/node_modules/@vscode/native-watchdog/build/Release/watchdog.node
	${RM} ${WRKSRC}/lib/vscode-reh-web-linux-x64/node

make-node-modules-archive:
	${MAKE} BOOTSTRAP_NODE_MODULES=yes clean extract
	cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} \
		npm ci --ignore-scripts --no-progress --no-audit \
		--no-fund --no-update-notifier
	cd ${WRKSRC} && ${TAR} -czf \
		${WRKDIR}/code-server-node-modules-${DISTVERSION}${EXTRACT_SUFX} \
		node_modules