ocran 1.3.18 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.txt +306 -292
  3. data/LICENSE.txt +22 -22
  4. data/README.md +549 -533
  5. data/exe/ocran +5 -5
  6. data/ext/extconf.rb +15 -0
  7. data/lib/ocran/build_constants.rb +16 -16
  8. data/lib/ocran/build_facade.rb +17 -17
  9. data/lib/ocran/build_helper.rb +110 -105
  10. data/lib/ocran/command_output.rb +22 -22
  11. data/lib/ocran/dir_builder.rb +162 -0
  12. data/lib/ocran/direction.rb +623 -458
  13. data/lib/ocran/file_path_set.rb +69 -69
  14. data/lib/ocran/gem_spec_queryable.rb +172 -172
  15. data/lib/ocran/host_config_helper.rb +57 -44
  16. data/lib/ocran/inno_setup_script_builder.rb +111 -111
  17. data/lib/ocran/launcher_batch_builder.rb +85 -85
  18. data/lib/ocran/library_detector.rb +61 -61
  19. data/lib/ocran/library_detector_posix.rb +55 -0
  20. data/lib/ocran/option.rb +323 -273
  21. data/lib/ocran/refine_pathname.rb +104 -104
  22. data/lib/ocran/runner.rb +115 -105
  23. data/lib/ocran/runtime_environment.rb +46 -46
  24. data/lib/ocran/stub_builder.rb +298 -264
  25. data/lib/ocran/version.rb +5 -5
  26. data/lib/ocran/windows_command_escaping.rb +15 -15
  27. data/lib/ocran.rb +7 -7
  28. data/share/ocran/lzma.exe +0 -0
  29. data/src/Makefile +75 -0
  30. data/src/edicon.c +161 -0
  31. data/src/error.c +100 -0
  32. data/src/error.h +66 -0
  33. data/src/inst_dir.c +334 -0
  34. data/src/inst_dir.h +157 -0
  35. data/src/lzma/7zTypes.h +529 -0
  36. data/src/lzma/Compiler.h +43 -0
  37. data/src/lzma/LzmaDec.c +1363 -0
  38. data/src/lzma/LzmaDec.h +236 -0
  39. data/src/lzma/Precomp.h +10 -0
  40. data/src/script_info.c +246 -0
  41. data/src/script_info.h +7 -0
  42. data/src/stub.c +133 -0
  43. data/src/stub.manifest +29 -0
  44. data/src/stub.rc +3 -0
  45. data/src/system_utils.c +1002 -0
  46. data/src/system_utils.h +209 -0
  47. data/src/system_utils_posix.c +500 -0
  48. data/src/unpack.c +574 -0
  49. data/src/unpack.h +85 -0
  50. data/src/vit-ruby.ico +0 -0
  51. metadata +52 -16
  52. data/share/ocran/edicon.exe +0 -0
  53. data/share/ocran/stub.exe +0 -0
  54. data/share/ocran/stubw.exe +0 -0
data/lib/ocran/option.rb CHANGED
@@ -1,273 +1,323 @@
1
- # frozen_string_literal: true
2
- require "pathname"
3
-
4
- module Ocran
5
- class Option
6
- load File.expand_path("refine_pathname.rb", __dir__) unless defined? RefinePathname
7
- using RefinePathname
8
-
9
- def initialize
10
- @options = {
11
- :add_all_core? => false,
12
- :add_all_encoding? => true,
13
- :argv => [],
14
- :auto_detect_dlls? => true,
15
- :chdir_before? => false,
16
- :enable_compression? => true,
17
- :enable_debug_extract? => false,
18
- :enable_debug_mode? => false,
19
- :extra_dlls => [],
20
- :force_console? => false,
21
- :force_windows? => false,
22
- :gem_options => [],
23
- :gemfile => nil,
24
- :icon_filename => nil,
25
- :inno_setup_script => nil,
26
- :load_autoload? => true,
27
- :output_override => nil,
28
- :quiet? => false,
29
- :rubyopt => nil,
30
- :run_script? => true,
31
- :script => nil,
32
- :source_files => [],
33
- :verbose? => false,
34
- :warning? => true,
35
- }
36
- end
37
-
38
- def usage
39
- <<EOF
40
- ocran [options] script.rb
41
-
42
- Ocran options:
43
-
44
- --help Display this information.
45
- --quiet Suppress output while building executable.
46
- --verbose Show extra output while building executable.
47
- --version Display version number and exit.
48
-
49
- Packaging options:
50
-
51
- --dll dllname Include additional DLLs from the Ruby bindir.
52
- --add-all-core Add all core ruby libraries to the executable.
53
- --gemfile <file> Add all gems and dependencies listed in a Bundler Gemfile.
54
- --no-enc Exclude encoding support files
55
-
56
- Gem content detection modes:
57
-
58
- --gem-minimal[=gem1,..] Include only loaded scripts
59
- --gem-guess=[gem1,...] Include loaded scripts & best guess (DEFAULT)
60
- --gem-all[=gem1,..] Include all scripts & files
61
- --gem-full[=gem1,..] Include EVERYTHING
62
- --gem-spec[=gem1,..] Include files in gemspec (Does not work with Rubygems 1.7+)
63
-
64
- minimal: loaded scripts
65
- guess: loaded scripts and other files
66
- all: loaded scripts, other scripts, other files (except extras)
67
- full: Everything found in the gem directory
68
-
69
- --[no-]gem-scripts[=..] Other script files than those loaded
70
- --[no-]gem-files[=..] Other files (e.g. data files)
71
- --[no-]gem-extras[=..] Extra files (README, etc.)
72
-
73
- scripts: .rb/.rbw files
74
- extras: C/C++ sources, object files, test, spec, README
75
- files: all other files
76
-
77
- Auto-detection options:
78
-
79
- --no-dep-run Don't run script.rb to check for dependencies.
80
- --no-autoload Don't load/include script.rb's autoloads.
81
- --no-autodll Disable detection of runtime DLL dependencies.
82
-
83
- Output options:
84
-
85
- --output <file> Name the exe to generate. Defaults to ./<scriptname>.exe.
86
- --no-lzma Disable LZMA compression of the executable.
87
- --innosetup <file> Use given Inno Setup script (.iss) to create an installer.
88
-
89
- Executable options:
90
-
91
- --windows Force Windows application (rubyw.exe)
92
- --console Force console application (ruby.exe)
93
- --chdir-first When exe starts, change working directory to app dir.
94
- --icon <ico> Replace icon with a custom one.
95
- --rubyopt <str> Set the RUBYOPT environment variable when running the executable
96
- --debug Executable will be verbose.
97
- --debug-extract Executable will unpack to local dir and not delete after.
98
- EOF
99
- end
100
-
101
- def parse(argv)
102
- while (arg = argv.shift)
103
- case arg
104
- when /\A--(no-)?lzma\z/
105
- @options[:enable_compression?] = !$1
106
- when "--no-dep-run"
107
- @options[:run_script?] = false
108
- when "--add-all-core"
109
- @options[:add_all_core?] = true
110
- when "--output"
111
- path = argv.shift
112
- @options[:output_override] = Pathname.new(path).expand_path if path
113
- when "--dll"
114
- path = argv.shift
115
- @options[:extra_dlls] << path if path
116
- when "--quiet"
117
- @options[:quiet?] = true
118
- when "--verbose"
119
- @options[:verbose?] = true
120
- when "--windows"
121
- @options[:force_windows?] = true
122
- when "--console"
123
- @options[:force_console?] = true
124
- when "--no-autoload"
125
- @options[:load_autoload?] = false
126
- when "--chdir-first"
127
- @options[:chdir_before?] = true
128
- when "--icon"
129
- path = argv.shift
130
- raise "Icon file #{path} not found" unless path && File.exist?(path)
131
- @options[:icon_filename] = Pathname.new(path).expand_path
132
- when "--rubyopt"
133
- @options[:rubyopt] = argv.shift
134
- when "--gemfile"
135
- path = argv.shift
136
- raise "Gemfile #{path} not found" unless path && File.exist?(path)
137
- @options[:gemfile] = Pathname.new(path).expand_path
138
- when "--innosetup"
139
- path = argv.shift
140
- raise "Inno Script #{path} not found" unless path && File.exist?(path)
141
- @options[:inno_setup_script] = Pathname.new(path).expand_path
142
- when "--no-autodll"
143
- @options[:auto_detect_dlls?] = false
144
- when "--version"
145
- require_relative "version"
146
- puts "Ocran #{VERSION}"
147
- raise SystemExit
148
- when "--no-warnings"
149
- @options[:warning?] = false
150
- when "--debug"
151
- @options[:enable_debug_mode?] = true
152
- when "--debug-extract"
153
- @options[:enable_debug_extract?] = true
154
- when "--"
155
- @options[:argv] = argv.dup
156
- argv.clear
157
- break
158
- when /\A--(no-)?enc\z/
159
- @options[:add_all_encoding?] = !$1
160
- when /\A--(no-)?gem-(\w+)(?:=(.*))?$/
161
- negate, group, list = $1, $2, $3
162
- @options[:gem_options] << [negate, group.to_sym, list&.split(",")] if group
163
- when "--help", /\A--./
164
- puts usage
165
- raise SystemExit
166
- else
167
- raise "#{arg} not found!" unless File.exist?(arg)
168
-
169
- if File.directory?(arg)
170
- raise "#{arg} is empty!" if Dir.empty?(arg)
171
- # If a directory is passed, we want all files under that directory
172
- @options[:source_files] += Pathname.new(arg).find.reject(&:directory?).map(&:expand_path)
173
- else
174
- @options[:source_files] << Pathname.new(arg).expand_path
175
- end
176
- end
177
- end
178
-
179
- raise "No script file specified" if source_files.empty?
180
-
181
- @options[:script] = source_files.first
182
-
183
- @options[:force_autoload?] = run_script? && load_autoload?
184
-
185
- @options[:output_executable] =
186
- if output_override
187
- output_override
188
- else
189
- executable = script
190
- # If debug mode is enabled, append "-debug" to the filename
191
- executable = executable.append_to_filename("-debug") if enable_debug_mode?
192
- # Build output files are created in the current directory
193
- executable.basename.sub_ext(".exe").expand_path
194
- end
195
-
196
- @options[:use_inno_setup?] = !!inno_setup_script
197
-
198
- @options[:verbose?] &&= !quiet?
199
-
200
- @options[:windowed?] = (script.extname?(".rbw") || force_windows?) && !force_console?
201
-
202
- if inno_setup_script
203
- if enable_debug_extract?
204
- raise "The --debug-extract option conflicts with use of Inno Setup"
205
- end
206
-
207
- if enable_compression?
208
- raise "LZMA compression must be disabled (--no-lzma) when using Inno Setup"
209
- end
210
-
211
- unless chdir_before?
212
- raise "Chdir-first mode must be enabled (--chdir-first) when using Inno Setup"
213
- end
214
- end
215
- end
216
-
217
- def add_all_core? = @options[__method__]
218
-
219
- def add_all_encoding? = @options[__method__]
220
-
221
- def argv = @options[__method__]
222
-
223
- def auto_detect_dlls? = @options[__method__]
224
-
225
- def chdir_before? = @options[__method__]
226
-
227
- def enable_compression? = @options[__method__]
228
-
229
- def enable_debug_extract? = @options[__method__]
230
-
231
- def enable_debug_mode? = @options[__method__]
232
-
233
- def extra_dlls = @options[__method__]
234
-
235
- def force_autoload? = @options[__method__]
236
-
237
- def force_console? = @options[__method__]
238
-
239
- def force_windows? = @options[__method__]
240
-
241
- def gem_options = @options[__method__]
242
-
243
- def gemfile = @options[__method__]
244
-
245
- def icon_filename = @options[__method__]
246
-
247
- def inno_setup_script = @options[__method__]
248
-
249
- def load_autoload? = @options[__method__]
250
-
251
- def output_executable = @options[__method__]
252
-
253
- def output_override = @options[__method__]
254
-
255
- def quiet? = @options[__method__]
256
-
257
- def rubyopt = @options[__method__]
258
-
259
- def run_script? = @options[__method__]
260
-
261
- def script = @options[__method__]
262
-
263
- def source_files = @options[__method__]
264
-
265
- def use_inno_setup? = @options[__method__]
266
-
267
- def verbose? = @options[__method__]
268
-
269
- def warning? = @options[__method__]
270
-
271
- def windowed? = @options[__method__]
272
- end
273
- end
1
+ # frozen_string_literal: true
2
+ require "pathname"
3
+
4
+ module Ocran
5
+ class Option
6
+ load File.expand_path("refine_pathname.rb", __dir__) unless defined? RefinePathname
7
+ using RefinePathname
8
+
9
+ def initialize
10
+ @options = {
11
+ :add_all_core? => false,
12
+ :add_all_encoding? => true,
13
+ :argv => [],
14
+ :auto_detect_dlls? => true,
15
+ :bundle_identifier => nil,
16
+ :macosx_bundle => nil,
17
+ :macosx_bundle? => false,
18
+ :chdir_before? => false,
19
+ :enable_compression? => true,
20
+ :enable_debug_extract? => false,
21
+ :enable_debug_mode? => false,
22
+ :extra_dlls => [],
23
+ :force_console? => false,
24
+ :force_windows? => false,
25
+ :gem_options => [],
26
+ :gemfile => nil,
27
+ :icon_filename => nil,
28
+ :inno_setup_script => nil,
29
+ :load_autoload? => true,
30
+ :output_dir => nil,
31
+ :output_override => nil,
32
+ :output_zip => nil,
33
+ :quiet? => false,
34
+ :rubyopt => nil,
35
+ :run_script? => true,
36
+ :script => nil,
37
+ :source_files => [],
38
+ :verbose? => false,
39
+ :warning? => true,
40
+ }
41
+ end
42
+
43
+ def usage
44
+ <<EOF
45
+ ocran [options] script.rb
46
+
47
+ Ocran options:
48
+
49
+ --help Display this information.
50
+ --quiet Suppress output while building executable.
51
+ --verbose Show extra output while building executable.
52
+ --version Display version number and exit.
53
+
54
+ Packaging options:
55
+
56
+ --dll dllname Include additional DLLs from the Ruby bindir.
57
+ --add-all-core Add all core ruby libraries to the executable.
58
+ --gemfile <file> Add all gems and dependencies listed in a Bundler Gemfile.
59
+ --no-enc Exclude encoding support files
60
+
61
+ Gem content detection modes:
62
+
63
+ --gem-minimal[=gem1,..] Include only loaded scripts
64
+ --gem-guess=[gem1,...] Include loaded scripts & best guess (DEFAULT)
65
+ --gem-all[=gem1,..] Include all scripts & files
66
+ --gem-full[=gem1,..] Include EVERYTHING
67
+ --gem-spec[=gem1,..] Include files in gemspec (Does not work with Rubygems 1.7+)
68
+
69
+ minimal: loaded scripts
70
+ guess: loaded scripts and other files
71
+ all: loaded scripts, other scripts, other files (except extras)
72
+ full: Everything found in the gem directory
73
+
74
+ --[no-]gem-scripts[=..] Other script files than those loaded
75
+ --[no-]gem-files[=..] Other files (e.g. data files)
76
+ --[no-]gem-extras[=..] Extra files (README, etc.)
77
+
78
+ scripts: .rb/.rbw files
79
+ extras: C/C++ sources, object files, test, spec, README
80
+ files: all other files
81
+
82
+ Auto-detection options:
83
+
84
+ --no-dep-run Don't run script.rb to check for dependencies.
85
+ --no-autoload Don't load/include script.rb's autoloads.
86
+ --no-autodll Disable detection of runtime DLL dependencies.
87
+
88
+ Output options:
89
+
90
+ --output <file> Name the exe to generate. Defaults to ./<scriptname>.exe.
91
+ --output-dir <dir> Output all files to a directory with a launch script instead of an exe.
92
+ --output-zip <file> Output a zip archive containing all files and a launch script.
93
+ --macosx-bundle Build a macOS .app bundle. Use --output to name it (default: <scriptname>.app).
94
+ --bundle-id <id> Bundle identifier for the macOS app bundle (default: com.example.<appname>).
95
+ --no-lzma Disable LZMA compression of the executable.
96
+ --innosetup <file> Use given Inno Setup script (.iss) to create an installer.
97
+
98
+ Executable options:
99
+
100
+ --windows Force Windows application (rubyw.exe)
101
+ --console Force console application (ruby.exe)
102
+ --chdir-first When exe starts, change working directory to app dir.
103
+ --icon <ico> Replace icon with a custom one.
104
+ --rubyopt <str> Set the RUBYOPT environment variable when running the executable
105
+ --debug Executable will be verbose.
106
+ --debug-extract Executable will unpack to local dir and not delete after.
107
+ EOF
108
+ end
109
+
110
+ def parse(argv)
111
+ while (arg = argv.shift)
112
+ case arg
113
+ when /\A--(no-)?lzma\z/
114
+ @options[:enable_compression?] = !$1
115
+ when "--no-dep-run"
116
+ @options[:run_script?] = false
117
+ when "--add-all-core"
118
+ @options[:add_all_core?] = true
119
+ when "--output"
120
+ path = argv.shift
121
+ @options[:output_override] = Pathname.new(path).expand_path if path
122
+ when "--output-dir"
123
+ path = argv.shift
124
+ @options[:output_dir] = Pathname.new(path).expand_path if path
125
+ when "--output-zip"
126
+ path = argv.shift
127
+ @options[:output_zip] = Pathname.new(path).expand_path if path
128
+ when "--macosx-bundle"
129
+ @options[:macosx_bundle?] = true
130
+ when "--bundle-id"
131
+ @options[:bundle_identifier] = argv.shift
132
+ when "--dll"
133
+ path = argv.shift
134
+ @options[:extra_dlls] << path if path
135
+ when "--quiet"
136
+ @options[:quiet?] = true
137
+ when "--verbose"
138
+ @options[:verbose?] = true
139
+ when "--windows"
140
+ @options[:force_windows?] = true
141
+ when "--console"
142
+ @options[:force_console?] = true
143
+ when "--no-autoload"
144
+ @options[:load_autoload?] = false
145
+ when "--chdir-first"
146
+ @options[:chdir_before?] = true
147
+ when "--icon"
148
+ path = argv.shift
149
+ raise "Icon file #{path} not found" unless path && File.exist?(path)
150
+ @options[:icon_filename] = Pathname.new(path).expand_path
151
+ when "--rubyopt"
152
+ @options[:rubyopt] = argv.shift
153
+ when "--gemfile"
154
+ path = argv.shift
155
+ raise "Gemfile #{path} not found" unless path && File.exist?(path)
156
+ @options[:gemfile] = Pathname.new(path).expand_path
157
+ when "--innosetup"
158
+ path = argv.shift
159
+ raise "Inno Script #{path} not found" unless path && File.exist?(path)
160
+ @options[:inno_setup_script] = Pathname.new(path).expand_path
161
+ when "--no-autodll"
162
+ @options[:auto_detect_dlls?] = false
163
+ when "--version"
164
+ require_relative "version"
165
+ puts "Ocran #{VERSION}"
166
+ raise SystemExit
167
+ when "--no-warnings"
168
+ @options[:warning?] = false
169
+ when "--debug"
170
+ @options[:enable_debug_mode?] = true
171
+ when "--debug-extract"
172
+ @options[:enable_debug_extract?] = true
173
+ when "--"
174
+ @options[:argv] = argv.dup
175
+ argv.clear
176
+ break
177
+ when /\A--(no-)?enc\z/
178
+ @options[:add_all_encoding?] = !$1
179
+ when /\A--(no-)?gem-(\w+)(?:=(.*))?$/
180
+ negate, group, list = $1, $2, $3
181
+ @options[:gem_options] << [negate, group.to_sym, list&.split(",")] if group
182
+ when "--help", /\A--./
183
+ puts usage
184
+ raise SystemExit
185
+ else
186
+ expanded = Dir.glob(arg)
187
+ if expanded.empty?
188
+ raise "#{arg} not found!" unless File.exist?(arg)
189
+ expanded = [arg]
190
+ end
191
+
192
+ expanded.each do |f|
193
+ if File.directory?(f)
194
+ raise "#{f} is empty!" if Dir.empty?(f)
195
+ # If a directory is passed, we want all files under that directory
196
+ @options[:source_files] += Pathname.new(f).find.reject(&:directory?).map(&:expand_path)
197
+ else
198
+ @options[:source_files] << Pathname.new(f).expand_path
199
+ end
200
+ end
201
+ end
202
+ end
203
+
204
+ raise "No script file specified" if source_files.empty?
205
+
206
+ @options[:script] = source_files.first
207
+
208
+ @options[:force_autoload?] = run_script? && load_autoload?
209
+
210
+ @options[:output_executable] =
211
+ if output_override
212
+ output_override
213
+ else
214
+ executable = script
215
+ # If debug mode is enabled, append "-debug" to the filename
216
+ executable = executable.append_to_filename("-debug") if enable_debug_mode?
217
+ # Build output files are created in the current directory
218
+ ext = Gem.win_platform? ? ".exe" : ""
219
+ executable.basename.sub_ext(ext).expand_path
220
+ end
221
+
222
+ if @options[:macosx_bundle?]
223
+ bundle_base = output_override || script.basename
224
+ @options[:macosx_bundle] = Pathname(bundle_base).sub_ext(".app").expand_path
225
+ end
226
+
227
+ @options[:use_inno_setup?] = !!inno_setup_script
228
+
229
+ @options[:verbose?] &&= !quiet?
230
+
231
+ @options[:windowed?] = (script.extname?(".rbw") || force_windows?) && !force_console?
232
+
233
+ if inno_setup_script
234
+ if enable_debug_extract?
235
+ raise "The --debug-extract option conflicts with use of Inno Setup"
236
+ end
237
+
238
+ if enable_compression?
239
+ raise "LZMA compression must be disabled (--no-lzma) when using Inno Setup"
240
+ end
241
+
242
+ unless chdir_before?
243
+ raise "Chdir-first mode must be enabled (--chdir-first) when using Inno Setup"
244
+ end
245
+ end
246
+
247
+ if output_dir && output_zip
248
+ raise "--output-dir and --output-zip cannot be used together"
249
+ end
250
+
251
+ if macosx_bundle && (output_dir || output_zip || inno_setup_script)
252
+ raise "--macosx-bundle cannot be combined with --output-dir, --output-zip, or --innosetup"
253
+ end
254
+ end
255
+
256
+ def add_all_core? = @options[__method__]
257
+
258
+ def add_all_encoding? = @options[__method__]
259
+
260
+ def argv = @options[__method__]
261
+
262
+ def bundle_identifier = @options[__method__]
263
+
264
+ def macosx_bundle = @options[__method__]
265
+
266
+ def auto_detect_dlls? = @options[__method__]
267
+
268
+ def chdir_before? = @options[__method__]
269
+
270
+ def enable_compression? = @options[__method__]
271
+
272
+ def enable_debug_extract? = @options[__method__]
273
+
274
+ def enable_debug_mode? = @options[__method__]
275
+
276
+ def extra_dlls = @options[__method__]
277
+
278
+ def force_autoload? = @options[__method__]
279
+
280
+ def force_console? = @options[__method__]
281
+
282
+ def force_windows? = @options[__method__]
283
+
284
+ def gem_options = @options[__method__]
285
+
286
+ def gemfile = @options[__method__]
287
+
288
+ def icon_filename = @options[__method__]
289
+
290
+ def inno_setup_script = @options[__method__]
291
+
292
+ def load_autoload? = @options[__method__]
293
+
294
+ def output_dir = @options[__method__]
295
+
296
+ def output_executable = @options[__method__]
297
+
298
+ def output_override = @options[__method__]
299
+
300
+ def output_zip = @options[__method__]
301
+
302
+ def quiet? = @options[__method__]
303
+
304
+ def rubyopt = @options[__method__]
305
+
306
+ def run_script? = @options[__method__]
307
+
308
+ def script = @options[__method__]
309
+
310
+ def source_files = @options[__method__]
311
+
312
+ def use_inno_setup? = @options[__method__]
313
+
314
+ def verbose? = @options[__method__]
315
+
316
+ def warning? = @options[__method__]
317
+
318
+ def windowed?
319
+ return false unless Gem.win_platform?
320
+ @options[:windowed?]
321
+ end
322
+ end
323
+ end