Class: BuildTool::Module

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

Overview

Represents the information associated with a buildable module.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, parent = nil) ⇒ Module

Create a module



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/build-tool/module.rb', line 13

def initialize( name, parent = nil )
    if name.nil?
        raise StandardError, "Module name is required!"
    end
    @active = nil
    @patches = Array.new
    @name = name
    @parent = parent
    @local_path = nil
    @build_prefix = nil
    @remote_path = nil
    @environment = nil
    @build_system = nil
    @install_prefix = nil
    @is_template = false
    @vcs_configuration = nil
    @feature = nil

    @long_description = nil
    @description = nil
end

Instance Attribute Details

#active=(value) ⇒ Object (writeonly)

Sets the attribute active

Parameters:

  • value

    the value to set the attribute active to.



39
40
41
# File 'lib/build-tool/module.rb', line 39

def active=(value)
  @active = value
end

#build_systemObject



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/build-tool/module.rb', line 91

def build_system
    # Return our own buildsystem if there is one
    return @build_system if @build_system
    # Return our parents buildsystem if there is one
    if @parent && @parent.build_system
        @build_system = @parent.build_system.dup
        @build_system.module = self
        return @build_system
    end
    # Nothing
    nil
end

#descriptionObject



128
129
130
# File 'lib/build-tool/module.rb', line 128

def description
    @description
end

#environmentObject



135
136
137
138
139
140
141
142
# File 'lib/build-tool/module.rb', line 135

def environment
    # Return our own buildsystem if there is one
    return @environment if @environment
    # Return our parents buildsystem if there is one
    return @parent.environment if @parent && @parent.environment
    # Nothing
    nil
end

#feature=(value) ⇒ Object (writeonly)

ATTRIBUTES



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

def feature=(value)
  @feature = value
end

#is_template=(value) ⇒ Object (writeonly)

Sets the attribute is_template

Parameters:

  • value

    the value to set the attribute is_template to.



183
184
185
# File 'lib/build-tool/module.rb', line 183

def is_template=(value)
  @is_template = value
end

#long_descriptionObject



198
199
200
# File 'lib/build-tool/module.rb', line 198

def long_description
    @long_description
end

#nameObject (readonly)

The module name



203
204
205
# File 'lib/build-tool/module.rb', line 203

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

#patchesObject (readonly)

Returns the value of attribute patches.



40
41
42
# File 'lib/build-tool/module.rb', line 40

def patches
  @patches
end

#vcs_configurationObject



226
227
228
229
230
231
232
233
234
235
236
# File 'lib/build-tool/module.rb', line 226

def vcs_configuration
    return @vcs_configuration if @vcs_configuration
    if @parent && @parent.vcs_configuration
        # puts "copying vcs for #{name} from #{@parent.name}"
        vc = @parent.vcs_configuration.class.new
        vc.copy_configuration( @parent.vcs_configuration )
        @vcs_configuration = vc
        return vc
    end
    nil
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/build-tool/module.rb', line 43

def active?
    # If the module is activated that wins
    if @active.nil?
        if @feature.nil?
            return true
        else
            return @feature.active?
        end
    else
        return @active
    end
end

#build_directoryObject

not inherited



57
58
59
# File 'lib/build-tool/module.rb', line 57

def build_directory
    build_prefix_required.join("bld", local_path)
end

#build_prefixObject



73
74
75
76
77
78
79
80
# File 'lib/build-tool/module.rb', line 73

def build_prefix
    # Return our own buildsystem if there is one
    return @build_prefix if @build_prefix
    # Return our parents buildsystem if there is one
    return @parent.build_prefix if @parent && @parent.build_prefix
    # Nothing
    nil
end

#build_prefix=(path) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/build-tool/module.rb', line 61

def build_prefix=( path )
    if path
        path = Pathname.new( path.sub( /\$HOME/, '~' ) )
        if path.to_s[0] != '~' and path.relative?
            raise ConfigurationError, "Build-prefix '#{path}' is relative!"
        end
        @build_prefix = path.expand_path
    else
        @build_prefix = nil
    end
end

#build_prefix_requiredObject

Will throw a exception if build_prefix is not set

Raises:



83
84
85
86
# File 'lib/build-tool/module.rb', line 83

def build_prefix_required
    return self.build_prefix if self.build_prefix
    raise ConfigurationError, "No build prefix configured for #{name}!"
end

#build_system_requiredObject

Will throw a exception if build_system is not set

Raises:



109
110
111
112
113
# File 'lib/build-tool/module.rb', line 109

def build_system_required
    return self.build_system if self.build_system
    # *TODO* try to guess the build system
    raise ConfigurationError, "No build system configured for #{name}!"
end

#checkedout?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/build-tool/module.rb', line 115

def checkedout?
    vcs_required.checkedout?
end

#cleanObject

ACTIONS



256
257
258
# File 'lib/build-tool/module.rb', line 256

def clean
    build_system_required.make( "clean" )
end

#cleanup_after_vcs_accessObject

Cleanup after vcs_access



312
313
314
315
316
317
318
319
320
321
# File 'lib/build-tool/module.rb', line 312

def cleanup_after_vcs_access
    if MJ::Tools::SSH::has_keys?
        logger.info ""
        logger.info "#### Cleaning up the ssh keys"
        MJ::Tools::SSH::keys.each do |file|
            logger.info "  - Removing key #{file}"
        end
        MJ::Tools::SSH::cleanup()
    end
end

#cloneObject

Clone the repository.



265
266
267
268
269
270
271
272
273
# File 'lib/build-tool/module.rb', line 265

def clone
    vcs_required.clone
    if !patches.empty?
        if !vcs.patches_supported?
            raise NotImplementedError, "Patch support not implemented for vcs #{vcs.name}"
        end
        vcs_required.apply_patches( patches )
    end
end

#configureObject



294
295
296
# File 'lib/build-tool/module.rb', line 294

def configure
    build_system_required.configure
end

#configured?Boolean

Returns:

  • (Boolean)


119
120
121
122
123
124
125
# File 'lib/build-tool/module.rb', line 119

def configured?
    if build_system
        return build_system.configured?
    else
        return false
    end
end

#environment_requiredObject

Will throw a exception if environment is not set

Raises:



145
146
147
148
# File 'lib/build-tool/module.rb', line 145

def environment_required
    return self.environment if self.environment
    raise ConfigurationError, "No environment configured for #{name}!"
end

#fetchObject

Fetch changes from the remote repository. Do not change the local checkout.



277
278
279
# File 'lib/build-tool/module.rb', line 277

def fetch
    vcs_required.fetch
end

#gcObject

Garbage collect



151
152
153
# File 'lib/build-tool/module.rb', line 151

def gc
    vcs.gc
end

#install(fast = false) ⇒ Object



307
308
309
# File 'lib/build-tool/module.rb', line 307

def install( fast = false )
    build_system_required.install( fast )
end

#install_prefixObject



168
169
170
171
172
173
174
175
# File 'lib/build-tool/module.rb', line 168

def install_prefix
    # Return our own buildsystem if there is one
    return @install_prefix if @install_prefix
    # Return our parents buildsystem if there is one
    return @parent.install_prefix if @parent && @parent.install_prefix
    # Nothing
    nil
end

#install_prefix=(path) ⇒ Object

Installation prefix



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/build-tool/module.rb', line 156

def install_prefix=( path )
    if path
        path = Pathname.new( path.sub( /\$HOME/, '~' ) )
        if path.to_s[0] != '~' and path.relative?
            raise ConfigurationError, "Install-prefix '#{path}' is relative!"
        end
        @install_prefix = path.expand_path
    else
        @install_prefix = nil
    end
end

#install_prefix_requiredObject

Will throw a exception if install_prefix is not set

Raises:



178
179
180
181
# File 'lib/build-tool/module.rb', line 178

def install_prefix_required
    return self.install_prefix if self.install_prefix
    raise ConfigurationError, "No install prefix configured for #{name}!"
end

#is_template?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/build-tool/module.rb', line 184

def is_template?
    @is_template
end

#local_pathObject



193
194
195
# File 'lib/build-tool/module.rb', line 193

def local_path
    @local_path || @name
end

#local_path=(local_path) ⇒ Object

Raises:



188
189
190
191
# File 'lib/build-tool/module.rb', line 188

def local_path=( local_path )
    raise ConfigurationError, "Attempt to set local_path for module template #{name}" if is_template?
    @local_path = local_path
end

#make(target = nil) ⇒ Object

Call make



303
304
305
# File 'lib/build-tool/module.rb', line 303

def make( target = nil )
    build_system_required.make( target )
end

#our_build_systemObject



104
105
106
# File 'lib/build-tool/module.rb', line 104

def our_build_system
    @build_system
end

#prepare_for_fetchObject

Check if an ssh-key is required and active it if necessary



324
325
326
327
328
329
# File 'lib/build-tool/module.rb', line 324

def prepare_for_fetch
    if vcs
        return vcs.prepare_for_fetch
    end
    true
end

#prepare_for_installationObject



355
356
357
# File 'lib/build-tool/module.rb', line 355

def prepare_for_installation
    return build_system_required.prepare_for_installation
end

#prepare_for_rebaseObject

Check if an ssh-key is required and active it if necessary



332
333
334
335
336
337
# File 'lib/build-tool/module.rb', line 332

def prepare_for_rebase
    if vcs
        return vcs.prepare_for_rebase
    end
    true
end

#ready_for_fetchObject

Check if an ssh-key is required and active it if necessary



340
341
342
343
344
345
# File 'lib/build-tool/module.rb', line 340

def ready_for_fetch
    if vcs
        return vcs.ready_for_fetch
    end
    true
end

#ready_for_rebaseObject



347
348
349
350
351
352
# File 'lib/build-tool/module.rb', line 347

def ready_for_rebase
    if vcs
        return vcs.ready_for_rebase
    end
    true
end

#rebaseObject

Update the local changes with remote changes. Do not fetch changes from the remote repository.



283
284
285
286
287
288
289
290
291
292
# File 'lib/build-tool/module.rb', line 283

def rebase
    vcs_required.rebase
    if !patches.empty?
        if !vcs.patches_supported?
            raise NotImplementedError, "Patch support not implemented for vcs #{vcs.name}"
        end
        vcs_required.apply_patches( patches )
    end
    build_system_required.after_rebase
end

#reconfigureObject



298
299
300
# File 'lib/build-tool/module.rb', line 298

def reconfigure
    build_system_required.reconfigure
end

#remote_pathObject



211
212
213
# File 'lib/build-tool/module.rb', line 211

def remote_path
    @remote_path || @name
end

#remote_path=(remote_path) ⇒ Object

Remote path

Raises:



206
207
208
209
# File 'lib/build-tool/module.rb', line 206

def remote_path=( remote_path )
    raise ConfigurationError, "Attempt to set remote_path for module template #{name}" if is_template?
    @remote_path = remote_path
end

#remove_build_directoryObject



260
261
262
# File 'lib/build-tool/module.rb', line 260

def remove_build_directory
    build_system_required.remove_build_directory
end

#source_directoryObject Also known as: source_directory_required



215
216
217
# File 'lib/build-tool/module.rb', line 215

def source_directory
    build_prefix_required.join("src", local_path)
end

#to_sObject



359
360
361
# File 'lib/build-tool/module.rb', line 359

def to_s
    "#{object_id}: #{name}"
end

#vcsObject



220
221
222
223
# File 'lib/build-tool/module.rb', line 220

def vcs
    return vcs_configuration.vcs( self ) if vcs_configuration
    nil
end

#vcs_configuration_requiredObject



238
239
240
241
242
243
244
# File 'lib/build-tool/module.rb', line 238

def vcs_configuration_required
    vc = vcs_configuration
    if vc.nil?
        raise ConfigurationError, "No version control system configure for module #{name}."
    end
    return vc
end

#vcs_requiredObject



246
247
248
249
250
251
# File 'lib/build-tool/module.rb', line 246

def vcs_required
    if source_directory.nil?
        raise ConfigurationError, "No source directory specified for module #{name}."
    end
    return vcs_configuration_required.vcs( self )
end