Class: Autobuild::GenomModule

Inherits:
Autotools show all
Defined in:
lib/autobuild/packages/genom.rb

Instance Attribute Summary collapse

Attributes inherited from Autotools

#aclocal_flags, #autoconf_flags, #autoheader_flags, #automake_flags, #bear_flags, #configureflags, #force_config_status, #using

Attributes inherited from Configurable

#source_tree_excludes

Attributes inherited from Package

#dependencies, #env, #failures, #importdir, #importer, #logdir, #name, #prefix, #srcdir, #statistics, #update, #updated, #utilities

Instance Method Summary collapse

Methods inherited from Autotools

#build, #common_utility_handling, #configure, #configurestamp, #create_regen_target, enable_bear_globally=, enable_bear_globally?, #install, #prepare_for_forced_build, #tool_program, #use, #using_bear?, #with_doc, #with_tests

Methods inherited from Configurable

#build, builddir, #builddir, builddir=, #builddir=, #buildstamp, #configure, #ensure_dependencies_installed, #prepare_for_forced_build, #prepare_for_rebuild

Methods inherited from Package

[], #add_env_op, #add_stat, #all_dependencies, #applied_post_install?, #apply_env, #apply_post_install, #checked_out?, clear, #depends_on, #depends_on?, #disable, #disable_doc, #disable_phases, #disabled?, #doc_dir, #doc_dir=, #doc_disabled, #doc_target_dir, #doc_target_dir=, #doc_task, each, #enable_doc, #env_add, #env_add_path, #env_add_prefix, #env_set, #env_source_after, #error, #failed?, #file, #find_in_path, #fingerprint, #full_env, #generates_doc?, #has_doc?, #import=, #import_invoked?, #imported?, #in_dir, #inspect, #install, #install_doc, #install_invoked?, #installed?, #installstamp, #isolate_errors, #message, #method_missing, #parallel_build_level, #parallel_build_level=, #post_install, #prepare_for_forced_build, #prepare_for_rebuild, #process_formatting_string, #progress, #progress_done, #progress_start, #provides, #resolve_dependency_env, #resolved_env, #respond_to_missing?, #run, #self_fingerprint, #source_tree, #task, #to_s, #update?, #update_environment, #updated?, #utility, #warn, #working_directory

Constructor Details

#initialize(*args, &config) ⇒ GenomModule

Returns a new instance of GenomModule.



13
14
15
16
17
18
# File 'lib/autobuild/packages/genom.rb', line 13

def initialize(*args, &config)
    @genomflags = []
    super

    use :autogen => 'autogen'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Autobuild::Package

Instance Attribute Details

#genomflagsObject

Returns the value of attribute genomflags.



11
12
13
# File 'lib/autobuild/packages/genom.rb', line 11

def genomflags
  @genomflags
end

Instance Method Details

#cpp_optionsObject

Extract the cpp options from the genom options



40
41
42
# File 'lib/autobuild/packages/genom.rb', line 40

def cpp_options
    [*genomflags].find_all { |opt| opt =~ /^-D/ }
end

#genom_dependenciesObject

Make the genom-stamp file depend on

* genom includes
* genom canvas
* the genom binary itself


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/autobuild/packages/genom.rb', line 95

def genom_dependencies
    # Get the genom pkg-config
    if Package['genom']
        'genom'
    else
        genom_pkg = PkgConfig.new('genom')

        includedir = File.join(genom_pkg.includedir, 'genom')
        source_tree includedir

        canvasdir = File.join(genom_pkg.prefix, "share", "genom", genom_pkg.version);;
        source_tree canvasdir

        binary = File.join(genom_pkg.exec_prefix, "bin", "genom")
        file binary

        [binary, includedir, canvasdir]
    end
end

#genomstampObject

The file touched by genom on successful generation



37
# File 'lib/autobuild/packages/genom.rb', line 37

def genomstamp; File.join(srcdir, '.genom', 'genom-stamp') end

#get_providesObject

Alias this package to the ones defined in the EXTRA_PKGCONFIG flag in configure.ac.user



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/autobuild/packages/genom.rb', line 79

def get_provides
    configure_ac_user = File.join(srcdir, 'configure.ac.user')
    return unless File.readable?(configure_ac_user)
    File.open(configure_ac_user) do |f|
        f.each_line { |line|
            if line =~ /^\s*EXTRA_PKGCONFIG\s*=\s*"?([\w\-]+(?:\s+[\w\-]+)*)"?/
                $1.split(/\s+/).each { |pkg| provides pkg }
            end
        }
    end
end

#get_requiresObject

Extracts dependencies using the requires: field in the .gen file



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/autobuild/packages/genom.rb', line 45

def get_requires
    apionly = genomflags.find { |f| f == '-a' }
    cpp = Autobuild.tool(:cpp)
    currentBuffer = nil
    Open3.popen3("#{cpp} #{cpp_options.join(" ")} #{srcdir}/#{name}.gen") do |cin, out, err|
        out.each_line do |line|
            if line =~ /^\s*(codels_)?requires\s*:.*$/
                currentBuffer = ""
            end
            if currentBuffer
                currentBuffer += line
                if currentBuffer =~ /^\s*(codels_)?requires\s*:\s*(\"?\s*[\w\-=><0-9.\s]+\s*\"?(?:\s*,\s*\"?\s*[\w\-=><0-9.\s]+\s*\"?)*);/
                    # Remove the codels_requires lines if -a is given to genom
                    unless $1 == "codels_" && apionly
                        $2.split(/,/).each do |name|
                            if name.strip =~ /\s*\"?\s*([\w\-]+)\s*[<=>]+\s*[0-9.]+\s*\"?\s*/
                                depends_on $1
                            else
                                depends_on name.strip
                            end
                        end
                    end
                    currentBuffer = nil
                elsif currentBuffer =~ /^\s*(?:codels_)?requires.*;$/
                    # Check that the regexp is not too strict
                    warn "%s: failed to match #{currentBuffer}"
                end
            end
        end
    end
end

#import(options = Hash.new) ⇒ Object



20
21
22
23
# File 'lib/autobuild/packages/genom.rb', line 20

def import(options = Hash.new)
    super
    get_provides
end

#prepareObject

Called before running the rake tasks and after all imports have been made



27
28
29
30
31
32
33
34
# File 'lib/autobuild/packages/genom.rb', line 27

def prepare
    genomflags.flatten!
    get_requires

    super

    file genomstamp => dependencies.map { |p| Package[p].installstamp }
end

#regenObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/autobuild/packages/genom.rb', line 115

def regen
    cmdline = [ 'genom', "#{name}.gen", *genomflags ]

    # Check that the module has been generated with the same flags
    genom_mk = "#{srcdir}/autoconf/genom.mk"
    if File.exist?(genom_mk)
        contents = File.open(genom_mk).readlines
        old_file = contents.find { |l| l =~ /^GENFILE/ }.gsub('GENFILE=', '').strip
        old_flags = Shellwords.shellwords(
                    contents.find { |l| l =~ /^GENFLAGS/ }.gsub('GENFLAGS=', ''))

        if old_file != "#{name}.gen" || !(old_flags - genomflags).empty? || !(genomflags - old_flags).empty?
            FileUtils.rm_f genomstamp
        end
    end

    file buildstamp => genomstamp
    file genomstamp => genom_dependencies
    file genomstamp => srcdir do
        isolate_errors do
            in_dir(srcdir) do
                progress_start "generating GenoM for %s", :done_message => 'generated GenoM for %s' do
                    run('genom', *cmdline)
                end
            end
        end
    end

    acuser = File.join(srcdir, "configure.ac.user")
    file File.join(srcdir, 'configure') => acuser do
        isolate_errors do
            # configure does not depend on the .gen file
            # since the generation takes care of rebuilding configure
            # if .gen has changed
            progress_start "generating autotools for %s", :done_message => 'generated autotools for %s' do
                in_dir(srcdir) { run('genom', File.expand_path('autogen',  srcdir)) }
            end
        end
    end

    super("#{srcdir}/autoconf/configure.ac")
end