Rewrite JSON parsing code in Perl for portability
This commit is contained in:
parent
ff6031a8ea
commit
d9e81e08f2
19
src/_cmake
19
src/_cmake
|
@ -141,21 +141,14 @@ _cmake_generator_options() {
|
|||
# --------------
|
||||
(( $+functions[_cmake_presets] )) ||
|
||||
_cmake_presets() {
|
||||
|
||||
local parse_presets; parse_presets='
|
||||
import json
|
||||
import os
|
||||
try:
|
||||
with open("CMakePresets.json") as preset_file:
|
||||
print(os.linesep.join([ x["name"] + ":" + x.get("description", "") for x in json.load(preset_file)["configurePresets"]]))
|
||||
except:
|
||||
pass
|
||||
|
||||
'
|
||||
|
||||
# TODO: Problems with quotes need eval
|
||||
# would need a way to exec the array
|
||||
local list_presets; list_presets=(${(f)"$(eval python <<< $parse_presets)"})
|
||||
local -a list_presets;
|
||||
|
||||
if [[ -e CMakePresets.json ]]; then
|
||||
# some old projects uses BOM in json file. strip UTF-8 BOM and then parse JSON
|
||||
list_presets=("${(@f)$(sed '1s/^\xEF\xBB\xBF//' < CMakePresets.json | perl -0777 -MJSON::PP -nE 'do{$k=$_;($e=$k)=~s/:/\\:/g; printf "$_->{name}:$_->{description}\n"} for @{decode_json($_)->{configurePresets}}' 2>/dev/null)}")
|
||||
fi
|
||||
|
||||
_describe 'presets' list_presets
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue