Joey Armstrong | 9956d97 | 2022-11-11 13:07:31 -0500 | [diff] [blame^] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
| 3 | # Copyright 2017-2022 Open Networking Foundation (ONF) and the ONF Contributors |
Matteo Scandolo | 2da7278 | 2022-06-13 11:30:07 -0700 | [diff] [blame] | 4 | # SPDX-FileCopyrightText: 2022-present Intel Corporation |
| 5 | # |
| 6 | # SPDX-License-Identifier: Apache-2.0 |
Joey Armstrong | 9956d97 | 2022-11-11 13:07:31 -0500 | [diff] [blame^] | 7 | # ----------------------------------------------------------------------- |
Matteo Scandolo | 2da7278 | 2022-06-13 11:30:07 -0700 | [diff] [blame] | 8 | |
Joey Armstrong | 9956d97 | 2022-11-11 13:07:31 -0500 | [diff] [blame^] | 9 | .DEFAULT_GOAL := test |
Matteo Scandolo | 2da7278 | 2022-06-13 11:30:07 -0700 | [diff] [blame] | 10 | |
Joey Armstrong | 9956d97 | 2022-11-11 13:07:31 -0500 | [diff] [blame^] | 11 | HIDE ?= @ |
| 12 | SHELL := bash -e -o pipefail |
| 13 | |
| 14 | dot ?= . |
| 15 | TOP ?= $(dot) |
| 16 | MAKEDIR ?= $(TOP)/makefiles |
| 17 | |
| 18 | env-clean = /usr/bin/env --ignore-environment |
| 19 | |
| 20 | jq = $(env-clean) jq |
| 21 | jq-args += --exit-status |
| 22 | |
| 23 | YAMLLINT = $(shell which yamllint) |
| 24 | yamllint := $(env-clean) $(YAMLLINT) |
| 25 | yamllint-args := -c .yamllint |
| 26 | |
| 27 | ##-------------------## |
| 28 | ##---] TARGETS [---## |
| 29 | ##-------------------## |
| 30 | all: |
| 31 | |
| 32 | lint += lint-json |
| 33 | lint += lint-yaml |
| 34 | |
| 35 | lint : $(lint) |
| 36 | test : lint |
| 37 | |
| 38 | ## ----------------------------------------------------------------------- |
| 39 | ## ----------------------------------------------------------------------- |
| 40 | lint-yaml yaml-lint: |
| 41 | ifeq ($(null),$(shell which yamllint)) |
Matteo Scandolo | 2da7278 | 2022-06-13 11:30:07 -0700 | [diff] [blame] | 42 | $(error "Please install yamllint to run linting") |
| 43 | endif |
Joey Armstrong | 9956d97 | 2022-11-11 13:07:31 -0500 | [diff] [blame^] | 44 | $(HIDE)$(env-clean) find . -name '*.yaml' -type f -print0 \ |
| 45 | | xargs -0 -t -n1 $(yamllint) $(yamllint-args) |
| 46 | |
| 47 | ## ----------------------------------------------------------------------- |
| 48 | ## ----------------------------------------------------------------------- |
| 49 | lint-json: |
| 50 | $(HIDE)$(env-clean) find . -name '*.json' -type f -print0 \ |
| 51 | | xargs -0 -t -n1 $(jq) $(jq-args) $(dot) >/dev/null |
| 52 | |
| 53 | ## ----------------------------------------------------------------------- |
| 54 | ## ----------------------------------------------------------------------- |
| 55 | pre-check: |
| 56 | @echo "[REQUIRED] Checking for linting tools" |
| 57 | $(HIDE)which jq |
| 58 | $(HIDE)which yamllint |
| 59 | @echo |
| 60 | |
| 61 | ## ----------------------------------------------------------------------- |
| 62 | ## ----------------------------------------------------------------------- |
| 63 | clean: |
| 64 | |
| 65 | ## ----------------------------------------------------------------------- |
| 66 | ## ----------------------------------------------------------------------- |
| 67 | todo: |
| 68 | @echo |
| 69 | @echo "USAGE: $(MAKE)" |
| 70 | @echo "[TODO]" |
| 71 | @echo " o Update to support standard makefile target behavior:" |
| 72 | @echo " all taget is test not default behavior for automation." |
| 73 | @echo " o Change lint target dep from test to check -or smoke" |
| 74 | @echo " target test sould be more involved with content validation" |
| 75 | @echo " o Refactor lint target(s) with voltha-system-tests/makefiles" |
| 76 | @echo " o Linting should be dependency driven," |
| 77 | @echo " only check when sources are modified." |
| 78 | @echo |
| 79 | |
| 80 | ## ----------------------------------------------------------------------- |
| 81 | ## ----------------------------------------------------------------------- |
| 82 | help: |
| 83 | @echo |
| 84 | @echo "USAGE: $(MAKE)" |
| 85 | @echo " lint perform syntax checks on source" |
| 86 | @echo " test perform syntax checks on source" |
| 87 | @echo " pre-check Verify tools and deps are available for testing" |
| 88 | @echo |
| 89 | @echo "[LINT]" |
| 90 | @echo " lint-json Syntax check .json sources" |
| 91 | @echo " lint-yaml Syntax check .yaml sources" |
| 92 | @echo |
| 93 | # [EOF] |