Debian Codegraph @

util/show-utils.sh

raw
1 #!/usr/bin/env bash
2
3 # spell-checker:ignore (shell) OSTYPE
4 # spell-checker:ignore (utils) cksum coreutils dircolors mkdir mktemp printenv printf readlink realpath grealpath rmdir shuf tsort unexpand
5 # spell-checker:ignore (jq) deps startswith
6
7 # Use GNU version for realpath on *BSD
8 REALPATH=$(command -v grealpath||command -v realpath)
9
10 ME="${0}"
11 ME_dir="$(dirname -- "${ME}")"
12 ME_parent_dir="$(dirname -- "${ME_dir}")"
13 ME_parent_dir_abs="$("${REALPATH}" -mP -- "${ME_parent_dir}" || "${REALPATH}" -- "${ME_parent_dir}")"
14
15 # refs: <https://forge.rust-lang.org/release/platform-support.html> , <https://docs.rs/platforms/0.2.1/platforms/platform/tier1/index.html>
16
17 # default utility list
18 default_utils=$(sed -n '/feat_common_core = \[/,/\]/p' Cargo.toml | sed '1d' |tr -d '],"\n') # $(sed -n '/feat_Tier1 = \[/,/\]/p' Cargo.toml | sed '1d;2d' |tr -d '],"\n') too?
19
20 project_main_dir="${ME_parent_dir_abs}"
21 # printf 'project_main_dir="%s"\n' "${project_main_dir}"
22 cd "${project_main_dir}" &&
23
24 # `jq` available?
25 if ! jq --version 1>/dev/null 2>&1; then
26 echo "WARN: missing \`jq\` (install with \`sudo apt install jq\`); falling back to default (only fully cross-platform) utility list" 1>&2
27 echo "$default_utils"
28 else
29 # Find 'coreutils' id with regex
30 # with cargo v1.76.0, id = "coreutils 0.0.26 (path+file://<coreutils local directory>)"
31 # with cargo >= v1.77.0
32 # - if local path != '<...>/coreutils' id = "path+file://<coreutils local directory>#[email protected]"
33 # - if local path == '<...>/coreutils' id = "path+file://<parent directory>/coreutils#0.0.26"
34 cargo metadata "$@" --format-version 1 | jq -r '[.resolve.nodes[] | select(.id|match(".*coreutils[ |@|#]\\d+\\.\\d+\\.\\d+")) | .deps[] | select(.pkg|match("uu_")) | .name | sub("^uu_"; "")] | sort | join(" ")'
35 fi