Skip to content

Commit

Permalink
Refactor logging to use BuilderOpsLogger module
Browse files Browse the repository at this point in the history
- Moved the logging implementation from the Builder class to the BuilderOpsLogger module.
- Modified the Builder class to prepend the BuilderOpsLogger module when build logging is needed, enhancing modularity and separation of concerns.
  • Loading branch information
shinokaro committed Jun 13, 2024
1 parent afd621b commit b469099
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
3 changes: 3 additions & 0 deletions bin/ocran
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,10 @@ EOF
builder.exec(installed_ruby_exe, target_script, *Ocran.arg)
end

require_relative "../lib/ocran/builder_ops_logger"
unless Ocran.inno_script
require_relative "../lib/ocran/stub_builder"
StubBuilder.prepend(BuilderOpsLogger) unless Ocran.quiet
StubBuilder.new(Ocran.output_executable,
chdir_before: Ocran.chdir_first,
debug_extract: Ocran.debug_extract,
Expand All @@ -779,6 +781,7 @@ EOF
Ocran.msg "Finished building #{Ocran.output_executable} (#{Ocran.output_executable.size} bytes)"
else
require_relative "../lib/ocran/inno_setup_builder"
InnoSetupBuilder.prepend(BuilderOpsLogger) unless Ocran.quiet
InnoSetupBuilder.new(Ocran.output_executable,
Ocran.inno_script,
chdir_before: Ocran.chdir_first,
Expand Down
36 changes: 36 additions & 0 deletions lib/ocran/builder_ops_logger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module Ocran
module BuilderOpsLogger
def mkdir(target)
puts "mkdir #{target}"
super
end

def cp(source, target)
puts "cp #{source} #{target}"
super
end

def touch(target)
puts "touch #{target}"
super
end

def exec(image, script, *argv)
args = argv.map { |s| replace_placeholder(s) }.join(" ")
puts "exec #{image} #{script} #{args}"
super
end

def export(name, value)
puts "export #{name}=#{replace_placeholder(value)}"
super
end

def replace_placeholder(s)
s.to_s.gsub(TEMPDIR_ROOT.to_s, "<tempdir>")
end
private :replace_placeholder
end
end
10 changes: 0 additions & 10 deletions lib/ocran/inno_setup_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ def compile

def mkdir(target)
@iss.mkdir(target)
Ocran.verbose_msg "m #{target}"
end

def cp(source, target)
@iss.cp(source, target)
Ocran.verbose_msg "a #{target}"
end

def touch(target)
Expand All @@ -69,18 +67,10 @@ def exec(image, script, *argv)
@script_info = true

@launcher.exec(image, script, *argv)
extra_argc = argv.map { |arg| quote_and_escape(arg) }.join(" ")
Ocran.verbose_msg "p #{image} #{script} #{show_path extra_argc}"
end

def export(name, value)
@launcher.export(name, value)
Ocran.verbose_msg "e #{name} #{show_path value}"
end

def show_path(x)
x.to_s.gsub(TEMPDIR_ROOT.to_s, "{app}")
end
private :show_path
end
end
11 changes: 0 additions & 11 deletions lib/ocran/stub_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def mkdir(path)
return if @paths[key]

@paths[key] = path
Ocran.verbose_msg "m #{path}"

write_opcode(OP_CREATE_DIRECTORY)
write_path(path)
Expand All @@ -118,7 +117,6 @@ def cp(src, tgt)

@files[key] = [tgt, src]

Ocran.verbose_msg "a #{tgt}"
write_opcode(OP_CREATE_FILE)
write_path(tgt)
write_file(src)
Expand All @@ -141,15 +139,11 @@ def exec(image, script, *argv)
end
@script_set = true

extra_argc = argv.map { |arg| "\"#{arg.gsub("\"", "\\\"")}\"" }.join(" ")

Ocran.verbose_msg "p #{image} #{script} #{show_path extra_argc}"
write_opcode(OP_SET_SCRIPT)
write_string_array(convert_to_native(image), convert_to_native(script), *argv)
end

def export(name, value)
Ocran.verbose_msg "e #{name} #{show_path value}"
write_opcode(OP_SETENV)
write_string(name.to_s)
write_string(value.to_s)
Expand All @@ -160,11 +154,6 @@ def close
@of.close
end

def show_path(x)
x.to_s.gsub(TEMPDIR_ROOT.to_s, "<tempdir>")
end
private :show_path

def compress
IO.popen([LZMA_PATH, "e", "-si", "-so"], "r+b") do |lzma|
_of, @of = @of, lzma
Expand Down

0 comments on commit b469099

Please sign in to comment.