2021-01-11 07:54:33 +00:00
|
|
|
{ lib, stdenv, vscode-utils
|
2019-07-08 02:11:07 +01:00
|
|
|
, fetchurl, unzip
|
|
|
|
, mono, writeScript, runtimeShell
|
|
|
|
, jq, clang-tools
|
2018-05-03 07:13:09 +01:00
|
|
|
, gdbUseFixed ? true, gdb # The gdb default setting will be fixed to specified. Use version from `PATH` otherwise.
|
2017-08-31 03:55:53 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
assert gdbUseFixed -> null != gdb;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Note that this version of the extension still has some nix specific issues
|
|
|
|
which could not be fixed merely by patching (inside a C# dll).
|
|
|
|
|
|
|
|
In particular, the debugger requires either gnome-terminal or xterm. However
|
|
|
|
instead of looking for the terminal executable in `PATH`, for any linux platform
|
|
|
|
the dll uses an hardcoded path to one of these.
|
|
|
|
|
|
|
|
So, in order for debugging to work properly, you merely need to create symlinks
|
|
|
|
to one of these terminals at the appropriate location.
|
|
|
|
|
|
|
|
The good news is the the utility library is open source and with some effort
|
|
|
|
we could build a patched version ourselves. See:
|
|
|
|
|
|
|
|
<https://github.com/Microsoft/MIEngine/blob/2885386dc7f35e0f1e44827269341e786361f28e/src/MICore/TerminalLauncher.cs#L156>
|
|
|
|
|
|
|
|
Also, the extension should eventually no longer require an external terminal. See:
|
|
|
|
|
|
|
|
<https://github.com/Microsoft/vscode-cpptools/issues/35>
|
|
|
|
|
|
|
|
Once the symbolic link temporary solution taken, everything shoud run smootly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
let
|
|
|
|
gdbDefaultsTo = if gdbUseFixed then "${gdb}/bin/gdb" else "gdb";
|
|
|
|
|
|
|
|
|
|
|
|
openDebugAD7Script = writeScript "OpenDebugAD7" ''
|
2019-02-26 11:45:54 +00:00
|
|
|
#!${runtimeShell}
|
2017-08-31 03:55:53 +01:00
|
|
|
BIN_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
|
|
|
${if gdbUseFixed
|
|
|
|
then ''
|
|
|
|
export PATH=''${PATH}''${PATH:+:}${gdb}/bin
|
|
|
|
''
|
|
|
|
else ""}
|
2018-10-30 21:18:05 +00:00
|
|
|
${mono}/bin/mono $BIN_DIR/bin/OpenDebugAD7.exe $*
|
2017-08-31 03:55:53 +01:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
|
2020-04-29 22:32:04 +01:00
|
|
|
vscode-utils.buildVscodeMarketplaceExtension rec {
|
2017-08-31 03:55:53 +01:00
|
|
|
mktplcRef = {
|
|
|
|
name = "cpptools";
|
|
|
|
publisher = "ms-vscode";
|
2020-09-21 02:35:47 +01:00
|
|
|
version = "1.0.1";
|
2020-04-29 22:32:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
vsix = fetchurl {
|
2020-05-18 02:15:38 +01:00
|
|
|
name = "${mktplcRef.publisher}-${mktplcRef.name}.zip";
|
2020-04-29 22:32:04 +01:00
|
|
|
url = "https://github.com/microsoft/vscode-cpptools/releases/download/${mktplcRef.version}/cpptools-linux.vsix";
|
2020-09-21 02:35:47 +01:00
|
|
|
sha256 = "1lb5pza2ny1ydan19596amabs1np10nq08yqsfbvvfw7zbg4gnyc";
|
2017-08-31 03:55:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
buildInputs = [
|
2018-05-03 07:13:09 +01:00
|
|
|
jq
|
2017-08-31 03:55:53 +01:00
|
|
|
];
|
|
|
|
|
2018-05-03 07:13:09 +01:00
|
|
|
postPatch = ''
|
2020-04-29 22:32:04 +01:00
|
|
|
mv ./package.json ./package_orig.json
|
2017-08-31 03:55:53 +01:00
|
|
|
|
2018-05-03 07:13:09 +01:00
|
|
|
# 1. Add activation events so that the extension is functional. This listing is empty when unpacking the extension but is filled at runtime.
|
2019-07-08 02:11:07 +01:00
|
|
|
# 2. Patch `package.json` so that nix's *gdb* is used as default value for `miDebuggerPath`.
|
2020-04-29 22:32:04 +01:00
|
|
|
cat ./package_orig.json | \
|
2018-10-29 23:45:25 +00:00
|
|
|
jq --slurpfile actEvts ${./package-activation-events.json} '(.activationEvents) = $actEvts[0]' | \
|
2018-05-03 07:13:09 +01:00
|
|
|
jq '(.contributes.debuggers[].configurationAttributes | .attach , .launch | .properties.miDebuggerPath | select(. != null) | select(.default == "/usr/bin/gdb") | .default) = "${gdbDefaultsTo}"' > \
|
|
|
|
./package.json
|
2017-08-31 03:55:53 +01:00
|
|
|
|
|
|
|
# Prevent download/install of extensions
|
|
|
|
touch "./install.lock"
|
|
|
|
|
|
|
|
# Mono runtimes from nix package (used by generated `OpenDebugAD7`).
|
2020-04-29 22:32:04 +01:00
|
|
|
mv ./debugAdapters/OpenDebugAD7 ./debugAdapters/OpenDebugAD7_orig
|
2017-08-31 03:55:53 +01:00
|
|
|
cp -p "${openDebugAD7Script}" "./debugAdapters/OpenDebugAD7"
|
|
|
|
|
|
|
|
# Clang-format from nix package.
|
2020-04-29 22:32:04 +01:00
|
|
|
mv ./LLVM/ ./LLVM_orig
|
|
|
|
mkdir "./LLVM/"
|
2017-08-31 03:55:53 +01:00
|
|
|
find "${clang-tools}" -mindepth 1 -maxdepth 1 | xargs ln -s -t "./LLVM"
|
2020-04-29 22:32:04 +01:00
|
|
|
|
|
|
|
# Patching cpptools and cpptools-srv
|
|
|
|
elfInterpreter="$(cat $NIX_CC/nix-support/dynamic-linker)"
|
|
|
|
patchelf --set-interpreter "$elfInterpreter" ./bin/cpptools
|
|
|
|
patchelf --set-interpreter "$elfInterpreter" ./bin/cpptools-srv
|
|
|
|
chmod a+x ./bin/cpptools{-srv,}
|
2017-08-31 03:55:53 +01:00
|
|
|
'';
|
|
|
|
|
2021-01-11 07:54:33 +00:00
|
|
|
meta = with lib; {
|
2017-08-31 03:55:53 +01:00
|
|
|
license = licenses.unfree;
|
2018-04-19 16:41:12 +01:00
|
|
|
maintainers = [ maintainers.jraygauthier ];
|
2018-05-03 07:13:09 +01:00
|
|
|
# A 32 bit linux would also be possible with some effort (specific download of binaries +
|
2017-08-31 03:55:53 +01:00
|
|
|
# patching of the elf files with 32 bit interpreter).
|
|
|
|
platforms = [ "x86_64-linux" ];
|
|
|
|
};
|
2018-04-19 16:41:12 +01:00
|
|
|
}
|