Fixed generated C files output path

In addition to the main fix...

- refactored GeneratorVisitor a bit
- slightly improve context in a debug message
This commit is contained in:
Michael Pfaff 2022-08-10 21:01:25 -04:00
parent bc636fa213
commit 68d112adec
Signed by: michael
GPG Key ID: CF402C4A012AA9D4
3 changed files with 37 additions and 28 deletions

View File

@ -88,7 +88,7 @@
<include name="org/lwjgl/opengl/KHRDebugCallback.java"/>
</javac>
<javac destdir="${lwjgl.target.gen.classes}" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processorGL">
<javac destdir="${lwjgl.target.gen.native}/opengl" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processorGL">
<compilerarg value="-proc:only"/>
<compilerarg value="-processor"/>
<compilerarg value="org.lwjgl.util.generator.GeneratorProcessor"/>
@ -111,8 +111,8 @@
</javac>
<!-- Generate OpenGL references -->
<javac destdir="${lwjgl.target.gen.classes}" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processor">
<compilerarg value="-proc:only"/>
<javac destdir="${lwjgl.target.gen.native}/opengl" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processor">
<compilerarg value="-proc:only"/>
<compilerarg value="-processor"/>
<compilerarg value="org.lwjgl.util.generator.opengl.GLReferencesGeneratorProcessor"/>
<compilerarg value="-processorpath"/>
@ -129,7 +129,7 @@
</javac>
<!-- Generate OpenGL context capabilities -->
<javac destdir="${lwjgl.target.gen.classes}" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processor">
<javac destdir="${lwjgl.target.gen.native}/opengl" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processor">
<compilerarg value="-proc:only"/>
<compilerarg value="-processor"/>
<compilerarg value="org.lwjgl.util.generator.opengl.GLGeneratorProcessor"/>
@ -170,7 +170,7 @@
<include name="org/lwjgl/opengles/KHRDebugCallback.java"/>
</javac>
<javac destdir="${lwjgl.target.gen.classes}" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gles}" fork="true" taskname="processor">
<javac destdir="${lwjgl.target.gen.native}/opengles" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gles}" fork="true" taskname="processor">
<compilerarg value="-proc:only"/>
<compilerarg value="-processor"/>
<compilerarg value="org.lwjgl.util.generator.GeneratorProcessor"/>
@ -193,7 +193,7 @@
</javac>
<!-- Generate OpenGL ES context capabilities -->
<javac destdir="${lwjgl.target.gen.classes}" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gles}" fork="true" taskname="processor">
<javac destdir="${lwjgl.target.gen.native}/opengles" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.gles}" fork="true" taskname="processor">
<compilerarg value="-proc:only"/>
<compilerarg value="-processor"/>
<compilerarg value="org.lwjgl.util.generator.opengl.GLESGeneratorProcessor"/>
@ -241,7 +241,7 @@
<compilerarg value="-Xlint:none"/>
</javac>
<javac destdir="${lwjgl.target.gen.classes}" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.cl}" fork="true" taskname="processor">
<javac destdir="${lwjgl.target.gen.native}/opencl" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.cl}" fork="true" taskname="processor">
<compilerarg value="-proc:only"/>
<compilerarg value="-processor"/>
<compilerarg value="org.lwjgl.util.generator.GeneratorProcessor"/>
@ -264,7 +264,7 @@
</javac>
<!-- Generate OpenCL capabilities -->
<javac destdir="${lwjgl.target.gen.classes}" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.cl}" fork="true" taskname="processor">
<javac destdir="${lwjgl.target.gen.native}/opencl" source="1.8" target="1.8" srcdir="${lwjgl.src.templates.cl}" fork="true" taskname="processor">
<compilerarg value="-proc:only"/>
<compilerarg value="-processor"/>
<compilerarg value="org.lwjgl.util.generator.opencl.CLGeneratorProcessor"/>

View File

@ -518,7 +518,7 @@ public class LWJGLUtil {
return path;
});
} catch (PrivilegedActionException e) {
logger().log("Failed to locate findLibrary method", e.getCause());
logger().log(() -> "Failed to locate findLibrary method on " + clazz, e.getCause());
c = c.getSuperclass();
}
}

View File

@ -331,25 +331,8 @@ public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
throw new RuntimeException("Failed to generate the Java sources for " + e, ex);
}
String qualified_interface_name = Utils.getQualifiedClassName(e);
final Path output = Path.of(this.gen_path + "/" + qualified_interface_name.replace('.', '/') + ".java");
String newStr = java_writer.toString();
try {
if (isFileExistingAndIdentical(output, newStr)) {
return DEFAULT_VALUE;
}
Files.createDirectories(output.getParent());
Files.createFile(output);
} catch (IOException ex) {
throw new RuntimeException("Failed to create the output file for " + e, ex);
}
//try (Writer java_file_writer = env.getFiler().createSourceFile(Utils.getQualifiedClassName(e), env.getElementUtils().getPackageOf(e)).openWriter()) {
try (Writer java_file_writer = new FileWriter(output.toFile())) {
java_file_writer.write(newStr);
env.getMessager().printMessage(Diagnostic.Kind.NOTE, "Generated class " + qualified_interface_name);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
saveGeneratedJavaSource(e, java_writer);
if (methods.size() > 0) {
boolean noNative = true;
for (ExecutableElement method : methods) {
@ -372,6 +355,32 @@ public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
return DEFAULT_VALUE;
}
private void saveGeneratedJavaSource(TypeElement e, StringWriter java_writer) {
String qualified_interface_name = Utils.getQualifiedClassName(e);
final Path output = Path.of(this.gen_path + "/" + qualified_interface_name.replace('.', '/') + ".java");
String newStr = java_writer.toString();
saveGeneratedSource(qualified_interface_name, output, newStr);
}
private void saveGeneratedSource(String name, Path output, String newStr) {
try {
if (isFileExistingAndIdentical(output, newStr)) {
return;
}
Files.createDirectories(output.getParent());
Files.createFile(output);
} catch (IOException ex) {
throw new RuntimeException("Failed to create the output file for " + name, ex);
}
//try (Writer java_file_writer = env.getFiler().createSourceFile(Utils.getQualifiedClassName(e), env.getElementUtils().getPackageOf(e)).openWriter()) {
try (Writer java_file_writer = new FileWriter(output.toFile())) {
java_file_writer.write(newStr);
env.getMessager().printMessage(Diagnostic.Kind.NOTE, "Generated class " + name);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
private static ByteBuffer readFile(final File file) throws IOException {
final FileChannel channel = new FileInputStream(file).getChannel();