Skip to content

Commit

Permalink
[ggj][bazel] fix: add Bazel handling for lack of resname helper class…
Browse files Browse the repository at this point in the history
…es (#540)

* fix: align resname ctors with superclass variants

* fix: avoid type collisions - refactor {Concrete,Vapor}Ref into AstNodes

* fix: better message null checks in Parser

* fix: map proto.Empty RPC types to void in ServiceClient

* fix: improve import(shortName) state-keeping in ImportWriterVisitor

* fix: fix stub pkg for all ServiceSettingsStub usages

* fix: handle older protos with javaMultipleFiles=false

* fix: gate isPaged on all fields for monolith back-compat

* fix: fail early if bazel lacks a grpc_service_config.json file

* fix: add Bazel handling for lack of resname helper classes

* fix: reverse conditional
  • Loading branch information
miraleung authored Nov 21, 2020
1 parent ef017b1 commit ab0c02f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 20 additions & 1 deletion rules_java_gapic/java_gapic.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,32 @@ def _java_gapic_postprocess_srcjar_impl(ctx):
# This may fail if there are spaces and/or too many files (exceed max length of command length).
{formatter} --replace $(find {output_dir_path} -type f -printf "%p ")
WORKING_DIR=`pwd`
# Main source files.
cd {output_dir_path}/src/main/java
zip -r $WORKING_DIR/{output_srcjar_name}.srcjar ./
# Resource name source files.
PROTO_DIR=$WORKING_DIR/{output_dir_path}/proto/src/main/java
PROTO_SRCJAR=$WORKING_DIR/{output_srcjar_name}-resource-name.srcjar
if [ ! -d $PROTO_DIR ]
then
# Some APIs don't have resource name helpers, like BigQuery v2.
# Create an empty file so we can finish building. Gating the resource name rule definition
# on file existences go against Bazel's design patterns, so we'll simply delete all empty
# files during the final packaging process (see java_gapic_pkg.bzl)
mkdir -p $PROTO_DIR
touch $PROTO_DIR/PlaceholderFile.java
fi
cd $WORKING_DIR/{output_dir_path}/proto/src/main/java
zip -r $WORKING_DIR/{output_srcjar_name}-resource-name.srcjar ./
zip -r $PROTO_SRCJAR ./
# Test source files.
cd $WORKING_DIR/{output_dir_path}/src/test/java
zip -r $WORKING_DIR/{output_srcjar_name}-tests.srcjar ./
cd $WORKING_DIR
mv {output_srcjar_name}.srcjar {output_main}
mv {output_srcjar_name}-resource-name.srcjar {output_resource_name}
mv {output_srcjar_name}-tests.srcjar {output_test}
Expand Down
4 changes: 4 additions & 0 deletions rules_java_gapic/java_gapic_pkg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ def _java_gapic_srcs_pkg_impl(ctx):
mkdir -p {package_dir_path}/src/main/java
unzip -q -o $src -d {package_dir_path}/src/main/java
rm -r -f {package_dir_path}/src/main/java/META-INF
# Remove empty files. If there are no resource names, one such file might have
# been created. See java_gapic.bzl.
rm $(find {package_dir_path}/src/main/java -size 0)
done
for proto_src in {proto_srcs}; do
mkdir -p {package_dir_path}/src/main/proto
Expand Down

0 comments on commit ab0c02f

Please sign in to comment.