From 9ccf3b03afad1e0b0e50405ae9bfc5b6ec56aca1 Mon Sep 17 00:00:00 2001 From: Denis Defreyne Date: Sat, 29 Feb 2020 11:28:08 +0100 Subject: [PATCH] Emit warning when contracts is loaded --- common/spec/spec_helper_head_core.rb | 2 ++ .../lib/nanoc/core/contracts_support.rb | 20 +++++++++++++++++++ nanoc-core/spec/meta_spec.rb | 7 ++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/common/spec/spec_helper_head_core.rb b/common/spec/spec_helper_head_core.rb index 2778ca14c7..d700813811 100644 --- a/common/spec/spec_helper_head_core.rb +++ b/common/spec/spec_helper_head_core.rb @@ -8,6 +8,8 @@ SimpleCov.formatter = SimpleCov::Formatter::Codecov end +ENV['NANOC_DEV_MODE'] = 'true' + require 'fuubar' require 'rspec/its' require 'timecop' diff --git a/nanoc-core/lib/nanoc/core/contracts_support.rb b/nanoc-core/lib/nanoc/core/contracts_support.rb index 464b19fcac..fa103d111f 100644 --- a/nanoc-core/lib/nanoc/core/contracts_support.rb +++ b/nanoc-core/lib/nanoc/core/contracts_support.rb @@ -103,6 +103,8 @@ def self.setup_once ::Contracts.const_set('Named', EnabledContracts::Named) ::Contracts.const_set('IterOf', EnabledContracts::IterOf) ::Contracts.const_set('AbsolutePathString', EnabledContracts::AbsolutePathString) + + warn_about_performance end @_contracts_support__should_enable @@ -126,6 +128,24 @@ def self.included(base) base.const_set('C', DisabledContracts) end end + + def self.warn_about_performance + return if ENV.key?('CI') + return if ENV.key?('NANOC_DEV_MODE') + + puts '-' * 78 + puts 'A NOTE ABOUT PERFORMANCE:' + puts 'The `contracts` gem is loaded, which enables extra run-time checks, but can drastically reduce Nanoc’s performance. The `contracts` gem is intended for development purposes, and is not recommended for day-to-day Nanoc usage.' + puts + + if defined?(Bundler) + puts 'To speed up compilation, remove `contracts` from the Gemfile and run `bundle install`.' + else + puts 'To speed up compilation, either uninstall the `contracts` gem, or use Bundler (https://bundler.io/) with a Gemfile that doesn’t include `contracts`.' + end + + puts '-' * 78 + end end end end diff --git a/nanoc-core/spec/meta_spec.rb b/nanoc-core/spec/meta_spec.rb index 36b443320d..b0d34d1309 100644 --- a/nanoc-core/spec/meta_spec.rb +++ b/nanoc-core/spec/meta_spec.rb @@ -76,7 +76,12 @@ it 'doesn’t log anything' do # TODO: don’t have any exceptions - regular_files = Dir['lib/nanoc/core/**/*.rb'] - ['lib/nanoc/core/data_source.rb'] + regular_files = + Dir['lib/nanoc/core/**/*.rb'] - + [ + 'lib/nanoc/core/data_source.rb', + 'lib/nanoc/core/contracts_support.rb', + ] expect(regular_files).to all(satisfy do |fn| content = File.read(fn)