From 863409162bba3f7f31de440c4fbe6e2552259dca Mon Sep 17 00:00:00 2001 From: Daniel Azuma Date: Sat, 9 Jan 2021 11:16:24 -0800 Subject: [PATCH] chore: Clean up after creating new gems during autosynth (#2343) --- .toys/generate.rb | 35 +++++++++++++++++++++++++++++++++++ script/synth.rb | 6 ++++++ 2 files changed, 41 insertions(+) create mode 100644 .toys/generate.rb diff --git a/.toys/generate.rb b/.toys/generate.rb new file mode 100644 index 000000000..ce5cf3f41 --- /dev/null +++ b/.toys/generate.rb @@ -0,0 +1,35 @@ +desc "Run standard Google client generation." + +optional_arg :api, desc: "API name (optional). Generates all APIs if omitted." +optional_arg :version, desc: "API version. Required if the API name is given." + +include :bundler, gemfile_path: "#{context_directory}/google-apis-generator/Gemfile" +include :exec, e: true + +def run + Dir.chdir "#{context_directory}/google-apis-generator" + case api + when "clean" + exec ["bin/generate-api", "gen", + "#{context_directory}/generated", + "--clean"] + when nil + p exec ["bin/generate-api", "gen", + "#{context_directory}/generated", + "--from-discovery", + "--no-preferred-only", + "--spot-check", + "--names=#{context_directory}/api_names.yaml", + "--names-out=#{context_directory}/api_names_out.yaml"], + in: [:string, "a\n"] + else + raise "Version is required if an API is given" unless version + exec ["bin/generate-api", "gen", + "#{context_directory}/generated", + "--api=#{api}.#{version}", + "--spot-check", + "--names=#{context_directory}/api_names.yaml", + "--names-out=#{context_directory}/api_names_out.yaml"], + in: [:string, "a\n"] + end +end diff --git a/script/synth.rb b/script/synth.rb index 89d382b23..f316d35c7 100755 --- a/script/synth.rb +++ b/script/synth.rb @@ -9,6 +9,12 @@ def execute cmd abort unless system cmd end +# In an autosynth (multi-library) run, a previous library synth may have +# created a new library. If so, autosynth doesn't clean up those newly created +# files (i.e. it runs git reset --hard but not git clean). Do that ourselves, +# so any previously created files don't pollute this and subsequent synth runs. +execute "git clean -df" + Dir.chdir "google-apis-generator" execute "bundle install"