require 'autobuild' require 'set' class Autobuild::Package def autoproj_name srcdir.gsub /^#{Regexp.quote(Autoproj.root_dir)}\//, '' end end module Autoproj 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") end def success STDERR.puts color("Build finished successfully at #{Time.now}", :bold, :green) if Autobuild.post_success_message puts Autobuild.post_success_message end end end 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 spec.to_str end end def self.current_file @file_stack.last end def self.define(package_type, spec, &block) package = Autobuild.send(package_type, spec, &block) Autoproj.manifest.register_package package, *current_file end @loaded_autobuild_files = Set.new def self.filter_load_exception(error, source, path) raise error if Autoproj.verbose rx_path = Regexp.quote(path) error_line = error.backtrace.find { |l| l =~ /#{rx_path}/ } line_number = Integer(/#{rx_path}:(\d+)/.match(error_line)[1]) if source.local? raise ConfigError, "#{path}:#{line_number}: #{error.message}", error.backtrace else raise ConfigError, "#{File.basename(path)}(source=#{source.name}):#{line_number}: #{error.message}", error.backtrace end end def self.import_autobuild_file(source, path) return if @loaded_autobuild_files.include?(path) @file_stack.push([source, File.basename(path)]) begin Kernel.load path rescue Exception => e filter_load_exception(e, source, path) end @loaded_autobuild_files << path ensure @file_stack.pop end end def ruby_doc(pkg, target = 'doc') pkg.doc_task do 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) 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)}" return rescue end # Check if this package is ignored if Autoproj.manifest.ignored?(package_name) return Autoproj.define(:dummy, spec) end Autoproj.define(package_type, spec) do |pkg| pkg.srcdir = pkg.name yield(pkg) if block_given? end end 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? pkg.with_doc do doc_html = File.join('doc', 'html') if File.directory? doc_html pkg.doc_dir = doc_html end 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 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? pkg.with_doc do doc_html = File.join('doc', 'html') if File.directory? doc_html pkg.doc_dir = doc_html end end end end end def ruby_common(pkg) 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") end end def pkg.prepare_for_rebuild super extdir = File.join(srcdir, 'ext') if File.directory?(extdir) FileUtils.rm_rf File.join(extdir, "build") end end def pkg.prepare 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 end end end def env_set(name, value) Autoproj.env_set(name, value) end def env_add(name, value) Autoproj.env_add(name, value) end def ruby_package(options) package_common(:import, options) do |pkg| class << pkg attr_accessor :doc_target end ruby_common(pkg) yield(pkg) if block_given? unless pkg.has_doc? ruby_doc(pkg, pkg.doc_target || 'redocs') end end end def orogen_package(options, &block) package_common(:orogen, options) do |pkg| yield(pkg) if block_given? end end def source_package(options) package_common(options) do |pkg| pkg.srcdir = pkg.name yield(pkg) if block_given? end end def configuration_option(*opts, &block) Autoproj.configuration_option(*opts, &block) end def user_config(*opts) Autoproj.user_config(*opts) end