Skip to content

Commit

Permalink
Memoize output_executable method and integrate into build_exe method
Browse files Browse the repository at this point in the history
- Add memoization to the existing output_executable method for improved performance.
- The output_executable method checks for Ocran.output_override and appends "-debug" to the filename if Ocran.debug is enabled, then changes the extension to ".exe".
- Replace the executable variable in build_exe method with the memoized output_executable method.
- Added comments to clarify the special handling of the debug mode in the output_executable method.
  • Loading branch information
shinokaro committed Jun 2, 2024
1 parent 45cff84 commit cdf6718
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions bin/ocran
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,14 @@ EOF
end

def self.output_executable
if Ocran.output_override
Ocran.output_override
else
executable = Ocran.main_script.basename.sub_ext(".exe")
executable = executable.append_to_filename("-debug") if Ocran.debug
executable
end
@output_executable ||= if Ocran.output_override
Ocran.output_override
else
executable = Ocran.main_script
# If debug mode is enabled, append "-debug" to the filename
executable = executable.append_to_filename("-debug") if Ocran.debug
executable.basename.sub_ext(".exe")
end
end

def self.windowed?
Expand Down Expand Up @@ -747,9 +748,7 @@ EOF
# Detect additional DLLs
dlls = Ocran.autodll ? Ocran.detect_dlls : []

executable = Ocran.output_executable

Ocran.msg "Building #{executable}"
Ocran.msg "Building #{Ocran.output_executable}"
target_script = nil
direction = proc do |sb|
# Add explicitly mentioned files
Expand Down Expand Up @@ -850,18 +849,18 @@ EOF

unless Ocran.inno_script
require_relative "../lib/ocran/stub_builder"
StubBuilder.new(executable,
StubBuilder.new(Ocran.output_executable,
chdir_before: Ocran.chdir_first,
debug_extract: Ocran.debug_extract,
debug_mode: Ocran.debug,
enable_compression: Ocran.lzma_mode,
gui_mode: Ocran.windowed?,
icon_path: Ocran.icon_filename,
&direction)
Ocran.msg "Finished building #{executable} (#{File.size(executable)} bytes)"
Ocran.msg "Finished building #{Ocran.output_executable} (#{Ocran.output_executable.size} bytes)"
else
require_relative "../lib/ocran/inno_setup_builder"
InnoSetupBuilder.new(executable,
InnoSetupBuilder.new(Ocran.output_executable,
Ocran.inno_script,
chdir_before: Ocran.chdir_first,
icon_path: Ocran.icon_filename,
Expand Down

0 comments on commit cdf6718

Please sign in to comment.