Posts mit dem Label RVM werden angezeigt. Alle Posts anzeigen
Posts mit dem Label RVM werden angezeigt. Alle Posts anzeigen

Montag, 31. Oktober 2011

YAML in Ruby 1.9

The other day I downloaded the production database from Zero-X to my local machine to run some tests.
Everything looked fine until I got to the game reports page, which looked wired, especially the agent views. It seemed that every empty field was occupied by an agent "00".

After digging deeper I identified the error in wrong loaded YAML records. Instead of loading a nil I got Syck::PrivateType. A null with only one ! was correctly loaded, but the data from production system had two !, which were loaded differently.

YAML.load ":a: !null"     # => {:a=>nil}
YAML.load ":a: !!null"    # => {:a=>#<Syck::PrivateType:0x000001024e6b98 ,="" @type_id="null" @value="">}

YAML::ENGINE.yamler  #=> "syck"

I tried the same tests on the production system, that runs Ubuntu 10.10 I get the following output:

YAML.load ":a: !null"     # => {:a=>nil}
YAML.load ":a: !!null"    # => {:a=>nil}

YAML::ENGINE.yamler  #=> "psych"

And voilà all data are loaded correctly! The difference is an other YAML Engine, on Mac OS X Snow Leopard Syck is used, while on Ubuntu Psych.
Some investigations later I got the answer. With Ruby 1.9.2 the standard library Syck was replaced with Psych, which depends on the libyaml library. But here it comes, only if it's found when Ruby is compiled. It still uses Sych as a fallback.

So in order to have the same behavior on my local and production system, I had first to install libyaml using ports and then recompile my Ruby.

sudo port install libyaml
rvm install ruby-1.9.2 --with-libyaml-dir=/opt/local/

You could also use homebrew, that has also the advantage that you don't have to specify the path to libyaml. Homebrew installs to /usr/local, which is checked by the install script.

brew install libyaml
rvm install ruby-1.9.2

Starting irb I still had to change to psych explicitly.

YAML::ENGINE.yamler = "psych"

Rails 3 changes automatically to psych if available.

One day later I found out, that I also could install Psych as Gem instead of recompiling Ruby.

gem install psych

UPDATE:

Some other days later, I began a new Rails project and I encountered the following conflict with psych:
../psych.bundle: warning: already initialized constant ANY
../psych.bundle: warning: already initialized constant UTF8
../psych.bundle: warning: already initialized constant UTF16LE
...

If you have psych 1.2.2 installed, than uninstall it again. Psych 1.2.3 should avoid the double laoding.
see here

Sonntag, 29. Mai 2011

Using Ruby 1.9.2 and Bundler with Zero-X

In the last few months I was working on bringing Zero-X to Rails 3. The new agent SDK reflects this changes in using now bundler.
In addition to the Rails migration, I ported Zero-X to Ruby 1.9.2. The next tournament on the 25. June 2011 will be the first running fully on 1.9.2. So make sure you're testing your agents in the future against 1.9.2.

For those not familiar with bundler and how to install Ruby 1.9.2, here some steps to get you started:
First we need Ruby 1.9.2. The easiest way to install it is by using RVM (Ruby Version Manager). You can get it by issuing this command in your shell:
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
Next we need the agent SDK, which you can download form the Zero-X website.

Unpack the SDK and change to that directory. You will now be asked to examine the .rvmrc file. This file tells RVM to use a specific Ruby Version within this directory. In our case the file contains:
rvm use 1.9.2
After controlling the file, type "yes". Now RVM is looking for Ruby 1.9.2 and if it doesn't exists, it will prompt you a warning and the instruction how to install it.
rvm install 1.9.2

Next we need bundler. As we installed RVM for the current user, we don't need to use sudo to install gems.
gem install bundler
Bundler can now install all necessary gems and check their dependcies.
bundle
You are set and ready to go:
bundle exec rake
or
bundle exec autotest
Enjoy!

Donnerstag, 24. September 2009

Migration auf Ruby 1.9.1

In den letzten Tagen habe ich mein Simulation Projekt auf Ruby 1.9 migriert. Leider verlief die Migration nicht ganz so einfach, wie ich mir das vorgestellt hatte. Teilweise muss nämlich eine exakte Version eines Gems installiert werden, ansonsten hagelt es Fehlermeldungen.
Um Ruby 1.8 und 1.9 parallel auf meinem Mac betreiben zu können, habe ich RVM installiert. Dies installiert alle zusätzlichen Ruby Versionen im Home-Verzeichnis unter .rvm. Zudem werden auch alle command line Befehle wie etwa 'rails' oder 'cucumber' separat gehandhabt. Unter RVM ist allerdings zu beachten, dass alle so hinzugefügten Gems nicht mit sudo installiert werden. Zudem musste ich eine frühere Version von Ruby 1.9, die ich noch unter /usr/local hatte, zuerst wegputzen.

Ich will hier nicht alle Leerläufe beschreiben, deshalb hier gleich die hoffentlich richtig Anleitung:

Um auf Ruby 1.9 zu wechseln:
rvm install 1.9
rvm use ruby 1.9
Darauf installiert RVM automatisch die aktuelle 1.9 Version.

Danach wenden wir uns gleich Rails selber zu. Die neuste Version 2.3.4 ist leider nicht lauffähig unter Ruby 1.9. Wenn auf die Session zugegriffen wird, erhaltet man folgenden Fehler:
undefined method `^' for "c":String (NoMethodError)
Deshalb muss auf 2.3.3 zurückgegriffen werden:
gem install -v='2.3.3' rails
Mein Projekt nutzt Cucumber und RSpec als Testframeworks. Hier können zwar die neusten Versionen installiert werden, jedoch muss auch Test-Unit mit der Version 1.2.3 und zwar exakt diese mitinstalliert werden:
gem install cucumber rspec rspec-rails webrat
gem install -v="1.2.3" test-unit
Als nächstes meldete Nokogiri, das von Webrat genutzt wird, einen Konflikt:
dyld: lazy symbol binding failed: Symbol not found: _rb_intern2
  Referenced from: /Users/adm/.rvm/gems/ruby/1.9.1/gems/nokogiri-1.3.3/lib/nokogiri/nokogiri.bundle
  Expected in: flat namespace

dyld: Symbol not found: _rb_intern2
  Referenced from: /Users/adm/.rvm/gems/ruby/1.9.1/gems/nokogiri-1.3.3/lib/nokogiri/nokogiri.bundle
  Expected in: flat namespace

Trace/BPT trap
Um diesen Konflikt zu lösen musste ich über Ports meine libxml Bibliothek aktualisieren und Nokogiri nochmals installieren:
sudo port install libxml2
sudo port install libxslt

gem install nokogiri
Danach startete mein Projekt endlich unter Ruby 1.9 auf. Meine eignen Konflikte mit 1.9 konnte ich dank meinen Testsuits innerhalb einer halben Stunde lösen. Gute Tests sind wirklich Gold wert.