Merge pull request #3614 from nickburlett/patch/incremental-build-dest-missing
Incremental build if destination file missing
This commit is contained in:
commit
f75346c799
|
@ -19,15 +19,18 @@ module Jekyll
|
|||
case document
|
||||
when Post, Page
|
||||
document.asset_file? || document.data['regenerate'] ||
|
||||
modified?(site.in_source_dir(document.relative_path))
|
||||
source_modified_or_dest_missing?(
|
||||
site.in_source_dir(document.relative_path), document.destination(@site.dest)
|
||||
)
|
||||
when Document
|
||||
!document.write? || document.data['regenerate'] || modified?(document.path)
|
||||
!document.write? || document.data['regenerate'] ||
|
||||
source_modified_or_dest_missing?(
|
||||
document.path, document.destination(@site.dest)
|
||||
)
|
||||
else
|
||||
if document.respond_to?(:path)
|
||||
modified?(document.path)
|
||||
else
|
||||
true
|
||||
end
|
||||
source_path = document.respond_to?(:path) ? document.path : nil
|
||||
dest_path = document.respond_to?(:destination) ? document.destination(@site.dest) : nil
|
||||
source_modified_or_dest_missing?(source_path, dest_path)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -67,6 +70,15 @@ module Jekyll
|
|||
@cache = {}
|
||||
end
|
||||
|
||||
|
||||
# Checks if the source has been modified or the
|
||||
# destination is missing
|
||||
#
|
||||
# returns a boolean
|
||||
def source_modified_or_dest_missing?(source_path, dest_path)
|
||||
modified?(source_path) || (dest_path and !File.exist?(dest_path))
|
||||
end
|
||||
|
||||
# Checks if a path's (or one of its dependencies)
|
||||
# mtime has changed
|
||||
#
|
||||
|
@ -74,6 +86,9 @@ module Jekyll
|
|||
def modified?(path)
|
||||
return true if disabled?
|
||||
|
||||
# objects that don't have a path are always regenerated
|
||||
return true if path.nil?
|
||||
|
||||
# Check for path in cache
|
||||
if cache.has_key? path
|
||||
return cache[path]
|
||||
|
|
|
@ -36,14 +36,50 @@ class TestRegenerator < JekyllUnitTest
|
|||
@regenerator.regenerate?(@document)
|
||||
@regenerator.regenerate?(@asset_file)
|
||||
|
||||
# we need to create the destinations for these files,
|
||||
# because regenerate? checks if the destination exists
|
||||
[@page, @post, @document, @asset_file].each do |item|
|
||||
if item.respond_to?(:destination)
|
||||
dest = item.destination(@site.dest)
|
||||
FileUtils.mkdir_p(File.dirname(dest))
|
||||
FileUtils.touch(dest)
|
||||
end
|
||||
end
|
||||
@regenerator.write_metadata
|
||||
@regenerator = Regenerator.new(@site)
|
||||
|
||||
# these should pass, since nothing has changed, and the
|
||||
# loop above made sure the desinations exist
|
||||
assert !@regenerator.regenerate?(@page)
|
||||
assert !@regenerator.regenerate?(@post)
|
||||
assert !@regenerator.regenerate?(@document)
|
||||
end
|
||||
|
||||
should "regenerate if destination missing" do
|
||||
# Process files
|
||||
@regenerator.regenerate?(@page)
|
||||
@regenerator.regenerate?(@post)
|
||||
@regenerator.regenerate?(@document)
|
||||
@regenerator.regenerate?(@asset_file)
|
||||
|
||||
@regenerator.write_metadata
|
||||
@regenerator = Regenerator.new(@site)
|
||||
|
||||
# make sure the files don't actually exist
|
||||
[@page, @post, @document, @asset_file].each do |item|
|
||||
if item.respond_to?(:destination)
|
||||
dest = item.destination(@site.dest)
|
||||
File.unlink(dest) unless !File.exist?(dest)
|
||||
end
|
||||
end
|
||||
|
||||
# while nothing has changed, the output files were not
|
||||
# generated, so they still need to be regenerated
|
||||
assert @regenerator.regenerate?(@page)
|
||||
assert @regenerator.regenerate?(@post)
|
||||
assert @regenerator.regenerate?(@document)
|
||||
end
|
||||
|
||||
should "always regenerate asset files" do
|
||||
assert @regenerator.regenerate?(@asset_file)
|
||||
end
|
||||
|
|
|
@ -495,6 +495,25 @@ class TestSite < JekyllUnitTest
|
|||
assert_equal mtime3, mtime4 # no modifications, so remain the same
|
||||
end
|
||||
|
||||
should "regnerate files that have had their destination deleted" do
|
||||
contacts_html = @site.pages.find { |p| p.name == "contacts.html" }
|
||||
@site.process
|
||||
|
||||
source = @site.in_source_dir(contacts_html.path)
|
||||
dest = File.expand_path(contacts_html.destination(@site.dest))
|
||||
mtime1 = File.stat(dest).mtime.to_i # first run must generate dest file
|
||||
|
||||
# simulate file modification by user
|
||||
File.unlink dest
|
||||
refute File.file?(dest)
|
||||
|
||||
sleep 1 # sleep for 1 second, since mtimes have 1s resolution
|
||||
@site.process
|
||||
assert File.file?(dest)
|
||||
mtime2 = File.stat(dest).mtime.to_i
|
||||
refute_equal mtime1, mtime2 # must be regenerated
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue