diff --git a/Rakefile b/Rakefile index 0803d7a..a250c55 100644 --- a/Rakefile +++ b/Rakefile @@ -42,7 +42,7 @@ task :test => :check_dependencies task :default => :test -require 'rake/rdoctask' +require 'rdoc/task' Rake::RDocTask.new do |rdoc| version = File.exist?('VERSION') ? File.read('VERSION') : "" diff --git a/lib/protobuf/generate_task.rb b/lib/protobuf/generate_task.rb new file mode 100644 index 0000000..1062ce9 --- /dev/null +++ b/lib/protobuf/generate_task.rb @@ -0,0 +1,31 @@ +require 'rubygems' +require 'rake' +require 'protobuf/compiler/compiler' + +module Protobuf + class GenerateTask < Rake::TaskLib + def initialize(*proto_paths, &block) + init(proto_paths) + + define(&block) + end + + def init(*proto_paths) + @proto_paths = Rake::FileList.new(proto_paths) + end + + def define + @proto_paths.each do |protobuf| + ruby_protobuf = File.join("lib", File.basename(protobuf, File.extname(protobuf)) + ".pb.rb") + + compile_task = file ruby_protobuf => protobuf do + Protobuf::Compiler.compile(protobuf, File.dirname(protobuf), File.dirname(ruby_protobuf)) + end + + task :protobuf => [ compile_task ] + + yield ruby_protobuf if block_given? + end + end + end +end