t4205: don't exit test script on failure
[git.git] / contrib / vscode / init.sh
blob521d303722595719c79d0ed6a11612327c2d0972
1 #!/bin/sh
3 die () {
4 echo "$*" >&2
5 exit 1
8 cd "$(dirname "$0")"/../.. ||
9 die "Could not cd to top-level directory"
11 mkdir -p .vscode ||
12 die "Could not create .vscode/"
14 # General settings
16 cat >.vscode/settings.json.new <<\EOF ||
18 "C_Cpp.intelliSenseEngine": "Default",
19 "C_Cpp.intelliSenseEngineFallback": "Disabled",
20 "[git-commit]": {
21 "editor.wordWrap": "wordWrapColumn",
22 "editor.wordWrapColumn": 72
24 "[c]": {
25 "editor.detectIndentation": false,
26 "editor.insertSpaces": false,
27 "editor.tabSize": 8,
28 "files.trimTrailingWhitespace": true
30 "[txt]": {
31 "editor.detectIndentation": false,
32 "editor.insertSpaces": false,
33 "editor.tabSize": 8,
34 "files.trimTrailingWhitespace": true
36 "files.associations": {
37 "*.h": "c",
38 "*.c": "c"
40 "cSpell.ignorePaths": [
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 "mksnpath",
96 "mktag",
97 "mktree",
98 "mmblob",
99 "mmbuffer",
100 "mmfile",
101 "noenv",
102 "nparents",
103 "ntpath",
104 "ondisk",
105 "ooid",
106 "oplen",
107 "osdl",
108 "pnew",
109 "pold",
110 "ppinfo",
111 "pushf",
112 "pushv",
113 "rawsz",
114 "rebasing",
115 "reencode",
116 "repo",
117 "rerere",
118 "scld",
119 "sharedrepo",
120 "spawnv",
121 "spawnve",
122 "spawnvpe",
123 "strdup'ing",
124 "submodule",
125 "submodules",
126 "topath",
127 "topo",
128 "tpatch",
129 "unexecutable",
130 "unhide",
131 "unkc",
132 "unkv",
133 "unmark",
134 "unmatch",
135 "unsets",
136 "unshown",
137 "untracked",
138 "untrackedcache",
139 "unuse",
140 "upos",
141 "uval",
142 "vreportf",
143 "wargs",
144 "wargv",
145 "wbuffer",
146 "wcmd",
147 "wcsnicmp",
148 "wcstoutfdup",
149 "wdeltaenv",
150 "wdir",
151 "wenv",
152 "wenvblk",
153 "wenvcmp",
154 "wenviron",
155 "wenvpos",
156 "wenvsz",
157 "wfile",
158 "wfilename",
159 "wfopen",
160 "wfreopen",
161 "wfullpath",
162 "which'll",
163 "wlink",
164 "wmain",
165 "wmkdir",
166 "wmktemp",
167 "wnewpath",
168 "wotype",
169 "wpath",
170 "wpathname",
171 "wpgmptr",
172 "wpnew",
173 "wpointer",
174 "wpold",
175 "wpos",
176 "wputenv",
177 "wrmdir",
178 "wship",
179 "wtarget",
180 "wtemplate",
181 "wunlink",
182 "xcalloc",
183 "xgetcwd",
184 "xmallocz",
185 "xmemdupz",
186 "xmmap",
187 "xopts",
188 "xrealloc",
189 "xsnprintf",
190 "xutftowcs",
191 "xutftowcsn",
192 "xwcstoutf"
194 "cSpell.ignoreRegExpList": [
195 "\\\"(DIRC|FSMN|REUC|UNTR)\\\"",
196 "\\\\u[0-9a-fA-Fx]{4}\\b",
197 "\\b(filfre|frotz|xyzzy)\\b",
198 "\\bCMIT_FMT_DEFAULT\\b",
199 "\\bde-munge\\b",
200 "\\bGET_OID_DISAMBIGUATORS\\b",
201 "\\bHASH_RENORMALIZE\\b",
202 "\\bTREESAMEness\\b",
203 "\\bUSE_STDEV\\b",
204 "\\Wchar *\\*\\W*utfs\\W",
205 "cURL's",
206 "nedmalloc'ed",
207 "ntifs\\.h",
211 die "Could not write settings.json"
213 # Infer some setup-specific locations/names
215 GCCPATH="$(which gcc)"
216 GDBPATH="$(which gdb)"
217 MAKECOMMAND="make -j5 DEVELOPER=1"
218 OSNAME=
220 case "$(uname -s)" in
221 MINGW*)
222 GCCPATH="$(cygpath -am "$GCCPATH")"
223 GDBPATH="$(cygpath -am "$GDBPATH")"
224 MAKE_BASH="$(cygpath -am /git-cmd.exe) --command=usr\\\\bin\\\\bash.exe"
225 MAKECOMMAND="$MAKE_BASH -lc \\\"$MAKECOMMAND\\\""
226 OSNAME=Win32
227 X=.exe
229 Linux)
230 OSNAME=Linux
232 Darwin)
233 OSNAME=macOS
235 esac
237 # Default build task
239 cat >.vscode/tasks.json.new <<EOF ||
241 // See https://go.microsoft.com/fwlink/?LinkId=733558
242 // for the documentation about the tasks.json format
243 "version": "2.0.0",
244 "tasks": [
246 "label": "make",
247 "type": "shell",
248 "command": "$MAKECOMMAND",
249 "group": {
250 "kind": "build",
251 "isDefault": true
257 die "Could not install default build task"
259 # Debugger settings
261 cat >.vscode/launch.json.new <<EOF ||
263 // Use IntelliSense to learn about possible attributes.
264 // Hover to view descriptions of existing attributes.
265 // For more information, visit:
266 // https://go.microsoft.com/fwlink/?linkid=830387
267 "version": "0.2.0",
268 "configurations": [
270 "name": "(gdb) Launch",
271 "type": "cppdbg",
272 "request": "launch",
273 "program": "\${workspaceFolder}/git$X",
274 "args": [],
275 "stopAtEntry": false,
276 "cwd": "\${workspaceFolder}",
277 "environment": [],
278 "MIMode": "gdb",
279 "miDebuggerPath": "$GDBPATH",
280 "setupCommands": [
282 "description": "Enable pretty-printing for gdb",
283 "text": "-enable-pretty-printing",
284 "ignoreFailures": true
291 die "Could not write launch configuration"
293 # C/C++ extension settings
295 make -f - OSNAME=$OSNAME GCCPATH="$GCCPATH" vscode-init \
296 >.vscode/c_cpp_properties.json <<\EOF ||
297 include Makefile
299 vscode-init:
300 @mkdir -p .vscode && \
301 incs= && defs= && \
302 for e in $(ALL_CFLAGS) \
303 '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \
304 '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
305 '-DBINDIR="$(bindir_relative_SQ)"' \
306 '-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"' \
307 '-DDEFAULT_GIT_TEMPLATE_DIR="$(template_dir_SQ)"' \
308 '-DETC_GITCONFIG="$(ETC_GITCONFIG_SQ)"' \
309 '-DETC_GITATTRIBUTES="$(ETC_GITATTRIBUTES_SQ)"' \
310 '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \
311 '-DCURL_DISABLE_TYPECHECK', \
312 '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
313 '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
314 '-DGIT_INFO_PATH="$(infodir_relative_SQ)"'; do \
315 case "$$e" in \
316 -I.) \
317 incs="$$(printf '% 16s"$${workspaceRoot}",\n%s' \
318 "" "$$incs")" \
319 ;; \
320 -I/*) \
321 incs="$$(printf '% 16s"%s",\n%s' \
322 "" "$${e#-I}" "$$incs")" \
323 ;; \
324 -I*) \
325 incs="$$(printf '% 16s"$${workspaceRoot}/%s",\n%s' \
326 "" "$${e#-I}" "$$incs")" \
327 ;; \
328 -D*) \
329 defs="$$(printf '% 16s"%s",\n%s' \
330 "" "$$(echo "$${e#-D}" | sed 's/"/\\&/g')" \
331 "$$defs")" \
332 ;; \
333 esac; \
334 done && \
335 echo '{' && \
336 echo ' "configurations": [' && \
337 echo ' {' && \
338 echo ' "name": "$(OSNAME)",' && \
339 echo ' "intelliSenseMode": "clang-x64",' && \
340 echo ' "includePath": [' && \
341 echo "$$incs" | sort | sed '$$s/,$$//' && \
342 echo ' ],' && \
343 echo ' "defines": [' && \
344 echo "$$defs" | sort | sed '$$s/,$$//' && \
345 echo ' ],' && \
346 echo ' "browse": {' && \
347 echo ' "limitSymbolsToIncludedHeaders": true,' && \
348 echo ' "databaseFilename": "",' && \
349 echo ' "path": [' && \
350 echo ' "$${workspaceRoot}"' && \
351 echo ' ]' && \
352 echo ' },' && \
353 echo ' "cStandard": "c11",' && \
354 echo ' "cppStandard": "c++17",' && \
355 echo ' "compilerPath": "$(GCCPATH)"' && \
356 echo ' }' && \
357 echo ' ],' && \
358 echo ' "version": 4' && \
359 echo '}'
361 die "Could not write settings for the C/C++ extension"
363 for file in .vscode/settings.json .vscode/tasks.json .vscode/launch.json
365 if test -f $file
366 then
367 if git diff --no-index --quiet --exit-code $file $file.new
368 then
369 rm $file.new
370 else
371 printf "The file $file.new has these changes:\n\n"
372 git --no-pager diff --no-index $file $file.new
373 printf "\n\nMaybe \`mv $file.new $file\`?\n\n"
375 else
376 mv $file.new $file
378 done