-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from mineiros-io/validate-makefile-phony-targets
add a new hook for checking PHONY targets
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
EXITCODE=0 | ||
|
||
validate_phony_targets() { | ||
local file=$1 | ||
local source=$(make -npq -f "${file}" | grep -E '^.PHONY:') | ||
local targets=$(sed -n 's#^.PHONY:\(.*\)#\1#p' <<< "${source}") | ||
|
||
for target in $targets; do | ||
# The q command for setting exit codes if a pattern doesn't match, | ||
# isn't supported in OSX / BSD sed. | ||
# We check the exact match as a workaround instead. | ||
# If the pattern doesn't match that means that the target doesn't exist. | ||
if test -z "$(sed -ne "s#^\(${target}:\).*#\1#p" "${file}")"; then | ||
echo "No target found for PHONY target: '$target'" | ||
EXITCODE=1 | ||
fi | ||
done | ||
} | ||
|
||
for file in "$@"; do | ||
validate_phony_targets "$file" | ||
done | ||
|
||
exit $EXITCODE |