Skip to content

Commit

Permalink
Add support for rpm embedded lua interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
moedan authored and ctron committed Sep 10, 2024
1 parent 50e4a55 commit 357bf3a
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions rpm/src/main/java/org/eclipse/packager/rpm/build/RpmBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = "<lua>";

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<RpmTag> header = new Header<>();

private final String name;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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.
Expand Down

0 comments on commit 357bf3a

Please sign in to comment.