You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by bo...@apache.org on 2010/03/05 06:34:26 UTC
svn commit: r919299 - in /buildr/trunk: CHANGELOG addon/buildr/protobuf.rb
Author: boisvert
Date: Fri Mar 5 05:34:26 2010
New Revision: 919299
URL: http://svn.apache.org/viewvc?rev=919299&view=rev
Log:
BUILDR-368 Support protocol buffer code generation (Pepijn Van Eeckhoudt)
Added:
buildr/trunk/addon/buildr/protobuf.rb
Modified:
buildr/trunk/CHANGELOG
Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=919299&r1=919298&r2=919299&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Fri Mar 5 05:34:26 2010
@@ -19,6 +19,8 @@
command line (and ignore transitive test dependencies)
* Added: ArtifactNamespace.{keys,clear} methods
* Added: BUILDR-326 Support unzipping tar.gz files (Antoine Toulme)
+* Added: BUILDR-368 Support protocol buffer code generation
+ (Pepijn Van Eeckhoudt)
* Added: BUILDR-375 Buildr now recognizes buildfile.rb and Buildfile.rb
(Kerry Wilson)
* Added: BUILDR-390 Buildr::group() should accept :classifier argument
Added: buildr/trunk/addon/buildr/protobuf.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/addon/buildr/protobuf.rb?rev=919299&view=auto
==============================================================================
--- buildr/trunk/addon/buildr/protobuf.rb (added)
+++ buildr/trunk/addon/buildr/protobuf.rb Fri Mar 5 05:34:26 2010
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with this
+# work for additional information regarding copyright ownership. The ASF
+# licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+
+module Buildr
+ # Provides Protocol buffer code generation tasks. Require explicitly using <code>require "buildr/protobuf"</code>.
+ module Protobuf
+ class << self
+ def protoc(*args)
+ options = Hash === args.last ? args.pop : {}
+ rake_check_options options, :output, :lang, :include
+
+ options[:lang] ||= :java
+ options[:output] ||= File.expand_path "target/generated/protoc"
+ options[:include] ||= []
+
+ command_line = []
+
+ command_line << "--#{options[:lang]}_out=#{options[:output]}" if options[:output]
+
+ (paths_from_sources(*args) + options[:include]).each { |i| command_line << "-I#{i}" }
+
+ command_line += files_from_sources(*args)
+
+ mkdir_p( options[:output] )
+
+ system protoc_path, *command_line
+ end
+
+ def protoc_path
+ ENV['PROTOC'] || "protoc"
+ end
+
+ def files_from_sources(*args)
+ args.flatten.map(&:to_s).collect { |f| File.directory?(f) ? FileList[f + "/**/*.proto"] : f }.flatten
+ end
+
+ def paths_from_sources(*args)
+ args.flatten.map(&:to_s).collect { |f| File.directory?(f) ? f : File.dirname(f) }
+ end
+ end
+
+ def protoc(*args)
+ if Hash === args.last
+ options = args.pop
+ else
+ options = {}
+ end
+
+ options[:output] ||= path_to(:target, :generated, :protoc)
+ options[:lang] ||= compile.language if compile.language
+
+ file(options[:output]=>Protobuf.files_from_sources(*args)) do |task|
+ Protobuf.protoc task.prerequisites, options
+ end
+ end
+
+ end
+
+ class Project
+ include Protobuf
+ end
+end