On 8/25/22 4:11 PM, some-java-user-99206970363698485...@vodafonemail.de wrote:
Hello, the JDK source code contains many Java classes which are specific to one platform / operating system, for example classes to interact with the file system or the AWT and Swing related classes are different for Windows and Linux. Is there a way to compile the Java source code for all platforms supported by the JDK at once? My goal is not to build a functional JDK, but to use the class files (or rather the compilation process) for static code analysis, specifically for analysis with CodeQL. I assume this might also be useful for other code analysis tools, and maybe also in general to detect Java compilation errors with the JDK source code. It appears the OpenJDK building instructions are always for building for a specific target platform and therefore skip compiling the Java code for other platforms. Additionally the `configure` command checks also check for tools needed to compile native code (e.g. Xcode or Visual Studio), even though for pure Java compilation they would not be needed (?). Therefore when you try to use multiple configurations (as described in the build instructions) it would require you to install all the tools for all platforms (if that is even possible on the same host operating system). Ideally I am looking for a solution which satisfies the following: - Compiles the Java source code for all supported platforms - Compiles all the Java source code in one build command execution - Or at least compiles the Java source code with separate build command executions, but which can all be run from the same host operating system (no need to use separate operating systems) - Does not require any of the tools for native compilation to be installed Though I am happy about any solution which gets as close as possible to this. Thanks already in advance!
This is not a usecase I have ever encountered before, and the build system does not have anything close to supporting it. I don't think you can achieve this without some serious effort.
Even if you were to include all the java source dirs, I'm pretty sure you couldn't compile them straight into the same output dir. Different versions of the same java class can appear in different platform directories. We also have a lot of generated java code where some may get generated differently depending on platform. For example in make/modules/java.base/gensrc/GensrcMisc.gmk, we use the native preprocessor to generate constants into a java class.
It's not possible to cross compile all platforms from any single OS, so you can't provide native toolchains for separate builds on the same host.
Depending on how close to correct you need the java class files to be produced, it could be possible to hack around in the build system to achieve something that is perhaps close enough, but as I said already, it won't be trivial. I doubt we would want to incorporate any such change into the build permanently without some very strong motivation.
/Erik