Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect PHONY and add PHONY linter #379

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
none: clean
SHELL := bash
.SHELLFLAGS := -eux -o pipefail -c
.DEFAULT_GOAL := setup
.DELETE_ON_ERROR: # If a recipe to build a file exits with an error, delete the file.
.SUFFIXES: # Remove the default suffixes which are for compiling C projects.
.NOTPARALLEL: # Disable use of parallel subprocesses.
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules

help:
@echo "make test test Ward"
Expand All @@ -15,13 +22,17 @@ help:
setup:
poetry install
poetry run pre-commit install
.PHONY: requirements
.PHONY: setup

format:
poetry run pre-commit run --all
.PHONY: format

lint: format
lint-make:
python scripts/lint-make
.PHONY: lint-make

lint: format lint-make
.PHONY: lint

test:
Expand Down
19 changes: 19 additions & 0 deletions scripts/lint-make
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys

with open('Makefile', 'rt') as makefile:
current_target = None
exit_code = 0
for line in makefile:
words = line.split()
if not words:
continue
elif words[0] == '.PHONY:':
phony_target = words[1]
if current_target != phony_target:
print(f'Error: make target has wrong phony. Found {phony_target!r}, expected {current_target!r}.')
exit_code = 1
current_target = None
elif words[0].endswith(':'):
current_target = words[0][:-1]

sys.exit(exit_code)