From 2b645c896aee01b661e83b89285e526262e19615 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Tue, 29 Jul 2025 14:47:53 +0200 Subject: [PATCH] make: style and sweep to from core --- Makefile | 2 +- Mk/common.mk | 26 ++++++++++++++++++++++ Mk/plugins.mk | 61 +++++---------------------------------------------- Mk/style.mk | 28 +++++++++++++++++++++++ Mk/sweep.mk | 26 ++++++++++++++++++++++ 5 files changed, 86 insertions(+), 57 deletions(-) create mode 100644 Mk/common.mk create mode 100644 Mk/style.mk create mode 100644 Mk/sweep.mk diff --git a/Makefile b/Makefile index 0b57baf29..e62676f33 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ list: .endfor # shared targets that are sane to run from the root directory -TARGETS= clean glint lint plist-fix revision style sweep test +TARGETS= clean glint lint revision style sweep test .for TARGET in ${TARGETS} ${TARGET}: diff --git a/Mk/common.mk b/Mk/common.mk new file mode 100644 index 000000000..bfd8be9ff --- /dev/null +++ b/Mk/common.mk @@ -0,0 +1,26 @@ +# Copyright (c) 2025 Franco Fichtner +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +.-include "${PLUGINSDIR}/../core/Mk/common.mk" diff --git a/Mk/plugins.mk b/Mk/plugins.mk index cac2579b0..4b939330b 100644 --- a/Mk/plugins.mk +++ b/Mk/plugins.mk @@ -52,7 +52,10 @@ PLUGIN_REVISION?= 0 PLUGIN_REQUIRES= PLUGIN_NAME PLUGIN_VERSION PLUGIN_COMMENT \ PLUGIN_MAINTAINER +.include "common.mk" .include "lint.mk" +.include "style.mk" +.include "sweep.mk" check: .for PLUGIN_REQUIRE in ${PLUGIN_REQUIRES} @@ -353,65 +356,11 @@ clean: check fi @rm -rf ${.CURDIR}/work -plist-fix: - -sweep: check - find ${.CURDIR}/src -type f -name "*.map" -print0 | \ - xargs -0 -n1 rm - find ${.CURDIR}/src ! -name "*.min.*" ! -name "*.svg" \ - ! -name "*.ser" -type f -print0 | \ - xargs -0 -n1 ${SCRIPTSDIR}/cleanfile - find ${.CURDIR} -type f -depth 1 -print0 | \ - xargs -0 -n1 ${SCRIPTSDIR}/cleanfile - -glint: sweep style-fix plist-fix lint +glint: sweep lint revision: @MAKE=${MAKE} ${SCRIPTSDIR}/revbump.sh ${.CURDIR} -STYLEDIRS?= src/etc/inc src/opnsense - -style: check - @: > ${.CURDIR}/.style.out -.for STYLEDIR in ${STYLEDIRS} - @if [ -d ${.CURDIR}/${STYLEDIR} ]; then \ - (phpcs --standard=${PLUGINSDIR}/ruleset.xml \ - ${.CURDIR}/${STYLEDIR} || true) > \ - ${.CURDIR}/.style.out; \ - fi -.endfor - @echo -n "Total number of style warnings: " - @grep '| WARNING' ${.CURDIR}/.style.out | wc -l - @echo -n "Total number of style errors: " - @grep '| ERROR' ${.CURDIR}/.style.out | wc -l - @cat ${.CURDIR}/.style.out - @rm ${.CURDIR}/.style.out - -style-fix: check -.for STYLEDIR in ${STYLEDIRS} - @if [ -d ${.CURDIR}/${STYLEDIR} ]; then \ - phpcbf --standard=${PLUGINSDIR}/ruleset.xml \ - ${.CURDIR}/${STYLEDIR} || true; \ - fi -.endfor - -style-python: check - @if [ -d ${.CURDIR}/src ]; then \ - pycodestyle --ignore=E501 ${.CURDIR}/src || true; \ - fi - -style-model: - @if [ -d ${.CURDIR}/src/opnsense/mvc/app/models ]; then \ - for MODEL in $$(find ${.CURDIR}/src/opnsense/mvc/app/models -depth 3 \ - -name "*.xml"); do \ - perl -i -pe 's/(.*?)<\/default>/$$1<\/Default>/g' $${MODEL}; \ - perl -i -pe 's/(.*?)<\/multiple>/$$1<\/Multiple>/g' $${MODEL}; \ - perl -i -pe 's/(.*?)<\/required>/$$1<\/Required>/g' $${MODEL}; \ - perl -i -pe 's/(.*?)<\/mask>/$$1<\/Mask>/g' $${MODEL}; \ - perl -i -pe 's/(.*?)<\/asList>/$$1<\/AsList>/g' $${MODEL}; \ - done; \ - fi - test: check @if [ -d ${.CURDIR}/src/opnsense/mvc/tests ]; then \ cd ${LOCALBASE}/opnsense/mvc/tests && \ @@ -423,4 +372,4 @@ commit: ensure-workdirs @/bin/echo -n "${.CURDIR:C/\// /g:[-2]}/${.CURDIR:C/\// /g:[-1]}: " > \ ${WRKDIR}/.commitmsg && git commit -eF ${WRKDIR}/.commitmsg . -.PHONY: check plist-fix +.PHONY: check diff --git a/Mk/style.mk b/Mk/style.mk new file mode 100644 index 000000000..ec11a8d2b --- /dev/null +++ b/Mk/style.mk @@ -0,0 +1,28 @@ +# Copyright (c) 2025 Franco Fichtner +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +CORE_PYTHON_DOT= ${PLUGIN_PYTHON:C/./&./1} + +.-include "${PLUGINSDIR}/../core/Mk/style.mk" diff --git a/Mk/sweep.mk b/Mk/sweep.mk new file mode 100644 index 000000000..ced1d0ea3 --- /dev/null +++ b/Mk/sweep.mk @@ -0,0 +1,26 @@ +# Copyright (c) 2025 Franco Fichtner +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +.-include "${PLUGINSDIR}/../core/Mk/sweep.mk"