Git fork
1#!/bin/sh
2
3die () {
4 echo "$*" >&2
5 exit 1
6}
7
8cd "$(dirname "$0")"/../.. ||
9die "Could not cd to top-level directory"
10
11mkdir -p .vscode ||
12die "Could not create .vscode/"
13
14# General settings
15
16cat >.vscode/settings.json.new <<\EOF ||
17{
18 "C_Cpp.intelliSenseEngine": "Default",
19 "C_Cpp.intelliSenseEngineFallback": "Disabled",
20 "[git-commit]": {
21 "editor.wordWrap": "wordWrapColumn",
22 "editor.wordWrapColumn": 72
23 },
24 "[c]": {
25 "editor.detectIndentation": false,
26 "editor.insertSpaces": false,
27 "editor.tabSize": 8,
28 "files.trimTrailingWhitespace": true
29 },
30 "[txt]": {
31 "editor.detectIndentation": false,
32 "editor.insertSpaces": false,
33 "editor.tabSize": 8,
34 "files.trimTrailingWhitespace": true
35 },
36 "files.associations": {
37 "*.h": "c",
38 "*.c": "c"
39 },
40 "cSpell.ignorePaths": [
41 ],
42 "cSpell.words": [
43 "DATAW",
44 "DBCACHED",
45 "DFCHECK",
46 "DTYPE",
47 "Hamano",
48 "HCAST",
49 "HEXSZ",
50 "HKEY",
51 "HKLM",
52 "IFGITLINK",
53 "IFINVALID",
54 "ISBROKEN",
55 "ISGITLINK",
56 "ISSYMREF",
57 "Junio",
58 "LPDWORD",
59 "LPPROC",
60 "LPWSTR",
61 "MSVCRT",
62 "NOARG",
63 "NOCOMPLETE",
64 "NOINHERIT",
65 "RENORMALIZE",
66 "STARTF",
67 "STARTUPINFOEXW",
68 "Schindelin",
69 "UCRT",
70 "YESNO",
71 "argcp",
72 "beginthreadex",
73 "committish",
74 "contentp",
75 "cpath",
76 "cpidx",
77 "ctim",
78 "dequote",
79 "envw",
80 "ewah",
81 "fdata",
82 "fherr",
83 "fhin",
84 "fhout",
85 "fragp",
86 "fsmonitor",
87 "hnsec",
88 "idents",
89 "includeif",
90 "interpr",
91 "iprog",
92 "isexe",
93 "iskeychar",
94 "kompare",
95 "mktag",
96 "mktree",
97 "mmblob",
98 "mmbuffer",
99 "mmfile",
100 "noenv",
101 "nparents",
102 "ntpath",
103 "ondisk",
104 "ooid",
105 "oplen",
106 "osdl",
107 "pnew",
108 "pold",
109 "ppinfo",
110 "pushf",
111 "pushv",
112 "rawsz",
113 "rebasing",
114 "reencode",
115 "repo",
116 "rerere",
117 "scld",
118 "sharedrepo",
119 "spawnv",
120 "spawnve",
121 "spawnvpe",
122 "strdup'ing",
123 "submodule",
124 "submodules",
125 "topath",
126 "topo",
127 "tpatch",
128 "unexecutable",
129 "unhide",
130 "unkc",
131 "unkv",
132 "unmark",
133 "unmatch",
134 "unsets",
135 "unshown",
136 "untracked",
137 "untrackedcache",
138 "unuse",
139 "upos",
140 "uval",
141 "vreportf",
142 "wargs",
143 "wargv",
144 "wbuffer",
145 "wcmd",
146 "wcsnicmp",
147 "wcstoutfdup",
148 "wdeltaenv",
149 "wdir",
150 "wenv",
151 "wenvblk",
152 "wenvcmp",
153 "wenviron",
154 "wenvpos",
155 "wenvsz",
156 "wfile",
157 "wfilename",
158 "wfopen",
159 "wfreopen",
160 "wfullpath",
161 "which'll",
162 "wlink",
163 "wmain",
164 "wmkdir",
165 "wmktemp",
166 "wnewpath",
167 "wotype",
168 "wpath",
169 "wpathname",
170 "wpgmptr",
171 "wpnew",
172 "wpointer",
173 "wpold",
174 "wpos",
175 "wputenv",
176 "wrmdir",
177 "wship",
178 "wtarget",
179 "wtemplate",
180 "wunlink",
181 "xcalloc",
182 "xgetcwd",
183 "xmallocz",
184 "xmemdupz",
185 "xmmap",
186 "xopts",
187 "xrealloc",
188 "xsnprintf",
189 "xutftowcs",
190 "xutftowcsn",
191 "xwcstoutf"
192 ],
193 "cSpell.ignoreRegExpList": [
194 "\\\"(DIRC|FSMN|REUC|UNTR)\\\"",
195 "\\\\u[0-9a-fA-Fx]{4}\\b",
196 "\\b(filfre|frotz|xyzzy)\\b",
197 "\\bCMIT_FMT_DEFAULT\\b",
198 "\\bde-munge\\b",
199 "\\bGET_OID_DISAMBIGUATORS\\b",
200 "\\bHASH_RENORMALIZE\\b",
201 "\\bTREESAMEness\\b",
202 "\\bUSE_STDEV\\b",
203 "\\Wchar *\\*\\W*utfs\\W",
204 "cURL's",
205 "nedmalloc'ed",
206 "ntifs\\.h",
207 ],
208}
209EOF
210die "Could not write settings.json"
211
212# Infer some setup-specific locations/names
213
214GCCPATH="$(which gcc)"
215GDBPATH="$(which gdb)"
216MAKECOMMAND="make -j5 DEVELOPER=1"
217OSNAME=
218X=
219case "$(uname -s)" in
220MINGW*)
221 GCCPATH="$(cygpath -am "$GCCPATH")"
222 GDBPATH="$(cygpath -am "$GDBPATH")"
223 MAKE_BASH="$(cygpath -am /git-cmd.exe) --command=usr\\\\bin\\\\bash.exe"
224 MAKECOMMAND="$MAKE_BASH -lc \\\"$MAKECOMMAND\\\""
225 OSNAME=Win32
226 X=.exe
227 ;;
228Linux)
229 OSNAME=Linux
230 ;;
231Darwin)
232 OSNAME=macOS
233 ;;
234esac
235
236# Default build task
237
238cat >.vscode/tasks.json.new <<EOF ||
239{
240 // See https://go.microsoft.com/fwlink/?LinkId=733558
241 // for the documentation about the tasks.json format
242 "version": "2.0.0",
243 "tasks": [
244 {
245 "label": "make",
246 "type": "shell",
247 "command": "$MAKECOMMAND",
248 "group": {
249 "kind": "build",
250 "isDefault": true
251 }
252 }
253 ]
254}
255EOF
256die "Could not install default build task"
257
258# Debugger settings
259
260cat >.vscode/launch.json.new <<EOF ||
261{
262 // Use IntelliSense to learn about possible attributes.
263 // Hover to view descriptions of existing attributes.
264 // For more information, visit:
265 // https://go.microsoft.com/fwlink/?linkid=830387
266 "version": "0.2.0",
267 "configurations": [
268 {
269 "name": "(gdb) Launch",
270 "type": "cppdbg",
271 "request": "launch",
272 "program": "\${workspaceFolder}/git$X",
273 "args": [],
274 "stopAtEntry": false,
275 "cwd": "\${workspaceFolder}",
276 "environment": [],
277 "MIMode": "gdb",
278 "miDebuggerPath": "$GDBPATH",
279 "setupCommands": [
280 {
281 "description": "Enable pretty-printing for gdb",
282 "text": "-enable-pretty-printing",
283 "ignoreFailures": true
284 }
285 ]
286 }
287 ]
288}
289EOF
290die "Could not write launch configuration"
291
292# C/C++ extension settings
293
294make -f - OSNAME=$OSNAME GCCPATH="$GCCPATH" vscode-init \
295 >.vscode/c_cpp_properties.json <<\EOF ||
296include Makefile
297
298vscode-init:
299 @mkdir -p .vscode && \
300 incs= && defs= && \
301 for e in $(ALL_CFLAGS) \
302 '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
303 '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
304 '-DBINDIR="$(bindir_relative_SQ)"' \
305 '-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"' \
306 '-DDEFAULT_GIT_TEMPLATE_DIR="$(template_dir_SQ)"' \
307 '-DETC_GITCONFIG="$(ETC_GITCONFIG_SQ)"' \
308 '-DETC_GITATTRIBUTES="$(ETC_GITATTRIBUTES_SQ)"' \
309 '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
310 '-DCURL_DISABLE_TYPECHECK', \
311 '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
312 '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
313 '-DGIT_INFO_PATH="$(infodir_relative_SQ)"'; do \
314 case "$$e" in \
315 -I.) \
316 incs="$$(printf '% 16s"$${workspaceRoot}",\n%s' \
317 "" "$$incs")" \
318 ;; \
319 -I/*) \
320 incs="$$(printf '% 16s"%s",\n%s' \
321 "" "$${e#-I}" "$$incs")" \
322 ;; \
323 -I*) \
324 incs="$$(printf '% 16s"$${workspaceRoot}/%s",\n%s' \
325 "" "$${e#-I}" "$$incs")" \
326 ;; \
327 -D*) \
328 defs="$$(printf '% 16s"%s",\n%s' \
329 "" "$$(echo "$${e#-D}" | sed 's/"/\\&/g')" \
330 "$$defs")" \
331 ;; \
332 esac; \
333 done && \
334 echo '{' && \
335 echo ' "configurations": [' && \
336 echo ' {' && \
337 echo ' "name": "$(OSNAME)",' && \
338 echo ' "intelliSenseMode": "clang-x64",' && \
339 echo ' "includePath": [' && \
340 echo "$$incs" | sort | sed '$$s/,$$//' && \
341 echo ' ],' && \
342 echo ' "defines": [' && \
343 echo "$$defs" | sort | sed '$$s/,$$//' && \
344 echo ' ],' && \
345 echo ' "browse": {' && \
346 echo ' "limitSymbolsToIncludedHeaders": true,' && \
347 echo ' "databaseFilename": "",' && \
348 echo ' "path": [' && \
349 echo ' "$${workspaceRoot}"' && \
350 echo ' ]' && \
351 echo ' },' && \
352 echo ' "cStandard": "c11",' && \
353 echo ' "cppStandard": "c++17",' && \
354 echo ' "compilerPath": "$(GCCPATH)"' && \
355 echo ' }' && \
356 echo ' ],' && \
357 echo ' "version": 4' && \
358 echo '}'
359EOF
360die "Could not write settings for the C/C++ extension"
361
362for file in .vscode/settings.json .vscode/tasks.json .vscode/launch.json
363do
364 if test -f $file
365 then
366 if git diff --no-index --quiet --exit-code $file $file.new
367 then
368 rm $file.new
369 else
370 printf "The file $file.new has these changes:\n\n"
371 git --no-pager diff --no-index $file $file.new
372 printf "\n\nMaybe \`mv $file.new $file\`?\n\n"
373 fi
374 else
375 mv $file.new $file
376 fi
377done