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:



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

def []( var )
    # 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



130
131
132
# File 'lib/build-tool/build-system/base.rb', line 130

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

#active?Boolean

Returns:

  • (Boolean)


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

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

#after_rebaseObject



191
192
# File 'lib/build-tool/build-system/base.rb', line 191

def after_rebase
end

#append(var, value) ⇒ Object



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

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



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/build-tool/build-system/base.rb', line 224

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



168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/build-tool/build-system/base.rb', line 168

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:



181
182
183
184
# File 'lib/build-tool/build-system/base.rb', line 181

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
# 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?
        return parent_option_hash.merge( @options )
    else
        return parent_option_hash
    end
end

#option_namesObject



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

def option_names
    # Check the parents names (if any)
    par = parent
    if par
        parent_option_names = par.option_names
    else
        parent_option_names = []
    end
    # If this build-system declaration is not active we are done
    if active?
        return  ( @options.keys + parent_option_names ).uniq
    else
        return parent_option_names
    end
end

#option_set?(var) ⇒ Boolean

Returns:

  • (Boolean)


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

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.



163
164
165
# File 'lib/build-tool/build-system/base.rb', line 163

def prepare_for_installation
    return check_install_prefix
end

#prepend(var, value) ⇒ Object



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

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

#progressbar(title, &block) ⇒ Object



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

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

#recipeObject



251
252
253
# File 'lib/build-tool/build-system/base.rb', line 251

def recipe
    Application::instance.recipe
end

#remove_build_directoryObject



255
256
257
# File 'lib/build-tool/build-system/base.rb', line 255

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

#remove_source_directoryObject



259
260
261
# File 'lib/build-tool/build-system/base.rb', line 259

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

#set(var, value) ⇒ Object



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

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

#source_directoryObject

Raises:



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

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

#to_sObject



94
95
96
# File 'lib/build-tool/build-system/base.rb', line 94

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