# encoding: utf-8 # require 'kde-build/tools/ssh.rb' require 'kde-build/tools/logging.rb' module BuildTool class ConfigureError < Exception end class BuildError < Exception end class Module def initialize(config) @config = config @build_system = nil @vcs = nil end def activate_ssh_key # No key, no cookies return if !@config.ssh_key ssh = MJ::Tools::SSH.new if !ssh.has_key? ssh_key ssh.add_key(ssh_file) end end def name @config.name end # The build directory def build_directory "#{workdir}/bld/#{local_path}" end def local_path @local_path = @config.local_path || @config.remote_path end def build( install ) $log.info("Compiling") rc = nil while_logging_to( name, "50_build" ) do rc = if install build_system.make( "install" ) else build_system.make end if rc != 0 raise BuildError, "make returned error code #{rc}" end $log.info( "successfully built" ) end end # The build system def build_system if not @build_system if not @config.build_system klass = BuildTool::BuildSystem::Registry.guess( source_directory ) if !klass raise ModuleError, "Failed to guess the build system for #{name}" end else klass = BuildTool::BuildSystem::get(@config.build_system.name) end @build_system = klass.new( self ) @build_system.configuration = @config.build_system end @build_system end def remove_build_directory $log.info("removing #{build_directory}") build_system.remove_build_directory end # Configure the module def reconfigure( clean = false ) $log.info("Reconfiguring") while_logging_to( name, "30_configure" ) do if !$noop and !vcs.checkedout? raise ConfigureError, "Module is not checked out." end rc = build_system.reconfigure( clean ) if rc != 0 raise ConfigureError, "configure returned error code #{rc}" end end end # Configure the module def configure $log.info("configuring") while_logging_to( name, "30_configure" ) do if !$noop and !vcs.checkedout? raise ConfigureError, "Module is not checked out." end rc = build_system.configure if rc != 0 raise ConfigureError, "configure returned error code #{rc}" end end end # Is the module already configured? def configured? if !vcs.checkedout? return false end build_system.configured? end def checkedout? vcs.checkedout? end def env @config.env end def fetch $log.info("Fetching from #{remote_path}") while_logging_to( name, "20_fetch" ) do vcs.fetch end end def init $log.info("Initializing #{local_path} from #{remote_path}") while_logging_to( name, "10_initialize" ) do vcs.init end end def ssh_key return @config.ssh_key end def ssh_file return @config.ssh_file end # The root directory for the +/bld+, +/src+ and +/log+ directories def workdir Application::instance.workdir end def rebase $log.info("rebasing") while_logging_to( name, "40_rebase" ) do vcs.rebase end end # The absolute remote path def remote_path "#{repository}/#{@config.remote_path}" end # The repository url def repository @config.repository end def prefix @config.prefix end # The absolute source directory. def source_directory "#{workdir}/src/#{local_path}" end # reimplement def to_yaml_type "!michael-jansen.biz,2009-01-01/Module" end # ######### # protected # ######### def vcs if ! @vcs @vcs = VCS::get(@config.vcs.name).new( remote_path, source_directory ) @vcs.configuration = @config.vcs end @vcs end end end