lib/autoproj/autobuild.rb in autoproj-1.3.4 vs lib/autoproj/autobuild.rb in autoproj-1.4.0

- old
+ new

@@ -1,15 +1,19 @@ +require 'find' +require 'fileutils' require 'autobuild' require 'set' class Autobuild::Package - def autoproj_name + def autoproj_name # :nodoc: srcdir.gsub /^#{Regexp.quote(Autoproj.root_dir)}\//, '' end end module Autoproj + # Subclass of Autobuild::Reporter, used to display a message when the build + # finishes/fails. class Reporter < Autobuild::Reporter def error(error) error_lines = error.to_s.split("\n") STDERR.puts color("Build failed: #{error_lines.shift}", :bold, :red) STDERR.puts error_lines.join("\n") @@ -20,19 +24,16 @@ puts Autobuild.post_success_message end end end + # Displays a warning message def self.warn(message) STDERR.puts Autoproj.console.color(" WARN: #{message}", :magenta) end - @definition_files = Hash.new @file_stack = Array.new - class << self - attr_reader :definition_files - end def self.package_name_from_options(spec) if spec.kind_of?(Hash) spec.to_a.first.first.to_str else @@ -76,20 +77,22 @@ 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 hosted on groupfiles/Autonomy -def package_common(package_type, spec) +# Common setup for packages +def package_common(package_type, spec) # :nodoc: package_name = Autoproj.package_name_from_options(spec) begin Rake::Task[package_name] Autoproj.warn "#{package_name} from #{Autoproj.current_file[0]} is overriden by the definition in #{Autoproj.definition_source(package_name)}" @@ -106,10 +109,24 @@ pkg.srcdir = pkg.name yield(pkg) if block_given? end end +def import_package(options, &block) + package_common(:import, options, &block) +end + +# Define a cmake package +# +# Example: +# +# cmake_package 'package_name' do |pkg| +# pkg.define "CMAKE_BUILD_TYPE", "Release" +# end +# +# +pkg+ is an Autobuild::CMake instance. See the Autobuild API for more +# information. def cmake_package(options, &block) package_common(:cmake, options) do |pkg| Autoproj.add_build_system_dependency 'cmake' yield(pkg) if block_given? unless pkg.has_doc? @@ -121,12 +138,19 @@ end end end end -# Use this method to import and build CMake packages that are hosted on the -# groupfiles server, on the autonomy project folder +# Define an autotools package +# +# Example: +# autotools_package 'package_name' do |pkg| +# pkg.configureflags << "--enable-llvm" +# end +# +# +pkg+ is an Autobuild::Autotools instance. See the Autobuild API for more +# information. def autotools_package(options, &block) package_common(:autotools, options) do |pkg| Autoproj.add_build_system_dependency 'autotools' yield(pkg) if block_given? unless pkg.has_doc? @@ -138,24 +162,36 @@ end end end end -def ruby_common(pkg) +# Common setup for Ruby packages +def ruby_common(pkg) # :nodoc: def pkg.prepare_for_forced_build super extdir = File.join(srcdir, 'ext') if File.directory?(extdir) - FileUtils.rm_rf File.join(extdir, "build", "CMakeCache.txt") - FileUtils.rm_rf File.join(extdir, "Makefile") + Find.find(extdir) do |file| + next if file !~ /\<Makefile\>|\<CMakeCache.txt\>$/ + FileUtils.rm_rf file + end end end def pkg.prepare_for_rebuild super extdir = File.join(srcdir, 'ext') if File.directory?(extdir) - FileUtils.rm_rf File.join(extdir, "build") + Find.find(extdir) do |file| + if file =~ /Makefile/ + Autobuild::Subprocess.run self, 'build', Autobuild.tool("make"), "-C", File.dirname(file), "clean" + end + end + Find.find(extdir) do |file| + if File.directory?(file) && file == "build" + FileUtils.rm_rf file + end + end end end def pkg.prepare super @@ -178,10 +214,21 @@ end def env_add(name, value) Autoproj.env_add(name, value) end + +# Defines a Ruby package +# +# Example: +# +# ruby_package 'package_name' do |pkg| +# pkg.doc_target = 'doc' +# end +# +# +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 end @@ -192,26 +239,45 @@ ruby_doc(pkg, pkg.doc_target || 'redocs') end end end +# Defines an oroGen package. By default, autoproj will look for an orogen file +# called package_basename.orogen if the package is called dir/package_basename +# +# Example: +# orogen_package 'package_name' do |pkg| +# pkg.orogen_file = "my.orogen" +# pkg.corba = false +# end +# +# +pkg+ is an Autobuild::Orogen instance. See the Autobuild API for more +# information. def orogen_package(options, &block) package_common(:orogen, options) do |pkg| yield(pkg) if block_given? end end +# Defines an import-only package, i.e. a package that is simply checked out but +# not built in any way def source_package(options) package_common(options) do |pkg| pkg.srcdir = pkg.name yield(pkg) if block_given? end end +# Define a configuration option +# +# See Autoproj.configuration_option def configuration_option(*opts, &block) Autoproj.configuration_option(*opts, &block) end -def user_config(*opts) - Autoproj.user_config(*opts) +# Retrieves the configuration value for the given option +# +# See Autoproj.user_config +def user_config(key) + Autoproj.user_config(key) end