From 897f973cdc42275d1cfd703079ed53a7d7c52bef Mon Sep 17 00:00:00 2001 From: Rob Percival Date: Fri, 3 Aug 2012 12:49:10 +0100 Subject: [PATCH 1/3] Added Rake task for generating Ruby protobuf scripts from protobuf files --- lib/protobuf/generate_task.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/protobuf/generate_task.rb diff --git a/lib/protobuf/generate_task.rb b/lib/protobuf/generate_task.rb new file mode 100644 index 0000000..3308aff --- /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[proto_paths] + end + + def define + for protobuf in @proto_paths + 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 From 78d02c801bca3a75af20ba67b95382791b2a2198 Mon Sep 17 00:00:00 2001 From: Rob Percival Date: Fri, 3 Aug 2012 12:58:43 +0100 Subject: [PATCH 2/3] rake/rdoctask is deprecated - use rdoc/task instead --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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') : "" From e819a28e944c269f9a96ee22a299b69f710b7e83 Mon Sep 17 00:00:00 2001 From: Rob Percival Date: Fri, 3 Aug 2012 13:59:14 +0100 Subject: [PATCH 3/3] fixup! Added Rake task for generating Ruby protobuf scripts from protobuf files Fixed a couple of small bugs that can occur when more than one protobuf file is compiled. --- lib/protobuf/generate_task.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/generate_task.rb b/lib/protobuf/generate_task.rb index 3308aff..1062ce9 100644 --- a/lib/protobuf/generate_task.rb +++ b/lib/protobuf/generate_task.rb @@ -11,11 +11,11 @@ def initialize(*proto_paths, &block) end def init(*proto_paths) - @proto_paths = Rake::FileList[proto_paths] + @proto_paths = Rake::FileList.new(proto_paths) end def define - for protobuf in @proto_paths + @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