Class: Ocran::Option
- Inherits:
-
Object
- Object
- Ocran::Option
- Defined in:
- lib/ocran/option.rb
Instance Method Summary collapse
- #add_all_core? ⇒ Boolean
- #add_all_encoding? ⇒ Boolean
- #argv ⇒ Object
- #auto_detect_dlls? ⇒ Boolean
- #chdir_before? ⇒ Boolean
- #enable_compression? ⇒ Boolean
- #enable_debug_extract? ⇒ Boolean
- #enable_debug_mode? ⇒ Boolean
- #extra_dlls ⇒ Object
- #force_autoload? ⇒ Boolean
- #force_console? ⇒ Boolean
- #force_windows? ⇒ Boolean
- #gem_options ⇒ Object
- #gemfile ⇒ Object
- #icon_filename ⇒ Object
-
#initialize ⇒ Option
constructor
A new instance of Option.
- #inno_setup_script ⇒ Object
- #load_autoload? ⇒ Boolean
- #output_executable ⇒ Object
- #output_override ⇒ Object
- #parse(argv) ⇒ Object
- #quiet? ⇒ Boolean
- #rubyopt ⇒ Object
- #run_script? ⇒ Boolean
- #script ⇒ Object
- #source_files ⇒ Object
- #usage ⇒ Object
- #use_inno_setup? ⇒ Boolean
- #verbose? ⇒ Boolean
- #warning? ⇒ Boolean
- #windowed? ⇒ Boolean
Constructor Details
#initialize ⇒ Option
Returns a new instance of Option.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ocran/option.rb', line 9 def initialize @options = { :add_all_core? => false, :add_all_encoding? => true, :argv => [], :auto_detect_dlls? => true, :chdir_before? => false, :enable_compression? => true, :enable_debug_extract? => false, :enable_debug_mode? => false, :extra_dlls => [], :force_console? => false, :force_windows? => false, :gem_options => [], :gemfile => nil, :icon_filename => nil, :inno_setup_script => nil, :load_autoload? => true, :output_override => nil, :quiet? => false, :rubyopt => nil, :run_script? => true, :script => nil, :source_files => [], :verbose? => false, :warning? => true, } end |
Instance Method Details
#add_all_core? ⇒ Boolean
217 |
# File 'lib/ocran/option.rb', line 217 def add_all_core? = @options[__method__] |
#add_all_encoding? ⇒ Boolean
219 |
# File 'lib/ocran/option.rb', line 219 def add_all_encoding? = @options[__method__] |
#argv ⇒ Object
221 |
# File 'lib/ocran/option.rb', line 221 def argv = @options[__method__] |
#auto_detect_dlls? ⇒ Boolean
223 |
# File 'lib/ocran/option.rb', line 223 def auto_detect_dlls? = @options[__method__] |
#chdir_before? ⇒ Boolean
225 |
# File 'lib/ocran/option.rb', line 225 def chdir_before? = @options[__method__] |
#enable_compression? ⇒ Boolean
227 |
# File 'lib/ocran/option.rb', line 227 def enable_compression? = @options[__method__] |
#enable_debug_extract? ⇒ Boolean
229 |
# File 'lib/ocran/option.rb', line 229 def enable_debug_extract? = @options[__method__] |
#enable_debug_mode? ⇒ Boolean
231 |
# File 'lib/ocran/option.rb', line 231 def enable_debug_mode? = @options[__method__] |
#extra_dlls ⇒ Object
233 |
# File 'lib/ocran/option.rb', line 233 def extra_dlls = @options[__method__] |
#force_autoload? ⇒ Boolean
235 |
# File 'lib/ocran/option.rb', line 235 def force_autoload? = @options[__method__] |
#force_console? ⇒ Boolean
237 |
# File 'lib/ocran/option.rb', line 237 def force_console? = @options[__method__] |
#force_windows? ⇒ Boolean
239 |
# File 'lib/ocran/option.rb', line 239 def force_windows? = @options[__method__] |
#gem_options ⇒ Object
241 |
# File 'lib/ocran/option.rb', line 241 def = @options[__method__] |
#gemfile ⇒ Object
243 |
# File 'lib/ocran/option.rb', line 243 def gemfile = @options[__method__] |
#icon_filename ⇒ Object
245 |
# File 'lib/ocran/option.rb', line 245 def icon_filename = @options[__method__] |
#inno_setup_script ⇒ Object
247 |
# File 'lib/ocran/option.rb', line 247 def inno_setup_script = @options[__method__] |
#load_autoload? ⇒ Boolean
249 |
# File 'lib/ocran/option.rb', line 249 def load_autoload? = @options[__method__] |
#output_executable ⇒ Object
251 |
# File 'lib/ocran/option.rb', line 251 def output_executable = @options[__method__] |
#output_override ⇒ Object
253 |
# File 'lib/ocran/option.rb', line 253 def output_override = @options[__method__] |
#parse(argv) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/ocran/option.rb', line 101 def parse(argv) while (arg = argv.shift) case arg when /\A--(no-)?lzma\z/ @options[:enable_compression?] = !$1 when "--no-dep-run" @options[:run_script?] = false when "--add-all-core" @options[:add_all_core?] = true when "--output" path = argv.shift @options[:output_override] = Pathname.new(path). if path when "--dll" path = argv.shift @options[:extra_dlls] << path if path when "--quiet" @options[:quiet?] = true when "--verbose" @options[:verbose?] = true when "--windows" @options[:force_windows?] = true when "--console" @options[:force_console?] = true when "--no-autoload" @options[:load_autoload?] = false when "--chdir-first" @options[:chdir_before?] = true when "--icon" path = argv.shift raise "Icon file #{path} not found" unless path && File.exist?(path) @options[:icon_filename] = Pathname.new(path). when "--rubyopt" @options[:rubyopt] = argv.shift when "--gemfile" path = argv.shift raise "Gemfile #{path} not found" unless path && File.exist?(path) @options[:gemfile] = Pathname.new(path). when "--innosetup" path = argv.shift raise "Inno Script #{path} not found" unless path && File.exist?(path) @options[:inno_setup_script] = Pathname.new(path). when "--no-autodll" @options[:auto_detect_dlls?] = false when "--version" require_relative "version" puts "Ocran #{VERSION}" raise SystemExit when "--no-warnings" @options[:warning?] = false when "--debug" @options[:enable_debug_mode?] = true when "--debug-extract" @options[:enable_debug_extract?] = true when "--" @options[:argv] = argv.dup argv.clear break when /\A--(no-)?enc\z/ @options[:add_all_encoding?] = !$1 when /\A--(no-)?gem-(\w+)(?:=(.*))?$/ negate, group, list = $1, $2, $3 @options[:gem_options] << [negate, group.to_sym, list&.split(",")] if group when "--help", /\A--./ puts usage raise SystemExit else raise "#{arg} not found!" unless File.exist?(arg) if File.directory?(arg) raise "#{arg} is empty!" if Dir.empty?(arg) # If a directory is passed, we want all files under that directory @options[:source_files] += Pathname.new(arg).find.reject(&:directory?).map(&:expand_path) else @options[:source_files] << Pathname.new(arg). end end end raise "No script file specified" if source_files.empty? @options[:script] = source_files.first @options[:force_autoload?] = run_script? && load_autoload? @options[:output_executable] = if output_override output_override else executable = script # If debug mode is enabled, append "-debug" to the filename executable = executable.append_to_filename("-debug") if enable_debug_mode? # Build output files are created in the current directory executable.basename.sub_ext(".exe"). end @options[:use_inno_setup?] = !!inno_setup_script @options[:verbose?] &&= !quiet? @options[:windowed?] = (script.extname?(".rbw") || force_windows?) && !force_console? if inno_setup_script if enable_debug_extract? raise "The --debug-extract option conflicts with use of Inno Setup" end if enable_compression? raise "LZMA compression must be disabled (--no-lzma) when using Inno Setup" end unless chdir_before? raise "Chdir-first mode must be enabled (--chdir-first) when using Inno Setup" end end end |
#quiet? ⇒ Boolean
255 |
# File 'lib/ocran/option.rb', line 255 def quiet? = @options[__method__] |
#rubyopt ⇒ Object
257 |
# File 'lib/ocran/option.rb', line 257 def rubyopt = @options[__method__] |
#run_script? ⇒ Boolean
259 |
# File 'lib/ocran/option.rb', line 259 def run_script? = @options[__method__] |
#script ⇒ Object
261 |
# File 'lib/ocran/option.rb', line 261 def script = @options[__method__] |
#source_files ⇒ Object
263 |
# File 'lib/ocran/option.rb', line 263 def source_files = @options[__method__] |
#usage ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ocran/option.rb', line 38 def usage <<EOF ocran [options] script.rb Ocran options: --help Display this information. --quiet Suppress output while building executable. --verbose Show extra output while building executable. --version Display version number and exit. Packaging options: --dll dllname Include additional DLLs from the Ruby bindir. --add-all-core Add all core ruby libraries to the executable. --gemfile <file> Add all gems and dependencies listed in a Bundler Gemfile. --no-enc Exclude encoding support files Gem content detection modes: --gem-minimal[=gem1,..] Include only loaded scripts --gem-guess=[gem1,...] Include loaded scripts & best guess (DEFAULT) --gem-all[=gem1,..] Include all scripts & files --gem-full[=gem1,..] Include EVERYTHING --gem-spec[=gem1,..] Include files in gemspec (Does not work with Rubygems 1.7+) minimal: loaded scripts guess: loaded scripts and other files all: loaded scripts, other scripts, other files (except extras) full: Everything found in the gem directory --[no-]gem-scripts[=..] Other script files than those loaded --[no-]gem-files[=..] Other files (e.g. data files) --[no-]gem-extras[=..] Extra files (README, etc.) scripts: .rb/.rbw files extras: C/C++ sources, object files, test, spec, README files: all other files Auto-detection options: --no-dep-run Don't run script.rb to check for dependencies. --no-autoload Don't load/include script.rb's autoloads. --no-autodll Disable detection of runtime DLL dependencies. Output options: --output <file> Name the exe to generate. Defaults to ./<scriptname>.exe. --no-lzma Disable LZMA compression of the executable. --innosetup <file> Use given Inno Setup script (.iss) to create an installer. Executable options: --windows Force Windows application (rubyw.exe) --console Force console application (ruby.exe) --chdir-first When exe starts, change working directory to app dir. --icon <ico> Replace icon with a custom one. --rubyopt <str> Set the RUBYOPT environment variable when running the executable --debug Executable will be verbose. --debug-extract Executable will unpack to local dir and not delete after. EOF end |
#use_inno_setup? ⇒ Boolean
265 |
# File 'lib/ocran/option.rb', line 265 def use_inno_setup? = @options[__method__] |
#verbose? ⇒ Boolean
267 |
# File 'lib/ocran/option.rb', line 267 def verbose? = @options[__method__] |
#warning? ⇒ Boolean
269 |
# File 'lib/ocran/option.rb', line 269 def warning? = @options[__method__] |
#windowed? ⇒ Boolean
271 |
# File 'lib/ocran/option.rb', line 271 def windowed? = @options[__method__] |