Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tahirmt/3d15a86b07ee125f1ce99072ca1f3240 to your computer and use it in GitHub Desktop.
Save tahirmt/3d15a86b07ee125f1ce99072ca1f3240 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"'/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment