Skip to content

Commit

Permalink
Created
Browse files Browse the repository at this point in the history
  • Loading branch information
larsch committed Apr 5, 2009
0 parents commit 9b27187
Show file tree
Hide file tree
Showing 15 changed files with 2,224 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .autotest
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- ruby -*-

require 'autotest/restart'

# Autotest.add_hook :initialize do |at|
# at.extra_files << "../some/external/dependency.rb"
#
# at.libs << ":../some/external"
#
# at.add_exception 'vendor'
#
# at.add_mapping(/dependency.rb/) do |f, _|
# at.files_matching(/test_.*rb$/)
# end
#
# %w(TestA TestB).each do |klass|
# at.extra_class_map[klass] = "test/test_misc.rb"
# end
# end

# Autotest.add_hook :run_command do |at|
# system "rake build"
# end
6 changes: 6 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== 1.0.0 / 2009-04-05

* 1 major enhancement

* Birthday!

7 changes: 7 additions & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
History.txt
Manifest.txt
README.txt
Rakefile
bin/ocra
lib/ocra.rb
test/test_ocra.rb
48 changes: 48 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
= ocra

* FIX (url)

== DESCRIPTION:

FIX (describe your package)

== FEATURES/PROBLEMS:

* FIX (list of features or problems)

== SYNOPSIS:

FIX (code sample of usage)

== REQUIREMENTS:

* FIX (list of requirements)

== INSTALL:

* FIX (sudo gem install, anything else)

== LICENSE:

(The MIT License)

Copyright (c) 2009 FIX

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.
27 changes: 27 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- ruby -*-

require 'rubygems'
require 'hoe'
require './lib/ocra.rb'

Hoe.new('ocra', Ocra::VERSION) do |p|
# p.rubyforge_name = 'ocrax' # if different than lowercase project name
p.developer('Lars Christensen', '[email protected]')
end


file 'share/ocra/stub.exe' => 'src/stub.exe' do
mv 'src/stub.exe', 'share/ocra/stub.exe'
end

file 'src/stub.exe' do
chdir 'src' do
system("mingw32-make")
end
end

task :stub => 'share/ocra/stub.exe'

task :test => :stub

# vim: syntax=Ruby
155 changes: 155 additions & 0 deletions bin/ocra.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#!/usr/bin/env ruby
# -*- ruby -*-

$lzma_mode = true
$extra_dlls = []
$files = []

usage = <<EOF
ocra [--dll dllname] [--no-lzma] script.rb
--dll dllname Include additional DLLs from the Ruby bindir.
--no-lzma Disable LZMA compression of the executable.
--quiet Suppress output.
--help Display this information.
EOF

while arg = ARGV.shift
case arg
when /\A--(no-)?lzma\z/
$lzma_mode = !$1
when /\A--dll\z/
$extra_dlls << ARGV.shift
when /\A--quiet\z/
$quiet = true
when /\A--help\z/, /\A--/
puts usage
exit
else
$files << arg
end
end

if $files.empty?
puts usage
exit
end

if defined? Gem
puts "=== Warning: Rubygems is loaded. Rubygems will be included the archive."
puts " RUBYOPT=#{ENV['RUBYOPT']}"
end

puts "=== Loading script to check dependencies" unless $quiet
load $files[0]
libs = $LOADED_FEATURES.map { |scr|
sp = $:.find { |path| File.file?(File.join(path, scr)) }
[scr, sp]
}

if defined?(DATA)
$sebimage = DATA.read(DATA.readline.to_i).unpack("m")[0]
$lzmaimage = DATA.read(DATA.readline.to_i).unpack("m")[0]
$lzmapath = File.join(ENV['TEMP'], 'lzma.exe').tr('/','\\')
puts $lzmapath
puts $lzmaimage.size
File.open($lzmapath, "wb") { |f| f << $lzmaimage }
else
$sebimage = File.open(File.join(File.dirname(__FILE__), '../share/ocra/stub.exe'), "rb") { |f| f.read }
$lzmapath = File.join(File.dirname(__FILE__), '../share/ocra/lzma.exe')
raise "lzma.exe not found" unless File.exist?($lzmapath)
end
# $sebimage = File.open("seb.exe", "rb") { |f| f.read }

require 'rbconfig'
bindir = RbConfig::CONFIG['bindir']
libruby_so = RbConfig::CONFIG['LIBRUBY_SO']

Signature = [0x41, 0xb6, 0xba, 0x4e]
OP_END = 0
OP_CREATE_DIRECTORY = 1
OP_CREATE_FILE = 2
OP_CREATE_PROCESS = 3
OP_DECOMPRESS_LZMA = 4

class SebBuilder
def initialize(path)
@paths = {}
File.open(path, "wb") do |f|
f.write($sebimage)
if $lzma_mode
@of = ""
else
@of = f
end
yield(self)

if $lzma_mode
File.open("tmpin", "wb") { |tmp| tmp.write(@of) }
system("#{$lzmapath} e tmpin tmpout 2>NUL") or fail
@c = File.open("tmpout", "rb") { |tmp| tmp.read }
f.write([OP_DECOMPRESS_LZMA, @c.size, @c].pack("VVA*"))
f.write([OP_END].pack("V"))
else
f.write(@of) if $lzma_mode
end

f.write([OP_END].pack("V"))
f.write([$sebimage.size].pack("V"))
f.write(Signature.pack("C*"))
end
end
def mkdir(path)
@paths[path] = true
puts "m #{path}" unless $quiet
@of << [OP_CREATE_DIRECTORY, path].pack("VZ*")
end
def ensuremkdir(tgt)
return if tgt == "."
if not @paths[tgt]
ensuremkdir(File.dirname(tgt))
mkdir(tgt)
end
end
def createfile(src, tgt)
ensuremkdir(File.dirname(tgt))
str = File.open(src, "rb") { |s| s.read }
puts "a #{tgt}" unless $quiet
@of << [OP_CREATE_FILE, tgt, str.size, str].pack("VZ*VA*")
end
def createprocess(image, cmdline)
@of << [OP_CREATE_PROCESS, image, cmdline].pack("VZ*Z*")
end
def close
@of.close
end
end


executable = $files[0].sub(/(\.rb)?$/, '.exe')

puts "=== Building #{executable}" unless $quiet
SebBuilder.new(executable) do |sb|
sb.mkdir('src')
sb.createfile($files[0], 'src\\' + $files[0])
sb.mkdir('bin')
sb.createfile(File.join(bindir, "ruby.exe"), "bin\\ruby.exe")
sb.createfile(File.join(bindir, libruby_so), "bin\\msvcrt-ruby18.dll")
$extra_dlls.each { |dll|
sb.createfile(File.join(bindir, dll), File.join("bin", dll).tr('/','\\'))
}

libs.each { |path, tgt|
jn = File.join(tgt, path)
if jn =~ /\/(lib\/ruby\/.*)$/
dst = $1
else
dst = tgt
end
dst.tr!('/', '\\')
sb.createfile(jn, dst)
}

sb.createprocess("bin\\ruby.exe", "ruby.exe \xff\\src\\" + $files[0])
end
puts "=== Finished (Final size was #{File.size(executable)})" unless $quiet
3 changes: 3 additions & 0 deletions lib/ocra.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Ocra
VERSION = '1.0.0'
end
Binary file added share/ocra/lzma.exe
Binary file not shown.
14 changes: 14 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SRCS = stub.c lzma/lzmadec.c
OBJS = $(SRCS:.c=.o)
CC = gcc

CFLAGS = -Wall -O2 -DWITH_LZMA -Ilzma
# CFLAGS += -D_DEBUG

all: stub.exe

stub.exe: $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -s -o stub

clean:
rm $(OBJS)
Loading

0 comments on commit 9b27187

Please sign in to comment.