blob: 67757bb4343198ee8458fb78ecce28e8d2343288 [file] [log] [blame]
Joey Armstrongee4d8262023-08-22 15:19:19 -04001# -*- makefile -*-
2# -----------------------------------------------------------------------
Joey Armstrongaadcaa42024-02-01 19:54:17 -05003# Copyright 2017-2024 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrongee4d8262023-08-22 15:19:19 -04004# SPDX-FileCopyrightText: 2022-present Intel Corporation
5#
6# SPDX-License-Identifier: Apache-2.0
7# -----------------------------------------------------------------------
8
9.DEFAULT_GOAL := test
10
11HIDE ?= @
12SHELL := bash -e -o pipefail
13
14dot ?= .
15TOP ?= $(dot)
16MAKEDIR ?= $(TOP)/makefiles
17
18env-clean = /usr/bin/env --ignore-environment
19
20jq = $(env-clean) jq
21jq-args += --exit-status
22
23YAMLLINT = $(shell which yamllint)
24yamllint := $(env-clean) $(YAMLLINT)
25yamllint-args := -c .yamllint
26
27##-------------------##
28##---] TARGETS [---##
29##-------------------##
30all:
31
32lint += lint-json
33lint += lint-yaml
34
35lint : $(lint)
36test : lint
37
38## -----------------------------------------------------------------------
39## -----------------------------------------------------------------------
40lint-yaml yaml-lint:
41ifeq ($(null),$(shell which yamllint))
42 $(error "Please install yamllint to run linting")
43endif
44 $(HIDE)$(env-clean) find . -name '*.yaml' -type f -print0 \
45 | xargs -0 -t -n1 $(yamllint) $(yamllint-args)
46
47## -----------------------------------------------------------------------
48## -----------------------------------------------------------------------
49lint-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## -----------------------------------------------------------------------
55pre-check:
56 @echo "[REQUIRED] Checking for linting tools"
57 $(HIDE)which jq
58 $(HIDE)which yamllint
59 @echo
60
61## -----------------------------------------------------------------------
62## -----------------------------------------------------------------------
63clean:
64
65## -----------------------------------------------------------------------
66## -----------------------------------------------------------------------
67todo:
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## -----------------------------------------------------------------------
82help:
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]