lib/autoproj/autobuild.rb in autoproj-1.4.4 vs lib/autoproj/autobuild.rb in autoproj-1.5.0
- old
+ new
@@ -1,13 +1,33 @@
require 'find'
require 'fileutils'
require 'autobuild'
require 'set'
-class Autobuild::Package
- def autoproj_name # :nodoc:
- srcdir.gsub /^#{Regexp.quote(Autoproj.root_dir)}\//, ''
+module Autobuild
+ class Package
+ def autoproj_name # :nodoc:
+ srcdir.gsub /^#{Regexp.quote(Autoproj.root_dir)}\//, ''
+ end
+
+ alias __depends_on__ depends_on
+ def depends_on(name)
+ if Autoproj.osdeps.has?(name)
+ @os_packages ||= Set.new
+ @os_packages << name
+ else
+ __depends_on__(name)
+ end
+ end
+
+ def depends_on_os_package(name)
+ depends_on(name)
+ end
+
+ def os_packages
+ @os_packages ||= Set.new
+ end
end
end
module Autoproj
# Subclass of Autobuild::Reporter, used to display a message when the build
@@ -78,20 +98,10 @@
ensure
@file_stack.pop
end
end
-# Sets up a documentation target on pkg that runs 'rake <target>'
-def ruby_doc(pkg, target = 'doc')
- pkg.doc_task do
- pkg.progress "generating documentation for %s"
- pkg.doc_disabled unless File.file?('Rakefile')
- Autobuild::Subprocess.run pkg.name, 'doc', 'rake', target
- end
-
-end
-
# Common setup for packages
def package_common(package_type, spec, &block) # :nodoc:
package_name = Autoproj.package_name_from_options(spec)
begin
@@ -162,23 +172,25 @@
end
end
end
end
-# Common setup for Ruby packages
-def ruby_common(pkg) # :nodoc:
- def pkg.prepare_for_forced_build
+# This module is used to extend importer packages to handle ruby packages
+# properly
+module Autoproj::RubyPackage
+ def prepare_for_forced_build # :nodoc:
super
extdir = File.join(srcdir, 'ext')
if File.directory?(extdir)
Find.find(extdir) do |file|
next if file !~ /\<Makefile\>|\<CMakeCache.txt\>$/
FileUtils.rm_rf file
end
end
end
- def pkg.prepare_for_rebuild
+
+ def prepare_for_rebuild # :nodoc:
super
extdir = File.join(srcdir, 'ext')
if File.directory?(extdir)
Find.find(extdir) do |file|
if File.directory?(file) && File.basename(file) == "build"
@@ -192,24 +204,26 @@
end
end
end
end
- def pkg.prepare
+ def import
super
- Autobuild.update_environment srcdir
- end
- pkg.post_install do
- Autobuild.progress "setting up Ruby package #{pkg.name}"
- Autobuild.update_environment pkg.srcdir
- if File.file?('Rakefile')
- if File.directory?('ext')
- Autobuild::Subprocess.run pkg.name, 'post-install', 'rake', 'setup'
- end
+ Autobuild.update_environment srcdir
+ libdir = File.join(srcdir, 'lib')
+ if File.directory?(libdir)
+ Autobuild.env_add_path 'RUBYLIB', libdir
end
end
+
+ # The Rake task that is used to set up the package. Defaults to "default".
+ # Set to nil to disable documentation generation
+ attr_accessor :rake_setup_task
+ # The Rake task that is used to generate documentation. Defaults to "doc".
+ # Set to nil to disable documentation generation
+ attr_accessor :rake_doc_task
end
def env_set(name, value)
Autoproj.env_set(name, value)
end
@@ -228,17 +242,45 @@
#
# +pkg+ is an Autobuild::Importer instance. See the Autobuild API for more
# information.
def ruby_package(options)
package_common(:import, options) do |pkg|
- class << pkg
- attr_accessor :doc_target
+ pkg.exclude << /\.so$/
+ pkg.exclude << /Makefile$/
+ pkg.exclude << /mkmf.log$/
+ pkg.exclude << /\.o$/
+
+ pkg.extend Autoproj::RubyPackage
+ pkg.rake_setup_task = "default"
+ pkg.rake_doc_task = "redocs"
+
+ # Set up code
+ pkg.post_install do
+ Autobuild.progress "setting up Ruby package #{pkg.name}"
+ Autobuild.update_environment pkg.srcdir
+ # Add lib/ unconditionally, as we know that it is a ruby package.
+ # Autobuild will add it only if there is a .rb file in the directory
+ libdir = File.join(pkg.srcdir, 'lib')
+ if File.directory?(libdir)
+ Autobuild.env_add_path 'RUBYLIB', libdir
+ end
+
+ if pkg.rake_setup_task && File.file?(File.join(pkg.srcdir, 'Rakefile'))
+ Autobuild::Subprocess.run pkg, 'post-install',
+ 'rake', pkg.rake_setup_task
+ end
end
- ruby_common(pkg)
yield(pkg) if block_given?
- unless pkg.has_doc?
- ruby_doc(pkg, pkg.doc_target || 'redocs')
+
+ # Documentation code. Ignore if the user provided its own documentation
+ # task, or disabled the documentation generation altogether by setting
+ # rake_doc_task to nil
+ if !pkg.has_doc? && pkg.rake_doc_task
+ pkg.doc_task do
+ pkg.progress "generating documentation for %s"
+ Autobuild::Subprocess.run pkg, 'doc', 'rake', pkg.rake_doc_task
+ end
end
end
end
# Defines an oroGen package. By default, autoproj will look for an orogen file