Fix relocation breaking runClient & runServer

This commit is contained in:
s809
2025-01-29 23:59:23 +05:00
parent 7f4f8a40eb
commit 9e6953a596
2 changed files with 18 additions and 12 deletions
+5 -2
View File
@@ -111,10 +111,11 @@ class NativeTransformer implements Transformer {
private final HashMap<String, byte[]> rewrittenFiles = new HashMap()
private var nativeRelocator
public File rootDir
NativeTransformer() {
try {
int exitCode = Runtime.getRuntime().exec(new String[]{"python", "--version"}).waitFor();
int exitCode = Runtime.getRuntime().exec(new String[]{"python", "--version"}).waitFor()
if (exitCode == 0) {
enabled = true
}
@@ -150,7 +151,7 @@ class NativeTransformer implements Transformer {
byte[] content = context.is.readAllBytes()
if (nativeRelocator == null) {
nativeRelocator = new NativeRelocator()
nativeRelocator = new NativeRelocator(rootDir.toPath().resolve("relocate_natives"))
}
try {
@@ -395,6 +396,8 @@ subprojects { p ->
// librariesLocation isn't used because it's too long for replacing paths in native libraries
// Allowing strings larger than the original string would require shifting the entire binary's contents
transform(NativeTransformer) {
rootDir = project.rootDir
before {
relocate "org.sqlite", "dh_sqlite", {
exclude "org/sqlite/native/**"
+13 -10
View File
@@ -6,8 +6,8 @@ import java.util.concurrent.CompletableFuture;
class NativeRelocator
{
private static final Path rootDirectory = Path.of(System.getProperty("user.dir"), "relocate_natives");
private static final Path cacheRoot = rootDirectory.resolve("cache");
private final Path rootDirectory;
private final Path cacheRoot;
/**
* Initializes the NativeRelocator by preparing the environment if necessary.
@@ -15,15 +15,18 @@ class NativeRelocator
*
* @throws Exception if the preparation script fails or an unsupported OS is detected.
*/
NativeRelocator() throws Exception
NativeRelocator(Path rootDirectory) throws Exception
{
if (rootDirectory.resolve(".venv").toFile().exists())
this.rootDirectory = rootDirectory;
this.cacheRoot = this.rootDirectory.resolve("cache");
if (this.rootDirectory.resolve(".venv").toFile().exists())
{
return;
}
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.directory(rootDirectory.toFile());
processBuilder.directory(this.rootDirectory.toFile());
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("win"))
@@ -146,12 +149,12 @@ class NativeRelocator
public byte[] fixModifiedBinary(Path outputFilePath, byte[] content) throws Exception
{
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.directory(rootDirectory.toFile());
processBuilder.directory(this.rootDirectory.toFile());
processBuilder.command(
rootDirectory.resolve(".venv/Scripts").toFile().exists()
? rootDirectory.resolve(".venv/Scripts/python.exe").toString()
: rootDirectory.resolve(".venv/bin/python").toString(),
this.rootDirectory.resolve(".venv/Scripts").toFile().exists()
? this.rootDirectory.resolve(".venv/Scripts/python.exe").toString()
: this.rootDirectory.resolve(".venv/bin/python").toString(),
"./fix_modified_binary.py",
outputFilePath.toString()
);
@@ -184,7 +187,7 @@ class NativeRelocator
*/
public byte[] processBinary(String outputPath, byte[] content, Map<String, String> replacements) throws Exception
{
Path outputFilePath = cacheRoot.resolve(outputPath);
Path outputFilePath = this.cacheRoot.resolve(outputPath);
//noinspection ResultOfMethodCallIgnored
outputFilePath.getParent().toFile().mkdirs();