Class: BuildTool::BuildSystem::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/build-tool/build-system/base.rb

Overview

Base class for all build system implementations

Direct Known Subclasses

AutoConf, CMake, Custom, None, QMake, Qt

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ Base

Returns a new instance of Base.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/build-tool/build-system/base.rb', line 15

def initialize ( parent = nil )
    @module  = nil
    @default = nil
    @options = Hash.new
    @out_of_source = true
    @supported_options = Array.new
    @feature = nil
    if parent and parent.name == name
        @parent = parent
    else
        @parent = nil
    end
end

Instance Attribute Details

#defaultsObject

Returns the value of attribute defaults.



35
36
37
# File 'lib/build-tool/build-system/base.rb', line 35

def defaults
  @defaults
end

#featureObject

Returns the value of attribute feature.



33
34
35
# File 'lib/build-tool/build-system/base.rb', line 33

def feature
  @feature
end

#moduleObject

ATTRIBUTES



32
33
34
# File 'lib/build-tool/build-system/base.rb', line 32

def module
  @module
end

#out_of_sourceObject

Returns the value of attribute out_of_source.



34
35
36
# File 'lib/build-tool/build-system/base.rb', line 34

def out_of_source
  @out_of_source
end

Instance Method Details

#[](var) ⇒ Object

Raises:



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/build-tool/build-system/base.rb', line 108

def []( var )
    # Check if the value is explicitly set to None
    if @options.has_key?( var ) and @options[ var ].nil?
        return "<unset>"
    end
    # Get the parents value (if any)
    par = parent
    if par and par.option_set?( var )
        parentval = par[var]
    else
        parentval = nil
    end
    # If this build-system declaration is not active we are done
    if !active?
        return parentval       if !parentval.nil?
        raise UnknownOptionError, "[#{self.module.name}] Build system inactive. No parent found."
    end
    # Now check our value and merge with parents
    if @options.has_key?( var )
        return @options[ var ].
            sub( '{{{}}} ', parentval.nil? ? "" : "#{parentval} " ).
            sub( ' {{{}}}', parentval.nil? ? "" : " #{parentval}" )
    end
    return parentval       if !parentval.nil?
    return ""              if @supported_options.include?( var )
    raise UnknownOptionError, "[#{self.module.name}] Option #{var} is unknown for build-system #{name}"
end

#[]=(var, value) ⇒ Object



136
137
138
# File 'lib/build-tool/build-system/base.rb', line 136

def []=( var, value )
    @options[ var ] = value
end

#active?Boolean

Returns:

  • (Boolean)


100
101
102
103
104
105
106
# File 'lib/build-tool/build-system/base.rb', line 100

def active?
    if @feature.nil?
        true
    else
        @feature.active?
    end
end

#after_rebaseObject



197
198
# File 'lib/build-tool/build-system/base.rb', line 197

def after_rebase
end

#append(var, value) ⇒ Object



150
151
152
153
154
155
156
# File 'lib/build-tool/build-system/base.rb', line 150

def append( var, value )
    if option_set?( var )
        self[var]= self[var] + " " + value
    else
        self[var]= "{{{}}} " + value
    end
end

#build_directoryObject



37
38
39
# File 'lib/build-tool/build-system/base.rb', line 37

def build_directory
    @module.build_directory
end

#check_build_directory(create = false) ⇒ Object



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/build-tool/build-system/base.rb', line 230

def check_build_directory( create = false )
    if !out_of_source
        if File.exist? build_directory
            if !File.symlink?( build_directory )
                raise ConfigurationError, "Build directory #{build_directory} exists and is not a symlink!"
            end
            return true
        elsif create && !$noop
            FileUtils.mkdir_p( Pathname.new( build_directory ).parent )
            File.symlink( source_directory, build_directory )
            return true
        end
        return false
    else
        if File.exist? build_directory
            if !File.directory? build_directory
                raise ConfigurationError, "Build directory #{build_directory} exists and is not a directory!"
            end
            return true
        elsif create && !$noop
            FileUtils.mkdir_p( build_directory )
            return true
        end
        return false
    end
end

#check_install_prefixObject

Check that the installation prefix exists and is writable



174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/build-tool/build-system/base.rb', line 174

def check_install_prefix
    prefix = @module.install_prefix_required
    if !prefix.exist? or !prefix.writable?
        begin
            FileUtils.mkdir_p prefix.to_s
        rescue Errno::EACCES => e
            logger.error "#{name}: The directory #{prefix.to_s} is not writable! Installation will fail!"
            return false
        end
    end
    return true
end

#dupObject



41
42
43
# File 'lib/build-tool/build-system/base.rb', line 41

def dup
    self.class.new( self )
end

#envObject



45
46
47
# File 'lib/build-tool/build-system/base.rb', line 45

def env
    @module.environment.values
end

#install_prefixObject

Raises:



187
188
189
190
# File 'lib/build-tool/build-system/base.rb', line 187

def install_prefix
    return @module.install_prefix_required if @module
    raise ConfigurationError, "No module set for build-system"
end

#option_hashObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/build-tool/build-system/base.rb', line 62

def option_hash
    # Check the parents names (if any)
    par = parent
    if par
        parent_option_hash = par.option_hash
    else
        parent_option_hash = {}
    end
    # If this build-system declaration is not active we are done
    if active?
        rc = parent_option_hash.merge( @options )
    else
        rc = parent_option_hash
    end
    rc.delete_if { |k, v| v.nil? }
end

#option_namesObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/build-tool/build-system/base.rb', line 79

def option_names
    # Check the parents names (if any)
    par = parent
    if par
        parent_option_hash = par.option_hash
    else
        parent_option_hash = {}
    end
    # If this build-system declaration is not active we are done
    if active?
        rc = parent_option_hash.merge( @options )
    else
        rc = parent_option_hash
    end
    return rc.keys
end

#option_set?(var) ⇒ Boolean

Returns:

  • (Boolean)


140
141
142
143
144
# File 'lib/build-tool/build-system/base.rb', line 140

def option_set?( var )
    return true if active? && @options.has_key?( var )
    return true if parent  && parent.option_set?( var )
    return false
end

#parentObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/build-tool/build-system/base.rb', line 49

def parent
    if @parent
        par = @parent
    elsif @module && @module.parent && @module.parent.build_system && ( @module.parent.build_system.name == name )
        par = @module.parent.build_system
    elsif @module
        par = defaults
    else
        par = nil
    end
    return par
end

#prepare_for_installationObject

This method checks if the build-system is prepared for installation. Do not check if the module is configured, this will be done by Module. Only check stuff that is outside of the scope of build-tool.



169
170
171
# File 'lib/build-tool/build-system/base.rb', line 169

def prepare_for_installation
    return check_install_prefix
end

#prepend(var, value) ⇒ Object



158
159
160
161
162
163
164
# File 'lib/build-tool/build-system/base.rb', line 158

def prepend( var, value )
    if option_set?( var )
        self[var]= value + " " + self[var]
    else
        self[var]= value + " {{{}}}"
    end
end

#progressbar(title, &block) ⇒ Object



200
201
202
203
# File 'lib/build-tool/build-system/base.rb', line 200

def progressbar( title, &block )
    logger.info title
    yield
end

#recipeObject



257
258
259
# File 'lib/build-tool/build-system/base.rb', line 257

def recipe
    Application::instance.recipe
end

#remove_build_directoryObject



261
262
263
# File 'lib/build-tool/build-system/base.rb', line 261

def remove_build_directory
    FileUtils.rm_rf( build_directory, :noop => $noop )
end

#remove_source_directoryObject



265
266
267
# File 'lib/build-tool/build-system/base.rb', line 265

def remove_source_directory
    FileUtils.rm_rf( source_directory, :noop => $noop )
end

#set(var, value) ⇒ Object



146
147
148
# File 'lib/build-tool/build-system/base.rb', line 146

def set( var, value )
    self[var]= value
end

#source_directoryObject

Raises:



192
193
194
195
# File 'lib/build-tool/build-system/base.rb', line 192

def source_directory
    return @module.source_directory_required if @module
    raise ConfigurationError, "No module set for build-system"
end

#to_sObject



96
97
98
# File 'lib/build-tool/build-system/base.rb', line 96

def to_s
    return "#{self.module.name} #{self.name} #{@options.keys.join( ', ')}"
end