2016-10-22 08:52:49 -04:00
|
|
|
#!/usr/bin/env bash
|
2016-09-16 17:53:53 -04:00
|
|
|
|
2016-10-22 08:52:49 -04:00
|
|
|
# Author: w0rp <devw0rp@gmail.com>, hauleth <lukasz@niemier.pl>
|
2016-10-03 14:20:13 -04:00
|
|
|
# Description: This script wraps DMD so we can get something which is capable of reading
|
|
|
|
# D code from stdin.
|
2016-09-16 17:53:53 -04:00
|
|
|
|
2016-10-22 08:52:49 -04:00
|
|
|
set -eu
|
2016-09-16 17:53:53 -04:00
|
|
|
|
2016-10-22 08:52:49 -04:00
|
|
|
check_dubfile() {
|
|
|
|
[[ -e "$1/dub.json" || -e "$1/dub.sdl" || -e "$1/package.json" ]]
|
|
|
|
}
|
2016-09-16 17:53:53 -04:00
|
|
|
|
2016-10-22 08:52:49 -04:00
|
|
|
traverse() {
|
|
|
|
path=$(pwd)
|
|
|
|
while [ "$path" != "/" ] \
|
|
|
|
&& ! check_dubfile "$path"
|
|
|
|
do
|
|
|
|
path=$(dirname "$path")
|
|
|
|
done
|
2016-09-16 17:53:53 -04:00
|
|
|
|
2016-10-22 08:52:49 -04:00
|
|
|
echo "$path"
|
|
|
|
}
|
2016-09-18 05:38:54 -04:00
|
|
|
|
2016-10-22 08:52:49 -04:00
|
|
|
import_line_options() {
|
|
|
|
root="$(traverse)"
|
2016-09-18 05:38:54 -04:00
|
|
|
|
2016-10-22 08:52:49 -04:00
|
|
|
if check_dubfile "$root"
|
|
|
|
then
|
|
|
|
dub describe --root="$root" --import-paths | awk '{ print "-I" $0 }'
|
|
|
|
else
|
|
|
|
echo -n
|
|
|
|
fi
|
|
|
|
}
|
2016-09-18 05:38:54 -04:00
|
|
|
|
2016-10-22 08:52:49 -04:00
|
|
|
temp_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'ale_linters')
|
|
|
|
temp_file="$temp_dir/file.d"
|
|
|
|
trap 'rm -r "$temp_dir"' EXIT
|
2016-09-18 05:38:54 -04:00
|
|
|
|
2016-11-01 16:17:13 -04:00
|
|
|
while read -r; do
|
|
|
|
echo "$REPLY" >> "$temp_file"
|
|
|
|
done
|
2016-09-18 05:38:54 -04:00
|
|
|
|
2016-10-22 08:52:49 -04:00
|
|
|
dmd $(import_line_options) "$@" "$temp_file"
|