Skip to content

Commit 5fa0f8d

Browse files
author
Jaroslav Tulach
committed
Polishing hacker's guide
1 parent e79e8d2 commit 5fa0f8d

File tree

3 files changed

+98
-51
lines changed

3 files changed

+98
-51
lines changed

BUILD.md

Lines changed: 79 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,95 @@
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)
32

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:
59

610
```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
812
```
913

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+
3062
```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
3264
```
3365

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
3567

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+
```
3785

38-
Use following command to debug a test:
86+
and you should be able to debug a test with following command line:
3987

4088
```bash
4189
$ JAVA_HOME=/jdk-8/ ant -f make/langtools/netbeans/nb-javac test \
4290
-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
4492
```
4593

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.

README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,49 @@
11
# About nb-javac!
2-
"nb-javac" is backport of OpenJDK "javac", i.e., the Java compiler that
3-
takes sources from the latest JDK and backports them to run on JDK8.
4-
This has long been part of NetBeans, providing a highly tuned Java compiler
2+
_nb-javac_ is a backport of OpenJDK "javac", i.e., the Java compiler. _nbjavac_
3+
takes sources from the latest JDK and backports them to run on JDK8+.
4+
The _nb-javac_ has long been part of NetBeans, providing a highly tuned Java compiler
55
specifically for the Java editor i.e., parsing and lexing for features
66
such as syntax coloring, code completion.
77

88
# Prerequisite
99
- Git
1010
- Ant 1.9.9 or above
11-
- JDK 8 or above (to build nb-javac)
12-
- Apache Maven
11+
- JDK 14 to build
12+
- JDK 8 to test
13+
- Apache Maven to publish to Maven central
1314

1415
# Building nb-javac jar files
15-
1. Obtain the code with the following command
16+
17+
Detailed description of the [build process](BUILD.md) is available in a
18+
separate [development documentation](BUILD.md). Here are just
19+
the most straigtforward steps to get the final artifacts.
20+
21+
### Obtain the code with the following command
1622

1723
```
1824
$ git clone https://github.com/oracle/nb-javac.git
1925
```
2026

21-
2. To get a specific version use the following command
27+
### Get a specific version use the following command
2228

2329
```bash
2430
$ git checkout <release_tag_name>
2531
```
2632

27-
3. Run the below command to build nb-javac.
33+
### Run the below command to build nb-javac.
2834

2935
```bash
30-
$ JAVA_HOME=/jdk-14/ ant -f ./make/langtools/netbeans/nb-javac clean
31-
$ JAVA_HOME=/jdk-14/ ant -f ./make/langtools/netbeans/nb-javac jar
36+
$ JAVA_HOME=/jdk-14/ ant -f ./make/langtools/netbeans/nb-javac clean jar
3237
```
3338

34-
Two jars namely `javac-api*.jar` and `javac-impl*.jar` are going to appear
39+
Two jars namely `nb-javac-*-api.jar` and `nb-javac-*-impl.jar` are going to appear
3540
at location `./make/langtools/netbeans/nb-javac/dist/`. It is also possible to
3641
sanity test the generated Javac on JDK8:
3742
```bash
38-
$ JAVA_HOME=/bin/jdk-8/ ant -f ./make/langtools/netbeans/nb-javac test
43+
$ JAVA_HOME=/jdk-8/ ant -f ./make/langtools/netbeans/nb-javac test
3944
```
4045

41-
4. Run below command to zip the source code of nb-javac
46+
### Generate ZIP with the source code of nb-javac
4247

4348
```bash
4449
$ JAVA_HOME=/jdk-14/ ant -f ./make/langtools/netbeans/nb-javac zip-nb-javac-sources

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if ! [ -f $JAVA_HOME14/jmods/java.base.jmod ]; then
2222
fi
2323

2424
export JAVA_HOME=$JAVA_HOME14
25-
ant $ANT_ARGS_EXTRA -f make/langtools/netbeans/nb-javac jar
25+
ant $ANT_ARGS_EXTRA -f make/langtools/netbeans/nb-javac clean jar
2626

2727

2828
export JAVA_HOME=$JAVA_HOME8

0 commit comments

Comments
 (0)