mirror of
https://github.com/dense-analysis/ale
synced 2024-12-16 19:35:42 +00:00
e293e0b5ab
* Use `cat` instead of `read -r` to stream stdin to file * Cleanup dmd-wrapper * Fix typo * Make wrapper work on macOS * Use fifo instead of temporary file * Fix stdin-wrapper * Use `awk` instead of `read` hackery * Finish refactoring * Fix `exec` issue * Add myself as an coauthor of wrapper scripts (no shame at all :P) * Fix dmd-wrapper * Extract check_dubfile
42 lines
819 B
Bash
Executable File
42 lines
819 B
Bash
Executable File
#!/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"
|