Class: Autobuild::Configurable

Inherits:
Package
  • Object
show all
Defined in:
lib/autobuild/configurable.rb

Overview

Base class for packages that require a configuration + build step.

Child classes must provide a #configurestamp file which represents the last configuration step done. This file is updated by a call to #configure (see below)

Three new methods are added, which can be reimplemented in child classes:

  • configure does configure the package. It is ran after all depended-upon packages are installed.

  • build is ran after configure if the configure stamp and/or the source files have been updated. The #buildstamp stampfile represents when the last build has been done. The build must be done in the #builddir directory.

  • install is ran after build.

Direct Known Subclasses

Autotools, CMake, Python

Instance Attribute Summary collapse

Attributes inherited from Package

#dependencies, #env, #failures, #importdir, #importer, #logdir, #name, #prefix, #srcdir, #statistics, #update, #updated, #utilities

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Package

[], #add_env_op, #add_stat, #all_dependencies, #applied_post_install?, #apply_env, #apply_post_install, #checked_out?, clear, #depends_on, #depends_on?, #disable, #disable_doc, #disable_phases, #disabled?, #doc_dir, #doc_dir=, #doc_disabled, #doc_target_dir, #doc_target_dir=, #doc_task, each, #enable_doc, #env_add, #env_add_path, #env_add_prefix, #env_set, #env_source_after, #error, #failed?, #file, #find_in_path, #fingerprint, #full_env, #generates_doc?, #has_doc?, #import, #import=, #import_invoked?, #imported?, #in_dir, #inspect, #install, #install_doc, #install_invoked?, #installed?, #installstamp, #isolate_errors, #message, #method_missing, #parallel_build_level, #parallel_build_level=, #post_install, #process_formatting_string, #progress, #progress_done, #progress_start, #provides, #resolve_dependency_env, #resolved_env, #respond_to_missing?, #run, #self_fingerprint, #source_tree, #task, #to_s, #update?, #update_environment, #updated?, #utility, #warn, #working_directory

Constructor Details

#initialize(spec = Hash.new) ⇒ Configurable

Returns a new instance of Configurable.



27
28
29
30
31
# File 'lib/autobuild/configurable.rb', line 27

def initialize(spec = Hash.new)
    @source_tree_excludes = Array.new
    @builddir = nil
    super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Autobuild::Package

Instance Attribute Details

#source_tree_excludesArray<Regexp> (readonly)

Set of regexp matching paths that should not be considered as source files

This is used to determine whether the source code changed (and therefore whether the package should be rebuilt). Autobuild sets up a default set of common excludes, use this to add custom ones

Returns:

  • (Array<Regexp>)


25
26
27
# File 'lib/autobuild/configurable.rb', line 25

def source_tree_excludes
  @source_tree_excludes
end

Class Method Details

.builddirObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/autobuild/configurable.rb', line 34

def builddir
    if @builddir
        @builddir
    else
        ancestors.each do |klass|
            if (result = klass.instance_variable_get(:@builddir))
                return result
            end
        end
        nil
    end
end

.builddir=(new) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/autobuild/configurable.rb', line 47

def builddir=(new)
    if new.nil? || new.empty?
        raise ConfigException, "builddir must be non-nil and non-empty"
    end
    if Pathname.new(new).absolute?
        raise ConfigException, "absolute builddirs are not supported"
    end

    @builddir = new
end

Instance Method Details

#buildObject

Do the build in builddir



148
# File 'lib/autobuild/configurable.rb', line 148

def build; end

#builddirObject

Returns the absolute builddir



67
68
69
# File 'lib/autobuild/configurable.rb', line 67

def builddir
    File.expand_path(@builddir || self.class.builddir, srcdir)
end

#builddir=(new) ⇒ Object

Raises:



60
61
62
63
64
# File 'lib/autobuild/configurable.rb', line 60

def builddir=(new)
    raise ConfigException.new(self), "builddir must be non-empty" if new.empty?

    @builddir = new
end

#buildstampObject

Build stamp This returns the name of the file which marks when the package has been successfully built for the last time. The path is absolute



74
75
76
# File 'lib/autobuild/configurable.rb', line 74

def buildstamp
    "#{builddir}/#{STAMPFILE}"
end

#configureObject

Configure the builddir directory before starting make



134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/autobuild/configurable.rb', line 134

def configure
    if File.exist?(builddir) && !File.directory?(builddir)
        raise ConfigException.new(self, 'configure'),
              "#{builddir} already exists but is not a directory"
    end

    FileUtils.mkdir_p builddir unless File.directory?(builddir)

    yield if block_given?

    Autobuild.touch_stamp(configurestamp)
end

#ensure_dependencies_installedObject



91
92
93
94
95
# File 'lib/autobuild/configurable.rb', line 91

def ensure_dependencies_installed
    dependencies.each do |pkg|
        Rake::Task[Package[pkg].installstamp].invoke
    end
end

#prepareObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/autobuild/configurable.rb', line 97

def prepare
    source_tree srcdir do |pkg|
        if builddir != srcdir
            pkg.exclude << Regexp.new("^#{Regexp.quote(builddir)}")
        end
        if doc_dir && (doc_dir != srcdir)
            pkg.exclude << Regexp.new("^#{Regexp.quote(doc_dir)}")
        end
        pkg.exclude.concat(source_tree_excludes)
    end

    super

    stamps = dependencies.map { |pkg| Autobuild::Package[pkg].installstamp }
    file configurestamp => stamps do
        @install_invoked = true
        isolate_errors do
            ensure_dependencies_installed
            configure
            progress_done # Safety net for forgotten progress_done calls
        end
    end
    task "#{name}-prepare" => configurestamp

    file buildstamp => [srcdir, configurestamp] do
        @install_invoked = true
        isolate_errors do
            ensure_dependencies_installed
            build
            progress_done # Safety net for forgotten progress_done calls
        end
    end
    task "#{name}-build" => buildstamp
    file installstamp => buildstamp
end

#prepare_for_forced_buildObject



78
79
80
81
82
83
# File 'lib/autobuild/configurable.rb', line 78

def prepare_for_forced_build
    super

    FileUtils.rm_f buildstamp
    FileUtils.rm_f configurestamp
end

#prepare_for_rebuildObject



85
86
87
88
89
# File 'lib/autobuild/configurable.rb', line 85

def prepare_for_rebuild
    super

    FileUtils.rm_rf(builddir) if File.exist?(builddir) && builddir != srcdir
end