From 2a84687c2208485cdff232673af3833aed2cf10a Mon Sep 17 00:00:00 2001 From: jiro4989 Date: Sun, 31 Dec 2023 11:48:35 +0900 Subject: [PATCH] add: new requires, build-requires parameters #14 --- action.yml | 8 ++++++++ entrypoint.sh | 2 ++ template.spec | 2 ++ tools/src/replacetool.nim | 25 +++++++++++++++++++++---- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 3ef7d71..9eb0d1b 100644 --- a/action.yml +++ b/action.yml @@ -32,6 +32,14 @@ inputs: post: description: 'Package post.' default: '' + build_requires: + description: 'Package build requires.' + # NOTE: for nim parseops package bugs + default: '-' + requires: + description: 'Package requires.' + # NOTE: for nim parseops package bugs + default: '-' outputs: file_name: description: 'File name of resulting .rpm file. This does not contain a debuginfo file.' diff --git a/entrypoint.sh b/entrypoint.sh index bae2c81..ab48e1c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,6 +10,8 @@ fi /replacetool \ --specfile:/template.spec \ + --build-requires:"$INPUT_BUILD_REQUIRES" \ + --requires:"$INPUT_REQUIRES" \ --summary:"$INPUT_SUMMARY" \ --package-root:"$INPUT_PACKAGE_ROOT" \ --package:"$INPUT_PACKAGE" \ diff --git a/template.spec b/template.spec index ece9e9a..cd06c40 100644 --- a/template.spec +++ b/template.spec @@ -10,6 +10,8 @@ Vendor: {{VENDOR}} Source: tmp.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot BuildArch: {{ARCH}} +{{BUILD_REQUIRES}} +{{REQUIRES}} %description {{DESC}} diff --git a/tools/src/replacetool.nim b/tools/src/replacetool.nim index 6dee392..7bf9e60 100644 --- a/tools/src/replacetool.nim +++ b/tools/src/replacetool.nim @@ -3,7 +3,7 @@ import os, strutils, parseopt type Options = object specFile, summary, package, packageRoot, maintainer, version, arch, desc, - license, vendor, post: string + license, vendor, post, buildRequires, requires: string proc getCmdOpts(params: seq[string]): Options = var optParser = initOptParser(params) @@ -35,6 +35,10 @@ proc getCmdOpts(params: seq[string]): Options = result.license = val of "post": result.post = val + of "build-requires": + result.buildRequires = val + of "requires": + result.requires = val of cmdEnd: assert false # cannot happen else: @@ -46,7 +50,7 @@ proc generateInstallScript(path: string): seq[string] = result.add("cp -p " & path[1..^1] & " %{buildroot}" & head & "/") proc replaceTemplate(body, summary, package, maintainer, version, arch, desc, - install, files, license, vendor, post: string): string = + install, files, license, vendor, post, buildRequires, requires: string): string = result = body .replace("{{SUMMARY}}", summary) @@ -60,19 +64,22 @@ proc replaceTemplate(body, summary, package, maintainer, version, arch, desc, .replace("{{FILES}}", files) .replace("{{LICENSE}}", license) .replace("{{POST}}", post) + .replace("{{BUILD_REQUIRES}}", buildRequires) + .replace("{{REQUIRES}}", requires) proc formatDescription(desc: string): string = "Description: " & desc proc fixFile(file, summary, package, maintainer, version, arch, desc, install, - files, license, vendor, post: string) = + files, license, vendor, post, buildRequires, requires: string) = let body = readFile(file) fixedBody = replaceTemplate(body, summary = summary, package = package, maintainer = maintainer, version = version, arch = arch, desc = desc, install = install, files = files, license = license, - vendor = vendor, post = post) + vendor = vendor, post = post, + buildRequires = buildRequires, requires = requires) writeFile(file, fixedBody) proc getInstallFiles(packageRoot: string): (seq[string], seq[string]) = @@ -103,6 +110,14 @@ when isMainModule and not defined modeTest: license = params.license post = params.post + # NOTE: for bugs std/parseopt + buildRequires = + if params.buildRequires == "-": "" + else: params.buildRequires + requires = + if params.requires == "-": "" + else: params.requires + let (installScript, files) = getInstallFiles(packageRoot) fixFile(params.specfile, summary = summary, @@ -116,4 +131,6 @@ when isMainModule and not defined modeTest: license = license, vendor = vendor, post = post, + buildRequires = buildRequires, + requires = requires, )