From 357bf3aaf7721e718fb74f586d6302b3c4b7f460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=B6ser=2C=20Daniel?= Date: Thu, 29 Aug 2024 10:06:22 +0200 Subject: [PATCH] Add support for rpm embedded lua interpreter --- .../packager/rpm/build/RpmBuilder.java | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/rpm/src/main/java/org/eclipse/packager/rpm/build/RpmBuilder.java b/rpm/src/main/java/org/eclipse/packager/rpm/build/RpmBuilder.java index 5a926ed..f8f8b58 100644 --- a/rpm/src/main/java/org/eclipse/packager/rpm/build/RpmBuilder.java +++ b/rpm/src/main/java/org/eclipse/packager/rpm/build/RpmBuilder.java @@ -32,6 +32,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.Consumer; @@ -582,6 +583,12 @@ protected void customizeSymbolicLink(final FileEntry entry, final FileInformatio private static final String DEFAULT_INTERPRETER = "/bin/sh"; + private static final String EMBEDDED_LUA_INTERPRETER = ""; + + private static final String EMBEDDED_LUA_INTERPRETER_REQUIREMENT_NAME = "rpmlib(BuiltinLuaScripts)"; + + private static final String EMBEDDED_LUA_INTERPRETER_REQUIREMENT_VERSION = "4.2.2-1"; + protected final Header header = new Header<>(); private final String name; @@ -1178,8 +1185,7 @@ public void addSymbolicLink(final String targetName, final String linkTo, final } public void setPreInstallationScript(final String interpreter, final String script) { - addRequirement(interpreter, null, RpmDependencyFlags.INTERPRETER); - addRequirement(interpreter, null, RpmDependencyFlags.SCRIPT_PRE, RpmDependencyFlags.INTERPRETER); + addInterpreterRequirement(interpreter, RpmDependencyFlags.SCRIPT_PRE); setScript(RpmTag.PREINSTALL_SCRIPT_PROG, RpmTag.PREINSTALL_SCRIPT, interpreter, script); } @@ -1188,8 +1194,7 @@ public void setPreInstallationScript(final String script) { } public void setPostInstallationScript(final String interpreter, final String script) { - addRequirement(interpreter, null, RpmDependencyFlags.INTERPRETER); - addRequirement(interpreter, null, RpmDependencyFlags.SCRIPT_POST, RpmDependencyFlags.INTERPRETER); + addInterpreterRequirement(interpreter, RpmDependencyFlags.SCRIPT_POST); setScript(RpmTag.POSTINSTALL_SCRIPT_PROG, RpmTag.POSTINSTALL_SCRIPT, interpreter, script); } @@ -1198,8 +1203,7 @@ public void setPostInstallationScript(final String script) { } public void setPreRemoveScript(final String interpreter, final String script) { - addRequirement(interpreter, null, RpmDependencyFlags.INTERPRETER); - addRequirement(interpreter, null, RpmDependencyFlags.SCRIPT_PREUN, RpmDependencyFlags.INTERPRETER); + addInterpreterRequirement(interpreter, RpmDependencyFlags.SCRIPT_PREUN); setScript(RpmTag.PREREMOVE_SCRIPT_PROG, RpmTag.PREREMOVE_SCRIPT, interpreter, script); } @@ -1208,8 +1212,7 @@ public void setPreRemoveScript(final String script) { } public void setPostRemoveScript(final String interpreter, final String script) { - addRequirement(interpreter, null, RpmDependencyFlags.INTERPRETER); - addRequirement(interpreter, null, RpmDependencyFlags.SCRIPT_POSTUN, RpmDependencyFlags.INTERPRETER); + addInterpreterRequirement(interpreter, RpmDependencyFlags.SCRIPT_POSTUN); setScript(RpmTag.POSTREMOVE_SCRIPT_PROG, RpmTag.POSTREMOVE_SCRIPT, interpreter, script); } @@ -1218,8 +1221,7 @@ public void setPostRemoveScript(final String script) { } public void setVerifyScript(final String interpreter, final String script) { - addRequirement(interpreter, null, RpmDependencyFlags.INTERPRETER); - addRequirement(interpreter, null, RpmDependencyFlags.SCRIPT_VERIFY, RpmDependencyFlags.INTERPRETER); + addInterpreterRequirement(interpreter, RpmDependencyFlags.SCRIPT_VERIFY); setScript(RpmTag.VERIFY_SCRIPT_PROG, RpmTag.VERIFY_SCRIPT, interpreter, script); } @@ -1228,8 +1230,7 @@ public void setVerifyScript(final String script) { } public void setPreTransactionScript(final String interpreter, final String script) { - addRequirement(interpreter, null, RpmDependencyFlags.INTERPRETER); - addRequirement(interpreter, null, RpmDependencyFlags.SCRIPT_PREUN, RpmDependencyFlags.INTERPRETER); + addInterpreterRequirement(interpreter, RpmDependencyFlags.SCRIPT_PREUN); setScript(RpmTag.PRETRANSACTION_SCRIPT_PROG, RpmTag.PRETRANSACTION_SCRIPT, interpreter, script); } @@ -1238,8 +1239,7 @@ public void setPreTransactionScript(final String script) { } public void setPostTransactionScript(final String interpreter, final String script) { - addRequirement(interpreter, null, RpmDependencyFlags.INTERPRETER); - addRequirement(interpreter, null, RpmDependencyFlags.SCRIPT_POSTUN, RpmDependencyFlags.INTERPRETER); + addInterpreterRequirement(interpreter, RpmDependencyFlags.SCRIPT_POSTUN); setScript(RpmTag.POSTTRANSACTION_SCRIPT_PROG, RpmTag.POSTTRANSACTION_SCRIPT, interpreter, script); } @@ -1257,6 +1257,22 @@ private void setScript(final RpmTag interpreterTag, final RpmTag scriptTag, fina } } + private void addInterpreterRequirement(final String interpreter, RpmDependencyFlags scriptPhaseFlag) { + if (isEmbeddedLuaInterpreter(interpreter)) { + addRequirement(EMBEDDED_LUA_INTERPRETER_REQUIREMENT_NAME, EMBEDDED_LUA_INTERPRETER_REQUIREMENT_VERSION, + RpmDependencyFlags.INTERPRETER, RpmDependencyFlags.LESS, RpmDependencyFlags.EQUAL, RpmDependencyFlags.RPMLIB); + addRequirement(EMBEDDED_LUA_INTERPRETER_REQUIREMENT_NAME, EMBEDDED_LUA_INTERPRETER_REQUIREMENT_VERSION, + scriptPhaseFlag, RpmDependencyFlags.INTERPRETER, RpmDependencyFlags.LESS, RpmDependencyFlags.EQUAL, RpmDependencyFlags.RPMLIB); + } else { + addRequirement(interpreter, null, RpmDependencyFlags.INTERPRETER); + addRequirement(interpreter, null, scriptPhaseFlag, RpmDependencyFlags.INTERPRETER); + } + } + + private boolean isEmbeddedLuaInterpreter(final String interpreter) { + return Objects.equals(interpreter, EMBEDDED_LUA_INTERPRETER); + } + /** * Return the minimum required version of RPM for supporting all features of * this generated RPM.