Class: Ocran::InnoSetupScriptBuilder

Inherits:
Object
  • Object
show all
Extended by:
WindowsCommandEscaping
Includes:
WindowsCommandEscaping
Defined in:
lib/ocran/inno_setup_script_builder.rb

Constant Summary collapse

ISCC_CMD =
"ISCC"
ISCC_SUCCESS =
0
ISCC_INVALID_PARAMS =
1
ISCC_COMPILATION_FAILED =
2

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WindowsCommandEscaping

escape_double_quotes, quote_and_escape

Constructor Details

#initialize(inno_setup_script) ⇒ InnoSetupScriptBuilder

Returns a new instance of InnoSetupScriptBuilder.



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ocran/inno_setup_script_builder.rb', line 48

def initialize(inno_setup_script)
  # ISSC generates the installer files relative to the directory of the
  # ISS file. Therefore, it is necessary to create Tempfiles in the
  # working directory.
  @build_file = Tempfile.new("", Dir.pwd)
  if inno_setup_script
    IO.copy_stream(inno_setup_script, @build_file)
  end
  @dirs = FilePathSet.new
  @files = FilePathSet.new
end

Class Method Details

.compile(iss_filename, quiet: false) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ocran/inno_setup_script_builder.rb', line 16

def compile(iss_filename, quiet: false)
  # "where" and ">NUL" only exist on Windows; use "command -v" on POSIX
  # (e.g. when testing the pipeline with a fake ISCC on Linux/macOS).
  iscc_found = if Gem.win_platform?
                 true # ISCC is invoked directly; failure is reported below
               else
                 system("command -v #{quote_and_escape(ISCC_CMD)} > /dev/null 2>&1")
               end
  unless iscc_found
    raise "ISCC command not found. Is the InnoSetup directory in your PATH?"
  end

  cmd_line = [ISCC_CMD]
  cmd_line << "/Q" if quiet
  cmd_line << iss_filename
  system(*cmd_line)

  case $?&.exitstatus
  when ISCC_SUCCESS
    # ISCC reported success
  when ISCC_INVALID_PARAMS
    raise "ISCC reports invalid command line parameters"
  when ISCC_COMPILATION_FAILED
    raise "ISCC reports that compilation failed"
  else
    raise "ISCC failed to run"
  end
end

Instance Method Details

#buildObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ocran/inno_setup_script_builder.rb', line 60

def build
  @build_file.tap do |f|
    if @dirs.any?
      f.puts
      f.puts "[Dirs]"
      @dirs.each { |_source, target| f.puts build_dir_item(target) }
    end

    if @files.any?
      f.puts
      f.puts "[Files]"
      @files.each { |source, target| f.puts build_file_item(source, target) }
    end
  end.close
  path
end

#compile(verbose: false) ⇒ Object



81
82
83
# File 'lib/ocran/inno_setup_script_builder.rb', line 81

def compile(verbose: false)
  InnoSetupScriptBuilder.compile(path, quiet: !verbose)
end

#cp(source, target) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/ocran/inno_setup_script_builder.rb', line 96

def cp(source, target)
  unless File.exist?(source)
    raise "The file does not exist (#{source})"
  end

  @files.add?(source, target)
end

#mkdir(target) ⇒ Object



85
86
87
# File 'lib/ocran/inno_setup_script_builder.rb', line 85

def mkdir(target)
  @dirs.add?("/", target)
end

#pathObject



77
78
79
# File 'lib/ocran/inno_setup_script_builder.rb', line 77

def path
  @build_file.to_path
end

Symbolic links cannot be expressed in an Inno Setup script. They only occur when building from POSIX hosts (e.g. libruby.so links); Windows installations do not need them, so they are skipped.



92
93
94
# File 'lib/ocran/inno_setup_script_builder.rb', line 92

def symlink(_target, _link_name)
  nil
end