diff --git a/lib/terraspace/app.rb b/lib/terraspace/app.rb index 46ea8ed4..e8b05838 100644 --- a/lib/terraspace/app.rb +++ b/lib/terraspace/app.rb @@ -43,6 +43,9 @@ def defaults config.build.default_pass_files = ["/files/"] config.build.pass_files = [] config.build.dependency_words = [] + # copy_modules = nil # => Will show a warning and default to true + # copy_modules = true # => Will be default in next major version + config.build.copy_modules = nil # speed improvement config.bundle = ActiveSupport::OrderedOptions.new config.bundle.logger = ts_logger diff --git a/lib/terraspace/builder.rb b/lib/terraspace/builder.rb index 0de9d012..8051258e 100644 --- a/lib/terraspace/builder.rb +++ b/lib/terraspace/builder.rb @@ -69,7 +69,7 @@ def build_dir(type_dir) with_each_mod(type_dir) do |mod| is_root_module = mod.cache_dir == @mod.cache_dir next if is_root_module # handled by build_stacks - Compiler::Perform.new(mod).compile + Compiler::Perform.new(mod, type_dir: type_dir).compile end end diff --git a/lib/terraspace/compiler/perform.rb b/lib/terraspace/compiler/perform.rb index 2559b53a..b8f1d1f4 100644 --- a/lib/terraspace/compiler/perform.rb +++ b/lib/terraspace/compiler/perform.rb @@ -3,8 +3,9 @@ class Perform include CommandsConcern include Basename - def initialize(mod) - @mod = mod + def initialize(mod, options={}) + # options for type_dir + @mod, @options = mod, options end def compile @@ -60,7 +61,7 @@ def compile_config_file(file) end def compile_mod_file(src_path) - content = Strategy::Mod.new(@mod, src_path).run + content = Strategy::Mod.new(@mod, src_path, @options).run Writer.new(@mod, src_path: src_path).write(content) end diff --git a/lib/terraspace/compiler/strategy/abstract_base.rb b/lib/terraspace/compiler/strategy/abstract_base.rb index 85536ef1..22c38a66 100644 --- a/lib/terraspace/compiler/strategy/abstract_base.rb +++ b/lib/terraspace/compiler/strategy/abstract_base.rb @@ -1,7 +1,8 @@ module Terraspace::Compiler::Strategy class AbstractBase - def initialize(mod, src_path) - @mod, @src_path = mod, src_path + def initialize(mod, src_path, options={}) + # options for type_dir + @mod, @src_path, @options = mod, src_path, options end end end diff --git a/lib/terraspace/compiler/strategy/mod.rb b/lib/terraspace/compiler/strategy/mod.rb index 09ef1d24..a763180b 100644 --- a/lib/terraspace/compiler/strategy/mod.rb +++ b/lib/terraspace/compiler/strategy/mod.rb @@ -1,5 +1,7 @@ module Terraspace::Compiler::Strategy class Mod < AbstractBase + include Terraspace::Util::Logging + def run klass = strategy_class(@src_path) strategy = klass.new(@mod, @src_path) # IE: Terraspace::Compiler::Strategy::Mod::Rb.new @@ -7,6 +9,9 @@ def run end def strategy_class(path) + # Significant speed improvement + return Mod::Pass if copy_modules? + ext = File.extname(path).sub('.','') return Mod::Pass if ext.empty? # infinite loop without this return Mod::Pass if Terraspace.pass_file?(path) or !text_file?(path) @@ -14,6 +19,39 @@ def strategy_class(path) "Terraspace::Compiler::Strategy::Mod::#{ext.camelize}".constantize rescue Mod::Pass end + @@copy_modules_warned = false + def copy_modules? + return false unless @options[:type_dir] == "modules" + + copy_modules = Terraspace.config.build.copy_modules + if copy_modules.nil? && @@copy_modules_warned == false + logger.info "WARN: config.build.copy_modules is not set. Defaulting to true.".color(:yellow) + logger.info <<~EOL + The terraspace building behavior is to copy modules from + the app/modules folder to the .terraspace-cache for speed. + Most do not need app/modules to be compiled. + Other files like app/stacks and tfvars files are still compiled. + This is a change from previous versions of Terraspace, where + all files were compiled. + + You can turn this warning off by setting: + + .terraspace/config.rb + + Terraspace.configure do |config| + config.build.copy_modules = true + end + + In future Terraspace versions, the default will be true. + There will be no warning message, but it will still be configurable. + EOL + copy_modules = true + @@copy_modules_warned = true + end + + copy_modules + end + private def text_file?(filename) TextFile.new(filename).check