[macruby-changes] [560] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Sep 5 18:05:12 PDT 2008
Revision: 560
http://trac.macosforge.org/projects/ruby/changeset/560
Author: lsansonetti at apple.com
Date: 2008-09-05 18:05:11 -0700 (Fri, 05 Sep 2008)
Log Message:
-----------
adding new IB parser
Modified Paths:
--------------
MacRuby/trunk/instruby.rb
Added Paths:
-----------
MacRuby/trunk/bin/rb_nibtool
Added: MacRuby/trunk/bin/rb_nibtool
===================================================================
--- MacRuby/trunk/bin/rb_nibtool (rev 0)
+++ MacRuby/trunk/bin/rb_nibtool 2008-09-06 01:05:11 UTC (rev 560)
@@ -0,0 +1,159 @@
+#!/usr/bin/env ruby
+# This script is called by Interface Builder. Do not touch it unless you
+# really know what you're doing.
+#
+# This file is covered by the Ruby license.
+#
+# Copyright (C) 2008, Apple Inc
+
+require 'optparse'
+require 'ripper/filter'
+
+framework 'Foundation'
+
+class NibPlistGenerator < Ripper::Filter
+
+ DOES_NOTHING =
+ "This option does nothing, it's there for backward compatibility"
+
+ def self.new(argv)
+ file = nil
+ OptionParser.new do |opts|
+ opts.banner = "Usage: #{__FILE__} [options]"
+ opts.on('-p', '--plist', DOES_NOTHING) {}
+ opts.on('-s', '--sorted-plist', DOES_NOTHING) {}
+ opts.on('-f', '--file PATH', 'Path to Ruby file') do |_file|
+ file = case _file
+ when '' then nil
+ when '-' then '/dev/stdin'
+ else _file
+ end
+ end
+ opts.on('-h', '--help', 'Print this message') { fail opts }
+ begin
+ opts.parse!(argv)
+ rescue OptionParser::InvalidOption => e
+ puts e
+ fail opts
+ end
+ fail opts if file.nil?
+ end
+
+ o = super(File.read(file)); o.parse(nil); o
+ end
+
+ def dump(io)
+ h = {}
+ h['IBClasses'] = @ib_classes.map do |k|
+ { 'CLASS' => k.name,
+ 'LANGUAGE' => 'Ruby',
+ 'OUTLETS' => k.outlets,
+ 'ACTIONS' => k.actions,
+ 'SUPERCLASS' => k.super }
+ end
+ unless d = NSPropertyListSerialization.dataFromPropertyList(h,
+ format:NSPropertyListXMLFormat_v1_0, errorDescription:nil)
+ $stderr.puts "Cannot serialize #{h} as a plist"
+ exit 1
+ end
+ io.write NSString.alloc.initWithData(d, encoding:NSUTF8StringEncoding)
+ end
+
+ private
+
+ def fail(opts); puts opts; exit 1; end
+
+ class IBClass
+ attr_accessor :name, :super, :outlets, :actions
+ def initialize(name)
+ @name = name
+ @super = 'NSObject'
+ @outlets = []
+ @actions = []
+ end
+ end
+
+ def on_default(event, token, data)
+ @token_n ||= 0
+
+ return token if event == :on_sp
+
+ p @token_n, event, token, data, '---' if $DEBUG
+
+ if event == :on_kw
+ if token == 'class'
+ @def_class = true
+ elsif token == 'def'
+ @def_method = true
+ end
+
+ elsif event == :on_const
+ if @def_class
+ @def_class = nil
+ @waiting_for_superclass = @token_n
+ (@ib_classes ||= []) << @current_class = IBClass.new(token)
+
+ elsif @waiting_for_superclass
+ raise "current_class undefined" unless @current_class
+ @current_class.super = token
+ end
+
+ elsif event == :on_ident
+ if token == 'attr_accessor' or token == 'attr_writer' \
+ or token == 'ib_outlet' or token == 'ib_outlets'
+ @waiting_for_outlet = @token_n
+
+ elsif @waiting_for_outlet
+ raise "current_class undefined" unless @current_class
+ @current_class.outlets << token
+ @waiting_for_outlet += 1 # maybe another outlet is coming...
+
+ elsif @def_method
+ @def_method = nil
+ @current_method = token
+ @waiting_for_method_end = @token_n
+ @on_def_method_paren = 0
+ end
+ end
+
+ if @waiting_for_superclass and @token_n != @waiting_for_superclass
+ if event == :on_op and token == '<'
+ @waiting_for_superclass += 1
+ else
+ @waiting_for_superclass = nil
+ end
+ end
+
+ if @waiting_for_outlet and @token_n != @waiting_for_outlet
+ if (event == :on_symbeg and token == ':') \
+ or (event == :on_comma and token == ',')
+ @waiting_for_outlet += 1
+ else
+ @waiting_for_outlet = nil
+ end
+ end
+
+ if @waiting_for_method_end and @token_n != @waiting_for_method_end
+ if event == :on_lparen
+ @on_def_method_paren += 1
+ @waiting_for_method_end += 1
+ elsif event == :on_rparen
+ @on_def_method_paren -= 1
+ @waiting_for_method_end += 1
+ elsif event == :on_ident and token == 'sender'
+ @waiting_for_method_end += 1
+ elsif event == :on_nl or event == :on_ignored_nl \
+ or event == :on_semicolon or event == :on_comment
+ @current_class.actions << @current_method
+ else
+ @waiting_for_method_end = nil
+ end
+ end
+
+ @token_n += 1
+ token
+ end
+end
+
+gen = NibPlistGenerator.new(ARGV)
+gen.dump(STDOUT)
Property changes on: MacRuby/trunk/bin/rb_nibtool
___________________________________________________________________
Added: svn:executable
+ *
Modified: MacRuby/trunk/instruby.rb
===================================================================
--- MacRuby/trunk/instruby.rb 2008-09-05 23:10:45 UTC (rev 559)
+++ MacRuby/trunk/instruby.rb 2008-09-06 01:05:11 UTC (rev 560)
@@ -305,9 +305,15 @@
for src in Dir["bin/*"]
next unless File.file?(src)
next if /\/[.#]|(\.(old|bak|orig|rej|diff|patch|core)|~|\/core)$/i =~ src
+
+ bname = File.basename(src)
+ name = case bname
+ when 'hotcocoa', 'rb_nibtool'
+ bname
+ else
+ ruby_install_name.sub(/ruby/, bname)
+ end
- name = (File.basename(src) == "hotcocoa" ? "hotcocoa" : ruby_install_name.sub(/ruby/, File.basename(src)))
-
shebang = ''
body = ''
open(src, "rb") do |f|
@@ -475,6 +481,8 @@
mkdir_p dest_bin, :mode => 0755
Dir.entries(with_destdir(CONFIG['bindir'])).each do |bin|
next if bin[0] == '.'
+ # Except rb_nibtool!
+ next if bin == 'rb_nibtool'
link = File.join("../../../", CONFIG['bindir'], bin)
link.sub!(/#{MACRUBY_VERSION}/, 'Current')
ln_sfh link, File.join(dest_bin, File.basename(bin))
@@ -501,6 +509,12 @@
end
end
+puts "installing IB support"
+ib_dest = '/Developer/usr/bin'
+mkdir_p ib_dest
+install('bin/rb_nibtool', ib_dest, :mode => $prog_mode)
+install('tool/rb_nibtool.old', ib_dest, :mode => $prog_mode)
+
touch_file = '/System/Library/Frameworks/.bridgesupport_dylib_gcmarked'
if $destdir.empty? and File.exist?(touch_file)
puts "bridge support dylibs already fixed"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080905/23b81e34/attachment-0001.html
More information about the macruby-changes
mailing list