From e06826bf9e71e2a8f8825cc3dd0bc1e00ba8c2e4 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Thu, 4 Feb 2021 22:58:17 +0100 Subject: [PATCH] Framework: support version meta data JSON file --- Mk/defaults.mk | 15 +++++++++++++-- Mk/plugins.mk | 21 +++++++++++++++------ Scripts/version.sh | 34 ++++++++++++++++++++++++++++++++++ Templates/version | 11 +++++++++++ 4 files changed, 73 insertions(+), 8 deletions(-) create mode 100755 Scripts/version.sh create mode 100644 Templates/version diff --git a/Mk/defaults.mk b/Mk/defaults.mk index 089cdc705f..1ec722ffe0 100644 --- a/Mk/defaults.mk +++ b/Mk/defaults.mk @@ -26,9 +26,14 @@ LOCALBASE?= /usr/local PAGER?= less -PKG!= which pkg || echo true +PKG= ${LOCALBASE}/sbin/pkg +.if ! exists(${PKG}) +PKG= true +.endif GIT!= which git || echo true +GITVERSION= ${SCRIPTSDIR}/version.sh + _PLUGIN_ARCH!= uname -p PLUGIN_ARCH?= ${_PLUGIN_ARCH} @@ -64,7 +69,13 @@ PLUGIN_PYTHON?= 37 REPLACEMENTS= PLUGIN_ABI \ PLUGIN_ARCH \ - PLUGIN_FLAVOUR + PLUGIN_FLAVOUR \ + PLUGIN_HASH \ + PLUGIN_MAINTAINER \ + PLUGIN_NAME \ + PLUGIN_PKGNAME \ + PLUGIN_PKGVERSION \ + PLUGIN_WWW SED_REPLACE= # empty diff --git a/Mk/plugins.mk b/Mk/plugins.mk index b1eff47759..119380b033 100644 --- a/Mk/plugins.mk +++ b/Mk/plugins.mk @@ -27,13 +27,22 @@ all: check .include "defaults.mk" +PLUGINSDIR= ${.CURDIR}/../.. +TEMPLATESDIR= ${PLUGINSDIR}/Templates +SCRIPTSDIR= ${PLUGINSDIR}/Scripts + +.if exists(${GIT}) && exists(${GITVERSION}) +PLUGIN_COMMIT!= ${GITVERSION} +.else +PLUGIN_COMMIT= unknown 0 undefined +.endif + +PLUGIN_HASH?= ${PLUGIN_COMMIT:[3]} + PLUGIN_DESC= pkg-descr PLUGIN_SCRIPTS= +PRE_INSTALL +POST_INSTALL \ +PRE_DEINSTALL +POST_DEINSTALL -PLUGINSDIR= ${.CURDIR}/../.. -TEMPLATESDIR= ${PLUGINSDIR}/Templates - PLUGIN_WWW?= https://opnsense.org/ PLUGIN_REVISION?= 0 @@ -183,7 +192,7 @@ install: check mv "${DESTDIR}${LOCALBASE}/$${FILE}" "${DESTDIR}${LOCALBASE}/$${FILE%%.in}"; \ fi; \ done - @echo "${PLUGIN_PKGVERSION}" > "${DESTDIR}${LOCALBASE}/opnsense/version/${PLUGIN_NAME}" + cat ${TEMPLATESDIR}/version | sed ${SED_REPLACE} > "${DESTDIR}${LOCALBASE}/opnsense/version/${PLUGIN_NAME}" plist: check @(cd ${.CURDIR}/src; find * -type f) | while read FILE; do \ @@ -312,9 +321,9 @@ sweep: check fi find ${.CURDIR}/src ! -name "*.min.*" ! -name "*.svg" \ ! -name "*.ser" -type f -print0 | \ - xargs -0 -n1 ${.CURDIR}/../../Scripts/cleanfile + xargs -0 -n1 ${SCRIPTSDIR}/cleanfile find ${.CURDIR} -type f -depth 1 -print0 | \ - xargs -0 -n1 ${.CURDIR}/../../Scripts/cleanfile + xargs -0 -n1 ${SCRIPTSDIRs/cleanfile STYLEDIRS?= src/etc/inc src/opnsense diff --git a/Scripts/version.sh b/Scripts/version.sh new file mode 100755 index 0000000000..402d840839 --- /dev/null +++ b/Scripts/version.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +# Copyright (c) 2015 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. + +set -e + +VERSION=$(git describe --abbrev=0 --always ${1}) +REVISION=$(git rev-list ${VERSION}.. --count) +HASH=$(git rev-list HEAD --max-count=1 | cut -c1-9) + +echo ${VERSION} ${REVISION} ${HASH} diff --git a/Templates/version b/Templates/version new file mode 100644 index 0000000000..95baa8fe04 --- /dev/null +++ b/Templates/version @@ -0,0 +1,11 @@ +{ + "product_abi": "%%PLUGIN_ABI%%", + "product_arch": "%%PLUGIN_ARCH%%", + "product_email": "%%PLUGIN_MAINTAINER%%", + "product_flavour": "%%PLUGIN_FLAVOUR%%", + "product_hash": "%%PLUGIN_HASH%%", + "product_id": "%%PLUGIN_PKGNAME%%", + "product_name": "%%PLUGIN_NAME%%", + "product_version": "%%PLUGIN_PKGVERSION%%", + "product_website": "%%PLUGIN_WWW%%" +}