From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6654108059374190592 X-Received: by 2002:a1c:700d:: with SMTP id l13mr1110312wmc.14.1549280262509; Mon, 04 Feb 2019 03:37:42 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a1c:20c8:: with SMTP id g191ls1816056wmg.4.gmail; Mon, 04 Feb 2019 03:37:42 -0800 (PST) X-Google-Smtp-Source: AHgI3IZRso2HRE7pOaaSGwaKsf83HnVpW3I9zgpY2cOwgxYDbqj4Fk+LZQplsTJM8OOrAhzZACxg X-Received: by 2002:a1c:7d03:: with SMTP id y3mr1112641wmc.8.1549280262058; Mon, 04 Feb 2019 03:37:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549280262; cv=none; d=google.com; s=arc-20160816; b=tq9n8xVe8+NCYrRWDHK4GFXIQp+bJIBnZpiSrFIL4YlTsHJuE/t7ZLTmMzibBmVOkI tUh4KyN2hm3wN3gj0oP59pKQisb+hyq7E50cknV+E/AVj6QKOnt0W5SWGoZ5mmY+/8ll DzfiCj6bfYWmfACOtVDOgPxjck9/VGNh/44qHumyVqPXrZ3+j5IMRQ5ShrzKQ3YSHx3N jhqAxQs/8SHO6kpS3uvJQ4brmaQi+2k9+usHgWwzep+6QRLatIyvNvmS/ipMpr6ODP/k 2xd8FRqpMSGUZb2yebQ2+PnycRC03g++0JUVe6gQWmXYdns9QzbISHGf/FAuqY43HBOo oK0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=I1RwdPEITHvgmtpPcOQ+V167A6YLvezh9MkVt5QpyZY=; b=D5jC3O3WWIO2OtkPePYrzZVnDSdax5DAYULcK00FM3mybFA8+wBT5PxPKXL6vyBsiV VVHiW7F9r2R9ljRuWTFCOezLhWj4lEBhE+fg+LpzzcrUSlLGpbIrOmi7VqlMFkf0bPVE a+y7Ds1m1tmr+zvBRimG8eLI5EFon+MuAOWJ3jZQlAVfAo0Kekqnh7i2OWO5gUSRT0L5 zRDrO5n29JfWYuEVhYYct4jg//wOnvI8kJQTjf3Rn+DcYIbQpDhTvvD/XVWz8IUfEyIb pZPaivyD/Dq4oqu2MvEFpkfZTszK/gN1FCxnj11jKxgxxP7O5HdFC1ML9AJO4wxq4Kot RyaQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of claudius.heine.ext@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=claudius.heine.ext@siemens.com Return-Path: Received: from goliath.siemens.de (goliath.siemens.de. [192.35.17.28]) by gmr-mx.google.com with ESMTPS id s130si451772wme.4.2019.02.04.03.37.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Feb 2019 03:37:42 -0800 (PST) Received-SPF: pass (google.com: domain of claudius.heine.ext@siemens.com designates 192.35.17.28 as permitted sender) client-ip=192.35.17.28; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of claudius.heine.ext@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=claudius.heine.ext@siemens.com Received: from mail1.sbs.de (mail1.sbs.de [192.129.41.35]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id x14BbfhA010445 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 4 Feb 2019 12:37:41 +0100 Received: from ring.ppmd.siemens.net (linux-ses-ext02.ppmd.siemens.net [139.25.69.181]) by mail1.sbs.de (8.15.2/8.15.2) with ESMTP id x14BbeRH010886; Mon, 4 Feb 2019 12:37:41 +0100 From: claudius.heine.ext@siemens.com To: isar-users@googlegroups.com Cc: Claudius Heine Subject: [RFC PATCH v2 1/1] meta: added do_transform_template task as templating system and switch Date: Mon, 4 Feb 2019 12:37:37 +0100 Message-Id: <20190204113737.19784-2-claudius.heine.ext@siemens.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204113737.19784-1-claudius.heine.ext@siemens.com> References: <20190204113737.19784-1-claudius.heine.ext@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUID: caWCUVMO/lUy From: Claudius Heine Signed-off-by: Claudius Heine --- meta/classes/base.bbclass | 44 +++++++++++++++++++ meta/classes/dpkg-base.bbclass | 2 +- .../debian/{changelog => changelog.tmpl} | 2 +- meta/recipes-bsp/u-boot/files/debian/control | 19 -------- .../u-boot/files/debian/control.tmpl | 19 ++++++++ meta/recipes-bsp/u-boot/u-boot-custom.inc | 12 ++--- .../debian/{changelog => changelog.tmpl} | 2 +- .../linux-module/files/debian/control | 11 ----- .../linux-module/files/debian/control.tmpl | 11 +++++ meta/recipes-kernel/linux-module/module.inc | 7 ++- 10 files changed, 86 insertions(+), 43 deletions(-) rename meta/recipes-bsp/u-boot/files/debian/{changelog => changelog.tmpl} (74%) delete mode 100644 meta/recipes-bsp/u-boot/files/debian/control create mode 100644 meta/recipes-bsp/u-boot/files/debian/control.tmpl rename meta/recipes-kernel/linux-module/files/debian/{changelog => changelog.tmpl} (74%) delete mode 100644 meta/recipes-kernel/linux-module/files/debian/control create mode 100644 meta/recipes-kernel/linux-module/files/debian/control.tmpl diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass index d4082de..d65c2de 100644 --- a/meta/classes/base.bbclass +++ b/meta/classes/base.bbclass @@ -135,6 +135,50 @@ python do_unpack() { addtask unpack after do_fetch before do_build +TEMPLATE_FILES ??= "" +TEMPLATE_VARS ??= "PN PV DESCRIPTION HOMEPAGE MAINTAINER KERNEL_NAME MACHINE \ + DISTRO_ARCH" + +do_transform_template[vardeps] = "TEMPLATE_FILES ${TEMPLATE_VARS}" +do_transform_template[stamp-extra-info] = "${DISTRO}-${DISTRO_ARCH}" +python do_transform_template() { + import subprocess, contextlib + + template_vars = (d.getVar('TEMPLATE_VARS', True) or "").split() + if len(template_vars) == 0: + return + + template_files = (d.getVar('TEMPLATE_FILES', True) or "").split() + if len(template_files) == 0: + return + + cmd = "envsubst" + args = " ".join("\${{{}}}".format(i) for i in template_vars) + env = os.environ.copy() + + for varname in template_vars: + value = d.getVar(varname, True) + if value: + env.update({varname: value}) + + for template_file in template_files: + output_file = (os.path.splitext(template_file)[0] + if template_file.endswith(".tmpl") + else (template_file + ".out")) + bb.note("{} {} [in: {} out: {}]".format(cmd, args, + template_file, output_file)) + with contextlib.ExitStack() as stack: + input = stack.enter_context(open(template_file, 'rb')) + output = stack.enter_context(open(output_file, 'wb')) + process = subprocess.Popen([cmd, args], stdin=input, + stdout=output, env=env) + bb.note("args: ", repr(process.args)) + if process.wait() != 0: + bb.fatal("processing of template failed") +} + +addtask do_transform_template after do_unpack before do_build + addtask build do_build[dirs] = "${TOPDIR}" python base_do_build () { diff --git a/meta/classes/dpkg-base.bbclass b/meta/classes/dpkg-base.bbclass index f1b127c..fe96850 100644 --- a/meta/classes/dpkg-base.bbclass +++ b/meta/classes/dpkg-base.bbclass @@ -40,7 +40,7 @@ do_prepare_build() { true } -addtask prepare_build after do_patch before do_build +addtask prepare_build after do_patch do_transform_template before do_build do_prepare_build[stamp-extra-info] = "${DISTRO}-${DISTRO_ARCH}" # If Isar recipes depend on each other, they typically need the package # deployed to isar-apt diff --git a/meta/recipes-bsp/u-boot/files/debian/changelog b/meta/recipes-bsp/u-boot/files/debian/changelog.tmpl similarity index 74% rename from meta/recipes-bsp/u-boot/files/debian/changelog rename to meta/recipes-bsp/u-boot/files/debian/changelog.tmpl index c1c3516..6e59e06 100644 --- a/meta/recipes-bsp/u-boot/files/debian/changelog +++ b/meta/recipes-bsp/u-boot/files/debian/changelog.tmpl @@ -1,4 +1,4 @@ -@PN@ (@PV@) unstable; urgency=low +${PN} (${PV}) unstable; urgency=low * Generated package. diff --git a/meta/recipes-bsp/u-boot/files/debian/control b/meta/recipes-bsp/u-boot/files/debian/control deleted file mode 100644 index 6b4c839..0000000 --- a/meta/recipes-bsp/u-boot/files/debian/control +++ /dev/null @@ -1,19 +0,0 @@ -Source: @PN@ -Section: admin -Priority: optional -Standards-Version: 3.9.6 -Build-Depends: @BUILD_DEPENDS@ -Maintainer: ISAR project - -Package: u-boot-@MACHINE@ -Architecture: @DISTRO_ARCH@ -Description: @DESCRIPTION@, bootloader binaries - -Package: u-boot-@MACHINE@-dev -Architecture: @DISTRO_ARCH@ -Description: @DESCRIPTION@, bootloader libraries - -Package: u-boot-tools -Architecture: linux-any -Depends: ${shlibs:Depends}, ${misc:Depends} -Description: @DESCRIPTION@, companion tools diff --git a/meta/recipes-bsp/u-boot/files/debian/control.tmpl b/meta/recipes-bsp/u-boot/files/debian/control.tmpl new file mode 100644 index 0000000..ca9c35d --- /dev/null +++ b/meta/recipes-bsp/u-boot/files/debian/control.tmpl @@ -0,0 +1,19 @@ +Source: ${PN} +Section: admin +Priority: optional +Standards-Version: 3.9.6 +Build-Depends: ${U_BOOT_BUILD_DEPENDS} +Maintainer: ISAR project + +Package: u-boot-${MACHINE} +Architecture: ${DISTRO_ARCH} +Description: ${DESCRIPTION}, bootloader binaries + +Package: u-boot-${MACHINE}-dev +Architecture: ${DISTRO_ARCH} +Description: ${DESCRIPTION}, bootloader libraries + +Package: u-boot-tools +Architecture: linux-any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: ${DESCRIPTION}, companion tools diff --git a/meta/recipes-bsp/u-boot/u-boot-custom.inc b/meta/recipes-bsp/u-boot/u-boot-custom.inc index 4b38c88..5afc97b 100644 --- a/meta/recipes-bsp/u-boot/u-boot-custom.inc +++ b/meta/recipes-bsp/u-boot/u-boot-custom.inc @@ -17,14 +17,14 @@ SRC_URI += "file://debian/" U_BOOT_BUILD_DEPENDS ?= "bc, bison, flex, device-tree-compiler" +BUILD_DEPENDS="${U_BOOT_BUILD_DEPENDS}" + +TEMPLATE_FILES = "${WORKDIR}/debian/changelog.tmpl \ + ${WORKDIR}/debian/control.tmpl" +TEMPLATE_VARS += "U_BOOT_CONFIG U_BOOT_BIN U_BOOT_BUILD_DEPENDS" + do_prepare_build() { cp -r ${WORKDIR}/debian ${S}/ - sed -i -e 's/@PN@/${PN}/g' -e 's/@PV@/${PV}/g' \ - -e 's/@BUILD_DEPENDS@/${U_BOOT_BUILD_DEPENDS}/g' \ - -e 's/@MACHINE@/${MACHINE}/g' \ - -e 's/@DISTRO_ARCH@/${DISTRO_ARCH}/g' \ - -e 's/@DESCRIPTION@/${DESCRIPTION}/g' \ - ${S}/debian/changelog ${S}/debian/control echo "${U_BOOT_BIN} /usr/lib/u-boot/${MACHINE}" > \ ${S}/debian/u-boot-${MACHINE}.install diff --git a/meta/recipes-kernel/linux-module/files/debian/changelog b/meta/recipes-kernel/linux-module/files/debian/changelog.tmpl similarity index 74% rename from meta/recipes-kernel/linux-module/files/debian/changelog rename to meta/recipes-kernel/linux-module/files/debian/changelog.tmpl index c1c3516..6e59e06 100644 --- a/meta/recipes-kernel/linux-module/files/debian/changelog +++ b/meta/recipes-kernel/linux-module/files/debian/changelog.tmpl @@ -1,4 +1,4 @@ -@PN@ (@PV@) unstable; urgency=low +${PN} (${PV}) unstable; urgency=low * Generated package. diff --git a/meta/recipes-kernel/linux-module/files/debian/control b/meta/recipes-kernel/linux-module/files/debian/control deleted file mode 100644 index 1ee634c..0000000 --- a/meta/recipes-kernel/linux-module/files/debian/control +++ /dev/null @@ -1,11 +0,0 @@ -Source: @PN@ -Section: kernel -Priority: optional -Standards-Version: 3.9.6 -Build-Depends: linux-headers-@KERNEL_NAME@ -Maintainer: ISAR project - -Package: @PN@ -Architecture: any -Depends: linux-image-@KERNEL_NAME@, kmod -Description: @DESCRIPTION@ diff --git a/meta/recipes-kernel/linux-module/files/debian/control.tmpl b/meta/recipes-kernel/linux-module/files/debian/control.tmpl new file mode 100644 index 0000000..3b3292d --- /dev/null +++ b/meta/recipes-kernel/linux-module/files/debian/control.tmpl @@ -0,0 +1,11 @@ +Source: ${PN} +Section: kernel +Priority: optional +Standards-Version: 3.9.6 +Build-Depends: linux-headers-${KERNEL_NAME} +Maintainer: ISAR project + +Package: ${PN} +Architecture: any +Depends: linux-image-${KERNEL_NAME}, kmod +Description: ${DESCRIPTION} diff --git a/meta/recipes-kernel/linux-module/module.inc b/meta/recipes-kernel/linux-module/module.inc index cb7b8ad..28bfef5 100644 --- a/meta/recipes-kernel/linux-module/module.inc +++ b/meta/recipes-kernel/linux-module/module.inc @@ -19,12 +19,11 @@ AUTOLOAD ?= "" inherit dpkg +TEMPLATE_FILES = "${WORKDIR}/debian/control.tmpl \ + ${WORKDIR}/debian/changelog.tmpl" + do_prepare_build() { cp -r ${WORKDIR}/debian ${S}/ - sed -i -e 's/@PN@/${PN}/g' -e 's/@PV@/${PV}/g' \ - -e 's/@KERNEL_NAME@/${KERNEL_NAME}/g' \ - -e 's/@DESCRIPTION@/${DESCRIPTION}/g' \ - ${S}/debian/changelog ${S}/debian/control for module in "${AUTOLOAD}"; do echo "echo $module >> /etc/modules" >> ${S}/debian/postinst -- 2.20.1