lib/kameleon/engine.rb in kameleon-builder-2.10.9 vs lib/kameleon/engine.rb in kameleon-builder-2.10.10

- old
+ new

@@ -15,24 +15,25 @@ @recipe = recipe @cleaned_sections = [] @cwd = @recipe.global["kameleon_cwd"] @build_recipe_path = File.join(@cwd, ".build_recipe") + @recipe.global["checkpointing_enabled"] = @options[:enable_checkpointing] ? "true" : "false" @recipe.global["persistent_cache"] = @options[:enable_cache] ? "true" : "false" build_recipe = load_build_recipe # restore previous build uuid unless build_recipe.nil? %w(kameleon_uuid kameleon_short_uuid).each do |key| @recipe.global[key] = build_recipe["global"][key] end end - @enable_checkpoint = @options[:enable_checkpoint] - @enable_checkpoint = true unless @options[:from_checkpoint].nil? - @microstep_checkpoint = @options[:microstep_checkpoint] + @checkpointing = @options[:enable_checkpointing] + @checkpointing = true unless @options[:from_checkpoint].nil? + @microstep_checkpoint = @options[:microstep_checkpoints] # Check if the recipe have checkpoint entry - if @enable_checkpoint && @recipe.checkpoint.nil? + if @checkpointing && @recipe.checkpoint.nil? fail BuildError, "Checkpoint is unavailable for this recipe" end if @options[:enable_cache] || @options[:from_cache] then if @recipe.global["in_context"]["proxy_cache"].nil? then @@ -76,11 +77,11 @@ if @options[:enable_cache] || @options[:from_cache] then @cache.recipe_files = @recipe.all_files end unless @options[:no_create_build_dir] begin - Kameleon.ui.info("Creating kameleon build directory : #{@cwd}") + Kameleon.ui.info("Creating kameleon build directory: #{@cwd}") FileUtils.mkdir_p @cwd rescue raise BuildError, "Failed to create build directory #{@cwd}" end @cache.start if @cache @@ -143,11 +144,11 @@ directory_name end def create_checkpoint(microstep_id) @recipe.checkpoint["create"].each do |cmd| - safe_exec_cmd(cmd.dup.gsub!("@microstep_id", microstep_id)) + safe_exec_cmd(cmd.dup.gsub!("@microstep_id", microstep_id), :log_level => "warn") end end def checkpoint_enabled? @recipe.checkpoint["enabled?"].each do |cmd| @@ -200,53 +201,62 @@ end end macrostep.sequence do |microstep| microstep_time = Time.now.to_i microstep_checkpoint_duration = 0 - step_prefix = "Step #{ microstep.order } : " + step_prefix = "Step #{ microstep.order }: " Kameleon.ui.info("#{step_prefix}#{ microstep.slug }") - if @enable_checkpoint + if @checkpointing if microstep.on_checkpoint == "skip" - Kameleon.ui.msg("--> Skipped") + Kameleon.ui.msg("--> Skipped because checkpointing is enabled") next end - if microstep.in_cache && microstep.on_checkpoint == "use_cache" - Kameleon.ui.msg("--> Using checkpoint") + if microstep.in_cache and microstep.on_checkpoint != "redo" + Kameleon.ui.msg("--> Checkpoint ahead, do nothing") else begin Kameleon.ui.msg("--> Running the step...") microstep.commands.each do |cmd| safe_exec_cmd(cmd) end rescue SystemExit, Interrupt reload_contexts breakpoint(nil) end - unless microstep.on_checkpoint == "redo" - unless checkpointed and @microstep_checkpoint == "first" - if checkpoint_enabled? - microstep_checkpoint_time = Time.now.to_i - Kameleon.ui.msg("--> Creating checkpoint : #{ microstep.identifier }") - create_checkpoint(microstep.identifier) - checkpointed = true - microstep_checkpoint_duration = Time.now.to_i - microstep_checkpoint_time - macrostep_checkpoint_duration += microstep_checkpoint_duration - Kameleon.ui.verbose("Checkpoint creation for MicroStep #{microstep.name} took: #{microstep_checkpoint_duration} secs") - end + if checkpoint_enabled? + if (@microstep_checkpoint == "first" and checkpointed) + Kameleon.ui.msg("--> Do not create a checkpoint for this microstep: macrostep was already checkpointed once") + elsif microstep.on_checkpoint == "redo" + Kameleon.ui.msg("--> Do not create a checkpoint for this microstep: it must be redone everytime") + elsif microstep.on_checkpoint == "disabled" + Kameleon.ui.msg("--> Do not create a checkpoint for this microstep: it is disabled") + else + microstep_checkpoint_time = Time.now.to_i + Kameleon.ui.msg("--> Creating checkpoint: #{ microstep.identifier }") + create_checkpoint(microstep.identifier) + checkpointed = true + microstep_checkpoint_duration = Time.now.to_i - microstep_checkpoint_time + macrostep_checkpoint_duration += microstep_checkpoint_duration + Kameleon.ui.verbose("Checkpoint creation for MicroStep #{microstep.name} took: #{microstep_checkpoint_duration} secs") end end end else - begin - Kameleon.ui.msg("--> Running the step...") - microstep.commands.each do |cmd| - safe_exec_cmd(cmd) + if microstep.on_checkpoint == "only" + Kameleon.ui.msg("--> Skipped because checkpointing is not enabled") + next + else + begin + Kameleon.ui.msg("--> Running the step...") + microstep.commands.each do |cmd| + safe_exec_cmd(cmd) + end + rescue SystemExit, Interrupt + reload_contexts + breakpoint(nil) + end end - rescue SystemExit, Interrupt - reload_contexts - breakpoint(nil) - end end Kameleon.ui.verbose("MicroStep #{microstep.name} took: #{Time.now.to_i - microstep_time - microstep_checkpoint_duration} secs") end Kameleon.ui.info("Step #{macrostep.name} took: #{Time.now.to_i - macrostep_time - macrostep_checkpoint_duration} secs") end @@ -276,11 +286,11 @@ breakpoint(cmd.value) when "reload_context" context = "exec_" + cmd.value expected_names = map.keys.map { |k| k.gsub "exec_", "" } unless map.keys.include? context - Kameleon.ui.error("Invalid context name arguments. Expected : "\ + Kameleon.ui.error("Invalid context name arguments. Expected: "\ "#{expected_names}") fail ExecError else map[context].reload end @@ -294,11 +304,11 @@ first_cmd, second_cmd = cmd.value expected_cmds = ["exec_in", "exec_out", "exec_local"] execute = true [first_cmd.key, second_cmd.key].each do |key| unless expected_cmds.include?(key) - Kameleon.ui.error("Invalid pipe arguments. Expected : "\ + Kameleon.ui.error("Invalid pipe arguments. Expected: "\ "#{expected_cmds}") fail ExecError end if kwargs[:only_with_context] and map[key].closed? Kameleon.ui.debug("Not executing pipe command (context closed sub command #{key})") @@ -347,11 +357,11 @@ cmds = cmd.value cmds.each do |cmd| exec_cmd(cmd, kwargs) end else - Kameleon.ui.warn("Unknown command : #{cmd.key}") + Kameleon.ui.warn("Unknown command: #{cmd.key}") end end def breakpoint(message, kwargs = {}) @@ -405,11 +415,11 @@ end end end def rescue_exec_error(cmd) - message = "Error occured when executing the following command :\n" + message = "Error occured when executing the following command:\n" cmd.string_cmd.split( /\r?\n/ ).each {|m| message << "\n> #{m}" } if Kameleon.env.script? raise ExecError, message end return breakpoint(message, :enable_retry => true) @@ -421,28 +431,32 @@ Kameleon.ui.info("Removing all checkpoints") @recipe.checkpoint["clear"].each do |cmd| begin exec_cmd(cmd, kwargs) rescue - Kameleon.ui.warn("An error occurred while executing : #{cmd.value}") + Kameleon.ui.warn("An error occurred while executing: #{cmd.value}") end end end @recipe.sections.values.each do |section| next if @cleaned_sections.include?(section.name) Kameleon.ui.info("Cleaning #{section.name} section") section.clean_macrostep.sequence do |microstep| - if @enable_checkpoint + if @checkpointing if microstep.on_checkpoint == "skip" next end + else + if microstep.on_checkpoint == "only" + next + end end microstep.commands.each do |cmd| begin exec_cmd(cmd, kwargs) rescue - Kameleon.ui.warn("An error occurred while executing : #{cmd.value}") + Kameleon.ui.warn("An error occurred while executing: #{cmd.value}") end end end end @cache.stop_web_proxy if @options[:enable_cache] ## stopping polipo @@ -553,22 +567,22 @@ Kameleon.ui.info "-> Draw DAG for #{recipe_path}" return graph end def build - if @enable_checkpoint + if @checkpointing @from_checkpoint = @options[:from_checkpoint] if @from_checkpoint.nil? || @from_checkpoint == "last" @from_checkpoint = list_checkpoints.last else unless list_checkpoints.include?@from_checkpoint - fail BuildError, "Unknown checkpoint hash : #{@from_checkpoint}." \ + fail BuildError, "Unknown checkpoint hash: #{@from_checkpoint}." \ " Use checkpoints command to find a valid" \ " checkpoint" end end unless @from_checkpoint.nil? - Kameleon.ui.info("Restoring last build from step : #{@from_checkpoint}") + Kameleon.ui.info("Restoring last build from step: #{@from_checkpoint}") apply_checkpoint @from_checkpoint @recipe.microsteps.each do |microstep| microstep.in_cache = true if microstep.identifier == @from_checkpoint break