diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 46a7007b2c3..56d706f56c5 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -19,6 +19,12 @@ "commands": [ "generate-sbom" ] + }, + "Google.Api.Generator.Rest": { + "version": "1.5.0", + "commands": [ + "google-rest-generator" + ] } } } \ No newline at end of file diff --git a/CSharpGeneratorFunctions.sh b/CSharpGeneratorFunctions.sh deleted file mode 100755 index 26ae6fdc14c..00000000000 --- a/CSharpGeneratorFunctions.sh +++ /dev/null @@ -1,53 +0,0 @@ -# This is intended to be imported using the "source" function -# from any script that wants to invoke the C#-based generator. - -declare -r GAPIC_GENERATOR_VERSION=1.4.29 - -TMP_CSHARP_GENERATOR_DIR=tmp-gapic-generator-csharp -if [[ $CSHARP_GENERATOR_DIR == "" ]] -then - CSHARP_GENERATOR_DIR=$TMP_CSHARP_GENERATOR_DIR -fi - -# Installs the C# generator in a tmp-gapic-generator-csharp directory, -# unless an existing generator directory is specified via the -# CSHARP_GENERATOR_DIR environment variable. -# When installing, if the directory already exists, it is deleted first. -# The tag for GAPIC_GENERATOR_VERSION (declared at the top of this file) -# is checked out. -install_csharp_generator() { - if [[ $CSHARP_GENERATOR_DIR == $TMP_CSHARP_GENERATOR_DIR ]] - then - echo "Installing C# generator in $CSHARP_GENERATOR_DIR" - rm -rf $CSHARP_GENERATOR_DIR - - git clone --quiet --recursive \ - https://github.com/googleapis/gapic-generator-csharp.git \ - $CSHARP_GENERATOR_DIR - git -C $CSHARP_GENERATOR_DIR checkout -q v$GAPIC_GENERATOR_VERSION - else - echo "Using C# generator in $CSHARP_GENERATOR_DIR" - fi - echo 'Building C# generator' - (cd $CSHARP_GENERATOR_DIR && \ - dotnet build -c Release -nologo -clp:NoSummary -v quiet Google.Api.Generator.Rest) - echo 'Generator build complete' -} - -# Runs the C# generator, which is expected to be installed in -# tmp-gapic-generator-csharp as per install_csharp_generator() -# Expected arguments: -# - Discovery doc -# - Output directory (a subdirectory will be created under this) -# - Features file -# - Enum storage file -run_csharp_generator() { - # We call the generator frequently; dotnet run takes a while to start it, - # even with --no-build and --no-restore. - # Using "dotnet" with the DLL is more portable than executing the .exe file directly. - # TODO: Rather than hard-coding this, we could build into a new directory (once) - # where we'd always have a fresh copy. - dotnet \ - $CSHARP_GENERATOR_DIR/Google.Api.Generator.Rest/bin/Release/net6.0/Google.Api.Generator.Rest.dll \ - "$1" "$2" "$3" "$4" -} diff --git a/GenerateApis.sh b/GenerateApis.sh index 98e82b4a271..0fe0118d8b6 100755 --- a/GenerateApis.sh +++ b/GenerateApis.sh @@ -38,8 +38,7 @@ then fi fi -source ./CSharpGeneratorFunctions.sh -install_csharp_generator +dotnet tool restore > /dev/null CODE_GENERATION_DIR=Src/Generated @@ -55,7 +54,7 @@ for file in $FILES do service=$(basename $file | sed 's/.json//g') echo "Generating $service from $file" - run_csharp_generator "$file" "$CODE_GENERATION_DIR" features.json "EnumStorage/$service.json" + dotnet google-rest-generator "$file" "$CODE_GENERATION_DIR" features.json "EnumStorage/$service.json" if [[ -f PostGeneration/$service.sh ]] then