1. Feb 28th, 2008

    svn checkout, rake setup

    Sam Ruby on the trials of getting Ape to run from SVN:

    If you do manage to check the file out, you see a Rakefile. This would imply that one might want to use rake. Trying it results in a message “You are missing a dependency required for meta-operations on this gem. No such file to load — echoe”

    Unfortunately that’s the case with too many Ruby projects.

    When you gem install, you get all the necessary runtime dependencies; svn checkout doesn’t have quite the same effect. And starting with the gem before diving head into source doesn’t always work: runtime and build dependencies are not the same.

    What wrong with a few undocumented, tedious, manual steps? As the corollary to Blodgett’s First Law says:

    Any step in a process that could be automated must be automated.

    We ran into the same problem in Buildr, as luck would have it, fixed it today. Victor Hugo Borja came up with the code snippet below that works on both RubyGems 0.9.5 and 1.1.0.

    Now all you have to do is svn checkout, followed by rake setup and you’re good to go.

    desc "If you're building from source, run this task first to setup the necessary dependencies."
    task 'setup' do
      gems = Gem::SourceIndex.from_installed_gems
      # Runtime dependencies from the Gem's spec.
      dependencies = spec.dependencies
      # Add build-time dependencies, like this:
      dependencies << Gem::Dependency.new('highline', '~>1.4')
      dependencies.each do |dep|
        if gems.search(dep.name, dep.version_requirements).empty?
          puts "Installing dependency: #{dep}"
          begin
            require 'rubygems/dependency_installer'
            Gem::DependencyInstaller.new(dep.name, dep.version_requirements).install
          rescue LoadError # < rubygems 1.0.1
            require 'rubygems/remote_installer'
            Gem::RemoteInstaller.new.install(dep.name, dep.version_requirements)
          end
        end
      end
    end
    

    Most likely your Rakefile will not load at all without some of these dependencies, so code defensively:

    begin
      require 'highline'
    rescue LoadError
      puts 'HighLine required, please run rake setup first'
    end
    

    Check for build dependencies early and often, fix Rakefile when necessary, your community will thank you.

    1. Mar 4th, 2008

      Ryan Davis

      your markup engine is munging your code.

      I’m going to fold in something similar into hoe when rubygems comes out.

    2. Mar 5th, 2008

      Assaf

      Thanks, fixed. What do you mean by “when rubygems comes out?”

    Your comment, here ⇓

    Or using OpenID