diff --git a/compiler.rb b/compiler.rb index d5007ae9d721..3d78d57d54e0 100755 --- a/compiler.rb +++ b/compiler.rb @@ -143,8 +143,10 @@ provider.generate output_path, types_to_generate, version end -# In order to only copy files once per provider this must be called outside of the products loop -# This will get called with the value from the final iteration of the loop +# In order to only copy/compile files once per provider this must be called outside +# of the products loop. This will get called with the provider from the final iteration +# of the loop provider&.copy_common_files(output_path, version) +provider&.compile_common_files(output_path, version) # rubocop:enable Metrics/BlockLength diff --git a/coverage/.last_run.json b/coverage/.last_run.json index 0fc13b06a540..ff4137cb9aee 100644 --- a/coverage/.last_run.json +++ b/coverage/.last_run.json @@ -1,5 +1,5 @@ { "result": { - "covered_percent": 78.81 + "covered_percent": 77.85 } } diff --git a/products/binaryauthorization/terraform.yaml b/products/binaryauthorization/terraform.yaml index a76af4f0198b..c6c9ceb4618a 100644 --- a/products/binaryauthorization/terraform.yaml +++ b/products/binaryauthorization/terraform.yaml @@ -108,4 +108,4 @@ files: !ruby/object:Provider::Config::Files # These files have templating (ERB) code that will be run. # This is usually to add licensing info, autogeneration notices, etc. compile: -<%= lines(indent(compile('provider/terraform/common~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> diff --git a/products/compute/ansible.yaml b/products/compute/ansible.yaml index 7daa8ad037f6..9b3c4ee7877e 100644 --- a/products/compute/ansible.yaml +++ b/products/compute/ansible.yaml @@ -347,5 +347,5 @@ overrides: !ruby/object:Provider::ResourceOverrides exclude: true files: !ruby/object:Provider::Config::Files compile: -<%= lines(indent(compile('provider/ansible/common~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/ansible/product~compile.yaml'), 4)) -%> tests: !ruby/object:Api::Resource::HashArray diff --git a/products/compute/terraform.yaml b/products/compute/terraform.yaml index d0dfdeec6045..3994a27e5384 100644 --- a/products/compute/terraform.yaml +++ b/products/compute/terraform.yaml @@ -967,4 +967,4 @@ files: !ruby/object:Provider::Config::Files # These files have templating (ERB) code that will be run. # This is usually to add licensing info, autogeneration notices, etc. compile: -<%= lines(indent(compile('provider/terraform/common~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> diff --git a/products/container/ansible.yaml b/products/container/ansible.yaml index 99f5c1d1ff49..9931f90e3b48 100644 --- a/products/container/ansible.yaml +++ b/products/container/ansible.yaml @@ -47,5 +47,5 @@ overrides: !ruby/object:Provider::ResourceOverrides - 'products/container/helpers/python/provider_node_pool.py' files: !ruby/object:Provider::Config::Files compile: -<%= lines(indent(compile('provider/ansible/common~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/ansible/product~compile.yaml'), 4)) -%> tests: !ruby/object:Api::Resource::HashArray diff --git a/products/containeranalysis/terraform.yaml b/products/containeranalysis/terraform.yaml index b8417130c10f..343fcb952a22 100644 --- a/products/containeranalysis/terraform.yaml +++ b/products/containeranalysis/terraform.yaml @@ -34,4 +34,4 @@ files: !ruby/object:Provider::Config::Files # These files have templating (ERB) code that will be run. # This is usually to add licensing info, autogeneration notices, etc. compile: -<%= lines(indent(compile('provider/terraform/common~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> diff --git a/products/dns/ansible.yaml b/products/dns/ansible.yaml index e461629826ee..5ceaecd8e795 100644 --- a/products/dns/ansible.yaml +++ b/products/dns/ansible.yaml @@ -93,5 +93,5 @@ overrides: !ruby/object:Provider::ResourceOverrides exclude: true files: !ruby/object:Provider::Config::Files compile: -<%= lines(indent(compile('provider/ansible/common~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/ansible/product~compile.yaml'), 4)) -%> tests: !ruby/object:Api::Resource::HashArray diff --git a/products/filestore/terraform.yaml b/products/filestore/terraform.yaml index c01375ae40d6..3d0276cb06c5 100644 --- a/products/filestore/terraform.yaml +++ b/products/filestore/terraform.yaml @@ -40,4 +40,4 @@ files: !ruby/object:Provider::Config::Files # These files have templating (ERB) code that will be run. # This is usually to add licensing info, autogeneration notices, etc. compile: -<%= lines(indent(compile('provider/terraform/common~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> diff --git a/products/monitoring/terraform.yaml b/products/monitoring/terraform.yaml index 6d33167f111a..eafd2bd95343 100644 --- a/products/monitoring/terraform.yaml +++ b/products/monitoring/terraform.yaml @@ -88,4 +88,4 @@ files: !ruby/object:Provider::Config::Files # These files have templating (ERB) code that will be run. # This is usually to add licensing info, autogeneration notices, etc. compile: -<%= lines(indent(compile('provider/terraform/common~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> diff --git a/products/pubsub/ansible.yaml b/products/pubsub/ansible.yaml index 0d3670bc218b..1a7f4abd2549 100644 --- a/products/pubsub/ansible.yaml +++ b/products/pubsub/ansible.yaml @@ -50,5 +50,5 @@ overrides: !ruby/object:Provider::ResourceOverrides - 'products/pubsub/helpers/python/provider_subscription.py' files: !ruby/object:Provider::Config::Files compile: -<%= lines(indent(compile('provider/ansible/common~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/ansible/product~compile.yaml'), 4)) -%> tests: !ruby/object:Api::Resource::HashArray diff --git a/products/redis/terraform.yaml b/products/redis/terraform.yaml index 8c111fe98361..fcf3f6d3a3c5 100644 --- a/products/redis/terraform.yaml +++ b/products/redis/terraform.yaml @@ -59,4 +59,4 @@ files: !ruby/object:Provider::Config::Files # These files have templating (ERB) code that will be run. # This is usually to add licensing info, autogeneration notices, etc. compile: -<%= lines(indent(compile('provider/terraform/common~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> diff --git a/products/resourcemanager/terraform.yaml b/products/resourcemanager/terraform.yaml index cc2d1514304f..f6948543ae0b 100644 --- a/products/resourcemanager/terraform.yaml +++ b/products/resourcemanager/terraform.yaml @@ -40,4 +40,4 @@ files: !ruby/object:Provider::Config::Files # These files have templating (ERB) code that will be run. # This is usually to add licensing info, autogeneration notices, etc. compile: -<%= lines(indent(compile('provider/terraform/common~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> diff --git a/products/spanner/ansible.yaml b/products/spanner/ansible.yaml index baf5026fc861..3fdc9df0626d 100644 --- a/products/spanner/ansible.yaml +++ b/products/spanner/ansible.yaml @@ -54,5 +54,5 @@ overrides: !ruby/object:Provider::ResourceOverrides exclude: true files: !ruby/object:Provider::Config::Files compile: -<%= lines(indent(compile('provider/ansible/common~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/ansible/product~compile.yaml'), 4)) -%> tests: !ruby/object:Api::Resource::HashArray diff --git a/products/sql/ansible.yaml b/products/sql/ansible.yaml index fc1f2b7d3caa..7c04f8ec4eb0 100644 --- a/products/sql/ansible.yaml +++ b/products/sql/ansible.yaml @@ -64,5 +64,5 @@ overrides: !ruby/object:Provider::ResourceOverrides files: !ruby/object:Provider::Config::Files copy: compile: -<%= lines(indent(compile('provider/ansible/common~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/ansible/product~compile.yaml'), 4)) -%> tests: !ruby/object:Api::Resource::HashArray diff --git a/products/storage/ansible.yaml b/products/storage/ansible.yaml index 26f009002e78..4835d3a5302a 100644 --- a/products/storage/ansible.yaml +++ b/products/storage/ansible.yaml @@ -44,5 +44,5 @@ overrides: !ruby/object:Provider::ResourceOverrides exclude: true files: !ruby/object:Provider::Config::Files compile: -<%= lines(indent(compile('provider/ansible/common~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/ansible/product~compile.yaml'), 4)) -%> tests: !ruby/object:Api::Resource::HashArray diff --git a/products/storage/terraform.yaml b/products/storage/terraform.yaml index fd18408ad39d..461fe9e192f5 100644 --- a/products/storage/terraform.yaml +++ b/products/storage/terraform.yaml @@ -57,4 +57,4 @@ files: !ruby/object:Provider::Config::Files # These files have templating (ERB) code that will be run. # This is usually to add licensing info, autogeneration notices, etc. compile: -<%= lines(indent(compile('provider/terraform/common~compile.yaml'), 4)) -%> +<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> diff --git a/provider/ansible/common~compile.yaml b/provider/ansible/product~compile.yaml similarity index 100% rename from provider/ansible/common~compile.yaml rename to provider/ansible/product~compile.yaml diff --git a/provider/core.rb b/provider/core.rb index 5fe72bbf2e7b..966ac3014a14 100644 --- a/provider/core.rb +++ b/provider/core.rb @@ -58,6 +58,9 @@ def generate(output_folder, types, version_name) # Compilation has to be the last step, as some files (e.g. # CONTRIBUTING.md) may depend on the list of all files previously copied # or compiled. + # common-compile.yaml is a special file that will get compiled by the last product + # used in a single invocation of the compiled. It should not contain product-specific + # information; instead, it should be run-specific such as the version to compile at. compile_files(output_folder, version_name) \ unless @config.files.nil? || @config.files.compile.nil? @@ -77,11 +80,21 @@ def copy_files(output_folder) def copy_common_files(output_folder, _version_name = nil) provider_name = self.class.name.split('::').last.downcase return unless File.exist?("provider/#{provider_name}/common~copy.yaml") - files = YAML.safe_load(compile("provider/#{provider_name}/common~copy.yaml")) + Google::LOGGER.info "Copying common files for #{provider_name}" + files = YAML.safe_load(compile("provider/#{provider_name}/common~copy.yaml")) copy_file_list(output_folder, files) end + def compile_common_files(output_folder, version_name = nil) + provider_name = self.class.name.split('::').last.downcase + return unless File.exist?("provider/#{provider_name}/common~compile.yaml") + + Google::LOGGER.info "Compiling common files for #{provider_name}" + files = YAML.safe_load(compile("provider/#{provider_name}/common~compile.yaml")) + compile_file_list(output_folder, files, version: version_name) + end + def copy_file_list(output_folder, files) files.each do |target, source| target_file = File.join(output_folder, target) diff --git a/provider/terraform/common~compile.yaml b/provider/terraform/common~compile.yaml index 56dd7748503f..c4569d1a14dd 100644 --- a/provider/terraform/common~compile.yaml +++ b/provider/terraform/common~compile.yaml @@ -12,9 +12,7 @@ # limitations under the License. # These files contains code that needs to be compiled before being delivered to # the final module tree structure: -<% dir = _version_name == 'beta' ? 'google-beta' : 'google' -%> -'<%= dir -%>/provider_<%= api.prefix[1..-1] -%>_gen.go': 'templates/terraform/provider_gen.erb' - +<% dir = version_name == 'beta' ? 'google-beta' : 'google' -%> <% Dir["provider/terraform/tests/*.go.erb"].each do |file_path| fname = file_path.split('/')[-1] -%> diff --git a/provider/terraform/product~compile.yaml b/provider/terraform/product~compile.yaml new file mode 100644 index 000000000000..63085cbb98a7 --- /dev/null +++ b/provider/terraform/product~compile.yaml @@ -0,0 +1,16 @@ +# Copyright 2018 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# These files contains code that needs to be compiled before being delivered to +# the final module tree structure: +<% dir = _version_name == 'beta' ? 'google-beta' : 'google' -%> +'<%= dir -%>/provider_<%= api.prefix[1..-1] -%>_gen.go': 'templates/terraform/provider_gen.erb'