Skip to content

Commit

Permalink
[Command::Build] add option to disable caching feature
Browse files Browse the repository at this point in the history
refs #11
  • Loading branch information
Roman Kříž committed May 29, 2016
1 parent 2bd64f9 commit bbbbd44
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
16 changes: 11 additions & 5 deletions lib/epuber/command/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class Build < Command

def self.options
[
['--check', 'Performs additional validation on sources + checks result epub with epubcheck.'],
['--write', 'Performs additional transformations which writes to source files.'],
['--release', 'Create release version of the book, no caching, everything creates from scratch.'],
['--check', 'Performs additional validation on sources + checks result epub with epubcheck.'],
['--write', 'Performs additional transformations which writes to source files.'],
['--release', 'Create release version of the book, no caching, everything creates from scratch.'],
['--no-cache', 'Turns off incremental build, can resolve some bugs but build takes much longer.']
].concat(super)
end

Expand All @@ -31,6 +32,7 @@ def initialize(argv)
@should_check = argv.flag?('check', false)
@should_write = argv.flag?('write', false)
@release_version = argv.flag?('release', false)
@no_cache = argv.flag?('no-cache', false)

super(argv)
end
Expand Down Expand Up @@ -59,7 +61,10 @@ def run
# Build all targets to always clean directory
targets.each do |target|
compiler = Epuber::Compiler.new(book, target)
compiler.compile(Epuber::Config.instance.release_build_path(target), check: true, write: @should_write, release: true, verbose: verbose?)
build_path = Epuber::Config.instance.release_build_path(target)
compiler.compile(build_path, check: true, write: @should_write,
release: true, verbose: verbose?,
no_cache: true)

archive_name = compiler.epub_name

Expand All @@ -76,7 +81,8 @@ def run
else
targets.each do |target|
compiler = Epuber::Compiler.new(book, target)
compiler.compile(Epuber::Config.instance.build_path(target), check: @should_check, write: @should_write, verbose: verbose?)
build_path = Epuber::Config.instance.build_path(target)
compiler.compile(build_path, check: @should_check, write: @should_write, verbose: verbose?, no_cache: @no_cache)
archive_path = compiler.archive(configuration_suffix: 'debug')

system(%(epubcheck "#{archive_path}")) if @should_check
Expand Down
3 changes: 2 additions & 1 deletion lib/epuber/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ def initialize(book, target)
#
# @return [void]
#
def compile(build_folder, check: false, write: false, release: false, verbose: false)
def compile(build_folder, check: false, write: false, release: false, verbose: false, no_cache: false)
@file_resolver = FileResolver.new(Config.instance.project_path, build_folder)
compilation_context.file_resolver = @file_resolver
compilation_context.should_check = check
compilation_context.should_write = write
compilation_context.release_build = release
compilation_context.verbose = verbose
compilation_context.no_cache = no_cache

self.class.globals_catcher.catch do
@build_folder = build_folder
Expand Down
8 changes: 8 additions & 0 deletions lib/epuber/compiler/compilation_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def perform_plugin_things(klass, source_type)
#
attr_accessor :release_build

# @return [Bool]
#
attr_accessor :no_cache

# @return [Bool]
#
attr_accessor :verbose
Expand All @@ -92,6 +96,10 @@ def debug?
!release_build
end

def incremental_build?
!no_cache
end

def initialize(book, target)
@book = book
@target = target
Expand Down
2 changes: 1 addition & 1 deletion lib/epuber/compiler/file_types/bade_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def process(compilation_context)
__const: Hash.new { |_hash, key| UI.warning("Undefined constant with key `#{key}`", location: caller_locations[0]) }.merge!(target.constants),
}

if up_to_date && precompiled_exists && compilation_context.debug?
if up_to_date && precompiled_exists && compilation_context.incremental_build?
precompiled = Bade::Precompiled.from_yaml_file(precompiled_path)

renderer = Bade::Renderer.from_precompiled(precompiled)
Expand Down
4 changes: 4 additions & 0 deletions lib/epuber/compiler/file_types/source_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def process(_compilation_context)
# @return [Bool]
#
def source_file_up_to_date?
return false if compilation_context.no_cache

source_db = compilation_context.source_file_database
source_db.up_to_date?(source_path)
end
Expand All @@ -51,6 +53,8 @@ def source_file_up_to_date?
# @return [Bool]
#
def destination_file_up_to_date?
return false if compilation_context.no_cache

source_db = compilation_context.source_file_database
target_db = compilation_context.target_file_database

Expand Down

0 comments on commit bbbbd44

Please sign in to comment.