Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter check to macOS #1301

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024, Gluon
* Copyright (c) 2019, 2025, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -406,22 +406,7 @@ String getLinker() {

@Override
Predicate<Path> getTargetSpecificNativeLibsFilter() {
return this::checkFileArchitecture;
}

private boolean checkFileArchitecture(Path path) {
try {
ProcessRunner pr = new ProcessRunner("objdump", "-f", path.toFile().getAbsolutePath());
pr.showSevereMessage(false);
int op = pr.runProcess("objdump");
if (op == 0) {
return true;
}
} catch (IOException | InterruptedException e) {
Logger.logSevere("Unrecoverable error checking file " + path + ": " + e);
}
Logger.logDebug("Ignore file " + path + " since objdump failed on it");
return false;
return FileOps::checkFileArchitecture;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024, Gluon
* Copyright (c) 2019, 2025, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -43,6 +43,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class MacOSTargetConfiguration extends DarwinTargetConfiguration {
Expand Down Expand Up @@ -145,6 +146,11 @@ List<String> getTargetSpecificNativeLibsFlags(Path libPath, List<String> libs) {
.collect(Collectors.toList());
}

@Override
Predicate<Path> getTargetSpecificNativeLibsFilter() {
return FileOps::checkFileArchitecture;
}

@Override
public boolean packageApp() throws IOException, InterruptedException {
boolean sign = !projectConfiguration.getReleaseConfiguration().isSkipSigning();
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/com/gluonhq/substrate/util/FileOps.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024, Gluon
* Copyright (c) 2019, 2025, Gluon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -783,6 +783,28 @@ public static void downloadFromGitHub(String link, Path filePath) throws IOExcep
}
}

/**
* Checks if a file matches the architecture, on Unix systems.
* This can be used to identify if native libraries present in the classpath should be
* added or not to the native image.
* @param path Path of the file
* @return True if the file matches the current architecture
*/
public static boolean checkFileArchitecture(Path path) {
try {
ProcessRunner pr = new ProcessRunner("objdump", "-f", path.toFile().getAbsolutePath());
jperedadnr marked this conversation as resolved.
Show resolved Hide resolved
pr.showSevereMessage(false);
int op = pr.runProcess("objdump");
if (op == 0) {
return true;
}
} catch (IOException | InterruptedException e) {
Logger.logSevere("Unrecoverable error checking file " + path + ": " + e);
}
Logger.logDebug("Ignore file " + path + " since objdump failed on it");
return false;
}

/**
* Prints the progress of a file download
*/
Expand Down
Loading