Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not store temp data per-env #1069

Merged
merged 1 commit into from Jan 16, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+44 −39
Diff settings

Always

Just for now

Do not store temp data per-env

This trips up the dependency tracker and outdatedness checker and can
cause wrong compilation output.
  • Loading branch information...
ddfreyne committed Jan 16, 2017
commit 70eaae5ce74f12a7e05fcc2be16adedc3f728d52
@@ -11,8 +11,8 @@ class ChecksumStore < ::Nanoc::Int::Store
c_obj = C::Or[Nanoc::Int::Item, Nanoc::Int::Layout, Nanoc::Int::Configuration, Nanoc::Int::CodeSnippet]

contract C::KeywordArgs[site: C::Maybe[Nanoc::Int::Site], objects: C::IterOf[c_obj]] => C::Any
def initialize(site: nil, objects:)
super(Nanoc::Int::Store.tmp_path_for(env_name: (site.config.env_name if site), store_name: 'checksums'), 1)
def initialize(site: nil, objects:) # rubocop:disable Lint/UnusedMethodArgument
super('tmp/checksums', 1)

@objects = objects

@@ -7,8 +7,8 @@ class CompiledContentCache < ::Nanoc::Int::Store
include Nanoc::Int::ContractsSupport

contract C::KeywordArgs[env_name: C::Maybe[String], items: C::IterOf[Nanoc::Int::Item]] => C::Any
def initialize(env_name: nil, items:)
super(Nanoc::Int::Store.tmp_path_for(env_name: env_name, store_name: 'compiled_content'), 2)
def initialize(env_name: nil, items:) # rubocop:disable Lint/UnusedMethodArgument
super('tmp/compiled_content', 2)

@items = items
@cache = {}
@@ -7,8 +7,8 @@ class DependencyStore < ::Nanoc::Int::Store
attr_accessor :objects

# @param [Array<Nanoc::Int::Item, Nanoc::Int::Layout>] objects
def initialize(objects, env_name: nil)
super(Nanoc::Int::Store.tmp_path_for(env_name: env_name, store_name: 'dependencies'), 4)
def initialize(objects, env_name: nil) # rubocop:disable Lint/UnusedMethodArgument
super('tmp/dependencies', 4)

@objects = objects
@new_objects = []
@@ -4,8 +4,8 @@ class OutdatednessStore < ::Nanoc::Int::Store
include Nanoc::Int::ContractsSupport

contract C::KeywordArgs[site: C::Maybe[Nanoc::Int::Site], reps: Nanoc::Int::ItemRepRepo] => C::Any
def initialize(site: nil, reps:)
super(Nanoc::Int::Store.tmp_path_for(env_name: (site.config.env_name if site), store_name: 'outdatedness'), 1)
def initialize(site: nil, reps:) # rubocop:disable Lint/UnusedMethodArgument
super('tmp/outdatedness', 1)

@outdated_reps = Set.new
@all_reps = reps
@@ -4,8 +4,8 @@ module Nanoc::Int
#
# @api private
class RuleMemoryStore < ::Nanoc::Int::Store
def initialize(env_name: nil)
super(Nanoc::Int::Store.tmp_path_for(env_name: env_name, store_name: 'rule_memory'), 1)
def initialize(env_name: nil) # rubocop:disable Lint/UnusedMethodArgument
super('tmp/rule_memory', 1)

@rule_memories = {}
end
@@ -36,13 +36,6 @@ def initialize(filename, version)
@version = version
end

# Logic for building tmp path from active environment and store name
# @api private
contract C::KeywordArgs[env_name: C::Maybe[String], store_name: String] => String
def self.tmp_path_for(env_name:, store_name:)
File.join('tmp', env_name.to_s, store_name)
end

# @group Loading and storing data

# @return The data that should be written to the disk
@@ -0,0 +1,34 @@
describe 'GH-1067', site: true, stdio: true do
before do
File.write('nanoc.yaml', <<EOS)
environments:
default:
build: dev
prod:
build: prod
EOS

File.write('content/foo.erb', 'build=<%= @config[:build] %>')

File.write('Rules', <<EOS)
compile '/*' do
filter :erb
write item.identifier
end
EOS
end

it 'recompiles when env changes' do
ENV['NANOC_ENV'] = nil
Nanoc::CLI.run(%w(compile))
expect(File.read('output/foo.erb')).to eql('build=dev')

ENV['NANOC_ENV'] = nil
Nanoc::CLI.run(%w(compile -e prod))
expect(File.read('output/foo.erb')).to eql('build=prod')

ENV['NANOC_ENV'] = nil
Nanoc::CLI.run(%w(compile))
expect(File.read('output/foo.erb')).to eql('build=dev')
end
end
@@ -34,26 +34,4 @@ def test_delete_and_reload_on_error
store.load
assert_equal(nil, store.data)
end

def test_tmp_path_with_nil_env
tmp_path_for_checksum = Nanoc::Int::Store.tmp_path_for(env_name: nil, store_name: 'checksum')
tmp_path_for_rule_memory = Nanoc::Int::Store.tmp_path_for(env_name: nil, store_name: 'rule_memory')
tmp_path_for_dependencies = Nanoc::Int::Store.tmp_path_for(env_name: nil, store_name: 'dependencies')
tmp_path_for_compiled_content = Nanoc::Int::Store.tmp_path_for(env_name: nil, store_name: 'compiled_content')
assert_equal('tmp/checksum', tmp_path_for_checksum)
assert_equal('tmp/rule_memory', tmp_path_for_rule_memory)
assert_equal('tmp/dependencies', tmp_path_for_dependencies)
assert_equal('tmp/compiled_content', tmp_path_for_compiled_content)
end

def test_tmp_path_with_test_env
tmp_path_for_checksum = Nanoc::Int::Store.tmp_path_for(env_name: 'test', store_name: 'checksum')
tmp_path_for_rule_memory = Nanoc::Int::Store.tmp_path_for(env_name: 'test', store_name: 'rule_memory')
tmp_path_for_dependencies = Nanoc::Int::Store.tmp_path_for(env_name: 'test', store_name: 'dependencies')
tmp_path_for_compiled_content = Nanoc::Int::Store.tmp_path_for(env_name: 'test', store_name: 'compiled_content')
assert_equal('tmp/test/checksum', tmp_path_for_checksum)
assert_equal('tmp/test/rule_memory', tmp_path_for_rule_memory)
assert_equal('tmp/test/dependencies', tmp_path_for_dependencies)
assert_equal('tmp/test/compiled_content', tmp_path_for_compiled_content)
end
end
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.