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