Skip to content

Instantly share code, notes, and snippets.

@wakinchan
Last active February 29, 2024 13:14
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wakinchan/75bc1b75c812e432561a639566af518b to your computer and use it in GitHub Desktop.
Save wakinchan/75bc1b75c812e432561a639566af518b to your computer and use it in GitHub Desktop.
Generate Target Dependencies for Package.swift
#!/usr/bin/env sh
# usage: sh ./generate-target-dependencies.sh | dot -Tsvg -o target-graph.svg
packages=`swift package describe --type json`
targets=`echo $packages | jq '.targets'`
target_names=`echo $targets | jq -r '.[] | .name'`
body=""
template=`cat <<EOF
digraph DependenciesGraph {
node [shape = box]
%BODY%
}
`
for target_name in `echo $target_names`; do
label='"'$target_name'" [label="'$target_name'"]'
body+="$label\n"
target_dependencies=`echo $targets | jq -r '.[] | select(.name == "'$target_name'") | select(.target_dependencies != null) | .target_dependencies | .[]'`
for target_dependency in `echo $target_dependencies`; do
target='"'$target_name'" -> "'$target_dependency'"'
body+="$target\n"
done
done
echo "$template" | sed -e 's/%BODY%/'"$body"'/'
@wakinchan
Copy link
Author

wakinchan commented Jul 13, 2022

It is possible to output such svg. Low resolution for convenience.

Screenshot 2022-07-13 at 20 27 14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment