Skip to content

Commit

Permalink
add: new requires, build-requires parameters #14
Browse files Browse the repository at this point in the history
  • Loading branch information
jiro4989 committed Dec 31, 2023
1 parent 6a966c1 commit 2a84687
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down
2 changes: 2 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
2 changes: 2 additions & 0 deletions template.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Vendor: {{VENDOR}}
Source: tmp.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
BuildArch: {{ARCH}}
{{BUILD_REQUIRES}}
{{REQUIRES}}

%description
{{DESC}}
Expand Down
25 changes: 21 additions & 4 deletions tools/src/replacetool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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]) =
Expand Down Expand Up @@ -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,
Expand All @@ -116,4 +131,6 @@ when isMainModule and not defined modeTest:
license = license,
vendor = vendor,
post = post,
buildRequires = buildRequires,
requires = requires,
)

0 comments on commit 2a84687

Please sign in to comment.