Buildr ruby error, can't convert Rake::FileTask into String - ruby

I have the following buildr buildfile segment:
require "buildr/protobuf"
....
define "protobuf-stuff" do
pbs = protoc(
Dir[_("pbsrc/some/pkg/*.proto")], {
:include => [_("pbsrc")],
})
comp = compile.from(pbs).with(PROTOBUF_LIB) # MARK
package :jar
end
Buildr is 1.4.4, installed with the Linux install script on two machnies.
Machine 1: Debian 32bit, ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
Machine 2: Ubuntu 64bit, ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
Machine 1 compiles everything file. Machine 2 fails on the MARK-ed place, with
Buildr aborted!
TypeError : can't convert Rake::FileTask into String
/usr/lib/ruby/gems/1.8/gems/buildr-1.4.4/lib/buildr/core/application.rb:414:in `raw_load_buildfile'
/usr/lib/ruby/gems/1.8/gems/buildr-1.4.4/lib/buildr/core/application.rb:218:in `load_buildfile'
/usr/lib/ruby/gems/1.8/gems/buildr-1.4.4/lib/buildr/core/application.rb:213:in `load_buildfile'
Now I can see that pbs is a FileTask and not a string.. but how come one machine accepts it, the other not? Is there a forced conversion to String?
Some buildr traces are attached at http://pastebin.com/nf4HiYx9 .
Thank you.

The stacktrace on pastebin is very different from the stacktrace pasted here, from what I can see.
Where is the protoc method defined ? Is it part of Buildr core ?
The reason why it fails on one machine and not the other might be the version of Ruby you have, given that the line that fails is "if File.exist? path". path there is supposed to be a String, but is probably converted to a String in one case but not the other.
The overall fix is to add a call after calling protoc(...), protoc(...).map(&:to_s).
I hope this helped.

I figured that adding .to_s helps and everything is fine. But I could appreciate an answer telling where exactly the implicit conversion was lost, and why is it good (if so).
/from my earlier comment/

Related

Validating ruby installation after install?

I've installed Ruby 2.1.1 via source.
I've seen suggestions to type ruby -v, which I assume would show that the binary isn't corrupted, but are there more comprehensive ways to ensure that it's working as expect? Unit-tests, benchmarks, etc to validate it's functional?
Run make test after compiling in the directory you’ve compiled in. (This might actually happen by default, I can’t remember. There’s also make test-all, among others.)
ruby -v will show you the current version of ruby installed on your machine.
If you want, just create a hello.rb with puts "hello" and run it using ruby hello.rb to check if it is interpreting the ruby code correctly. So you know that its functional.

get specification of executed gem from within

I have build a gem and want it to print its version.
I cant use Gem::Specification.find_by_name('mygem').version
because there are several versions of it installed.
Lets just say my program has just a single src file /bin/myruby containing this:
#!/usr/bin/env ruby
mygem_version = ???
puts "This is my gems version: #{mygem_version}"
A common convention is to create a lib/<your_gem_name>/version.rb that defines a YourGemName::VERSION constant. Then, you can refer to that constant in your gemspec, which is Ruby code that gets evaluated when the gem is built.
Read http://timelessrepo.com/making-ruby-gems for a guide that uses this approach.
If you're using Bundler (think rails), try
Bundler.definition.specs
else, make sure your gem has a VERSION constant you can ask these things
This worked for me and always returned the correct version.
#!/usr/bin/env ruby
puts "This is my gems version: #{Gem.loaded_specs['mygem'].version}"

Ruby - 'require': 127: The specified procedure could not be found (LoadError)

So, I have a small Ruby program, which is a simple "Hello World" - the code is below
require 'ray'
Ray.game 'Hello world!', :size => [800, 600] do
register { add_hook :quit, method(:exit!) }
scene :hello do
#text = text 'Hello, Ruby!', :angle => 30, :at => [100, 100], :size => 30
render { |win| win.draw #text }
end
scenes << :hello
end
and it worked just fine on my Win7-32 bit machine. However, when I took the exact same program to my Win7-64 bit machine, the Ruby interpreter spitted out the following message:
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': 127:
The specified procedure could not be found. - C:/Ruby193/lib/ruby/gems/1.9.1
/gems/ray-0.2.0/lib/ray_ext.so (LoadError)
From the error message, it seemed like the "ray_ext.so" was missing, but actually it was there:
Both PCs have the exact same version of Ruby (1.9.3), and exact same list of gems installed, yet how come the exact same program worked just fine on the 32-bit Win7 but failed on the 64-bit Win7?
I tried to re-install the gem (ray) again, as well as updating the gem list, but that didn't resolve the issue. From what I discovered from the web, it seemed that this was a "dll" linkage problem (correct me if I'm wrong), but I didn't know how to fix it (excuse me, I'm still a noob in Ruby), except to re-install the gem - which didn't work.
Is there anything else that I can try? Do you think that this is purely the gem's problem (which is not compatible with Win7-64 bit)?
Thank you for your help.
In short, use latest Ruby.
When I install Jekyll on my Windows 7 64bit, I got the same error (Yes, the version of Ruby is 1.9.3). It didn't disappear until I change my Ruby to 2.0.0 (not 2.0.0-x64).
Although I don't understand Ruby at all, I hope this can solve your problem. Thank you.
I had the problem. I tried setting the right oracle bin path pointing to oci.dll, that didn't work. I copied over the oci.dll to ruby\bin directory and later it gave me another error. I had to copy orauts.dll and there you go...the application worked.
Hope that helps others.

ruby and erb not responding in centos

I've installed ruby with rvm on a centos 6.3 VM and when I attempt to run ruby with no parameters (or erb for that matter) I get no response back, it just sits there.
Running 'ruby' just drops the cursor to the next line like it's waiting for more input or something else to happen. Typing any ruby commands during this time does nothing AFAIK. I do not get any errors, but I'm not exactly sure where to look. I have to control-c to break out of it.
Few interesting things:
(I'm fairly new to linux, so be gentle)
running the command ruby -v
gets me:
ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-linux]
so it seems like it's installed
running:
echo "puts 'hello'" |ruby
gets me:
hello
I've created a different user and then logged in with that user and the behavior is the same.
I've installed rails and then created a rails app and I can do rails c use the rails console
Other notes that may or may not be relevant:
I've recently installed KDE. I did have ruby working before installing KDE but I can't say it was the installation of KDE that messed it up.
I've already uninstalled ruby using rvm and reinstalled, same thing.
Uninstalled rvm and reinstalled.
I've no idea where to go with this or what information would be useful.
Run irb to get an interactive session. This is a REPL, a Read-Eval-Print Loop.
To see Ruby do something in response to running the interpreter and feeding it standard input interactively, try something like:
$ ruby
p :hello
^D
If you just type ruby, I'm not sure anything will happen until it reads the entire input file ... i.e., sees a Control/D indicating standard input end-of-file.
I believe your looking for irb - the interactive Ruby interpreter.
erb is an interpreter that expects a file argument.
$ erb hello-world.rb

Is there a trick to profiling memory usage w/ ruby-prof using an rvm gemset?

I've been trying to get ruby-prof working for memory usage on Mac OS X w/ Ruby 1.8.7 and so far I'm not having much luck.
I understand from the documentation that RubyProf::MEMORY mode requires a patched version of Ruby. I've tried installing the GC-patched version (which I found referenced in the Rails documentation) through RVM:
rvm reinstall 1.8.7 --patch ruby187gc
Based on the output of this command, everything looks good. I clearly see "Applying patch 'ruby187gc'" in the console output.
The problem seems to come when trying to use an RVM gemset. I wrote the following script to test this:
require "ruby-prof"
RubyProf.measure_mode = RubyProf::MEMORY
results = RubyProf.profile do
# code to measure
end
File.open(File.join(File.dirname(__FILE__), "profile-graph.html"), "w") do |file|
RubyProf::GraphHtmlPrinter.new(results).print(file)
end
When I preceed this script with rvm use 1.8.7 --patch ruby187gc, it creates the file "profile-graph.html" showing memory usage of all the different method calls in the script, as I'd expect. However, when I try something like rvm use 1.8.7#gemset_name --patch ruby187gc, the output file contains all "nan" values.
What gives? Is there some special trick to using a patched version of Ruby along with an RVM gemset? Does the problem lie elsewhere? I'm crossing my fingers and hoping that someone has run into a very similar problem and figured this out before.
Ah, I was overcomplicating things. Turns out I just needed to uninstall and reinstall the ruby-prof gem (after patching Ruby).

Resources