• Home
Name Date Size #Lines LOC

..--

tests/03-May-2024-295238

README.mdD03-May-20249.3 KiB227194

common_util.pyD03-May-202413.8 KiB430314

install_tools.shD03-May-20241.3 KiB3424

ojluni_cleanup_merged_branches.shD03-May-2024446 2112

ojluni_merge_package.shD03-May-20246.5 KiB256222

ojluni_merge_to_master.pyD03-May-202417.2 KiB530396

ojluni_modify_expectation.pyD03-May-20249.2 KiB258183

ojluni_refresh_files.pyD03-May-20249.2 KiB260178

ojluni_upgrade_identicals.pyD03-May-20243.4 KiB10764

ojluni_versions_report.pyD03-May-20242.1 KiB6434

requirements.inD03-May-202410 21

requirements.txtD03-May-2024755 1918

README.md

1If you want to import files from the OpenJDK into `libcore/`, you are reading
2the right documentation.
3
4# Concept
5
6```text
7---------A----------C------------   expected_upstream
8          \          \
9-----------B----------D----------   master
10```
11
12The general idea is to get a change from OpenJDK into libcore in AOSP by
13`git merge` from an OpenJDK branch. However, each file in `ojluni/` can come
14from a different OpenJDK version. `expected_upstream` is a staging branch
15storing the OpenJDK version of each file. Thus, we can use `git merge` when
16we update an `ojluni/` file from a new upstream version, and the command should
17automatically merge the file if no merge conflict.
18
19# Workflow
20
21## Prerequisite
22* python3
23* pip3
24* A remote `aosp` is setup in your local git repository
25
26## 1. Setup
27```shell
28cd $ANDROID_BUILD_TOP/libcore
29source ./tools/expected_upstream/install_tools.sh
30```
31
32## 2. Upgrade a java class to a higher OpenJDK version
33For example, upgrade `java.lang.String` to 11.0.13-ga version:
34
35```shell
36ojluni_modify_expectation modify java.lang.String jdk11u/jdk-11.0.13-ga
37ojluni_merge_to_master # -b <bug id> if it fixes any bug
38```
39
40or if `java.lang.String` is missing in the EXPECTED_UPSTREAM file:
41```shell
42ojluni_modify_expectation add jdk11u/jdk-11.0.13-ga java.lang.String
43ojluni_merge_to_master # -b <bug id> if it fixes any bug
44```
45
46`ojluni_merge_to_master` will `git-merge` from the upstream branch.
47If you see any merge conflicts, please resolve the merge conflicts as usual,
48and then run `git commit` to finalize the commit.
49
50### Iteration
51You can build and test the change. If you need to import more files,
52```shell
53ojluni_modify_expectation ...
54# -a imports more files into the last merge commit instead of a new commit
55ojluni_merge_to_master -a
56```
57
58### Bash Autocompletion
59For auto-completion, `ojluni_modify_expectation` supports bash autocompletion.
60```shell
61$ ojluni_modify_expectation modify java.lang.Str    # <tab>
62java.lang.StrictMath                       java.lang.StringBuilder                    java.lang.StringUTF16
63java.lang.String                           java.lang.StringCoding
64java.lang.StringBuffer                     java.lang.StringIndexOutOfBoundsException
65```
66
67## 2a. Add a java test from the upstream
68
69The process is similar to the above commands, but needs to run
70`ojluni_modify_expectation` with an `add` subcommand.
71
72For example, add a test for `String.isEmpty()` method:
73```shell
74ojluni_modify_expectation add jdk8u/jdk8u121-b13 java.lang.String.IsEmpty
75# -a imports more files into the last merge commit instead of a new commit
76ojluni_merge_to_master -a
77```
78Note: `java.lang.String.IsEmpty` is a test class in the upstream repository.
79
80# 3. Upload your changes for code reviews
81
82After you build and test, you are satisfied with your change, you can upload
83the change with the following commands
84
85```shell
86# Upload the original upstream files to the expected_upstream branch
87$ git push aosp HEAD^2:refs/for/expected_upstream
88# Upload the merge commit to the master branch
89$ repo upload --cbr .
90```
91
92# Directory Layout
93in the `aosp/expected_upstream` branch.
941. `ojluni/`
95    * It has the same layout as the ojluni/ files in `aosp/master`
962. `EXPECTED_UPSTREAM` file
97    * The table has 3 columns, i.e.
98        1. Destination path in `ojluni/`
99        2. Expected upstream version / an upstream git tag
100        3. Upstream source path
101    * The file format is like .csv file using a `,` separator
1023. `tools/expected_upstream/`
103    * Contains the tools
104
105# Understanding your change
106
107## Changes that should be made via the `aosp/expected_upstream` branch
1081. Add or upgrade a file from the upstream OpenJDK
109    * You are reading the right document! This documentation tells you how to
110      import the file from the upstream. Later, you can merge the file and
111      `expected_upstream` into `aosp/master` branch.
1122. Remove an `ojluni/` file that originally came from the OpenJDK
113    * Please remove the file on both `aosp/master` and `aosp/expected_upstream`
114      branches. Don't forget to remove the entry in the `EXPECTED_UPSTREAM` too.
1153. Revert the merge commit on `aosp/master` from `expected_upstream`
116    * If you don't plan to re-land your change on `aosp/master`, you should
117      probably revert the change `aosp/expected_upstream` as well.
118    * If you plan to re-land your change, your re-landing commit won't be
119      a merge commit, because `git` doesn't allow you to merge the same commit
120      twice into the same branch. You have 2 options
121        1. Revert your change on `expected_upsteam` too and start over again
122          when you reland your change
123        2. Just accept that the re-landing commit won't be a merge commit.
124
125## Changes that shouldn't happen in the `aosp/expected_upstream` branch
126In general, if you want to change an `ojluni/` file by a text editor / IDE
127manually, you should make the change on `aosp/master`.
128
1291. Changes to non-OpenJDK files
130    * Those files are usually under the `luni/` folder, you can make the change
131      directly on `aosp/master`
1322. Adding / updating a patch to an existing `ojluni/` file
133    * You can make the change directly on `aosp/master`. Please follow this
134      [patch style guideline](https://goto.google.com/libcore-openjdk8-verify).
1353. Cherry-picking a commit from upstream
136    * You should first try to update an `ojluni/` file to a particular upstream
137      version. If you can't but still want to cherry-pick a upstream fix, you
138      should do so on the `aosp/master` branch.
1394. Changes to non-OpenJDK files in `ojluni/`
140    * Files, e.g. Android.bp, don't come from the upstream. You can make the
141      change directly on `aosp/master`.
142
143
144
145# [Only relevant if using `ojluni_refresh_files`] Submit your change in [AOSP gerrit](http://r.android.com/)
146```text
147----11.0.13-ga----------------   openjdk/jdk11u
148         \
149          A
150           \
151------------B-----C------------   expected_upstream
152                   \
153--------------------D---E------   master
154```
155Here are the order of events / votes required to submit your CL on gerrit as of
156Nov 2021.
1571. `Presubmit-Verified +2` on all 5 CLs
158    * Due to [b/204973624](http://b/204973624), you may `Bypass-Presubmit +1`
159      on commit `A` and `B` if the presubmit fails.
1602. `Code-review +2` on all 5 CLs from an Android Core Library team member
1613. If needed, `API-review +1` on commit `E` from an Android API council member
1624. Click the submit button / `Autosubmit +1` on commit `B`, `C` and `E`
163    * Never submit commit `A` individually without submitting `B` together.
164        * Otherwise, gerrit will create another merge commit from `A` without
165          submitting `B`.
166    * Due a Gerrit bug, you can't submit the commit `C` before submitting `B`
167      first manually, even though `B` is the direct parent of `C`. So just
168      submit `B` yourself manually.
169    * If you can't submit the CL due a permission issue, ask an Android Core
170      Library member to submit.
171
172## [Only relevant if using `ojluni_refresh_files`] Life of a typical change
173
174Commit graph of a typical change
175```text
176----11.0.13-ga----------------   openjdk/jdk11u
177         \
178          A
179           \
180------------B-----C------------   expected_upstream
181                   \
182--------------------D---E------   master
183```
184
185Typically, you will need 5 CLs
186* Commit `A` imports the file and moves the file in the `ojluni/` folder
187* Commit `B` merges the file into the expected_upstream with other `ojluni`
188  files
189    * Commit `A` and `B` are created by the `ojluni_refresh_files` script
190* Commit `C` edits the entry in the `EXPECTED_UPSTREAM` file
191* Commit `D` is a merge commit created by `git merge`
192* Commit `E` adds Android patches
193    * Includes other changes to non-OpenJDK files, e.g. `Android.bp`,
194      `api/current.txt`.
195
196### Why can't have a single commit to replace the commits `A`, `B` and `C`?
197* Preserve the upstream history. We can later `git blame` with the upstream
198  history.
199
200# [Only relevant if using `ojluni_refresh_files`] Known bugs
201* `repo upload` may not succeed because gerrit returns error.
202    1. Just try to run `repo upload` again!
203        * The initial upload takes a long time because it tries to sync with the
204          remote AOSP gerrit server. The second upload is much faster because
205          the `git` objects have been uploaded.
206    2. `repo upload` returns TimeOutException, but the CL has been uploaded.
207       Just find your CL in http://r.android.com/. See http://b/202848945
208    3. Try to upload the merge commits 1 by 1
209    ```shell
210    git rev-parse HEAD # a sha is printed and you will need it later
211    git reset HEAD~1 # reset to a earlier commit
212    repo upload --cbr . # try to upload it again
213    git reset <the sha printed above>
214    ```
215* After `ojluni_modify_expectation add` and `ojluni_refresh_files`, a `git commit -a`
216  would include more files than just EXPECTED_UPSTREAM, because `git`, e.g. `git status`,
217  isn't aware of changes in the working tree / in the file system. This can lead to
218  an error when checking out the branch that is based on master.
219    1. Do a `git checkout --hard <initial commit before the add>`
220    2. Rerun the `ojluni_modify_expectation add` and `ojluni_refresh_files`
221    3. `git stash && git stash pop`
222    4. Commit the updated EXPECTED_UPSTREAM and proceed
223
224# Report bugs
225* Report bugs if the git repository is corrupted!
226    * Sometimes, you can recover the repository by running `git reset aosp/expected_upstream`
227