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



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/build-tool/module.rb', line 87

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



124
125
126
# File 'lib/build-tool/module.rb', line 124

def description
    @description
end

#environmentObject



131
132
133
134
135
136
137
138
# File 'lib/build-tool/module.rb', line 131

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.



175
176
177
# File 'lib/build-tool/module.rb', line 175

def is_template=(value)
  @is_template = value
end

#long_descriptionObject



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

def long_description
    @long_description
end

#nameObject (readonly)

The module name



195
196
197
# File 'lib/build-tool/module.rb', line 195

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



218
219
220
221
222
223
224
225
226
227
228
# File 'lib/build-tool/module.rb', line 218

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



69
70
71
72
73
74
75
76
# File 'lib/build-tool/module.rb', line 69

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
# File 'lib/build-tool/module.rb', line 61

def build_prefix=( path )
    if path
        @build_prefix = Pathname.new( File.expand_path( path ) )
    else
        @build_prefix = nil
    end
end

#build_prefix_requiredObject

Will throw a exception if build_prefix is not set

Raises:



79
80
81
82
# File 'lib/build-tool/module.rb', line 79

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:



105
106
107
108
109
# File 'lib/build-tool/module.rb', line 105

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)


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

def checkedout?
    vcs_required.checkedout?
end

#clean(remove_build_directory = false) ⇒ Object

ACTIONS



248
249
250
251
252
253
254
255
256
# File 'lib/build-tool/module.rb', line 248

def clean( remove_build_directory = false )
    if remove_build_directory
        logger.info "Removing build directory."
        build_system_required.remove_build_directory
    else
        logger.info "Cleaning build directory."
        build_system_required.make( "clean" )
    end
end

#cleanup_after_vcs_accessObject

Cleanup after vcs_access



307
308
309
310
311
312
313
314
315
316
# File 'lib/build-tool/module.rb', line 307

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.



260
261
262
263
264
265
266
267
268
# File 'lib/build-tool/module.rb', line 260

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



289
290
291
# File 'lib/build-tool/module.rb', line 289

def configure
    build_system_required.configure
end

#configured?Boolean

Returns:

  • (Boolean)


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

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:



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

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.



272
273
274
# File 'lib/build-tool/module.rb', line 272

def fetch
    vcs_required.fetch
end

#gcObject

Garbage collect



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

def gc
    vcs.gc
end

#install(fast = false) ⇒ Object



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

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

#install_prefixObject



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

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



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

def install_prefix=( path )
    if path
        @install_prefix = Pathname.new( File.expand_path( path.to_s ) )
    else
        @install_prefix = nil
    end
end

#install_prefix_requiredObject

Will throw a exception if install_prefix is not set

Raises:



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

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)


176
177
178
# File 'lib/build-tool/module.rb', line 176

def is_template?
    @is_template
end

#local_pathObject



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

def local_path
    @local_path || @name
end

#local_path=(local_path) ⇒ Object

Raises:



180
181
182
183
# File 'lib/build-tool/module.rb', line 180

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



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

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

#our_build_systemObject



100
101
102
# File 'lib/build-tool/module.rb', line 100

def our_build_system
    @build_system
end

#prepare_for_installationObject



325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/build-tool/module.rb', line 325

def prepare_for_installation
    prefix = 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

#prepare_for_vcs_accessObject

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



319
320
321
322
323
# File 'lib/build-tool/module.rb', line 319

def prepare_for_vcs_access
    if vcs
        return vcs.prepare_for_access
    end
end

#rebaseObject

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



278
279
280
281
282
283
284
285
286
287
# File 'lib/build-tool/module.rb', line 278

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



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

def reconfigure
    build_system_required.reconfigure
end

#remote_pathObject



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

def remote_path
    @remote_path || @name
end

#remote_path=(remote_path) ⇒ Object

Remote path

Raises:



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

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

#source_directoryObject Also known as: source_directory_required



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

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

#to_sObject



338
339
340
# File 'lib/build-tool/module.rb', line 338

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

#vcsObject



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

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

#vcs_configuration_requiredObject



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

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



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

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