summary refs log tree commit diff
path: root/pkgs/applications/editors/vscode/extensions/cpptools/update_helper.sh
blob: 00ef77553242dd230518fd88f763196b04be9823 (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
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
#!/usr/bin/env nix-shell
#! nix-shell -p coreutils -p jq -p unzip -i bash
set -euo pipefail

#
# A little script to help maintaining this package. It will:
#
#  -  download the specified version of the extension to the store and print its url, packed store path and hash
#  -  unpack the extension, bring it to the store and print its store path and hash
#  -  fetch its runtimes dependencies from the 'package.json' file using the 'jq' utility, unpack those to the store
#     and print its url store path and hash
#  -  patch elf of the binaries that got a nix replacement
#  -  bring the patched version to the store
#  -  run their '--version' and call 'ldd'
#  -  print the version of the runtime deps nix replacements.
#
# TODO: Print to a properly formated nix file all the required information to fetch everything (extension + runtime deps).
# TODO: Print x86 and maybe darwin runtime dependencies.
#

scriptDir=$(cd "`dirname "$0"`"; pwd)
echo "scriptDir='$scriptDir'"

extPublisher="vscode"
extName="cpptools"
defaultExtVersion="0.16.1"
extVersion="${1:-$defaultExtVersion}"

echo
echo "------------- Downloading extension ---------------"

extZipStoreName="${extPublisher}-${extName}.zip"
extUrl="https://ms-vscode.gallery.vsassets.io/_apis/public/gallery/publisher/ms-vscode/extension/cpptools/${extVersion}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage"
echo "extUrl='$extUrl'"
storePathWithSha=$(nix-prefetch-url --name "$extZipStoreName" --print-path "$extUrl" 2> /dev/null)

cpptoolsZipStorePath="$(echo "$storePathWithSha" | tail -n1)"
cpptoolsZipSha256="$(echo "$storePathWithSha" | head -n1)"
echo "cpptoolsZipStorePath='$cpptoolsZipStorePath'"
echo "cpptoolsZipSha256='$cpptoolsZipSha256'"


extStoreName="${extPublisher}-${extName}"


function rm_tmpdir() {
  #echo "Removing \`tmpDir='$tmpDir'\`"
  rm -rf -- "$tmpDir"
  unset tmpDir
  trap - INT TERM HUP EXIT
}
function make_trapped_tmpdir() {
  tmpDir=$(mktemp -d)
  trap rm_tmpdir INT TERM HUP EXIT
}

echo
echo "------------- Unpacked extension ---------------"

make_trapped_tmpdir
unzip -q -d "$tmpDir" "$cpptoolsZipStorePath"

cpptoolsStorePath="$(nix add-to-store -n "$extStoreName" "$tmpDir")"
cpptoolsSha256="$(nix hash-path --base32 --type sha512 "$cpptoolsStorePath")"
echo "cpptoolsStorePath='$cpptoolsStorePath'"
echo "cpptoolsSha256='$cpptoolsSha256'"

rm_tmpdir

storePathWithSha=$(nix-prefetch-url --print-path "file://${cpptoolsStorePath}/extension/package.json" 2> /dev/null)

extPackageJSONStorePath="$(echo "$storePathWithSha" | tail -n1)"
extPackageJSONSha256="$(echo "$storePathWithSha" | head -n1)"
echo "extPackageJSONStorePath='$extPackageJSONStorePath'"
echo "extPackageJSONSha256='$extPackageJSONSha256'"

print_runtime_dep() {

  local outName="$1"
  local extPackageJSONStorePath="$2"
  local depDesc="$3"

  local urlRaw=$(cat "$extPackageJSONStorePath" | jq -r --arg desc "$depDesc" '.runtimeDependencies[] | select(.description == $desc) | .url')
  local url=$(echo $urlRaw | xargs curl -Ls -o /dev/null -w %{url_effective})

  local urlRawVarStr="${outName}_urlRaw='$urlRaw'"
  local urlVarStr="${outName}_url='$url'"
  echo "$urlRawVarStr"
  echo "$urlVarStr"

  local storePathWithSha="$(nix-prefetch-url --unpack --print-path "$url" 2> /dev/null)"

  local storePath="$(echo "$storePathWithSha" | tail -n1)"
  local sha256="$(echo "$storePathWithSha" | head -n1)"

  local sha256VarStr="${outName}_sha256='$sha256'"
  local storePathVarStr="${outName}_storePath='$storePath'"
  echo "$sha256VarStr"
  echo "$storePathVarStr"

  eval "$urlRawVarStr"
  eval "$urlVarStr"
  eval "$sha256VarStr"
  eval "$storePathVarStr"
}

echo
echo "------------- Runtime dependencies ---------------"

print_runtime_dep "langComponentBinaries" "$extPackageJSONStorePath" "C/C++ language components (Linux / x86_64)"
print_runtime_dep "monoRuntimeBinaries" "$extPackageJSONStorePath" "Mono Runtime (Linux / x86_64)"
print_runtime_dep "clanFormatBinaries" "$extPackageJSONStorePath" "ClangFormat (Linux / x86_64)"


echo
echo "------------- Runtime deps missing elf deps ---------------"

source "$scriptDir/missing_elf_deps.sh"

echo
echo "------------- Runtime dep mono ---------------"

make_trapped_tmpdir
find "$monoRuntimeBinaries_storePath" -mindepth 1 -maxdepth 1 | xargs -d '\n' cp -rp -t "$tmpDir"
chmod -R a+rwx "$tmpDir"

ls -la "$tmpDir/debugAdapters"

patchelf_mono "$tmpDir/debugAdapters/mono.linux-x86_64"

chmod a+x "$tmpDir/debugAdapters/mono.linux-x86_64"
ldd "$tmpDir/debugAdapters/mono.linux-x86_64"
"$tmpDir/debugAdapters/mono.linux-x86_64" --version

monoRuntimeBinariesPatched_storePath="$(nix add-to-store -n "monoRuntimeBinariesPatched" "$tmpDir")"
echo "monoRuntimeBinariesPatched_storePath='$monoRuntimeBinariesPatched_storePath'"

rm_tmpdir


echo
echo "------------- Runtime dep clang ---------------"
make_trapped_tmpdir
find "$clanFormatBinaries_storePath" -mindepth 1 -maxdepth 1 | xargs -d '\n' cp -rp -t "$tmpDir"
chmod -R a+rwx "$tmpDir"

ls -la "$tmpDir/bin"

patchelf_clangformat "$tmpDir/bin/clang-format"

chmod a+x "$tmpDir/bin/clang-format"
ldd "$tmpDir/bin/clang-format"
"$tmpDir/bin/clang-format" --version


clanFormatBinariesPatched_storePath="$(nix add-to-store -n "clanFormatBinariesPatched" "$tmpDir")"
echo "clanFormatBinariesPatched_storePath='$clanFormatBinariesPatched_storePath'"

rm_tmpdir

echo
echo "------------- Nix mono ---------------"
print_nix_version_clangtools

echo
echo "------------- Nix mono ---------------"
print_nix_version_mono