Git Product home page Git Product logo

ocra's Introduction

ocran

home :: https://github.com/largo/ocran/

issues :: http://github.com/largo/ocran/issues

Description

OCRAN (One-Click Ruby Application Next) builds Windows executables from Ruby source code. The executable is a self-extracting, self-running executable that contains the Ruby interpreter, your source code and any additionally needed ruby libraries or DLL.

OCRAN is a fork of Ocra (https://github.com/larsch/ocra) in order to maintain compatibility with newer Ruby versions after 2.6

Recommended usage

Most commonly you will needs this, when you want to ship your program to windows servers / users that don't have Ruby installed. By default each time the .exe is opened it will extract the ruby interpeter along with the code to the temp directory. Since this process takes time, we recommend using the innosetup edition which will install your program together with the ruby intepreter into a directory.

Features

  • LZMA Compression (optional, default on)
  • Both windowed/console mode supported
  • Includes gems based on usage, or from a Bundler Gemfile

Problems & Bug Reporting

  • Windows support only

If you experience problems with OCRAN or have found a bug, please use the issue tracker on GitHub (http://github.com/largo/ocran/issues).

Safety

As this gem comes with binaries, we have taken actions to insure your safety. The gem releases are built on Github Actions. Feel free verify that it matches the version on rubygems. It ships with seb.exe and LZMA.exe in this repository, which come from official sources.

Installation

Gem:

gem install ocran

Alternatively you can download the gem at either http://rubygems.org/gems/ocran or https://github.com/largo/ocran/releases/.

Stand-alone Version: Get ocransa.rb from https://github.com/largo/ocran/releases/. Requires nothing but a working Ruby installation on Windows.

Synopsis

Building an executable:

ocran script.rb

Will package script.rb, the Ruby interpreter and all dependencies (gems and DLLs) into an executable named script.exe.

Command line:

ocran [options] script.rb [<other files> ...] [-- <script arguments> ...]

Options:

ocran --help

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+)

--[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.)

Gem modes:

  • 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

File groups:

  • 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.  

Compilation:

  • OCRAN will load your script (using Kernel#load) and build the executable when it exits.

  • Your program should 'require' all necessary files when invoked without arguments, so OCRAN can detect all dependencies.

  • DLLs are detected automatically but only those located in your Ruby installation are included.

  • .rb files will become console applications. .rbw files will become windowed application (without a console window popping up). Alternatively, use the --console or --windows options.

Running your application:

  • The 'current working directory' is not changed by OCRAN when running your application. You must change to the installation or temporary directory yourself. See also below.
  • When the application is running, the OCRAN_EXECUTABLE environment variable points to the .exe (with full path).
  • The temporary location of the script can be obtained by inspected the $0 variable.
  • OCRAN does not set up the include path. Use $:.unshift File.dirname($0) at the start of your script if you need to 'require' additional source files from the same directory as your main script.

Pitfalls:

  • Avoid modifying load paths at run time. Specify load paths using -I or RUBYLIB if you must, but don't expect OCRAN to preserve them for runtime. OCRAN may pack sources into other directories than you expect.
  • If you use .rbw files or the --windows option, then check that your application works with rubyw.exe before trying with OCRAN.
  • Avoid absolute paths in your code and when invoking OCRAN.

REQUIREMENTS:

  • Windows
  • Working Ruby installation.
  • Ruby Installation with devkit from rubyinstaller (when working with the source code only)

Stand-alone version

Get ocransa.rb from the github releases. Requires nothing but a working Ruby installation on Windows. (currently not supported - open an issue if you need this)

Technical details

OCRAN first runs the target script in order to detect any files that are loaded and used at runtime (Using Kernel#require and Kernel#load).

OCRAN embeds everything needed to run a Ruby script into a single executable file. The file contains the .exe stub which is compiled from C-code, and a custom opcode format containing instructions to create directories, save files, set environment variables and run programs. The OCRAN script generates this executable and the instructions to be run when it is launched.

When executed, the OCRAN stub extracts the Ruby interpreter and your scripts into a temporary directory. The directory will contains the same directory layout as your Ruby installlation. The source files for your application will be put in the 'src' subdirectory.

Libraries

Any code that is loaded through Kernel#require when your script is executed will be included in the OCRAN executable. Conditionally loaded code will not be loaded and included in the executable unless the code is actually run when OCRAN invokes your script. Otherwise, OCRAN won't know about it and will not include the source files.

RubyGems are handled specially. Whenever a file from a Gem is detected, OCRAN will attempt to include all the required files from that specific Gem, expect some unlikely needed files such as readme's and other documentation. This behaviour can be controlled by using the --gem-* options. Behaviour can be changed for all gems or specific gems using --gem-*=gemname.

Libraries found in non-standard path (for example, if you invoke OCRAN with "ruby -I some/path") will be placed into the site dir (lib/ruby/site_ruby). Avoid changing $LOAD_PATH or $: from your script to include paths outside your source tree, since OCRAN may place the files elsewhere when extracted into the temporary directory.

In case your script (or any of its dependencies) sets up autoloaded module using Kernel#autoload, OCRAN will automatically try to load them to ensure that they are all included in the executable. Modules that doesn't exist will be ignored (a warning will be logged).

Dynamic link libraries (.dll files, for example WxWidgets, or other source files) will be detected and included by OCRAN.

Including libraries non-automatically

If an application or framework is complicated enough that it tends to confuse Ocran's automatic dependency resolution, then you can use other means to specify what needs to be packaged with your app.

To disable automatic dependency resolution, use the --no-dep-run option; with it, Ocran will skip executing your program during the build process. This on the other hand requires using --gem-full option (see more below); otherwise Ocran will not include all the necessary files for the gems.

You will also probably need to use the --add-all-core option to include the Ruby core libraries.

If your app uses gems, then you can specify them in a Bundler (http://gembundler.com) Gemfile, then use the --gemfile option to supply it to Ocran. Ocran will automatically include all gems specified, and all their dependencies.

(Note: This assumes that the gems are installed in your system, not locally packaged inside the app directory by "bundle package")

These options are particularly useful for packaging Rails applications. For example, to package a Rails 3 app in the directory "someapp" and create an exe named "someapp.exe", without actually running the app during the build, you could use the following command:

ocran someapp/script/rails someapp --output someapp.exe --add-all-core \
--gemfile someapp/Gemfile --no-dep-run --gem-full --chdir-first -- server

Note the space between -- and server! It's important; server is an argument to be passed to rails when the script is ran.

Rails 2 apps can be packaged similarly, though you will have to integrate them with Bundler (http://gembundler.com/rails23.html) first.

Gem handling

By default, Ocran includes all scripts that are loaded by your script when it is run before packaging. Ocran detects which gems are using and includes any additional non-script files from those gems, except trivial files such as C/C++ source code, object files, READMEs, unit tests, specs, etc.

This behaviour can be changed by using the --gem-* options. There are four possible modes:

  • minimal: Include only loaded scripts
  • guess: Include loaded scripts and important files (DEFAULT)
  • all: Include all scripts and important files
  • full: Include all files

If you find that files are missing from the resulting executable, try first with --gem-all=gemname for the gem that is missing, and if that does not work, try --gem-full=gemname. The paranoid can use --gem-full to include all files for all required gems.

Creating an installer for your application

To make your application start up quicker, or to allow it to keep files in its application directory between runs, or if you just want to make your program seem more like a "regular" Windows application, you can have Ocran generate an installer for your app with the free Inno Setup software.

You will first have to download and install Inno Setup 5 or later, and also add its directory to your PATH (so that Ocran can find the ISCC compiler program). Once you've done that, you can use the --innosetup option to Ocran to supply an Inno Setup script. Do not add any [Files] or [Dirs] sections to the script; Ocran will figure those out itself.

To continue the Rails example above, let's package the Rails 3 app into an installer. Save the following as someapp.iss:

[Setup] AppName=SomeApp AppVersion=0.1 DefaultDirName={pf}\SomeApp DefaultGroupName=SomeApp OutputBaseFilename=SomeAppInstaller

[Icons] Name: "{group}\SomeApp"; Filename: "{app}\someapp.bat"; IconFilename: "{app}\someapp.ico"; Flags: runminimized; Name: "{group}\Uninstall SomeApp"; Filename: "{uninstallexe}"

Then, run Ocran with this command:

ocran someapp/script/rails someapp --output someapp.exe --add-all-core \
--gemfile someapp/Gemfile --no-dep-run --gem-full --chdir-first --no-lzma \
--icon someapp.ico --innosetup someapp.iss -- server

If all goes well, a file named "SomeAppInstaller.exe" will be placed into the Output directory.

Environment variables

OCRAN executables clear the RUBYLIB environment variable before your script is launched. This is done to ensure that your script does not use load paths from the end user's Ruby installation.

OCRAN executables set the RUBYOPT environment variable to the value it had when you invoked OCRAN. For example, if you had "RUBYOPT=rubygems" on your build PC, OCRAN ensures that it is also set on PC's running the executables.

OCRAN executables set OCRAN_EXECUTABLE to the full path of the executable, for example

ENV["OCRAN_EXECUTABLE"] # => C:\Program Files\MyApp\MyApp.exe

Working directory

The OCRAN executable does not change the working directory when it is launched, unless you use the --chdir-first option.

You should not assume that the current working directory when invoking an executable built with .exe is the location of the source script. It can be the directory where the executable is placed (when invoked through the Windows Explorer), the users' current working directory (when invoking from the Command Prompt), or even C:\\WINDOWS\\SYSTEM32 when the executable is invoked through a file association.

With the --chdir-first option, the working directory will always be the common parent directory of your source files. This should be fine for most applications. However, if your application is designed to run from the command line and take filenames as arguments, then you cannot use this option.

If you wish to maintain the user's working directory, but need to require additional Ruby scripts from the source directory, you can add the following line to your script:

$LOAD_PATH.unshift File.dirname($0)

Load path mangling

Adding paths to $LOAD_PATH or $: at runtime is not recommended. Adding relative load paths depends on the working directory being the same as where the script is located (See above). If you have additional library files in directories below the directory containing your source script you can use this idiom:

$LOAD_PATH.unshift File.join(File.dirname($0), 'path/to/script')

Detecting

You can detect whether OCRAN is currently building your script by looking for the 'Ocran' constant. If it is defined, OCRAN is currenly building the executable from your script. For example, you can use this to avoid opening a GUI window when compiling executables:

app = MyApp.new
app.main_loop unless defined?(Ocran)

Additional files and resources

You can add additional files to the OCRAN executable (for example images) by appending them to the command line. They should be placed in the source directory with your main script (or a subdirectory).

ocran mainscript.rb someimage.jpeg docs/document.txt

This will create the following layout in the temporary directory when your program is executed:

src/mainscript.rb
src/someimage.jpeg
src/docs/document.txt

Both files, directoriess and glob patterns can be specified on the command line. Files will be added as-is. If a directory is specified, OCRAN will include all files found below that directory. Glob patterns (See Dir.glob) can be used to specify a specific set of files, for example:

ocran script.rb assets/**/*.png

Command Line Arguments

To pass command line argument to your script (both while building and when run from the resulting executable), specify them after a -- marker. For example:

ocran script.rb -- --some-options=value

This will pass --some-options=value to the script when build and when running the executable. Any extra argument specified by the user when invoking the executable will be appended after the compile-time arguments.

Window/Console

By default, OCRAN builds console application from .rb-files and windowed applications (without console window) from .rbw-files.

Ruby on Windows provides two executables: ruby.exe is a console mode application and rubyw.exe is a windowed application which does not bring up a console window when launched using the Windows Explorer. By default, or if the --console option is used, OCRAN will use the console runtime (ruby.exe). OCRAN will automatically select the windowed runtime when your script has the ".rbw" extension, or if you specify the --windows command line option.

If your application works in console mode but not in windowed mode, first check if your script works without OCRAN using rubyw.exe. A script that prints to standard output (using puts, print etc.) will eventually cause an exception when run with rubyw.exe (when the IO buffers run full).

You can also try wrapping your script in an exception handler that logs any errors to a file:

begin
  # your script here
rescue Exception => e
  File.open("except.log") do |f|
    f.puts e.inspect
    f.puts e.backtrace
  end
end

CREDITS:

Lars Christensen and contributors for the OCRA project which this is forked from.

Kevin Walzer of codebykevin, Maxim Samsonov for ocra2, John Mair for codesigining support (to be merged)

Thanks for Igor Pavlov for the LZMA compressor and decompressor. The source code used was place into Public Domain by Igor Pavlov.

Erik Veenstra for rubyscript2exe which provided inspiration.

Dice for the default .exe icon (vit-ruby.ico, http://ruby.morphball.net/vit-ruby-ico_en.html)

LICENSE:

(The MIT License)

Copyright (c) 2009-2020 Lars Christensen Copyright (c) 2020-2023 The OCRAN Committers Team

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ocra's People

Contributors

andiidogawa avatar ccorn90 avatar davidmikesimon avatar jcangas avatar karhatsu avatar kimhmadsen avatar largo avatar larsch avatar octopushugs avatar saintpeter avatar shinokaro avatar siu avatar tac0x2a avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ocra's Issues

Failure in Automated Tests via GitHub Actions

I have noticed that our automated tests through GitHub Actions are failing. Upon reviewing the logs, a specific error has been identified as the cause.

Error Details

C:/hostedtoolcache/windows/Ruby/3.3.0/x64/lib/ruby/3.3.0/pathname.rb:534:in `relative_path_from': different prefix: "D:/" and "C:/Users/RUNNER~1/AppData/Local/Temp/.ocrantest-2784-620605354/stdoutredir" (ArgumentError)

This error occurs when attempting to calculate relative paths between different drives in a Windows environment. Specifically, the Pathname#relative_path_from method is failing to compute the relative path between a path on the D: drive and a path on the C: drive.

Proposed Solution

To resolve this issue, we need to adjust the environment settings in GitHub Actions to ensure that tests and scripts execute on the same drive. This may involve configuring GitHub Actions settings to enforce execution on a single drive.

If anyone has additional suggestions or approaches to address this problem, your feedback is highly appreciated.

Handling Paths Given to -r and -I in RUBYOPT

RUBYOPT or the --rubyopt option in OCRAN is the only way to provide Ruby startup options for executables generated by OCRAN. In the future, supporting the -r and -I options in RUBYOPT will be necessary.

In the past, OCRAN (OCRA) did nothing with the paths in RUBYOPT.

Since Ruby 3.2, Bundler sets absolute paths in RUBYOPT in a bundle exec environment. The current OCRAN detects and removes these absolute paths added by Bundler.(1369ee5)

We could replace the absolute paths in RUBYOPT with the absolute paths in the user's execution environment. However, in the user's execution environment, the paths may contain spaces, causing Ruby execution to fail.

Specifically, Ruby cannot correctly interpret quoted strings with -r or -I options in RUBYOPT. This is a Ruby issue. However, even if Ruby fixes this problem, we still need to support older versions of Ruby. We need a solution now.

Our options are:

  1. Modify the stub to allow specifying Ruby startup options (-r, -I).
  2. Modify the stub to launch Ruby and the application through a startup script built by OCRAN.

Implementing the first option requires changing the stub's source code.

The second option is already implemented in the InnoSetup builder. If complex preprocessing is required when launching the application, we can imagine a case where the application script set in OCRAN includes a "Ruby script to launch Ruby." (If we don't solve the problem now, someone will do it in the future.) If the second option works well, in the future, the significance of OCRAN providing a startup script builder will be defined as a service rather than a feature.

Note: I consider this a new feature. This functionality did not exist in OCRA.

win7 x86 support (win32)

file: a.rb ( oneline ) :

p RUBY_DESCRIPTION

C:\Users\Administrator>ocran a.rb
=== Loading script to check dependencies
"ruby 3.2.2 (2023-03-30 revision e51014f9c0) [i386-mingw32]"
...
LZMA 22.01 (x86) : Igor Pavlov : Public domain : 2022-07-15

Input size: 9667016 (9 MiB)
Output size: 2436907 (2 MiB)
=== Finished building a.exe (2485567 bytes)

C:\Users\Administrator>a.exe
This version of C:\Users\Administrator\a.exe is not compatible with the version
of Windows you're running. Check your computer's system information to see wheth
er you need a x86 (32-bit) or x64 (64-bit) version of the program, and then cont
act the software publisher.

C:\Users\Administrator>systeminfo | findstr -i type
System Type: X86-based PC

C:\Users\Administrator>ver
Microsoft Windows [Version 6.1.7601]

How to make it work with TkRuby?

Hello. It doesn't work for me with TkRuby.
Maybe someone knows how to make it work?

ruby 3.2.3 (2024-01-18 revision 52bb2ac0a6) [x64-mingw-ucrt]
tk (0.5.0)
ocran (1.3.15)

My file test_tk.rb
require 'tk' root = TkRoot.new { title "Ex1" } TkLabel.new(root) { text 'Hello, World!' pack { padx 55 ; pady 55; side 'left' } } Tk.mainloop

option 1
# ocran test_tk.rb --windows === Loading script to check dependencies === Attempting to trigger autoload of #<Class:Tk>::WinRegistry === Attempting to trigger autoload of #<Class:Tk>::ValidateConfigure === Attempting to trigger autoload of #<Class:Tk>::BinaryString === Attempting to trigger autoload of #<Class:Tk>::AUTO_PATH === Attempting to trigger autoload of #<Class:Tk>::Tile C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tk-0.5.0/lib/tk.rb:2887:in _invoke': can't invoke "font" command: application has been destroyed (RuntimeError)
from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tk-0.5.0/lib/tk.rb:2887:in _invoke' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tk-0.5.0/lib/tk.rb:1932:in _ip_invoke_core'
from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tk-0.5.0/lib/tk.rb:1965:in _tk_call_core' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tk-0.5.0/lib/tk.rb:1988:in tk_call'
from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tk-0.5.0/lib/tk/font.rb:126:in <class:TkFont>' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tk-0.5.0/lib/tk/font.rb:9:in <top (required)>'
from internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb:86:in require' from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in require'
from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tk-0.5.0/lib/tkextlib/tile.rb:293:in <module:Font>' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tk-0.5.0/lib/tkextlib/tile.rb:281:in module:Tile'
from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tk-0.5.0/lib/tkextlib/tile.rb:113:in <module:Tk>' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tk-0.5.0/lib/tkextlib/tile.rb:112:in <top (required)>'
from internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb:86:in require' from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in require'
from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:518:in const_get' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:518:in block (3 levels) in attempt_load_autoload'
from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:514:in each' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:514:in block (2 levels) in attempt_load_autoload'
from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:512:in each' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:512:in block in attempt_load_autoload'
from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:506:in loop' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:506:in attempt_load_autoload'
from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:774:in build_exe' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:1307:in block in <top (required)>'`

option 2 (compiled done but not executed)
`# ocran test_tk.rb --windows --no-autoload
=== Loading script to check dependencies
=== Using default specification C:/Ruby32-x64/lib/ruby/gems/3.2.0/specifications/default/error_highlight-0.5.1.gemspec for gem error_highlight-0.5.1
=== Detected gem error_highlight-0.5.1 (loaded, files)
=== 0 files, 0 bytes
=== Using default specification C:/Ruby32-x64/lib/ruby/gems/3.2.0/specifications/default/did_you_mean-1.6.3.gemspec for gem did_you_mean-1.6.3
=== Detected gem did_you_mean-1.6.3 (loaded, files)
=== 0 files, 0 bytes
=== Using default specification C:/Ruby32-x64/lib/ruby/gems/3.2.0/specifications/default/syntax_suggest-1.1.0.gemspec for gem syntax_suggest-1.1.0
=== Detected gem syntax_suggest-1.1.0 (loaded, files)
=== 1 files, 111 bytes
=== Detected gem ocran-1.3.15 (loaded, files)
=== 6 files, 284024 bytes
=== Detected gem tk-0.5.0 (loaded, files)
=== 415 files, 2939900 bytes
=== Including 61 encoding support files (3775488 bytes, use --no-enc to exclude)
=== Building test_tk.exe
=== Adding user-supplied source files
=== Adding ruby executable rubyw.exe
=== Adding detected DLL C:/Ruby32-x64/bin/ruby_builtin_dlls/libgmp-10.dll
=== Adding detected DLL C:/Ruby32-x64/msys64/ucrt64/bin/tk86.dll
=== Adding detected DLL C:/Ruby32-x64/msys64/ucrt64/bin/tcl86.dll
=== Adding detected DLL C:/Ruby32-x64/bin/ruby_builtin_dlls/zlib1.dll
=== Adding detected DLL C:/Ruby32-x64/bin/ruby_builtin_dlls/libffi-8.dll
=== Adding external manifest C:/Ruby32-x64/bin/ruby_builtin_dlls/ruby_builtin_dlls.manifest
=== Adding library files
=== Compressing 16729037 bytes

LZMA 22.01 (x86) : Igor Pavlov : Public domain : 2022-07-15

Input size: 16729037 (15 MiB)
Output size: 4445085 (4 MiB)
=== Finished building test_tk.exe (4492721 bytes)`

option 3
# ocran test_tk.rb --windows --no-autoload --debug === Loading script to check dependencies === Using default specification C:/Ruby32-x64/lib/ruby/gems/3.2.0/specifications/default/error_highlight-0.5.1.gemspec for gem error_highlight-0.5.1 === Detected gem error_highlight-0.5.1 (loaded, files) === 0 files, 0 bytes === Using default specification C:/Ruby32-x64/lib/ruby/gems/3.2.0/specifications/default/did_you_mean-1.6.3.gemspec for gem did_you_mean-1.6.3 === Detected gem did_you_mean-1.6.3 (loaded, files) === 0 files, 0 bytes === Using default specification C:/Ruby32-x64/lib/ruby/gems/3.2.0/specifications/default/syntax_suggest-1.1.0.gemspec for gem syntax_suggest-1.1.0 === Detected gem syntax_suggest-1.1.0 (loaded, files) === 1 files, 111 bytes === Detected gem ocran-1.3.15 (loaded, files) === 6 files, 284024 bytes === Detected gem tk-0.5.0 (loaded, files) === 415 files, 2939900 bytes === Including 61 encoding support files (3775488 bytes, use --no-enc to exclude) C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:84:in +': no implicit conversion of nil into String (TypeError)

  @path = sub(/(\.[^.]*?|)$/) { s.to_s + $1 }
                                         ^^
    from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:84:in `block in append_to_filename!'
    from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:88:in `sub'
    from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:88:in `sub'
    from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:84:in `append_to_filename!'
    from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:921:in `build_exe'
    from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:1307:in `block in <top (required)>'`

Should we support Ruby 2.x?

Should we support Ruby 2,6?
The version of RubyGems attached to Ruby2,6 is 3.0.3.1 and the following warning is reported when running tests in CI:

Your RubyGems version (3.0.3.1) has a bug that prevents `required_ruby_version` from working for Bundler.
Any scripts that use `gem install bundler` will break as soon as Bundler drops support for your Ruby version.
Please upgrade RubyGems to avoid future breakage and silence this warning by running `gem update --system 3.2.3`

Should we support Ruby 2,7?
Ruby 2.6 and 2.7 will no longer be supported from Bundler 2.5.
https://github.com/rubygems/rubygems/blob/master/bundler/CHANGELOG.md#breaking-changes
If we support Ruby 2.7, we will not be able to upgrade the version of Bundler.

Reporting Errors When Using the `--innosetup` Option

When using the --innosetup option, the following error message is reported by ISCC:

Error in C:\Users\(my project folder)\ocrantemp.iss: the process cannot access the file because it is being used by another process.

ocran/bin/ocran

Line 1184 in 0ace7ed

f.close()

Here, the IO to the ocrantemp.iss file is being closed, but it seems that Ruby has not released the file yet.
※ After adding GC.start right after this line of code, ISCC continued to execute.

If execution is continued, the following error is reported by ISCC:

Error on line 509 in C:\Users\(my project folder)\ocrantemp.iss: Source file "C:/Users/(user name)/AppData/Local/Temp/msys-2.0.dll20231003-14956-sga45n" does not exist.

Cool

A great fork of the ocra library for new ruby version!

Eliminating the --no-lzma option

I propose making LZMA compression a default feature of stub, which means eliminating the --no-lzma option.
Even when using InnoSetup, the state of the --no-lzma option had no impact on the actual application startup behavior before the fork from OCRA.
I cannot find any practical scenarios where an uncompressed mode in stub is necessary.
Does anyone require the --no-lzma option?

Compiled done but when executed :(

internal:C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb:85:in require': 126: The specified module could not be found. - C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/lib/ruby/3.2.0/x64-mingw-ucrt/openssl.so (LoadError) from <internal:C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in require'
from C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/lib/ruby/3.2.0/openssl.rb:13:in <top (required)>' from <internal:C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in require'
from internal:C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb:85:in require' from C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/gemhome/gems/httparty-0.21.0/lib/httparty/connection_adapter.rb:211:in attach_ssl_certificates'
from C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/gemhome/gems/httparty-0.21.0/lib/httparty/connection_adapter.rb:117:in connection' from C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/gemhome/gems/httparty-0.21.0/lib/httparty/connection_adapter.rb:80:in call'
from C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/gemhome/gems/httparty-0.21.0/lib/httparty/request.rb:197:in http' from C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/gemhome/gems/httparty-0.21.0/lib/httparty/request.rb:154:in perform'
from C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/gemhome/gems/httparty-0.21.0/lib/httparty.rb:612:in perform_request' from C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/gemhome/gems/httparty-0.21.0/lib/httparty.rb:542:in post'
from C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/gemhome/gems/httparty-0.21.0/lib/httparty.rb:649:in post' from C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/src/learn.rb:56:in block in

'
from C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/src/learn.rb:44:in each' from C:/Users/zd/AppData/Local/Temp/ocr7BD9.tmp/src/learn.rb:44:in '

The converted in .exe game doesn't launching

Hi, I tried to convert this game https://github.com/dtcristo/raycaster in standalone executable and got this:
C:/Users/usr/AppData/Local/Temp/ocr474E.tmp/gemhome/gems/gosu-1.4.6/lib/gosu/compat.rb:71:in 'initialize': While opening C:/Users (RuntimeError)ocal/Temp/ocr474E.tmp/assets/texture.png, the following error occured: The system cannot find the path specified.
from C:/Users/usr/AppData/Local/Temp/ocr474E.tmp/gemhome/gems/gosu-1.4.6/lib/gosu/compat.rb:71:in 'initialize'
from C:/Users/usr/AppData/Local/Temp/ocr474E.tmp/src/raycaster/camera.rb:14:in 'new'
from C:/Users/usr/AppData/Local/Temp/ocr474E.tmp/src/raycaster/camera.rb:14:in 'initialize'
from C:/Users/usr/AppData/Local/Temp/ocr474E.tmp/src/raycaster/window.rb:12:in 'new'
from C:/Users/usr/AppData/Local/Temp/ocr474E.tmp/src/raycaster/window.rb:12:in 'initialize'
from C:/Users/usr/AppData/Local/Temp/ocr474E.tmp/src/raycaster.rb:13:in 'new'
from C:/Users/usr/AppData/Local/Temp/ocr474E.tmp/src/raycaster.rb:13:in '

'

The .rb file itself was converted successfully.

not work --debug flag.

img

builder code:

path = "C:/Users/pc/Desktop/project/fautom"

# Find the location of the ruby2d gem
ruby2d_gem_path = `gem which ruby2d`.chomp

# If the gem location is not found, specify the path manually
if ruby2d_gem_path.empty?
  ruby2d_gem_path = "C:/path/to/ruby2d/gem"  # Replace with the actual path
end

# Use the full path to the ruby2d gem in the Ocra command
system("ocran #{path}/src/main.rbw --debug --gem-full #{ruby2d_gem_path} --no-dep-run")

# Move the compiled executable to the build directory
system("mv #{path}/src/main.exe #{path}/build/fautom.exe")

Error by ocran:

C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:84:in `+': no implicit conversion of nil into String (TypeError)

      @path = sub(/(\.[^.]*?|)$/) { s.to_s + $1 }
                                             ^^
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:84:in `block in append_to_filename!'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:88:in `sub'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:88:in `sub'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:84:in `append_to_filename!'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:921:in `build_exe'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/ocran-1.3.15/bin/ocran:1307:in `block in <top (required)>'

maybe, i'm stupid ://

`--icon src\app.ico` results in opcode error, without the setting build goes fine.

when setting an icon the exe gets an icon only i get an opcode error, without the icon it works just fine.

When building a app like so on windows 11

bundle exec ocran `
  --windows `
  --add-all-core `
  --no-lzma `
  --icon src\app.ico `
  --output icon-true.exe `
  src\window.rb

The app has the nice icon, only when starting you get this error

image

When building without the icon it all works fine, except for the icon obviously.

bundle exec ocran `
  --windows `
  --add-all-core `
  --no-lzma `
  --output icon-false.exe `
  src\window.rb

No icon, all is fine

image

Environment

MBP m2 max
UTM (https://mac.getutm.app/) running Windows 11 for Apple silicon
ruby: Ruby+Devkit 3.0.6-1 (x64) (https://rubyinstaller.org/downloads/)

window.rb

just a small file to see how glimmer would work with ocran.

require 'glimmer-dsl-libui'

include Glimmer


window('hello world', 300, 200, true) {
  on_closing do
    puts 'Bye Bye'
  end
}.show

Refactoring of stub.c

@Largo

The implementation of stub.c had security issues, such as the use of strcat with fixed-length buffers, and the code complexity made it difficult to review partial fixes due to the mixture of TCHAR and char types.

I spent a month thoroughly understanding stub.c and its design, and I have been refactoring stub.exe to make it secure and the code more readable. The refactoring follows these guidelines:

  • Use char type for string operations because the archive path strings are in UTF-8, allowing for paths with multibyte characters.
  • Use heap memory for file path operations to prevent buffer overflows, enabling support for paths longer than MAX_PATH.
  • Improve the archive data format to be more secure and compact.

This effort is still ongoing, but the implementation of stub has become safer than before. However, several more changes are needed to complete the secure implementation.

stub.c compiles successfully with Mingw32 and Mingw64 on Windows. Please let me know if there are any compilation issues with Wine.

lzma.exe: 4: Syntax error: Unterminated quoted string

I use ocran script.rb --no-autodll on my Linux computer to package this code in script.rb:

exit if defined?(Ocran)
STDIN.readchar

I get this output with an error:

/home/sergioro/.rvm/gems/ruby-3.0.3/gems/ocran-1.3.13/bin/ocran:20: warning: already initialized constant File::ALT_SEPARATOR
=== Loading script to check dependencies
=== Using default specification /home/sergioro/.rvm/rubies/ruby-3.0.3/lib/ruby/gems/3.0.0/specifications/default/did_you_mean-1.5.0.gemspec for gem did_you_mean-1.5.0
=== Detected gem did_you_mean-1.5.0 (loaded, files)
=== 	0 files, 0 bytes
=== Detected gem executable-hooks-1.6.1 (loaded, files)
=== 	11 files, 6366 bytes
=== Detected gem bundler-unload-1.0.2 (loaded, files)
=== 	4 files, 1683 bytes
=== Detected gem rubygems-bundler-1.4.5 (loaded, files)
=== 	7 files, 6035 bytes
=== Using default specification /home/sergioro/.rvm/rubies/ruby-3.0.3/lib/ruby/gems/3.0.0/specifications/default/bundler-2.2.32.gemspec for gem bundler-2.2.32
=== Detected gem bundler-2.2.32 (loaded, files)
=== 	2 files, 1572 bytes
=== Using default specification /home/sergioro/.rvm/rubies/ruby-3.0.3/lib/ruby/gems/3.0.0/specifications/default/pathname-0.1.0.gemspec for gem pathname-0.1.0
=== Detected gem pathname-0.1.0 (loaded, files)
=== 	0 files, 0 bytes
=== Detected gem ocran-1.3.13 (loaded, files)
=== 	5 files, 283329 bytes
=== Using default specification /home/sergioro/.rvm/rubies/ruby-3.0.3/lib/ruby/gems/3.0.0/specifications/default/set-1.0.1.gemspec for gem set-1.0.1
=== Detected gem set-1.0.1 (loaded, files)
=== 	0 files, 0 bytes
=== Including 61 encoding support files (8258520 bytes, use --no-enc to exclude)
=== Building script.exe
=== Adding user-supplied source files
=== Adding ruby executable ruby
=== Adding library files
=== Compressing 22785963 bytes
/home/sergioro/.rvm/gems/ruby-3.0.3/gems/ocran-1.3.13/share/ocran/lzma.exe: 1: MZ����@��: not found
/home/sergioro/.rvm/gems/ruby-3.0.3/gems/ocran-1.3.13/share/ocran/lzma.exe: 4: Syntax error: Unterminated quoted string
/home/sergioro/.rvm/gems/ruby-3.0.3/gems/ocran-1.3.13/bin/ocran:1141:in `block in initialize': unhandled exception
	from /home/sergioro/.rvm/gems/ruby-3.0.3/gems/ocran-1.3.13/bin/ocran:1116:in `open'
	from /home/sergioro/.rvm/gems/ruby-3.0.3/gems/ocran-1.3.13/bin/ocran:1116:in `initialize'
	from /home/sergioro/.rvm/gems/ruby-3.0.3/gems/ocran-1.3.13/bin/ocran:894:in `new'
	from /home/sergioro/.rvm/gems/ruby-3.0.3/gems/ocran-1.3.13/bin/ocran:894:in `build_exe'
	from /home/sergioro/.rvm/gems/ruby-3.0.3/gems/ocran-1.3.13/bin/ocran:1279:in `block in <top (required)>'

What might be causing this error? I suspect the error happens because I am using ocran in a linux. Is ocran supposed to run only in Windows?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.