ocran 1.4.0-x86_64-linux
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.
- checksums.yaml +7 -0
- data/CHANGELOG.txt +306 -0
- data/LICENSE.txt +23 -0
- data/README.md +549 -0
- data/exe/ocran +5 -0
- data/lib/ocran/build_constants.rb +16 -0
- data/lib/ocran/build_facade.rb +17 -0
- data/lib/ocran/build_helper.rb +110 -0
- data/lib/ocran/command_output.rb +22 -0
- data/lib/ocran/dir_builder.rb +162 -0
- data/lib/ocran/direction.rb +623 -0
- data/lib/ocran/empty_source +0 -0
- data/lib/ocran/file_path_set.rb +69 -0
- data/lib/ocran/gem_spec_queryable.rb +172 -0
- data/lib/ocran/host_config_helper.rb +57 -0
- data/lib/ocran/inno_setup_script_builder.rb +111 -0
- data/lib/ocran/launcher_batch_builder.rb +85 -0
- data/lib/ocran/library_detector.rb +61 -0
- data/lib/ocran/library_detector_posix.rb +55 -0
- data/lib/ocran/option.rb +323 -0
- data/lib/ocran/refine_pathname.rb +104 -0
- data/lib/ocran/runner.rb +115 -0
- data/lib/ocran/runtime_environment.rb +46 -0
- data/lib/ocran/stub_builder.rb +298 -0
- data/lib/ocran/version.rb +5 -0
- data/lib/ocran/windows_command_escaping.rb +15 -0
- data/lib/ocran.rb +7 -0
- data/share/ocran/lzma.exe +0 -0
- data/share/ocran/stub +0 -0
- metadata +109 -0
data/README.md
ADDED
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
# ocran
|
|
2
|
+
|
|
3
|
+
home :: https://github.com/largo/ocran/
|
|
4
|
+
|
|
5
|
+
issues :: http://github.com/largo/ocran/issues
|
|
6
|
+
|
|
7
|
+
## Description
|
|
8
|
+
|
|
9
|
+
OCRAN (One-Click Ruby Application Next) packages Ruby applications for
|
|
10
|
+
distribution. It bundles your script, the Ruby interpreter, gems, and native
|
|
11
|
+
libraries into a single self-contained artifact that runs without requiring
|
|
12
|
+
Ruby to be installed on the target machine.
|
|
13
|
+
|
|
14
|
+
OCRAN supports four output formats, all cross-platform:
|
|
15
|
+
|
|
16
|
+
* **Self-extracting executable** — bundles everything into a single binary that unpacks and runs transparently, with no Ruby installation required. Produces a `.exe` on Windows, and a native executable on Linux and macOS.
|
|
17
|
+
* **macOS app bundle** (`--macosx-bundle`) — wraps the executable in a `.app` bundle for Finder integration, Dock icons, and code signing.
|
|
18
|
+
* **Directory** (`--output-dir`) — copies all files into a folder with a ready-to-run launch script (`.sh` on Linux/macOS, `.bat` on Windows).
|
|
19
|
+
* **Zip archive** (`--output-zip`) — same as directory output, packed into a `.zip`.
|
|
20
|
+
|
|
21
|
+
OCRAN is a fork of [OCRA](https://github.com/larsch/ocra) maintained for
|
|
22
|
+
Ruby 3.2+ compatibility.
|
|
23
|
+
|
|
24
|
+
## Recommended usage
|
|
25
|
+
|
|
26
|
+
The most common use-case is shipping a program to Windows servers or users
|
|
27
|
+
who do not have Ruby installed. By default, each time the `.exe` is opened it
|
|
28
|
+
extracts the Ruby interpreter and your code to a temporary directory and runs
|
|
29
|
+
them from there.
|
|
30
|
+
|
|
31
|
+
Because extraction takes time on each launch, consider using the Inno Setup
|
|
32
|
+
option (`--innosetup`) to produce a proper installer that extracts once to a
|
|
33
|
+
permanent directory.
|
|
34
|
+
|
|
35
|
+
For cross-platform packaging or CI artifacts, use `--output-dir` or
|
|
36
|
+
`--output-zip` to produce a portable directory/archive that runs with the
|
|
37
|
+
bundled Ruby on Linux, macOS, or Windows.
|
|
38
|
+
|
|
39
|
+
## Features
|
|
40
|
+
|
|
41
|
+
* **Windows/Linux/macOS executable** — self-extracting, self-running executable (primary output)
|
|
42
|
+
* **macOS app bundle** — `.app` bundle with `Info.plist` for Finder/Dock/code-signing (`--macosx-bundle`)
|
|
43
|
+
* **Directory output** — portable directory with a launch script (`--output-dir`)
|
|
44
|
+
* **Zip archive output** — portable zip with a launch script (`--output-zip`)
|
|
45
|
+
* LZMA compression (optional, default on, for `.exe` only)
|
|
46
|
+
* Both windowed and console mode supported (Windows)
|
|
47
|
+
* Gems included based on actual usage, or from a Bundler Gemfile
|
|
48
|
+
* Code-signing compatible
|
|
49
|
+
* Multibyte (UTF-8) path support on Windows 10 1903+
|
|
50
|
+
|
|
51
|
+
## Problems & Bug Reporting
|
|
52
|
+
|
|
53
|
+
If you experience problems with OCRAN or have found a bug, please use the
|
|
54
|
+
issue tracker on GitHub (http://github.com/largo/ocran/issues).
|
|
55
|
+
|
|
56
|
+
## Safety
|
|
57
|
+
|
|
58
|
+
As this gem ships with binary blobs, releases are securely built on GitHub
|
|
59
|
+
Actions. Feel free to verify that the published gem matches the source.
|
|
60
|
+
|
|
61
|
+
This repository includes `lzma.exe` from the
|
|
62
|
+
[official ip7z/7zip release](https://github.com/ip7z/7zip/releases)
|
|
63
|
+
(version 22.01, from `lzma2201.7z`), used to compress Windows executables.
|
|
64
|
+
|
|
65
|
+
`stub.exe`, `stubw.exe`, and `edicon.exe` are compiled from source in this
|
|
66
|
+
repository.
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
gem install ocran
|
|
71
|
+
|
|
72
|
+
Alternatively, download from http://rubygems.org/gems/ocran or
|
|
73
|
+
https://github.com/largo/ocran/releases/.
|
|
74
|
+
|
|
75
|
+
## Synopsis
|
|
76
|
+
|
|
77
|
+
### Building a Windows executable:
|
|
78
|
+
|
|
79
|
+
ocran script.rb
|
|
80
|
+
|
|
81
|
+
Packages `script.rb`, the Ruby interpreter, and all dependencies (gems and
|
|
82
|
+
DLLs) into `script.exe`.
|
|
83
|
+
|
|
84
|
+
### Building a portable directory (Linux / macOS / Windows):
|
|
85
|
+
|
|
86
|
+
ocran --output-dir myapp/ script.rb
|
|
87
|
+
|
|
88
|
+
Copies all files into `myapp/` and writes a `script.sh` (or `script.bat` on
|
|
89
|
+
Windows) launch script.
|
|
90
|
+
|
|
91
|
+
### Building a macOS app bundle:
|
|
92
|
+
|
|
93
|
+
ocran --macosx-bundle script.rb
|
|
94
|
+
|
|
95
|
+
Produces `script.app/` — a standard macOS `.app` bundle containing the
|
|
96
|
+
self-extracting executable at `Contents/MacOS/script` and an `Info.plist`.
|
|
97
|
+
Open it with `open script.app` or double-click it in Finder.
|
|
98
|
+
|
|
99
|
+
ocran --macosx-bundle --output MyApp --bundle-id com.example.myapp --icon icon.icns script.rb
|
|
100
|
+
|
|
101
|
+
Custom name, bundle identifier and icon (must be `.icns` format). The icon is
|
|
102
|
+
placed at `Contents/Resources/AppIcon.icns` and referenced in `Info.plist`.
|
|
103
|
+
|
|
104
|
+
### Building a zip archive:
|
|
105
|
+
|
|
106
|
+
ocran --output-zip myapp.zip script.rb
|
|
107
|
+
|
|
108
|
+
Same as `--output-dir`, but packages the result into a zip file. Requires
|
|
109
|
+
`zip` on Linux/macOS or PowerShell on Windows.
|
|
110
|
+
|
|
111
|
+
### Command line:
|
|
112
|
+
|
|
113
|
+
ocran [options] script.rb [<other files> ...] [-- <script arguments> ...]
|
|
114
|
+
|
|
115
|
+
### Options:
|
|
116
|
+
|
|
117
|
+
ocran --help
|
|
118
|
+
|
|
119
|
+
#### General options:
|
|
120
|
+
|
|
121
|
+
* `--help`: Display available command-line options.
|
|
122
|
+
* `--quiet`: Suppress all output during the build process.
|
|
123
|
+
* `--verbose`: Provide detailed output during the build process.
|
|
124
|
+
* `--version`: Display the OCRAN version number and exit.
|
|
125
|
+
|
|
126
|
+
#### Packaging options:
|
|
127
|
+
|
|
128
|
+
* `--dll <dllname>`: Include additional DLLs from the Ruby `bin` directory.
|
|
129
|
+
* `--add-all-core`: Add all standard Ruby core libraries to the executable.
|
|
130
|
+
* `--gemfile <file>`: Include all gems and dependencies listed in a Bundler `Gemfile`.
|
|
131
|
+
* `--no-enc`: Exclude encoding support files to reduce output size.
|
|
132
|
+
|
|
133
|
+
#### Gem content detection modes:
|
|
134
|
+
|
|
135
|
+
These options control which files from included gems are added to the output.
|
|
136
|
+
|
|
137
|
+
* `--gem-minimal[=gem1,..]`: Include only scripts actually loaded during the dependency run.
|
|
138
|
+
* `--gem-guess[=gem1,..]`: Include loaded scripts and a best guess of other needed files (DEFAULT).
|
|
139
|
+
* `--gem-all[=gem1,..]`: Include all scripts and important files from the gem.
|
|
140
|
+
* `--gem-full[=gem1,..]`: Include every file in the gem directory.
|
|
141
|
+
* `--gem-spec[=gem1,..]`: Include files listed in the gemspec (not compatible with newer RubyGems).
|
|
142
|
+
|
|
143
|
+
Fine-tuning flags:
|
|
144
|
+
|
|
145
|
+
* `--[no-]gem-scripts[=..]`: Include/exclude non-loaded script files (`.rb`, `.rbw`).
|
|
146
|
+
* `--[no-]gem-files[=..]`: Include/exclude data files.
|
|
147
|
+
* `--[no-]gem-extras[=..]`: Include/exclude extras (READMEs, tests, C sources).
|
|
148
|
+
|
|
149
|
+
#### Auto-detection options:
|
|
150
|
+
|
|
151
|
+
* `--no-dep-run`: Skip running the script to detect dependencies. Use this if your script has side effects during load or if you are manually specifying all dependencies. Requires `--add-all-core` and `--gem-full`.
|
|
152
|
+
* `--no-autoload`: Do not attempt to load `autoload`ed constants.
|
|
153
|
+
* `--no-autodll`: Disable automatic detection of runtime DLL dependencies.
|
|
154
|
+
|
|
155
|
+
#### Output options:
|
|
156
|
+
|
|
157
|
+
* `--output <file>`: Name the generated executable. Defaults to `./<scriptname>.exe` on Windows and `./<scriptname>` on Linux/macOS.
|
|
158
|
+
* `--output-dir <dir>`: Output all files to a directory with a launch script instead of building an executable. Works on Linux, macOS, and Windows.
|
|
159
|
+
* `--output-zip <file>`: Output a zip archive containing all files and a launch script. Requires `zip` (Linux/macOS) or PowerShell (Windows).
|
|
160
|
+
* `--macosx-bundle`: Build a macOS `.app` bundle. Use `--output` to set the bundle name (default: `<scriptname>.app`). (macOS)
|
|
161
|
+
* `--bundle-id <id>`: Set the `CFBundleIdentifier` in `Info.plist` (default: `com.example.<appname>`). Used with `--macosx-bundle`.
|
|
162
|
+
* `--no-lzma`: Disable LZMA compression (faster build, larger executable).
|
|
163
|
+
* `--innosetup <file>`: Use an Inno Setup script (`.iss`) to create a Windows installer.
|
|
164
|
+
|
|
165
|
+
#### Executable options:
|
|
166
|
+
|
|
167
|
+
* `--windows`: Force a Windows GUI application (uses `rubyw.exe`). (Windows only)
|
|
168
|
+
* `--console`: Force a console application (uses `ruby.exe`). (Windows only)
|
|
169
|
+
* `--chdir-first`: Change working directory to the app's extraction directory before the script starts.
|
|
170
|
+
* `--icon <ico>`: Replace the default icon with a custom `.ico` file.
|
|
171
|
+
* `--rubyopt <str>`: Set `RUBYOPT` when the executable runs.
|
|
172
|
+
* `--debug`: Enable verbose output when the generated executable runs.
|
|
173
|
+
* `--debug-extract`: Unpack to a local directory and do not delete after execution (useful for troubleshooting).
|
|
174
|
+
|
|
175
|
+
### Compilation:
|
|
176
|
+
|
|
177
|
+
* OCRAN runs your script (using `Kernel#load`) and builds the output when it exits.
|
|
178
|
+
* Your program should `require` all necessary files when invoked without arguments so OCRAN can detect all dependencies.
|
|
179
|
+
* DLLs are detected automatically; only those within your Ruby installation are included.
|
|
180
|
+
* `.rb` files become console applications; `.rbw` files become windowed applications (without a console window popping up on Windows). Use `--console` or `--windows` to override.
|
|
181
|
+
|
|
182
|
+
### Running your application:
|
|
183
|
+
|
|
184
|
+
* The working directory is not changed by OCRAN unless you use `--chdir-first`. You must change to the installation or temporary
|
|
185
|
+
directory yourself. See also below.
|
|
186
|
+
* When a `.exe` is running, `OCRAN_EXECUTABLE` points to the `.exe` with its full path.
|
|
187
|
+
* The temporary location of the script is available via `$0`.
|
|
188
|
+
* OCRAN does not set up the include path. Add `$:.unshift File.dirname($0)` at the start of your script if you need to `require` additional files from the same directory as your main script.
|
|
189
|
+
|
|
190
|
+
### Directory and zip output (Linux / macOS / Windows):
|
|
191
|
+
|
|
192
|
+
When using `--output-dir` or `--output-zip`, OCRAN produces the same file
|
|
193
|
+
layout as a `.exe` would extract to:
|
|
194
|
+
|
|
195
|
+
bin/ # Ruby interpreter and shared libraries
|
|
196
|
+
lib/ # Ruby standard library
|
|
197
|
+
gems/ # Bundled gems
|
|
198
|
+
src/ # Your application source files
|
|
199
|
+
script.sh # Launch script (Linux/macOS) — or script.bat on Windows
|
|
200
|
+
|
|
201
|
+
The launch script sets `RUBYLIB`, `GEM_HOME`, `GEM_PATH`, and any other
|
|
202
|
+
environment variables, then runs your script with the bundled Ruby.
|
|
203
|
+
|
|
204
|
+
On Linux/macOS, make the script executable and run it:
|
|
205
|
+
|
|
206
|
+
chmod +x myapp/script.sh
|
|
207
|
+
./myapp/script.sh
|
|
208
|
+
|
|
209
|
+
On Windows, run the batch file:
|
|
210
|
+
|
|
211
|
+
myapp\script.bat
|
|
212
|
+
|
|
213
|
+
### Pitfalls:
|
|
214
|
+
|
|
215
|
+
* Avoid modifying load paths at runtime. Use `-I` or `RUBYLIB` if needed, but don't expect OCRAN to preserve them for runtime. OCRAN may pack sources into other directories than you
|
|
216
|
+
expect
|
|
217
|
+
* If you use `.rbw` files or `--windows`, verify your application works with `rubyw.exe` before building.
|
|
218
|
+
* Avoid absolute paths in your code and when invoking OCRAN.
|
|
219
|
+
|
|
220
|
+
### Multibyte path and filename support:
|
|
221
|
+
|
|
222
|
+
* OCRAN-built executables correctly handle multibyte paths (e.g. Japanese, emoji) on Windows 10 1903+.
|
|
223
|
+
* When using the executable from the console, run `chcp 65001` first to switch to UTF-8 on windows.
|
|
224
|
+
|
|
225
|
+
## Requirements
|
|
226
|
+
|
|
227
|
+
* Ruby 3.2+
|
|
228
|
+
* For building Windows `.exe`: Windows with RubyInstaller DevKit (mingw-w64), or Wine on Linux/macOS
|
|
229
|
+
* For `--output-dir` / `--output-zip`: any platform with Ruby 3.2+
|
|
230
|
+
* For `--output-zip` on Linux/macOS: the `zip` command must be available
|
|
231
|
+
* For `--output-zip` on Windows: PowerShell (included in Windows 8+)
|
|
232
|
+
|
|
233
|
+
### Output architecture
|
|
234
|
+
|
|
235
|
+
The architecture of the generated executable matches the Ruby interpreter used to run OCRAN:
|
|
236
|
+
|
|
237
|
+
* **macOS (Intel / Apple Silicon)** — The output binary targets the same CPU as your Ruby installation. If you build with an ARM64 Ruby (Apple Silicon), the result is an ARM64 executable and will not run on Intel Macs. Build on Intel (or with an Intel Ruby under Rosetta) to produce a universally compatible x86-64 binary.
|
|
238
|
+
|
|
239
|
+
* **Windows on ARM (Windows 11 ARM)** — RubyInstaller recently started shipping ARM64 builds; Installing the ARM64 RubyInstaller on a Windows ARM machine and running OCRAN from it will produce an ARM64 `.exe`. These run on ARM Windows natively. Installing the standard x86-64 RubyInstaller on a Windows ARM machine and running OCRAN from it will (probably?) produce an x86-64 `.exe`. These run on ARM Windows via the built-in x86-64 emulation layer, so the executables work on both ARM and x86-64 Windows targets. If you use `--no-lzma`, note that `lzma.exe` (the bundled compressor) is also x86-64 and relies on the same emulation.
|
|
240
|
+
|
|
241
|
+
## Development
|
|
242
|
+
|
|
243
|
+
### Quick start
|
|
244
|
+
|
|
245
|
+
git clone https://github.com/largo/ocran.git
|
|
246
|
+
cd ocran
|
|
247
|
+
bin/setup # install Bundler & all dev gems, build stubs
|
|
248
|
+
bundle exec rake # run the full Minitest suite
|
|
249
|
+
exe/ocran filename.rb # build filename.rb as an executable
|
|
250
|
+
|
|
251
|
+
### Developer utilities (`bin/` scripts)
|
|
252
|
+
|
|
253
|
+
| Script | Purpose |
|
|
254
|
+
|---------------|--------------------------------------------------------------------------|
|
|
255
|
+
| `bin/setup` | Installs Bundler and all required development gems, then builds stub.exe |
|
|
256
|
+
| `bin/console` | Launches an IRB console with OCRAN preloaded |
|
|
257
|
+
|
|
258
|
+
### Rake tasks
|
|
259
|
+
|
|
260
|
+
| Task | Purpose |
|
|
261
|
+
|--------------|------------------------------------------------------------------------|
|
|
262
|
+
| `rake build` | Compile stub(.exe) (requires MSVC or mingw-w64 + DevKit or Unix build tools) |
|
|
263
|
+
| `rake clean` | Remove generated binaries |
|
|
264
|
+
| `rake test` | Execute all unit & integration tests |
|
|
265
|
+
|
|
266
|
+
## Technical details
|
|
267
|
+
|
|
268
|
+
OCRAN first runs the target script to detect files loaded at runtime (via
|
|
269
|
+
`Kernel#require` and `Kernel#load`).
|
|
270
|
+
|
|
271
|
+
For `.exe` output, OCRAN embeds everything into a single executable: a C stub,
|
|
272
|
+
and a custom opcode stream containing instructions to create directories,
|
|
273
|
+
extract files, set environment variables, and launch the script. The stub
|
|
274
|
+
extracts everything to a temporary directory at runtime and runs the script.
|
|
275
|
+
|
|
276
|
+
For `--output-dir` / `--output-zip`, OCRAN performs the same file collection
|
|
277
|
+
but writes directly to the filesystem and generates a shell/batch launch
|
|
278
|
+
script instead of an opcode stream.
|
|
279
|
+
|
|
280
|
+
### Libraries
|
|
281
|
+
|
|
282
|
+
Any code loaded through `Kernel#require` when your script runs is included.
|
|
283
|
+
Conditionally loaded code is only included if it is actually executed during
|
|
284
|
+
the OCRAN build run.
|
|
285
|
+
Otherwise, OCRAN won't know about it and will not include
|
|
286
|
+
the source files.
|
|
287
|
+
You can use `defined?(OCRAN)` to check if the script is running while OCRAN is building it and exit the script after dependencies are loaded but before the main logic runs.
|
|
288
|
+
|
|
289
|
+
RubyGems are handled specially: when a file from a gem is detected, OCRAN
|
|
290
|
+
includes the required files from that gem. It does not automatically include all the files of the Gem, which could be required at runtime. This behavior is controlled with
|
|
291
|
+
the `--gem-*` options.
|
|
292
|
+
|
|
293
|
+
Libraries found in non-standard path (for example, if you invoke OCRAN
|
|
294
|
+
with "ruby -I some/path") will be placed into the site dir
|
|
295
|
+
(lib/ruby/site_ruby). Avoid changing `$LOAD_PATH` or
|
|
296
|
+
`$:` from your script to include paths outside your source
|
|
297
|
+
tree, since OCRAN may place the files elsewhere when extracted into the
|
|
298
|
+
temporary directory.
|
|
299
|
+
|
|
300
|
+
If your script uses `Kernel#autoload`, OCRAN will attempt to load those
|
|
301
|
+
constants so they are included in the output. Missing modules are ignored
|
|
302
|
+
with a warning.
|
|
303
|
+
|
|
304
|
+
Dynamic link libraries (.dll files, for example WxWidgets, or other
|
|
305
|
+
source files) will be detected and included by OCRAN.
|
|
306
|
+
|
|
307
|
+
### Including libraries non-automatically
|
|
308
|
+
|
|
309
|
+
If automatic dependency resolution is insufficient, use `--no-dep-run` to
|
|
310
|
+
skip running your script. This requires `--gem-full` and typically
|
|
311
|
+
`--add-all-core`.
|
|
312
|
+
|
|
313
|
+
You can specify gems via a Bundler Gemfile with `--gemfile`. OCRAN includes
|
|
314
|
+
all listed gems and their dependencies (they must be installed, not vendored
|
|
315
|
+
via `bundle package`).
|
|
316
|
+
|
|
317
|
+
Example — packaging a Rails app without running it:
|
|
318
|
+
|
|
319
|
+
ocran someapp/script/rails someapp --output someapp.exe --add-all-core \
|
|
320
|
+
--gemfile someapp/Gemfile --no-dep-run --gem-full --chdir-first -- server
|
|
321
|
+
|
|
322
|
+
Note the space between `--` and `server`! It's important; `server` is
|
|
323
|
+
an argument to be passed to rails when the script is ran.
|
|
324
|
+
### Gem handling
|
|
325
|
+
|
|
326
|
+
By default, OCRAN includes all scripts loaded by your script plus important
|
|
327
|
+
non-script files from those gems, excluding C/C++ sources, object files,
|
|
328
|
+
READMEs, tests, and specs.
|
|
329
|
+
|
|
330
|
+
Four modes:
|
|
331
|
+
|
|
332
|
+
* *minimal*: Loaded scripts only
|
|
333
|
+
* *guess*: Loaded scripts and important files (DEFAULT)
|
|
334
|
+
* *all*: All scripts and important files
|
|
335
|
+
* *full*: All files in the gem directory
|
|
336
|
+
|
|
337
|
+
If files are missing from the output, try `--gem-all=gemname` first, then
|
|
338
|
+
`--gem-full=gemname`. Use `--gem-full` to include everything for all gems.
|
|
339
|
+
|
|
340
|
+
### Code-signing a macOS app bundle
|
|
341
|
+
|
|
342
|
+
After building with `--macosx-bundle`, sign the bundle with your Developer ID:
|
|
343
|
+
|
|
344
|
+
codesign --deep --force --verify --verbose \
|
|
345
|
+
--sign "Developer ID Application: Your Name (TEAMID)" \
|
|
346
|
+
MyApp.app
|
|
347
|
+
|
|
348
|
+
Verify the signature:
|
|
349
|
+
|
|
350
|
+
codesign --verify --deep --strict --verbose=2 MyApp.app
|
|
351
|
+
spctl --assess --type execute --verbose MyApp.app
|
|
352
|
+
|
|
353
|
+
For distribution outside the Mac App Store, notarize with Apple:
|
|
354
|
+
|
|
355
|
+
# Submit for notarization (requires app-specific password or API key)
|
|
356
|
+
xcrun notarytool submit MyApp.app \
|
|
357
|
+
--apple-id you@example.com \
|
|
358
|
+
--team-id TEAMID \
|
|
359
|
+
--password APP_SPECIFIC_PASSWORD \
|
|
360
|
+
--wait
|
|
361
|
+
|
|
362
|
+
# Staple the notarization ticket so it works offline
|
|
363
|
+
xcrun stapler staple MyApp.app
|
|
364
|
+
|
|
365
|
+
Requirements:
|
|
366
|
+
* Xcode Command Line Tools (`xcode-select --install`)
|
|
367
|
+
* An Apple Developer account with a "Developer ID Application" certificate in Keychain
|
|
368
|
+
|
|
369
|
+
### Creating a Windows installer
|
|
370
|
+
|
|
371
|
+
To make your application start faster or keep files between runs, use
|
|
372
|
+
`--innosetup` to generate an Inno Setup installer.
|
|
373
|
+
|
|
374
|
+
Install Inno Setup 5+ and add it to your `PATH`, then supply an `.iss` script:
|
|
375
|
+
|
|
376
|
+
Make sure that iss is in the PATH environment variable by running the command `iss` in your terminal.
|
|
377
|
+
|
|
378
|
+
Do not add any [Files] or [Dirs] sections
|
|
379
|
+
to the script; Ocran will figure those out itself.
|
|
380
|
+
To continue the Rails example above, let's package the Rails application
|
|
381
|
+
into an installer. Save the following as `someapp.iss`:
|
|
382
|
+
|
|
383
|
+
[Setup]
|
|
384
|
+
AppName=SomeApp
|
|
385
|
+
AppVersion=0.1
|
|
386
|
+
DefaultDirName={pf}\SomeApp
|
|
387
|
+
DefaultGroupName=SomeApp
|
|
388
|
+
OutputBaseFilename=SomeAppInstaller
|
|
389
|
+
|
|
390
|
+
[Icons]
|
|
391
|
+
Name: "{group}\SomeApp"; Filename: "{app}\someapp.bat"; IconFilename: "{app}\someapp.ico"; Flags: runminimized;
|
|
392
|
+
Name: "{group}\Uninstall SomeApp"; Filename: "{uninstallexe}"
|
|
393
|
+
|
|
394
|
+
ocran someapp/script/rails someapp --output someapp.exe --add-all-core \
|
|
395
|
+
--gemfile someapp/Gemfile --no-dep-run --gem-full --chdir-first --no-lzma \
|
|
396
|
+
--icon someapp.ico --innosetup someapp.iss -- server
|
|
397
|
+
|
|
398
|
+
If all goes well, a file named "SomeAppInstaller.exe" will be placed
|
|
399
|
+
into the Output directory.
|
|
400
|
+
|
|
401
|
+
### Environment variables
|
|
402
|
+
|
|
403
|
+
OCRAN clears the `RUBYLIB` environment variable before running your script so it does not pick up load
|
|
404
|
+
paths from the end user's Ruby installation.
|
|
405
|
+
|
|
406
|
+
OCRAN sets the `RUBYOPT` environment variable to the value it had when you invoked OCRAN. For `.exe`
|
|
407
|
+
output, `OCRAN_EXECUTABLE` is set to the full path of the running executable:
|
|
408
|
+
|
|
409
|
+
ENV["OCRAN_EXECUTABLE"] # => C:\Program Files\MyApp\MyApp.exe
|
|
410
|
+
|
|
411
|
+
### Working directory
|
|
412
|
+
|
|
413
|
+
The OCRAN executable does not change the working directory when it starts. It only changes the working directory when you use
|
|
414
|
+
`--chdir-first`.
|
|
415
|
+
|
|
416
|
+
You should not assume that the current working directory when invoking
|
|
417
|
+
an executable built with .exe is the location of the source script. It
|
|
418
|
+
can be the directory where the executable is placed (when invoked
|
|
419
|
+
through the Windows Explorer), the users' current working directory
|
|
420
|
+
(when invoking from the Command Prompt), or even
|
|
421
|
+
`C:\\WINDOWS\\SYSTEM32` when the executable is invoked through
|
|
422
|
+
a file association.
|
|
423
|
+
|
|
424
|
+
With `--chdir-first`, the working directory is always the common parent
|
|
425
|
+
directory of your source files. Do not use this if your application takes
|
|
426
|
+
filenames as command-line arguments.
|
|
427
|
+
|
|
428
|
+
To `require` additional files from the source directory while keeping the
|
|
429
|
+
user's working directory:
|
|
430
|
+
|
|
431
|
+
$LOAD_PATH.unshift File.dirname($0)
|
|
432
|
+
|
|
433
|
+
### Detecting OCRAN at build time
|
|
434
|
+
|
|
435
|
+
Check for the `Ocran` constant to detect whether OCRAN is currently building
|
|
436
|
+
your script:
|
|
437
|
+
|
|
438
|
+
app = MyApp.new
|
|
439
|
+
app.main_loop unless defined?(Ocran)
|
|
440
|
+
|
|
441
|
+
### Additional files and resources
|
|
442
|
+
|
|
443
|
+
Append extra files, directories, or glob patterns to the command line:
|
|
444
|
+
|
|
445
|
+
ocran mainscript.rb someimage.jpeg docs/document.txt
|
|
446
|
+
ocran script.rb assets/**/*.png
|
|
447
|
+
|
|
448
|
+
This produces the following layout in the output (temp dir for `.exe`,
|
|
449
|
+
or the output directory for `--output-dir`):
|
|
450
|
+
|
|
451
|
+
src/mainscript.rb
|
|
452
|
+
src/someimage.jpeg
|
|
453
|
+
src/docs/document.txt
|
|
454
|
+
|
|
455
|
+
Both files, directoriess and glob patterns can be specified on the
|
|
456
|
+
command line. Files will be added as-is. If a directory is specified,
|
|
457
|
+
OCRAN will include all files found below that directory. Glob patterns
|
|
458
|
+
(See Dir.glob) can be used to specify a specific set of files, for
|
|
459
|
+
example:
|
|
460
|
+
|
|
461
|
+
ocran script.rb assets/**/*.png
|
|
462
|
+
|
|
463
|
+
### Command Line Arguments
|
|
464
|
+
|
|
465
|
+
Pass arguments to your script (both during the build run and at runtime)
|
|
466
|
+
after a `--` marker:
|
|
467
|
+
|
|
468
|
+
ocran script.rb -- --some-option=value
|
|
469
|
+
|
|
470
|
+
Extra arguments supplied by the user at runtime are appended after the
|
|
471
|
+
compile-time arguments.
|
|
472
|
+
|
|
473
|
+
### Load path mangling
|
|
474
|
+
|
|
475
|
+
Adding paths to `$LOAD_PATH` or `$:` at runtime is not recommended. Adding
|
|
476
|
+
relative load paths depends on the working directory being the same as where
|
|
477
|
+
the script is located (see above). If you have additional library files in
|
|
478
|
+
directories below the directory containing your source script, use this idiom:
|
|
479
|
+
|
|
480
|
+
$LOAD_PATH.unshift File.join(File.dirname($0), 'path/to/script')
|
|
481
|
+
|
|
482
|
+
### Window/Console
|
|
483
|
+
|
|
484
|
+
By default, OCRAN builds console applications from `.rb` files and windowed
|
|
485
|
+
applications (without a console window) from `.rbw` files.
|
|
486
|
+
|
|
487
|
+
Ruby on Windows provides two executables: `ruby.exe` is a console mode
|
|
488
|
+
application and `rubyw.exe` is a windowed application that does not bring up
|
|
489
|
+
a console window when launched from Windows Explorer. By default, or if
|
|
490
|
+
`--console` is used, OCRAN uses the console runtime. OCRAN automatically
|
|
491
|
+
selects the windowed runtime when your script has the `.rbw` extension, or
|
|
492
|
+
when you pass `--windows`.
|
|
493
|
+
|
|
494
|
+
If your application works in console mode but not in windowed mode, first
|
|
495
|
+
check that your script works without OCRAN using `rubyw.exe`. A script that
|
|
496
|
+
prints to standard output (`puts`, `print`, etc.) will eventually raise an
|
|
497
|
+
exception under `rubyw.exe` once the IO buffers fill up.
|
|
498
|
+
|
|
499
|
+
You can also wrap your script in an exception handler that logs errors to a
|
|
500
|
+
file:
|
|
501
|
+
|
|
502
|
+
begin
|
|
503
|
+
# your script here
|
|
504
|
+
rescue Exception => e
|
|
505
|
+
File.open("except.log", "w") do |f|
|
|
506
|
+
f.puts e.inspect
|
|
507
|
+
f.puts e.backtrace
|
|
508
|
+
end
|
|
509
|
+
end
|
|
510
|
+
|
|
511
|
+
## Credits
|
|
512
|
+
|
|
513
|
+
Lars Christensen and contributors for the OCRA project which this is forked from.
|
|
514
|
+
|
|
515
|
+
Kevin Walzer of codebykevin, Maxim Samsonov for ocra2, John Mair for
|
|
516
|
+
codesigning support.
|
|
517
|
+
|
|
518
|
+
Igor Pavlov for the LZMA compressor and decompressor (Public Domain).
|
|
519
|
+
|
|
520
|
+
Erik Veenstra for rubyscript2exe, which provided inspiration.
|
|
521
|
+
|
|
522
|
+
Dice for the default `.exe` icon (vit-ruby.ico,
|
|
523
|
+
http://ruby.morphball.net/vit-ruby-ico_en.html).
|
|
524
|
+
|
|
525
|
+
## License
|
|
526
|
+
|
|
527
|
+
(The MIT License)
|
|
528
|
+
|
|
529
|
+
Copyright (c) 2009-2020 Lars Christensen
|
|
530
|
+
Copyright (c) 2020-2025 The OCRAN Committers Team
|
|
531
|
+
|
|
532
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
533
|
+
a copy of this software and associated documentation files (the
|
|
534
|
+
'Software'), to deal in the Software without restriction, including
|
|
535
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
536
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
537
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
538
|
+
the following conditions:
|
|
539
|
+
|
|
540
|
+
The above copyright notice and this permission notice shall be
|
|
541
|
+
included in all copies or substantial portions of the Software.
|
|
542
|
+
|
|
543
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
544
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
545
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
546
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
547
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
548
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
549
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/exe/ocran
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ocran
|
|
4
|
+
module BuildConstants
|
|
5
|
+
# Alias for the temporary directory where files are extracted.
|
|
6
|
+
EXTRACT_ROOT = Pathname.new("|")
|
|
7
|
+
# Directory for source files in temporary directory.
|
|
8
|
+
SRCDIR = Pathname.new("src")
|
|
9
|
+
# Directory for Ruby binaries in temporary directory.
|
|
10
|
+
BINDIR = Pathname.new("bin")
|
|
11
|
+
# Directory for gem files in temporary directory.
|
|
12
|
+
GEMDIR = Pathname.new("gems")
|
|
13
|
+
# Directory for Ruby library in temporary directory.
|
|
14
|
+
LIBDIR = Pathname.new("lib")
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ocran
|
|
4
|
+
class BuildFacade
|
|
5
|
+
def initialize(filer, launcher)
|
|
6
|
+
@filer, @launcher = filer, launcher
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def mkdir(...) = @filer.__send__(__method__, ...)
|
|
10
|
+
|
|
11
|
+
def cp(...) = @filer.__send__(__method__, ...)
|
|
12
|
+
|
|
13
|
+
def export(...) = @launcher.__send__(__method__, ...)
|
|
14
|
+
|
|
15
|
+
def exec(...) = @launcher.__send__(__method__, ...)
|
|
16
|
+
end
|
|
17
|
+
end
|