[VOL-5297] Add more pre-commit hooks and git submodule install helpers.
makefiles/consts.mk
-------------------
o Define macro $(comma) for use in rules (helps avoid delimiter problems).
install/include.mk
install/README.md
------------------
o Common files installed by bin/setup.sh.
o Copy into a repositry when repo:onf-make is added as a git submodule.
.pre-commit-config.yaml
-----------------------
o Include more pre-commit hooks for checking.
o Added in voltha-lib-go, voltha-docs and others.
o Include here for central mgmt.
[HOWTO: test]
% make venv
% source .venv/bin/activate
% pre-commit
Change-Id: I15bb814b7d75a450d34af448cb88344d3922c907
Signed-off-by: Joey Armstrong <jarmstrong@linuxfoundation.org>
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index ab85bb6..41f6167 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -31,23 +31,42 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# -----------------------------------------------------------------------
-# .pre-commit-config-yaml 2024-04-10 v0.3
+# .pre-commit-config-yaml 2024-04-19 v0.4
# -----------------------------------------------------------------------
-# ci:
-# skip: [sync]
+#ci:
+# autofix_commit_msg: "Chore: pre-commit autoupdate"
+## skip: [sync]
+# skip:
+# # pre-commit.ci does not have actionlint installed
+# - actionlint
+#
+# exclude: '^docs/conf.py'
repos:
- # Sync from repo
- repo: https://github.com/pre-commit/pre-commit-hooks
+# rev: c4a0b883114b00d8d76b479c820ce7950211c99b # frozen: v4.5.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- - id: end-of-file-fixer
- - id: check-yaml
- id: check-added-large-files
-# - id: fix-encoding-pragma
+ - id: check-ast
+ - id: check-json
+ - id: check-merge-conflict
+ - id: check-xml
+ - id: check-yaml
+# - id: debug-statements
+ - id: end-of-file-fixer
+ - id: fix-encoding-pragma
# - id: double-quote-string-fixer
+ - id: requirements-txt-fixer
+ - id: mixed-line-ending
+ args: ['--fix=lf']
+
+ - repo: https://github.com/jorisroovers/gitlint
+ rev: acc9d9de6369b76d22cb4167029d2035e8730b98 # frozen: v0.19.1
+ hooks:
+ - id: gitlint
- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.10.0
@@ -73,7 +92,6 @@
- id: markdownlint
# - id: markdownlint_docker
-
## -----------------------------------------------------------------------
## [SOURCE] Docker
## -----------------------------------------------------------------------
@@ -84,8 +102,22 @@
# - id: hadolint-docker
## -----------------------------------------------------------------------
+## [SOURCE] Golang
+## -----------------------------------------------------------------------
+ - repo: https://github.com/golangci/golangci-lint
+ rev: v1.41.1
+ hooks:
+ - id: golangci-lint
+
+## -----------------------------------------------------------------------
## [SOURCE] REUSE License Checking
## -----------------------------------------------------------------------
+# - repo: https://github.com/fsfe/reuse-tool
+# rev: v3.0.2
+# hooks:
+# - id: reuse
+# - id: add-license-headers
+#
# - repo: https://github.com/ansys/pre-commit-hooks
# rev: v0.2.9
# hooks:
diff --git a/install/README.md b/install/README.md
new file mode 100644
index 0000000..6ecec93
--- /dev/null
+++ b/install/README.md
@@ -0,0 +1,14 @@
+Library makefiles
+=================
+
+$(sandbox-root)/include.mk
+ Source this makefile to import all makefile logic.
+
+$(sandbox-root)/lf/onf-make/
+$(sandbox-root)/lf/onf-make/include.mk
+ repo:onf-make contains common library makefile logic.
+ tag based checkout (frozen) as a git submodule.
+
+$(sandbox-root)/lf/local/
+$(sandbox-root)/lf/local/include.mk
+ per-repository targets and logic to customize makefile behavior.
diff --git a/install/include.mk b/install/include.mk
new file mode 100644
index 0000000..5d52907
--- /dev/null
+++ b/install/include.mk
@@ -0,0 +1,109 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2023-2024 Open Networking Foundation Contributors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# -----------------------------------------------------------------------
+# SPDX-FileCopyrightText: 2023-2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+## -----------------------------------------------------------------------
+## Infer path to cloned sandbox root
+## [TODO] Deprecate TOP=
+## -----------------------------------------------------------------------
+lf-sbx-root := $(abspath $(lastword $(MAKEFILE_LIST)))
+lf-sbx-root := $(subst /lf/include.mk,$(null),$(lf-sbx-root))
+
+## -----------------------------------------------------------------------
+## Define vars based on relative import (normalize symlinks)
+## Usage: include makefiles/onf/include.mk
+## -----------------------------------------------------------------------
+onf-mk-abs := $(abspath $(lastword $(MAKEFILE_LIST)))
+onf-mk-top := $(subst /include.mk,$(null),$(onf-mk-abs))
+onf-mk-lib := $(onf-mk-top)/onf-make/makefiles
+onf-mk-loc := $(onf-mk-top)/local
+
+TOP ?= $(patsubst %/makefiles/include.mk,%,$(onf-mk-abs))
+
+## -----------------------------------------------------------------------
+## This variable is a bridge to help transition away from legacy makefiles.
+## -----------------------------------------------------------------------
+legacy-mk := $(lf-sbx-root)/makefiles
+
+## ------------------------------------------------------
+## Two distinct vars needed to access library or project
+## ------------------------------------------------------
+ONF_MAKEDIR ?= $(onf-mk-lib)
+MAKEDIR ?= $(onf-mk-loc)
+
+# -----------------------------------------------------------------------
+# Load per-repository conditionals
+# Load late else alter MAKEFILE_LIST
+# NOTE: config.mk can be removed if dynamic feature detection by
+# file extension is added.
+# -----------------------------------------------------------------------
+include $(wildcard $(lf-sbx-root)/config.mk $(lf-sbx-root)/lf/config.mk)
+
+## -----------------------------------------------------------------------
+## Load makefiles in order:
+## 1) Library constants and logic loaded first
+## 2) Parameterize and augment targets from local (repo specific)
+## -----------------------------------------------------------------------
+include $(onf-mk-lib)/include.mk
+include $(onf-mk-loc)/include.mk
+
+## Define late so caller (?- env --ignore-environment -?)
+GIT ?= /usr/bin/env git
+
+## -----------------------------------------------------------------------
+## Intent: This target will update dependent git-submodule to the latest
+## version available from the remote repository. Subsequently
+## a checkin will be needed to make the submodule update permanent.
+## -----------------------------------------------------------------------
+.PHONY: update-git-submodules
+update-git-submodules:
+ $(GIT) submodule foreach git pull
+
+## -----------------------------------------------------------------------
+## Intent: On-demand cloning of git submodule(s).
+## -----------------------------------------------------------------------
+## Trigger: include $(onf-mk-lib)/include.mk
+## - When the make command attempts to include a makefile from the
+## repo:onf-make submodule, this target/dependency will initialize
+## and checkout all submodules the current repository depends on.
+## -----------------------------------------------------------------------
+.PHONY: git-submodules
+git-submodules : $(onf-mk-lib)/include.mk
+
+$(onf-mk-lib)/include.mk:
+
+ $(call banner-enter,(Checkout git submodules))
+
+ $(GIT) submodule update --init --recursive
+
+ $(call banner-leave,(Checkout git submodules))
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+help-git :
+ @printf ' %-33.33s %s\n' 'git-submodules' \
+ 'Init and recursive checkout of git submodule(s)'
+ @printf ' %-33.33s %s\n' 'update-git-submodules' \
+ 'Update git submodule(s) to the latest version'
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]
diff --git a/makefiles/consts.mk b/makefiles/consts.mk
index 7bb882d..6670254 100644
--- a/makefiles/consts.mk
+++ b/makefiles/consts.mk
@@ -1,6 +1,6 @@
# -*- makefile -*-
# -----------------------------------------------------------------------
-# Copyright 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
+# Copyright 2022-2024 Open Networking Foundation Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -13,19 +13,21 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-#
-# SPDX-FileCopyrightText: 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
+# -----------------------------------------------------------------------
+# SPDX-FileCopyrightText: 2022-2024 Open Networking Foundation Contributors
# SPDX-License-Identifier: Apache-2.0
# -----------------------------------------------------------------------
-# https://gerrit.opencord.org/plugins/gitiles/onf-make
-# ONF.makefile.version = 1.0
+# Intent: Defined constants for makefile use
# -----------------------------------------------------------------------
$(if $(DEBUG),$(warning ENTER))
-# include makefiles/constants.mk
+##-------------------##
+##---] GLOBALS [---## # export(s) are visible to sub-make calls
+##-------------------##
export dot :=.
export null :=#
+export comma := $(null),$(null)
export space := $(null) $(null)
export quote-single := $(null)'$(null)#'
export quote-double := $(null)"$(null)#"
@@ -36,7 +38,7 @@
## o $(info white$(\t)space
## o @echo "white$(tab)space"
## -----------------------------
-\t := $(NULL) $(NULL)
+\t := $(null) $(null)
tab := $(\t)
## -----------------------------------------------