Skip to content

Commit

Permalink
Allow for common resource configuration in the generator script
Browse files Browse the repository at this point in the history
  • Loading branch information
jskeet committed Oct 16, 2019
1 parent 1b2de06 commit 8e3259f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
34 changes: 34 additions & 0 deletions CommonResourcesConfig.json
@@ -0,0 +1,34 @@
{
"common_resources": [
{
"type": "cloudresourcemanager.googleapis.com/Project",
"csharp_package_name": "Google.Api.Gax",
"csharp_namespace": "Google.Api.Gax.ResourceNames",
"csharp_class_name": "ProjectName"
},
{
"type": "cloudresourcemanager.googleapis.com/Organization",
"csharp_package_name": "Google.Api.Gax",
"csharp_namespace": "Google.Api.Gax.ResourceNames",
"csharp_class_name": "OrganizationName"
},
{
"type": "cloudresourcemanager.googleapis.com/Folder",
"csharp_package_name": "Google.Api.Gax",
"csharp_namespace": "Google.Api.Gax.ResourceNames",
"csharp_class_name": "FolderName"
},
{
"type": "cloudbilling.googleapis.com/BillingAccount",
"csharp_package_name": "Google.Api.Gax",
"csharp_namespace": "Google.Api.Gax.ResourceNames",
"csharp_class_name": "BillingAccountName"
},
{
"type": "locations.googleapis.com/Location",
"csharp_package_name": "Google.Api.Gax",
"csharp_namespace": "Google.Api.Gax.ResourceNames",
"csharp_class_name": "LocationName"
}
]
}
31 changes: 26 additions & 5 deletions generateapis.sh
Expand Up @@ -59,22 +59,43 @@ generate_microgenerator() {
# We currently assume there's exactly one service config per API
GRPC_SERVICE_CONFIG=$(echo $API_SRC_DIR/*.json)

mkdir -p $PRODUCTION_PACKAGE_DIR
# Defalt to "all resources are common" but allow a per-API config file too.
COMMON_RESOURCES_CONFIG=CommonResourcesConfig.json
if [[ -f "$API_OUT_DIR/$1/$1/CommonResourcesConfig.json" ]]
then
COMMON_RESOURCES_CONFIG=$API_OUT_DIR/$1/$1/CommonResourcesConfig.json
fi

echo "Generating $1 (micro-generator)"
mkdir -p $PRODUCTION_PACKAGE_DIR

# Message and service generation. This doesn't need the common resources,
# and we don't want to pass in the common resources proto because we don't
# want to generate it.
$PROTOC \
--csharp_out=$PRODUCTION_PACKAGE_DIR \
--grpc_out=$PRODUCTION_PACKAGE_DIR \
--gapic_out=$API_TMP_DIR \
--gapic_opt=grpc-service-config=$GRPC_SERVICE_CONFIG \
--plugin=protoc-gen-grpc=$GRPC_PLUGIN \
-I $GOOGLEAPIS \
-I $CORE_PROTOS_ROOT \
--plugin=protoc-gen-grpc=$GRPC_PLUGIN \
$API_SRC_DIR/*.proto \
2>&1 | grep -v "but not used" || true # Ignore import warnings (and grep exit code)

# Client generation. This needs the common resources proto as a reference,
# but it won't generate anything for it.
$PROTOC \
--gapic_out=$API_TMP_DIR \
--gapic_opt=grpc-service-config=$GRPC_SERVICE_CONFIG,common-resources-config=$COMMON_RESOURCES_CONFIG \
--plugin=protoc-gen-gapic=$GAPIC_PLUGIN \
-I $GOOGLEAPIS \
-I $CORE_PROTOS_ROOT \
$API_SRC_DIR/*.proto \
$GOOGLEAPIS/google/cloud/common_resources.proto
2>&1 | grep -v "but not used" || true # Ignore import warnings (and grep exit code)

# The microgenerator currently creates Google.Cloud directories due to being given
# the common resources proto. Clean up for now; this is being fixed in the generator.
rm -rf $API_TMP_DIR/Google.Cloud{,.Snippets,.Tests}

# We generate our own project files
rm $(find tmp -name '*.csproj')

Expand Down

0 comments on commit 8e3259f

Please sign in to comment.