Skip to content

Commit

Permalink
tools: Use Google.Api.Generator from a dotnet tool
Browse files Browse the repository at this point in the history
  • Loading branch information
jskeet committed Sep 9, 2024
1 parent c4c7995 commit e4597d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
6 changes: 6 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"commands": [
"generate-sbom"
]
},
"Google.Api.Generator": {
"version": "1.5.0",
"commands": [
"google-gapic-generator"
]
}
}
}
36 changes: 9 additions & 27 deletions toolversions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ declare -r DOTCOVER_VERSION=2019.3.4
declare -r REPORTGENERATOR_VERSION=2.4.5.0
declare -r PROTOC_VERSION=3.25.2
declare -r GRPC_VERSION=2.60.0
if [[ $GAPIC_GENERATOR_VERSION == "" ]]
then
declare -r GAPIC_GENERATOR_VERSION=v1.4.32
else
echo "Using GAPIC generator override: ${GAPIC_GENERATOR_VERSION}"
fi

# Tools that only run under Windows (at the moment)
declare -r DOTCOVER=$TOOL_PACKAGES/JetBrains.dotCover.CommandLineTools.$DOTCOVER_VERSION/tools/dotCover.exe
Expand Down Expand Up @@ -102,32 +96,20 @@ install_microgenerator() {

# If the CSHARP_GENERATOR_DIR env variable is set
# we use that as the generator root dir.
if [[ "$CSHARP_GENERATOR_DIR" != "" ]]
then
declare -r GENERATOR_ROOT=$CSHARP_GENERATOR_DIR
else
declare -r GENERATOR_ROOT=$REPO_ROOT/gapic-generator-csharp
fi

export GAPIC_PLUGIN=$GENERATOR_ROOT/Google.Api.Generator/bin/Release/net6.0/$RUNTIME/publish/Google.Api.Generator$EXTENSION

if [[ "$CSHARP_GENERATOR_DIR" != "" ]]
then
echo "Skipping microgenerator fetch: an existing directory for the generator has been specified"
elif [ -d $GENERATOR_ROOT ]
then
git -C $GENERATOR_ROOT fetch -q --tags
git -C $GENERATOR_ROOT checkout -q $GAPIC_GENERATOR_VERSION
(cd $CSHARP_GENERATOR_DIR; \
dotnet restore -v quiet; \
dotnet publish -v quiet -nologo -clp:NoSummary -c Release --self-contained --runtime=$RUNTIME Google.Api.Generator)
export GAPIC_PLUGIN=$CSHARP_GENERATOR_DIR/Google.Api.Generator/bin/Release/net6.0/$RUNTIME/publish/Google.Api.Generator$EXTENSION
else
git clone https://github.com/googleapis/gapic-generator-csharp $GENERATOR_ROOT -q
git -C $GENERATOR_ROOT checkout -q $GAPIC_GENERATOR_VERSION
# We don't just use "dotnet tool restore", as we need it installed in a specific
# path in order to access the executable directly (as it's a protoc plugin).
rm -rf gapic-generator
dotnet tool install Google.Api.Generator --tool-path gapic-generator > /dev/null
export GAPIC_PLUGIN=$REPO_ROOT/gapic-generator/google-gapic-generator$EXTENSION
fi

# The dotnet restore step isn't generally required when cloning from elsewhere,
# but helps when running a local generator. (It does no harm even when not required.)
(cd $GENERATOR_ROOT; \
dotnet restore -v quiet; \
dotnet publish -v quiet -nologo -clp:NoSummary -c Release --self-contained --runtime=$RUNTIME Google.Api.Generator)
}

install_grpc() {
Expand Down

0 comments on commit e4597d7

Please sign in to comment.