Skip to content

Commit c2b1ad0

Browse files
committed
Copy runtime classes instead of jar
1 parent 524d811 commit c2b1ad0

File tree

10 files changed

+130
-101
lines changed

10 files changed

+130
-101
lines changed

.github/workflows/install.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
env:
1313
IDRIS2_TESTS_CG: jvm
1414
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
15-
PREVIOUS_VERSION: 0.6.0.5
15+
PREVIOUS_VERSION: 0.6.0.6
1616

1717
jobs:
1818
ubuntu-build:

.github/workflows/pre-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
env:
99
IDRIS2_TESTS_CG: jvm
1010
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
11-
PREVIOUS_VERSION: 0.6.0.5
11+
PREVIOUS_VERSION: 0.6.0.6
1212

1313
jobs:
1414
pre-release:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
env:
1515
IDRIS2_TESTS_CG: jvm
1616
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
17-
PREVIOUS_VERSION: 0.6.0.5
17+
PREVIOUS_VERSION: 0.6.0.6
1818

1919
jobs:
2020
release:

idris-jvm-assembler/pom.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,33 @@
4242
</execution>
4343
</executions>
4444
</plugin>
45+
<plugin>
46+
<artifactId>maven-dependency-plugin</artifactId>
47+
<executions>
48+
<execution>
49+
<id>unpack-runtime-jar</id>
50+
<phase>process-classes</phase>
51+
<goals>
52+
<goal>unpack</goal>
53+
</goals>
54+
<configuration>
55+
<artifactItems>
56+
<artifactItem>
57+
<groupId>io.github.mmhelloworld</groupId>
58+
<artifactId>idris-jvm-runtime</artifactId>
59+
<version>${project.version}</version>
60+
<type>jar</type>
61+
<overWrite>true</overWrite>
62+
<outputDirectory>${project.build.outputDirectory}/runtimeclasses</outputDirectory>
63+
<includes>**/*.class</includes>
64+
</artifactItem>
65+
</artifactItems>
66+
<overWriteReleases>true</overWriteReleases>
67+
<overWriteSnapshots>true</overWriteSnapshots>
68+
</configuration>
69+
</execution>
70+
</executions>
71+
</plugin>
4572
</plugins>
4673
</build>
4774

idris-jvm-assembler/src/main/java/io/github/mmhelloworld/idrisjvm/assembler/AsmGlobalState.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package io.github.mmhelloworld.idrisjvm.assembler;
22

33
import io.github.mmhelloworld.idrisjvm.runtime.Directories;
4+
import io.github.mmhelloworld.idrisjvm.runtime.Runtime;
45
import org.objectweb.asm.ClassWriter;
56

67
import java.io.BufferedInputStream;
78
import java.io.BufferedOutputStream;
9+
import java.io.BufferedReader;
810
import java.io.File;
911
import java.io.IOException;
1012
import java.io.InputStream;
13+
import java.io.InputStreamReader;
1114
import java.io.OutputStream;
1215
import java.nio.file.Path;
1316
import java.nio.file.Paths;
@@ -26,6 +29,7 @@
2629
import java.util.stream.Stream;
2730

2831
import static java.io.File.pathSeparator;
32+
import static java.lang.ClassLoader.getSystemClassLoader;
2933
import static java.lang.String.format;
3034
import static java.lang.Thread.currentThread;
3135
import static java.nio.file.Files.createTempDirectory;
@@ -74,6 +78,30 @@ public static void copyRuntimeJar(String directory) {
7478
copyRuntimeClasses(new File(runtimeJarFile), directory);
7579
}
7680

81+
private static void copyRuntimeClasses(String outputDirectory) {
82+
String packageName = Runtime.class.getPackage().getName();
83+
String packagePath = packageName.replaceAll("[.]", "/");
84+
ClassLoader classLoader = getSystemClassLoader();
85+
InputStream stream = classLoader.getResourceAsStream(packagePath);
86+
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
87+
reader.lines()
88+
.filter(className -> className.endsWith(".class"))
89+
.forEach(className -> copyRuntimeClass(classLoader, className, packagePath, outputDirectory));
90+
}
91+
92+
private static void copyRuntimeClass(ClassLoader classLoader, String className, String packagePath,
93+
String outputDirectory) {
94+
Path outputPath = Paths.get(outputDirectory, packagePath, className);
95+
outputPath.getParent().toFile().mkdirs();
96+
try (InputStream inputStream = new BufferedInputStream(classLoader
97+
.getResourceAsStream("runtimeclasses/" + packagePath + "/" + className));
98+
OutputStream outputStream = new BufferedOutputStream(newOutputStream(outputPath))) {
99+
copy(inputStream, outputStream);
100+
} catch (IOException exception) {
101+
throw new RuntimeException(exception);
102+
}
103+
}
104+
77105
private static void copyRuntimeClasses(File file, String directory) {
78106
try (JarFile jarFile = new JarFile(file)) {
79107
Collections.list(jarFile.entries()).stream()
@@ -164,11 +192,11 @@ public void classCodeEnd(String outputDirectory, String outputFile, String mainC
164192
writeClass(classNameAndClassWriter.getKey(), classNameAndClassWriter.getValue(), classDirectory));
165193
String mainClassNoSlash = mainClass.replace('/', '.');
166194
if (outputDirectory.isEmpty()) {
167-
copyRuntimeJar(normalizedOutputDirectory);
195+
copyRuntimeClasses(normalizedOutputDirectory);
168196
interpret(mainClassNoSlash, normalizedOutputDirectory);
169197
} else {
170198
new File(classDirectory).mkdirs();
171-
copyRuntimeJar(classDirectory);
199+
copyRuntimeClasses(classDirectory);
172200
Assembler.createExecutable(normalizedOutputDirectory, outputFile, mainClassNoSlash);
173201
}
174202
}

idris-jvm-compiler/pom.xml

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,12 @@
2020

2121
<build>
2222
<plugins>
23-
<plugin>
24-
<artifactId>maven-compiler-plugin</artifactId>
25-
<configuration>
26-
<source>${java.version}</source>
27-
<target>${java.version}</target>
28-
</configuration>
29-
</plugin>
3023
<plugin>
3124
<artifactId>maven-jar-plugin</artifactId>
3225
<executions>
3326
<execution>
3427
<id>default-jar</id>
35-
<phase>compile</phase>
28+
<phase>package</phase>
3629
</execution>
3730
</executions>
3831
</plugin>
@@ -93,6 +86,29 @@
9386
<configuration>
9487
<includeScope>compile</includeScope>
9588
<outputDirectory>${project.parent.basedir}/build/exec/idris2_app</outputDirectory>
89+
<excludeArtifactIds>idris-jvm-runtime</excludeArtifactIds>
90+
</configuration>
91+
</execution>
92+
<execution>
93+
<id>unpack-runtime-jar</id>
94+
<phase>process-classes</phase>
95+
<goals>
96+
<goal>unpack</goal>
97+
</goals>
98+
<configuration>
99+
<artifactItems>
100+
<artifactItem>
101+
<groupId>io.github.mmhelloworld</groupId>
102+
<artifactId>idris-jvm-runtime</artifactId>
103+
<version>${project.version}</version>
104+
<type>jar</type>
105+
<overWrite>true</overWrite>
106+
<outputDirectory>${project.parent.basedir}/build/exec/idris2_app</outputDirectory>
107+
<includes>**/*.class</includes>
108+
</artifactItem>
109+
</artifactItems>
110+
<overWriteReleases>true</overWriteReleases>
111+
<overWriteSnapshots>true</overWriteSnapshots>
96112
</configuration>
97113
</execution>
98114
</executions>
@@ -138,33 +154,6 @@
138154
</environmentVariables>
139155
</configuration>
140156
</execution>
141-
<execution>
142-
<id>runtime-jar-cleanup</id>
143-
<phase>process-test-classes</phase>
144-
<goals>
145-
<goal>java</goal>
146-
</goals>
147-
<configuration>
148-
<skip>${skipIdrisCompile}</skip>
149-
<!--
150-
This is a hack to remove bootstrap compiler runtime JAR under "build/exec/idris2_app".
151-
Idris JVM compiler copies runtime JAR into application output directories so that we don't
152-
have to setup the JAR explicitly in the classpath to run programs but for compiler code
153-
itself, we want to use the runtime JAR from the current version, not of the compiler that
154-
compiles the current code. This program compares the semantic versions of runtime JARs
155-
and removes the old JAR. This is specifically inside "test" directory so that dependencies
156-
for this class like "maven-artifact" dependency wouldn't be copied
157-
into "build/exec/idris2_app" directory.
158-
-->
159-
<mainClass>
160-
io.github.mmhelloworld.idrisjvm.compiler.RuntimeJarCleanup
161-
</mainClass>
162-
<classpathScope>test</classpathScope>
163-
<arguments>
164-
<argument>${project.parent.basedir}/build/exec/idris2_app</argument>
165-
</arguments>
166-
</configuration>
167-
</execution>
168157
<execution>
169158
<id>idris-install-libs</id>
170159
<phase>package</phase>
@@ -204,19 +193,49 @@
204193
</execution>
205194
</executions>
206195
</plugin>
196+
<plugin>
197+
<artifactId>maven-resources-plugin</artifactId>
198+
<executions>
199+
<execution>
200+
<id>copy-resources</id>
201+
<phase>process-classes</phase>
202+
<goals>
203+
<goal>copy-resources</goal>
204+
</goals>
205+
<configuration>
206+
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
207+
<resources>
208+
<resource>
209+
<directory>${project.parent.basedir}/build/exec/idris2_app</directory>
210+
<includes>
211+
<include>**/*.class</include>
212+
</includes>
213+
</resource>
214+
</resources>
215+
</configuration>
216+
</execution>
217+
</executions>
218+
</plugin>
207219
<plugin>
208220
<artifactId>maven-antrun-plugin</artifactId>
209221
<executions>
210222
<execution>
211-
<id>copy-compiler-jar</id>
223+
<id>delete-runtime-jar</id>
212224
<phase>process-classes</phase>
213225
<goals>
214226
<goal>run</goal>
215227
</goals>
216228
<configuration>
217229
<failOnError>false</failOnError>
218230
<target>
219-
<copy file="../build/exec/idris2_app/idris2.jar" tofile="./target/idris-jvm-compiler-${project.version}.jar" overwrite="true" />
231+
<!--
232+
This is to remove bootstrap compiler runtime JAR under build/exec/idris2_app. This is only temporary as old Idris
233+
JVM compiler copies runtime JAR into output directory. New compiler would copy the runtime classes instead of JAR
234+
so when we have the newer bootstrap compiler, this can be removed.
235+
-->
236+
<delete failonerror="false">
237+
<fileset dir="${project.parent.basedir}/build/exec/idris2_app" includes="idris-jvm-runtime-*.jar"/>
238+
</delete>
220239
</target>
221240
</configuration>
222241
</execution>

idris-jvm-compiler/src/assembly/bin.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
<directory>${project.parent.basedir}/libs/prelude/build/ttc</directory>
2727
<outputDirectory>/env/idris2-${idris.version}/prelude-${idris.version}</outputDirectory>
2828
</fileSet>
29-
<fileSet>
30-
<directory>${project.parent.basedir}/libs/prelude/build/ttc</directory>
31-
<outputDirectory>/env/idris2-${idris.version}/prelude-${idris.version}</outputDirectory>
32-
</fileSet>
3329
<fileSet>
3430
<directory>${project.parent.basedir}/libs/test/build/ttc</directory>
3531
<outputDirectory>/env/idris2-${idris.version}/test-${idris.version}</outputDirectory>

idris-jvm-compiler/src/main/java/io/github/mmhelloworld/idrisjvm/compiler/Placeholder.java

Lines changed: 0 additions & 4 deletions
This file was deleted.

idris-jvm-compiler/src/test/java/io/github/mmhelloworld/idrisjvm/compiler/RuntimeJarCleanup.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

pom.xml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<groupId>io.github.mmhelloworld</groupId>
@@ -30,9 +31,12 @@
3031
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3132
<project.scm.id>github</project.scm.id>
3233
<java.version>1.8</java.version>
34+
<maven.compiler.source>${java.version}</maven.compiler.source>
35+
<maven.compiler.target>${java.version}</maven.compiler.target>
3336
<junit-jupiter.version>5.7.2</junit-jupiter.version>
3437
<log4j.version>2.11.0</log4j.version>
3538
<build-helper-maven-plugin.version>3.1.0</build-helper-maven-plugin.version>
39+
<maven-clean-plugin.version>3.3.2</maven-clean-plugin.version>
3640
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
3741
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
3842
<maven-install-plugin.version>2.5.2</maven-install-plugin.version>
@@ -127,6 +131,11 @@
127131
<artifactId>exec-maven-plugin</artifactId>
128132
<version>${exec-maven-plugin.version}</version>
129133
</plugin>
134+
<plugin>
135+
<groupId>org.apache.maven.plugins</groupId>
136+
<artifactId>maven-clean-plugin</artifactId>
137+
<version>${maven-clean-plugin.version}</version>
138+
</plugin>
130139
<plugin>
131140
<groupId>org.apache.maven.plugins</groupId>
132141
<artifactId>maven-source-plugin</artifactId>
@@ -234,8 +243,10 @@
234243
<autoVersionSubmodules>true</autoVersionSubmodules>
235244
<releaseProfiles>release</releaseProfiles>
236245
<arguments>-DskipTests</arguments>
237-
<scmDevelopmentCommitComment>@{prefix} prepare for next development iteration [skip ci]</scmDevelopmentCommitComment>
238-
<scmReleaseCommitComment>@{prefix} prepare release @{releaseLabel} [skip ci]</scmReleaseCommitComment>
246+
<scmDevelopmentCommitComment>@{prefix} prepare for next development iteration [skip ci]
247+
</scmDevelopmentCommitComment>
248+
<scmReleaseCommitComment>@{prefix} prepare release @{releaseLabel} [skip ci]
249+
</scmReleaseCommitComment>
239250
</configuration>
240251
</plugin>
241252
</plugins>

0 commit comments

Comments
 (0)