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.



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

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.



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

def defaults
  @defaults
end

#featureObject

Returns the value of attribute feature.



30
31
32
# File 'lib/build-tool/build-system/base.rb', line 30

def feature
  @feature
end

#moduleObject

ATTRIBUTES



29
30
31
# File 'lib/build-tool/build-system/base.rb', line 29

def module
  @module
end

#out_of_sourceObject

Returns the value of attribute out_of_source.



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

def out_of_source
  @out_of_source
end

Instance Method Details

#[](var) ⇒ Object

Raises:



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

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} Option #{var} is unknown for build-system #{name}"
    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



127
128
129
# File 'lib/build-tool/build-system/base.rb', line 127

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

#active?Boolean

Returns:

  • (Boolean)


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

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

#after_rebaseObject



167
168
# File 'lib/build-tool/build-system/base.rb', line 167

def after_rebase
end

#append(var, value) ⇒ Object



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

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

#build_directoryObject



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

def build_directory
    @module.build_directory
end

#check_build_directory(create = false) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/build-tool/build-system/base.rb', line 195

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

#dupObject



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

def dup
    self.class.new( self )
end

#envObject



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

def env
    @module.environment.values
end

#install_prefixObject

Raises:



157
158
159
160
# File 'lib/build-tool/build-system/base.rb', line 157

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

#option_hashObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/build-tool/build-system/base.rb', line 59

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



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

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)


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

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

#parentObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/build-tool/build-system/base.rb', line 46

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

#prepend(var, value) ⇒ Object



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

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

#recipeObject



222
223
224
# File 'lib/build-tool/build-system/base.rb', line 222

def recipe
    Application::instance.recipe
end

#remove_build_directoryObject



226
227
228
# File 'lib/build-tool/build-system/base.rb', line 226

def remove_build_directory
    self.class.execute "rm -rf #{build_directory}"
end

#set(var, value) ⇒ Object



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

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

#source_directoryObject

Raises:



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

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

#to_sObject



91
92
93
# File 'lib/build-tool/build-system/base.rb', line 91

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