|
2 | 2 |
|
3 | 3 | import static scala.jdk.javaapi.CollectionConverters.asJava; |
4 | 4 |
|
| 5 | +import java.io.File; |
5 | 6 | import java.nio.file.Files; |
6 | 7 | import java.nio.file.Path; |
| 8 | +import java.nio.file.StandardCopyOption; |
7 | 9 | import java.util.LinkedHashSet; |
8 | 10 | import java.util.TreeSet; |
9 | 11 | import org.enso.compiler.core.EnsoParser; |
|
16 | 18 | public final class EnsoLibraryFeature implements Feature { |
17 | 19 | @Override |
18 | 20 | public void beforeAnalysis(BeforeAnalysisAccess access) { |
| 21 | + makeEnsoLibAvailableForShims(); |
19 | 22 |
|
20 | 23 | var libs = new LinkedHashSet<Path>(); |
21 | 24 | for (var p : access.getApplicationClassPath()) { |
@@ -97,4 +100,28 @@ public void beforeAnalysis(BeforeAnalysisAccess access) { |
97 | 100 | } |
98 | 101 | System.err.println("Registered " + classes.size() + " classes for reflection"); |
99 | 102 | } |
| 103 | + |
| 104 | + private void makeEnsoLibAvailableForShims() { |
| 105 | + boolean found = false; |
| 106 | + try { |
| 107 | + var from = new File("enso.lib").getAbsoluteFile(); |
| 108 | + System.err.println("Distributing enso.lib to (temporary) directories. From " + from); |
| 109 | + var target = new File("target").getAbsoluteFile(); |
| 110 | + assert target.isDirectory() : "It is a dir " + target; |
| 111 | + for (var ch : target.listFiles()) { |
| 112 | + if (ch.isDirectory() && ch.getName().contains("SVM")) { |
| 113 | + var to = new File(ch, "enso.lib"); |
| 114 | + System.err.println(" file to : " + to); |
| 115 | + Files.copy(from.toPath(), to.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| 116 | + found = true; |
| 117 | + } |
| 118 | + } |
| 119 | + } catch (Exception ex) { |
| 120 | + ex.printStackTrace(); |
| 121 | + } |
| 122 | + if (!found) { |
| 123 | + throw new IllegalStateException( |
| 124 | + "Cannot copy enso.lib into temporary directory of native-image"); |
| 125 | + } |
| 126 | + } |
100 | 127 | } |
0 commit comments