|
1 |
| -This projects shows a way to compile JDK 16+ javac to run on JDK 8+, |
2 |
| -for the pruposes of NetBeans ("nb-javac"). |
| 1 | +# Hacking Guide for the automatically generated [nbjavac](README.md) |
3 | 2 |
|
4 |
| -### Steps to compile nb-javac: |
| 3 | +The idea of the new build system is to take the JDK 16+ `javac` sources and |
| 4 | +automatically convert them to run on JDK 8+. As a result the sources come |
| 5 | +from real JDK repository. The `nbjavac` repository doesn't contain them. |
| 6 | +This repository only contains the build scripts and |
| 7 | +description of [advanced refactorings](https://netbeans.apache.org/jackpot/HintsFileFormat.html). |
| 8 | +Use: |
5 | 9 |
|
6 | 10 | ```bash
|
7 |
| -JAVA_HOME8=/jdk-8/ JAVA_HOME14=/jdk-14/ ./build.sh |
| 11 | +$ JAVA_HOME=/jdk-14/ ant -f ./make/langtools/netbeans/nb-javac jar |
8 | 12 | ```
|
9 | 13 |
|
10 |
| -### Manual steps to compile nb-javac: |
11 |
| - |
12 |
| -1. from JDK 16 (https://github.com/openjdk/jdk16), ideally commit 58dca9253d3ec7bc5745d5b814b33e1b4b8b08e8, copy `src/java.compiler` and `src/jdk.compiler` into `src/java.compiler` and `src/jdk.compiler` in this project |
13 |
| -2. from a JDK 16 build, copy: |
14 |
| -`com/sun/tools/javac/resources/CompilerProperties.java` |
15 |
| -into: |
16 |
| -`jdk.compiler/share/classes/com/sun/tools/javac/resources/CompilerProperties.java` |
17 |
| -and: |
18 |
| -`com/sun/tools/javac/resources/LauncherProperties.java` |
19 |
| -into: |
20 |
| -`jdk.compiler/share/classes/com/sun/tools/javac/resources/LauncherProperties.java` |
21 |
| -3. apply `temporary-patches/language-changes` patch. This includes backport language changes, |
22 |
| -which should eventually also be done using NetBeans/Jackpot |
23 |
| -4. open the `make/langtools/netbeans/nb-javac` project in NetBeans. Neccessary setup (in Project Properties): |
24 |
| --in Libraries tab, set Java Platform to JDK 11+ (tested with JDK 16) (JDK 8 javac contains a bug that will prevent compilation of the sources) |
25 |
| --in Build/Compiling tab, make sure there is an "Additiona Compiler Options" entry specifying -bootclasspath from JDK 8 (i.e. rt.jar) |
26 |
| -5. open `src/META-INF/upgrades/nbjavac.hint`, invoke Run File, select the project Custom Scope. Do the refactoring. (There should be 102 replacements done.) |
27 |
| -6. apply temporary-patches/manual-workarounds to workaround a few mistakes in the transformation |
28 |
| -7. the project should now be buildable. Not tried in NetBeans yet. |
29 |
| -8. If you would want to test on the commandline, apply `filesystems-run-on-jdk8` and clean & build. Then it should be possible to run like: |
| 14 | +to build everything at once. Read below to control individual steps of the build. |
| 15 | + |
| 16 | + |
| 17 | +### Getting the JDK repository |
| 18 | + |
| 19 | +The build requires JDK repository in `jdk` ssubdirectory of the root of `nb-javac` repository. |
| 20 | +If such directory doesn't exist, the build checks out one: |
| 21 | + |
| 22 | +```bash |
| 23 | +$ JAVA_HOME=/jdk-14/ ant -f ./make/langtools/netbeans/nb-javac init \ |
| 24 | + -Djdk.git.url=https://github.com/openjdk/jdk16 \ |
| 25 | + -Djdk.git.commit=jdk-16+36 |
| 26 | +``` |
| 27 | + |
| 28 | +If the `jdk` directory is present the build leaves its content untouched. E.g. |
| 29 | +a developer may clone the `jdk` repository manually, switch its content to any other tag, |
| 30 | +make changes in the `jdk/src/java.compiler/` or `jdk/src/jdk.compiler/` directories, |
| 31 | +etc. Bugfixes, features and other changes to `javac` sources are supposed to be done |
| 32 | +in the `jdk` subdirectory and integrated into the JDK's `javac` official repository. |
| 33 | + |
| 34 | +One can discard any changes by `rm -rf jdk`. Then the subsequent build checks |
| 35 | +a fresh copy of the `jdk` repository from scratch. The default values for |
| 36 | +`jdk.git.url` and `jdk.git.commit` properties are in the |
| 37 | +`./make/langtools/netbeans/nb-javac/nbproject/project.properties` |
| 38 | +file. |
| 39 | + |
| 40 | + |
| 41 | +### Automatically processing the sources |
| 42 | + |
| 43 | +Once the JDK's `javac` sources are in the `jdk` subdirectory, it is necessary |
| 44 | +to apply [advanced refactorings](./make/langtools/netbeans/nb-javac/src/META-INF/upgrade/nbjavac.hint) |
| 45 | +to them. This is done by executing the [jackpot](https://netbeans.apache.org/jackpot/HintsFileFormat.html) |
| 46 | +target: |
| 47 | + |
| 48 | +```bash |
| 49 | +$ JAVA_HOME=/jdk-14/ ant -f ./make/langtools/netbeans/nb-javac jackpot |
| 50 | +``` |
| 51 | + |
| 52 | +This step copies the `javac` sources from the `jdk` subdirectory into a sibling |
| 53 | +`src` subdirectory and applies necessary transformations to them. |
| 54 | +The goal of such transformations is to eliminate usage of JDK9+ APIs |
| 55 | +and replace them with JDK8 only APIs. |
| 56 | + |
| 57 | +The sources under the `src/java.compiler` and `src/jdk.compiler` shall not |
| 58 | +be edited manually. Rather than that edit the sources in the original |
| 59 | +`jdk/src/java.compiler/` and `jdk/src/jdk.compiler/` directories. To apply |
| 60 | +the refactorings again execute: |
| 61 | + |
30 | 62 | ```bash
|
31 |
| -java -Xbootclasspath/p:make/langtools/netbeans/nb-javac/dist/nb-javac-15-api.jar:make/langtools/netbeans/nb-javac/dist/nb-javac-15-impl.jar com.sun.tools.javac.Main --system <path-to-JDK16> TextBlock.java |
| 63 | +$ JAVA_HOME=/jdk-14/ ant -f ./make/langtools/netbeans/nb-javac clean jackpot |
32 | 64 | ```
|
33 | 65 |
|
34 |
| -Note step 8 is optional and only needed for experiments on command line, while running on JDK 8 and compiling for JDK 9+. Not needed in NetBeans. |
| 66 | +### The build |
35 | 67 |
|
36 |
| -### Debug test |
| 68 | +As described in [general documentation](README.md) use the following command to |
| 69 | +generate the final JAR files: |
| 70 | + |
| 71 | +```bash |
| 72 | +$ JAVA_HOME=/jdk-14/ ant -f ./make/langtools/netbeans/nb-javac clean jar |
| 73 | +``` |
| 74 | + |
| 75 | +JARs `nb-javac-*-api.jar` and `nb-javac-*-impl.jar` are going to appear |
| 76 | +at location `./make/langtools/netbeans/nb-javac/dist/`. |
| 77 | + |
| 78 | +### Debug & Develop |
| 79 | + |
| 80 | +Open the `nb-javac` project in NetBeans with |
| 81 | + |
| 82 | +```bash |
| 83 | +$ netbeans --open make/langtools/netbeans/nb-javac/ |
| 84 | +``` |
37 | 85 |
|
38 |
| -Use following command to debug a test: |
| 86 | +and you should be able to debug a test with following command line: |
39 | 87 |
|
40 | 88 | ```bash
|
41 | 89 | $ JAVA_HOME=/jdk-8/ ant -f make/langtools/netbeans/nb-javac test \
|
42 | 90 | -Dincludes=**/StringWrapperTest* \
|
43 |
| - -Drun.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,address=8000 |
| 91 | + -Drun.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,address=5005,suspend=y |
44 | 92 | ```
|
45 | 93 |
|
46 |
| -TODO (incomplete): |
47 |
| --automatic build (including CompilerProperties, etc.) |
48 |
| --cleanup |
49 |
| --fix nbjavac wrappers |
50 |
| --fix Jackpot |
51 |
| --resolve language changes |
52 |
| --jdeps needed? (classfile library?) |
53 |
| --test - all javac, nb-javac and NetBeans (including updates) |
| 94 | +Then you can connect the NetBeans IDE to port 5005 and step through the `nb-javac` |
| 95 | +generated code. |
0 commit comments