From 9d86add05a83b897c4a40ad996428656f5f44854 Mon Sep 17 00:00:00 2001 From: Benson Muite Date: Wed, 24 Dec 2025 17:11:05 +0300 Subject: [PATCH 1/3] Generate spec file when creating srpm --- .packit.yaml | 10 ++++++- Rakefile | 26 ++++++++++++++++++- packages/Rakefile | 8 ------ .../{openarm-can.spec => openarm-can.spec.in} | 11 ++------ 4 files changed, 36 insertions(+), 19 deletions(-) rename packages/fedora/{openarm-can.spec => openarm-can.spec.in} (84%) diff --git a/.packit.yaml b/.packit.yaml index 20372f0..5ecabc0 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -14,7 +14,15 @@ # https://packit.dev/docs/configuration/ -specfile_path: packages/fedora/openarm-can.spec +specfile_path: openarm-can.spec + +actions: + post-upstream-clone: + - rake spec + +srpm_build_deps: + - rubygem-json + - rubygem-rake notifications: pull_request: diff --git a/Rakefile b/Rakefile index 6aaf4c4..2911b2e 100644 --- a/Rakefile +++ b/Rakefile @@ -13,6 +13,7 @@ # limitations under the License. require "date" +require "fileutils" require_relative "helper" @@ -110,7 +111,6 @@ namespace :release do "CMakeLists.txt", "package.xml", "packages/debian/changelog", - "packages/fedora/openarm-can.spec", "python/CMakeLists.txt", "python/openarm_can/__init__.py", "python/pyproject.toml", @@ -165,3 +165,27 @@ task release: [ "release:tag", "release:ubuntu", ] + +desc "Create RPM spec file" +task :spec do + FileUtils.copy_file("packages/fedora/openarm-can.spec.in", "openarm-can.spec") + current_version = Helper.detect_version + Helper.update_content("openarm-can.spec") do |content| + content.sub!("%{VERSION}", current_version) + end + executable_files = Array.new() + File.readlines('CMakeLists.txt', chomp: true).each do |line| + if !!(line =~ /install\(TARGETS openarm-can-*.* DESTINATION \${CMAKE_INSTALL_BINDIR}\)/) + executable=line.delete_prefix("install(TARGETS ").delete_suffix(" DESTINATION ${CMAKE_INSTALL_BINDIR})") + executable_files.append("%{_bindir}/" + executable) + end + if !!(line =~ /setup\/openarm-can-[a-z0-9\-]/) + /(?.+)\s*setup\/\s*(?.+)/ =~ line + executable_files.append("%{_bindir}/" + executable) + end + end + executable_files.sort! + Helper.update_content("openarm-can.spec") do |content| + content.sub!("%{EXECUTABLES}", executable_files.join("\n")) + end +end diff --git a/packages/Rakefile b/packages/Rakefile index 6091959..6065a2f 100644 --- a/packages/Rakefile +++ b/packages/Rakefile @@ -89,14 +89,6 @@ class OpenArmCANPackageTask < PackageTask false end - def update_spec - update_content("fedora/openarm-can.spec") do |content| - content.gsub!(/^(Version:\s+)[\d.]+$/) do - "#{$1}#{@version}" - end - end - end - def define_archive_task file @archive_name do if File.exist?("../#{@archive_name}") diff --git a/packages/fedora/openarm-can.spec b/packages/fedora/openarm-can.spec.in similarity index 84% rename from packages/fedora/openarm-can.spec rename to packages/fedora/openarm-can.spec.in index a0de332..ee16839 100644 --- a/packages/fedora/openarm-can.spec +++ b/packages/fedora/openarm-can.spec.in @@ -13,7 +13,7 @@ # limitations under the License. Name: openarm-can -Version: 1.2.2 +Version: %{VERSION} Release: %{autorelease} Summary: OpenArm CAN control library @@ -68,14 +68,7 @@ Setup and configuration utility scripts. %files utils %license LICENSE.txt -%{_bindir}/openarm-can-change-baudrate -%{_bindir}/openarm-can-configure-socketcan -%{_bindir}/openarm-can-configure-socketcan-4-arms -%{_bindir}/openarm-can-demo -%{_bindir}/openarm-can-diagnosis -%{_bindir}/openarm-can-motor-check -%{_bindir}/openarm-can-set-zero -%{_bindir}/openarm-can-zero-position-calibration +%{EXECUTABLES} %changelog %autochangelog From 3f510f51a3d51ac8aa69eaf61b41c74ba15a0d73 Mon Sep 17 00:00:00 2001 From: Benson Muite Date: Fri, 26 Dec 2025 07:02:49 +0300 Subject: [PATCH 2/3] Harmonize substitution syntax Co-authored-by: Sutou Kouhei --- packages/fedora/openarm-can.spec.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fedora/openarm-can.spec.in b/packages/fedora/openarm-can.spec.in index ee16839..c037625 100644 --- a/packages/fedora/openarm-can.spec.in +++ b/packages/fedora/openarm-can.spec.in @@ -13,7 +13,7 @@ # limitations under the License. Name: openarm-can -Version: %{VERSION} +Version: @VERSION@ Release: %{autorelease} Summary: OpenArm CAN control library From 4b3304b8351807ae5fe7b0541c75eb9a86fc0e2d Mon Sep 17 00:00:00 2001 From: Benson Muite Date: Fri, 26 Dec 2025 07:18:43 +0300 Subject: [PATCH 3/3] Keep packaging related tasks together --- .packit.yaml | 4 +- packages/yum/Rakefile | 43 ++++++++++++++++++++ packages/{fedora => yum}/openarm-can.spec.in | 2 +- 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 packages/yum/Rakefile rename packages/{fedora => yum}/openarm-can.spec.in (99%) diff --git a/.packit.yaml b/.packit.yaml index 5ecabc0..59b0eb8 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -14,11 +14,11 @@ # https://packit.dev/docs/configuration/ -specfile_path: openarm-can.spec +specfile_path: packages/yum/openarm-can.spec actions: post-upstream-clone: - - rake spec + - rake -C packages/yum spec srpm_build_deps: - rubygem-json diff --git a/packages/yum/Rakefile b/packages/yum/Rakefile new file mode 100644 index 0000000..858d6e4 --- /dev/null +++ b/packages/yum/Rakefile @@ -0,0 +1,43 @@ +# Copyright 2025 Enactic, Inc. +# +# 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. + +require "fileutils" + +require_relative "../../helper" + +version = ENV["VERSION"] || Helper.detect_version + +desc "Create RPM spec file" +task :spec do + FileUtils.copy_file("openarm-can.spec.in", "openarm-can.spec") + current_version = Helper.detect_version + Helper.update_content("openarm-can.spec") do |content| + content.sub!("@VERSION@", current_version) + end + executable_files = Array.new() + File.readlines('../../CMakeLists.txt', chomp: true).each do |line| + if !!(line =~ /install\(TARGETS openarm-can-*.* DESTINATION \${CMAKE_INSTALL_BINDIR}\)/) + executable=line.delete_prefix("install(TARGETS ").delete_suffix(" DESTINATION ${CMAKE_INSTALL_BINDIR})") + executable_files.append("%{_bindir}/" + executable) + end + if !!(line =~ /setup\/openarm-can-[a-z0-9\-]/) + /(?.+)\s*setup\/\s*(?.+)/ =~ line + executable_files.append("%{_bindir}/" + executable) + end + end + executable_files.sort! + Helper.update_content("openarm-can.spec") do |content| + content.sub!("@EXECUTABLES@", executable_files.join("\n")) + end +end diff --git a/packages/fedora/openarm-can.spec.in b/packages/yum/openarm-can.spec.in similarity index 99% rename from packages/fedora/openarm-can.spec.in rename to packages/yum/openarm-can.spec.in index c037625..be8f160 100644 --- a/packages/fedora/openarm-can.spec.in +++ b/packages/yum/openarm-can.spec.in @@ -68,7 +68,7 @@ Setup and configuration utility scripts. %files utils %license LICENSE.txt -%{EXECUTABLES} +@EXECUTABLES@ %changelog %autochangelog