Commit eb70fb4a authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

Docs: add best practices for java_cpp_strings

No change to logic, only docs. This updates java_cpp_strings docs:

 * The first paragraph incorrectly stated this uses comments to
   determine the Java class name. This corrects that statement.
 * Merges the two GN steps into one, explains it's a best practice to
   add this to an android_library (or create a new one if there is
   none), and recommends private visibility for :java_switches_srcjar.

Test: Upload to gerrit > open file > click "gitiles"
Change-Id: I4ae45da15f7db02a9d4c101de1a23c40f154b464
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2369652
Commit-Queue: Bo <boliu@chromium.org>
Auto-Submit: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800838}
parent a747daf4
...@@ -5,9 +5,8 @@ ...@@ -5,9 +5,8 @@
## Introduction ## Introduction
Accessing C++ switches in Java is implemented via a Python script which analyzes Accessing C++ switches in Java is implemented via a Python script which analyzes
the C++ switches file and spits out the corresponding Java class. The generated the C++ switches file and generates the corresponding Java class, based on a
class name will be based upon the switch file name, and the path must be template file. The template file must be specified in the GN target.
specified in a comment within the switch file itself.
## Usage ## Usage
...@@ -33,30 +32,34 @@ specified in a comment within the switch file itself. ...@@ -33,30 +32,34 @@ specified in a comment within the switch file itself.
}} }}
``` ```
2. Add a new build target 2. Add a new build target and add it to the `srcjar_deps` of an
`android_library` target:
```gn ```gn
import("//build/config/android/rules.gni") if (is_android) {
import("//build/config/android/rules.gni")
java_cpp_strings("java_switches") {
sources = [
"//base/android/foo_switches.cc",
]
template = "//base/android/java_templates/FooSwitches.java.tmpl"
} }
```
3. Add the new target to the desired `android_library` targets `srcjar_deps`: if (is_android) {
java_cpp_strings("java_switches_srcjar") {
```gn # External code should depend on ":foo_java" instead.
android_library("base_java") { visibility = [ ":*" ]
srcjar_deps = [ sources = [
":java_switches", "//base/android/foo_switches.cc",
] ]
template = "//base/android/java_templates/FooSwitches.java.tmpl"
}
# If there's already an android_library target, you can add
# java_switches_srcjar to that target's srcjar_deps. Otherwise, the best
# practice is to create a new android_library just for this target.
android_library("foo_java") {
srcjar_deps = [ ":java_switches_srcjar" ]
}
} }
``` ```
4. The generated file `out/Default/gen/.../org/chromium/foo/FooSwitches.java` 3. The generated file `out/Default/gen/.../org/chromium/foo/FooSwitches.java`
would contain: would contain:
```java ```java
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment