summaryrefslogtreecommitdiff
path: root/dmd-wrapper
blob: dd2bb53adf4afa988492f7f167f5f79e38df5e1c (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
#!/bin/bash -eu

# This script wraps DMD so we can get something which is capable of reading
# D code from stdin.

temp_file=`mktemp`
mv "$temp_file" "$temp_file".d
temp_file="$temp_file".d

trap "rm $temp_file" EXIT

while read line; do
    echo "$line" >> "$temp_file"
done

# Read imports from DUB.
original_path="$(readlink -m .)"
path="$original_path"
import_line_options=''

# We need to look for variable configuration files in parent directories.
while [ "$path" != '/' ]; do
    if [ -f "$path/dub.sdl" ] || [ -f "$path/dub.json" ] || [ -f "$path/package.json" ]; then

        cd "$path"

         while read import_line; do
            import_line_options="$import_line_options -I$import_line"
        done <<< "$(dub describe --import-paths)"

        cd "$original_path"

        break
    fi

    path="$(dirname "$path")"
done

dmd $import_line_options "$@" "$temp_file"