gem ocra生成巨大的文件

时间:2015-02-02 08:31:46

标签: ruby gem filesize ocra

我创建了一个简单的ruby脚本

require 'gtk3'

def destroy( widget )
   Gtk.main_quit
end

Gtk.init
window = Gtk::Window.new :toplevel
window.set_title( "helloworld.rb" )
window.set_border_width( 10 )

window.signal_connect( "delete_event" ) {
   destroy(nil)
}

button = Gtk::Button.new :label => "Button"
window.add( button )
button.show
window.show
Gtk.main

此脚本使用按钮创建一个非常简单的GUI。如果我使用ocra gem使用命令

创建script.exe
ocra script.rbw

生成一个70 MB的文件,大小太大,不适合带按钮的简单窗口。 我究竟做错了什么?我可以做些什么来协调这个障碍? Ocra输出是这个(输出命令" ocra script.rb"而不是" ocra script.rbw",但过程是相同的)

=== Loading script to check dependencies
=== Attempting to trigger autoload of Gem::ConfigFile
=== Attempting to trigger autoload of Gem::DependencyList
=== Attempting to trigger autoload of Gem::DependencyResolver
=== Attempting to trigger autoload of Gem::Installer
=== Attempting to trigger autoload of Gem::RequestSet
=== Attempting to trigger autoload of Gem::Source
=== Attempting to trigger autoload of Gem::SourceList
=== Attempting to trigger autoload of Gem::SpecFetcher
=== Attempting to trigger autoload of CGI::HtmlExtension
=== Detected gem ocra-1.3.4 (loaded, files)
===     6 files, 191218 bytes
=== Detected gem pkg-config-1.1.6 (loaded, files)
===     3 files, 29263 bytes
=== Detected gem cairo-1.14.1-x64-mingw32 (loaded, files)
===     572 files, 80204194 bytes
=== Detected gem glib2-2.2.4-x64-mingw32 (loaded, files)
===     2115 files, 104593625 bytes
=== Detected gem gobject-introspection-2.2.4-x64-mingw32 (loaded, files)
===     231 files, 13768036 bytes
=== Detected gem gio2-2.2.4-x64-mingw32 (loaded, files)
===     3 files, 49152 bytes
=== Detected gem atk-2.2.4-x64-mingw32 (loaded, files)
===     208 files, 4281497 bytes
=== Detected gem pango-2.2.4-x64-mingw32 (loaded, files)
===     465 files, 95081429 bytes
=== Detected gem gdk_pixbuf2-2.2.4-x64-mingw32 (loaded, files)
===     188 files, 5588250 bytes
=== Detected gem cairo-gobject-2.2.4-x64-mingw32 (loaded, files)
===     5 files, 95261 bytes
=== Detected gem gdk3-2.2.4-x64-mingw32 (loaded, files)
===     3841 files, 114129504 bytes
=== Detected gem gtk3-2.2.4-x64-mingw32 (loaded, files)
===     42 files, 2942499 bytes
=== Detected gem io-console-0.4.2 (loaded, files)
=== WARNING: Gem io-console-0.4.2 root folder was not found, skipping
=== Including 53 encoding support files (3576320 bytes, use --no-enc to exclude)

DL is deprecated, please use Fiddle
=== Building example.exe
=== Adding user-supplied source files
=== Adding ruby executable ruby.exe
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/cairo-1.14.1-x64-
mingw32/vendor/local/bin/libcairo-2.dll
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/cairo-1.14.1-x64-
......
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/gdk_pixbuf2-2.2.4
-x64-mingw32/vendor/local/bin/libgdk_pixbuf-2.0-0.dll
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/gdk3-2.2.4-x64-mi
ngw32/vendor/local/bin/libgdk-3-0.dll
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/gdk3-2.2.4-x64-mi
ngw32/vendor/local/bin/libgtk-3-0.dll
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/pango-2.2.4-x64-m
ingw32/vendor/local/lib/pango/1.8.0/modules/pango-basic-win32.dll
=== Adding detected DLL C:/Ruby21-x64/bin/LIBEAY32.dll
=== Adding detected DLL C:/Ruby21-x64/bin/SSLEAY32.dll
=== Adding library files
=== Compressing 519431948 bytes
=== Finished building example.exe (95218080 bytes)

我使用cli script.rb

尝试相同的过程
puts "Hello World"

结果:2,6 Mb仅打印Hello World。 我该怎么办?

1 个答案:

答案 0 :(得分:2)

Ocra不是一个编译器,它是一种准备运行的红宝石。它需要ruby,所有加载的宝石和脚本并将它们打包在一起。

当你调用exe时,它会提取所有内容并使用包含的ruby调用ruby脚本。脚本执行后删除所有内容。如果您的脚本失败,则不会删除,并且您在临时目录中找到了大量文件。

require 'gtk3'的情况下,加载了gtk3支持的所有内容。这似乎很多。

你的 Hello World 的2.6MB不仅包含屏幕输出,而是ruby能够做的所有事情 - 即使它没有被执行,

你能做什么?试着找到一个不需要这么多的版本。