-
Notifications
You must be signed in to change notification settings - Fork 69
doc: Update DEVELOPMENT.md for local development. #1237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
274b12c
995342c
cfdf136
bbf502d
1dc5c1a
1da0fed
9b2bae6
a8b91e0
04a9c3f
8357c36
274e8ee
083e1e5
7edade2
73b6367
25561a4
663e595
a103bd6
1490865
e7d3e5f
5f70202
6d6cc52
6f5b31f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,13 +4,19 @@ | |
|
|
||
| 1. Clone this repo. | ||
|
|
||
| 2. Copy the Git pre-commit hooks. This will automatically check the build, run | ||
| tests, and perform linting before each commit. (Symlinks don't seem to work, | ||
| but if you find a way, please add it here!) | ||
| 2. (OPTIONAL) Copy the Git pre-commit hooks. This will automatically check the build, run | ||
| tests, and perform linting before each commit. (Symlinks don't seem to work, | ||
| but if you find a way, please add it here!) | ||
|
|
||
| ```sh | ||
| cp .githooks/pre-commit .git/hooks/pre-commit | ||
| ``` | ||
| ```sh | ||
| cp .githooks/pre-commit .git/hooks/pre-commit | ||
| ``` | ||
|
|
||
| ### Note: You may see this error with the pre-commits due to the monorepo migration: | ||
| ``` | ||
| [ERROR] No plugin found for prefix 'fmt' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/home/alicejli/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1] | ||
| ``` | ||
| Remove the pre-commit hooks. Tracking the issue in https://github.com/googleapis/gapic-generator-java/issues/1253 | ||
|
|
||
| ## Code Formatting | ||
|
|
||
|
|
@@ -41,7 +47,7 @@ | |
| mvn test | ||
| ``` | ||
|
|
||
| - Run a single or multiple unit tests: | ||
| - Run a single or multiple unit tests: | ||
|
|
||
| ```sh | ||
| mvn test -Dtest=JavaCodeGeneratorTest | ||
|
|
@@ -51,30 +57,30 @@ | |
|
|
||
| - Update all unit test golden files: | ||
|
|
||
| ```sh | ||
| mvn test -DupdateUnitGoldens | ||
| ``` | ||
| ```sh | ||
| mvn test -DupdateUnitGoldens | ||
blakeli0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| - Update a single unit test golden file, for example `JavaCodeGeneratorTest.java`: | ||
|
|
||
| ```sh | ||
| mvn test -DupdateUnitGoldens -Dtest=JavaCodeGeneratorTest | ||
| ``` | ||
| ```sh | ||
| mvn test -DupdateUnitGoldens -Dtest=JavaCodeGeneratorTest | ||
| ``` | ||
|
|
||
| - Run a single integration test for API like `Redis`, it generates Java source | ||
| code using the Java microgenerator and compares them with the goldens files | ||
| in `test/integration/goldens/redis`. | ||
|
|
||
| ```sh | ||
| bazel test //test/integration:redis | ||
| ``` | ||
| ```sh | ||
| bazel test //test/integration:redis | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should all of these
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, use bazelisk where applicable. |
||
| ``` | ||
|
|
||
| - Update integration test golden files, for example `Redis`. This clobbers all the | ||
| files in `test/integration/goldens/redis`. | ||
|
|
||
| ```sh | ||
| bazel run //test/integration:update_redis | ||
| ``` | ||
| ```sh | ||
| bazel run //test/integration:update_redis | ||
| ``` | ||
|
|
||
| ## Showcase Integration Testing | ||
|
|
||
|
|
@@ -160,40 +166,67 @@ $ cd showcase | |
| $ mvn compile -P update | ||
| ``` | ||
|
|
||
| ## Running the Plugin | ||
| ## Running the Plugin under googleapis with local gapic-generator-java | ||
|
|
||
| See also above section "Showcase Integration Testing". | ||
blakeli0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| To generate a production GAPIC API: | ||
|
|
||
| 1. Clone [googleapis](https://github.com/googleapis/googleapis). | ||
suztomo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 2. Point to local gapic-generator-java | ||
| 2. Modify `googleapis/WORKSPACE` to point to local gapic-generator-java | ||
|
|
||
| Normally, googleapis's build pulls in googleapis/gapic-generator-java from the | ||
| Internet: | ||
| Normally, googleapis's build pulls in gapic-generator-java from Maven Central. | ||
| For a local run, we first need to build a local SNAPSHOT jar of the generator. Then we point googleapis to | ||
| both the local SNAPSHOT jar and the local copy of the generator. | ||
|
|
||
| Before: | ||
| ``` | ||
| # Java microgenerator. | ||
| … | ||
| _gapic_generator_java_version = "2.1.0" | ||
|
|
||
| http_archive( | ||
| name = "gapic_generator_java", | ||
| … | ||
| urls = ["https://github.com/googleapis/gapic-generator-java/archive/v%s.zip" % _gapic_generator_java_version], | ||
| ) | ||
| _gapic_generator_java_version = "2.13.0" | ||
|
|
||
| maven_install( | ||
| artifacts = [ | ||
| "com.google.api:gapic-generator-java:" + _gapic_generator_java_version, | ||
| ], | ||
| #Update this False for local development | ||
| fail_on_missing_checksum = True, | ||
| repositories = [ | ||
| "m2Local", | ||
| "https://repo.maven.apache.org/maven2/", | ||
| ] | ||
| ) | ||
|
|
||
| http_archive( | ||
| name = "gapic_generator_java", | ||
| strip_prefix = "gapic-generator-java-%s" % _gapic_generator_java_version, | ||
| urls = ["https://github.com/googleapis/gapic-generator-java/archive/v%s.zip" % _gapic_generator_java_version], | ||
| ) | ||
| ``` | ||
|
|
||
| By replacing this portion using the built-in local_repository rule, you can make | ||
| it refer to your local development repo: | ||
| After | ||
|
|
||
| ``` | ||
| _gapic_generator_java_version = "2.13.1-SNAPSHOT" | ||
|
|
||
| maven_install( | ||
lqiu96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| artifacts = [ | ||
| "com.google.api:gapic-generator-java:" + _gapic_generator_java_version, | ||
| ], | ||
| #Update this False for local development | ||
| fail_on_missing_checksum = False, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I'm Bazel novice) Can't this True/False be a variable, based on _gapic-generator_java_version has SNAPSHOT?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's doable as Bazel scripts are basically a Python variant, but we may want to test non-SNAPSHOT version locally sometimes. |
||
| repositories = [ | ||
| "m2Local", | ||
| "https://repo.maven.apache.org/maven2/", | ||
| ] | ||
| ) | ||
|
|
||
| local_repository( | ||
| name = "gapic_generator_java", | ||
| path = "/home/<your id>/gapic-generator-java", | ||
| name = "gapic_generator_java", | ||
| path = "/absolute/path/to/your/local/gapic-generator-java", | ||
| ) | ||
| ``` | ||
|
|
||
| Note: At the time of writing, the gapic-generator version was `2.13.0`. Update the version to the latest version in the pom.xml | ||
|
|
||
| 3. Build the new target. | ||
|
|
||
|
|
@@ -207,5 +240,26 @@ To generate a production GAPIC API: | |
| bazel build //google/cloud/speech/v2:google-cloud-speech-v2-java | ||
| ``` | ||
|
|
||
| Note: If you are running into bazel build issues, you can try to remove gapic-generator-java cached in your local m2 | ||
lqiu96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Try running this command: | ||
| ``` | ||
| rm -rf ~/.m2/repository/com/google/api/ | ||
| ``` | ||
| and then rebuild gapic-generator-java (`mvn clean install`). | ||
|
|
||
| ## FAQ | ||
|
|
||
| ### Error in workspace: workspace() got unexpected keyword argument 'managed_directories' | ||
|
|
||
| Full Error: | ||
|
|
||
| ``` | ||
| ERROR: Traceback (most recent call last): | ||
| File "/home/alicejli/googleapis/WORKSPACE", line 1, column 10, in <toplevel> | ||
| workspace( | ||
| Error in workspace: workspace() got unexpected keyword argument 'managed_directories' | ||
| ERROR: Error computing the main repository mapping: Encountered error while reading extension file 'tools/build_defs/repo/http.bzl': no such package '@bazel_tools//tools/build_defs/repo': error loading package 'external': Could not load //external package | ||
| ``` | ||
|
|
||
| You may be using the latest version of bazel which this project does not support yet. Try installing bazelisk to force | ||
| bazel to use the version specified in `.bazeliskrc` | ||
Uh oh!
There was an error while loading. Please reload this page.