blob: 0a643500a8f8124baeec794f53cdaf0183da39bc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#!/usr/bin/env bash
# Author: w0rp <devw0rp@gmail.com>, hauleth <lukasz@niemier.pl>
# Description: This script wraps DMD so we can get something which is capable of reading
# D code from stdin.
set -eu
check_dubfile() {
[[ -e "$1/dub.json" || -e "$1/dub.sdl" || -e "$1/package.json" ]]
}
traverse() {
path=$(pwd)
while [ "$path" != "/" ] \
&& ! check_dubfile "$path"
do
path=$(dirname "$path")
done
echo "$path"
}
import_line_options() {
root="$(traverse)"
if check_dubfile "$root"
then
dub describe --root="$root" --import-paths | awk '{ print "-I" $0 }'
else
echo -n
fi
}
temp_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'ale_linters')
temp_file="$temp_dir/file.d"
trap 'rm -r "$temp_dir"' EXIT
cp /dev/stdin "$temp_file"
dmd $(import_line_options) "$@" "$temp_file"
|