Class: Autobuild::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/autobuild/package.rb

Overview

Basic block for the autobuilder

The build is done in three phases:

- import
- prepare
- build & install

In the first stage checks the source out and/or updates it.

In the second stage, packages create their dependency structure to handle specific build systems. For instance, it is there that build systems like CMake are handled so that reconfiguration happens if needed. In the same way, it is there that code generation will happen as well.

Finally, the build stage actually calls the package's build targets (of the form “package_name-build”, which will trigger the build if needed.

Defined Under Namespace

Modules: TaskExtension Classes: EnvOp, IncompatibleEnvironment

Constant Summary collapse

@@packages =
{}
@@provides =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec = Hash.new) {|_self| ... } ⇒ Package

Returns a new instance of Package.

Yields:

  • (_self)

Yield Parameters:



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/autobuild/package.rb', line 135

def initialize(spec = Hash.new)
    @srcdir = @importdir = @logdir = @prefix = nil
    @updated = false
    @update = nil
    @failed = nil
    @dependencies = Array.new
    @provides = Array.new
    @statistics = Hash.new
    @parallel_build_level = nil
    @failures = Array.new
    @post_install_blocks = Array.new
    @applied_post_install = false
    @in_dir_stack = Array.new
    @utilities = Hash.new
    @env = Array.new
    @imported = false
    @prepared = false
    @built = false
    @disabled = nil

    if Hash === spec
        name, depends = spec.to_a.first
    else
        name = spec
        depends = nil
    end

    name = name.to_s
    @name = name
    if Autobuild::Package[name]
        raise ConfigException, "package #{name} is already defined"
    end

    @@packages[name] = self

    # Call the config block (if any)
    yield(self) if block_given?

    doc_utility.source_dir ||= 'doc'
    doc_utility.target_dir ||= name

    # Define the default tasks
    task "#{name}-import" do
        isolate_errors { import }
        @imported = true
    end
    task :import => "#{name}-import"

    # Define the prepare task
    task "#{name}-prepare" => "#{name}-import" do
        isolate_errors { prepare }
        @prepared = true
    end
    task :prepare => "#{name}-prepare"

    task "#{name}-build"

    task :build => "#{name}-build"
    task(name) do
        Rake::Task["#{name}-import"].invoke
        Rake::Task["#{name}-prepare"].invoke
        Rake::Task["#{name}-build"].invoke
        Rake::Task["#{name}-doc"].invoke if has_doc? && Autobuild.do_doc
    end
    task :default => name

    # The dependencies will be declared in the import phase,  so save
    # them there for now
    @spec_dependencies = depends
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
# File 'lib/autobuild/package.rb', line 854

def method_missing(name, *args, &block)
    case name.to_s
    when /(\w+)_utility$/
        utility_name = $1

        unless args.empty?
            raise ArgumentError, "expected 0 arguments and got #{args.size}"
        end

        begin
            return utility(utility_name)
        rescue ArgumentError => e
            raise NoMethodError.new(name), e.message, e.backtrace
        end
    end
    super
end

Instance Attribute Details

#dependenciesObject (readonly)

The list of packages this one depends upon



62
63
64
# File 'lib/autobuild/package.rb', line 62

def dependencies
  @dependencies
end

#envArray<EnvOp> (readonly)

List of environment values added by this package with #env_add, #env_add_path or #env_set

Returns:



73
74
75
# File 'lib/autobuild/package.rb', line 73

def env
  @env
end

#failuresObject (readonly)

If something failed on this package, returns the corresponding exception object. Otherwise, returns nil



394
395
396
# File 'lib/autobuild/package.rb', line 394

def failures
  @failures
end

#importdirObject

Absolute path to the import directory. See #importdir=



86
87
88
# File 'lib/autobuild/package.rb', line 86

def importdir
    File.expand_path(@importdir || srcdir, Autobuild.srcdir)
end

#importerObject

Sets an importer object for this package



59
60
61
# File 'lib/autobuild/package.rb', line 59

def importer
  @importer
end

#logdirObject

Absolute path to the log directory for this package. See #logdir=



96
97
98
99
100
101
102
# File 'lib/autobuild/package.rb', line 96

def logdir
    if @logdir
        File.expand_path(@logdir, prefix)
    else
        Autobuild.logdir
    end
end

#nameObject (readonly)

the package name



29
30
31
# File 'lib/autobuild/package.rb', line 29

def name
  @name
end

#prefixObject

Absolute path to the installation directory. See #prefix=



91
92
93
# File 'lib/autobuild/package.rb', line 91

def prefix
    File.expand_path(@prefix || '', Autobuild.prefix)
end

#srcdirObject

Absolute path to the source directory. See #srcdir=



81
82
83
# File 'lib/autobuild/package.rb', line 81

def srcdir
    File.expand_path(@srcdir || name, Autobuild.srcdir)
end

#statisticsObject (readonly)

Some statistics about the commands that have been run



65
66
67
# File 'lib/autobuild/package.rb', line 65

def statistics
  @statistics
end

#update=(value) ⇒ Object (writeonly)

Sets whether this package should update itself or not. If false, the only importer operation that will be performed is checkout

If nil, the global setting Autobuild.do_update is used



116
117
118
# File 'lib/autobuild/package.rb', line 116

def update=(value)
  @update = value
end

#updated=(value) ⇒ Object (writeonly)

Sets the attribute updated

Parameters:

  • value

    the value to set the attribute updated to.



126
127
128
# File 'lib/autobuild/package.rb', line 126

def updated=(value)
  @updated = value
end

#utilities{String=>Utility} (readonly)

The set of utilities attached to this package

Returns:



45
46
47
# File 'lib/autobuild/package.rb', line 45

def utilities
  @utilities
end

Class Method Details

.[](name) ⇒ Object

Gets a package from its name



782
783
784
# File 'lib/autobuild/package.rb', line 782

def self.[](name)
    @@packages[name.to_s] || @@provides[name.to_s]
end

.clearObject

Removes all package definitions



787
788
789
790
# File 'lib/autobuild/package.rb', line 787

def self.clear
    @@packages.clear
    @@provides.clear
end

.each(with_provides = false, &block) ⇒ Object

Iterates on all available packages if with_provides is true, includes the list of package aliases



774
775
776
777
778
779
# File 'lib/autobuild/package.rb', line 774

def self.each(with_provides = false, &block)
    return enum_for(:each, with_provides) unless block

    @@packages.each(&block)
    @@provides.each(&block) if with_provides
end

Instance Method Details

#add_env_op(envop) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Adds a new operation to this package's environment setup. This is a helper for the other env_* methods

Parameters:



242
243
244
# File 'lib/autobuild/package.rb', line 242

def add_env_op(envop)
    env << envop
end

#add_stat(phase, duration) ⇒ Object



75
76
77
78
# File 'lib/autobuild/package.rb', line 75

def add_stat(phase, duration)
    @statistics[phase] ||= 0
    @statistics[phase] += duration
end

#all_dependencies(result = Set.new) ⇒ Object

Returns the name of all the packages self depends on



701
702
703
704
705
706
707
708
709
710
# File 'lib/autobuild/package.rb', line 701

def all_dependencies(result = Set.new)
    dependencies.each do |pkg_name|
        pkg = Autobuild::Package[pkg_name]
        unless result.include?(pkg.name)
            result << pkg.name
            pkg.all_dependencies(result)
        end
    end
    result
end

#applied_post_install?Boolean

Whether #apply_post_install has been called

Returns:

  • (Boolean)


48
49
50
# File 'lib/autobuild/package.rb', line 48

def applied_post_install?
    @applied_post_install
end

#apply_env(env, set = Hash.new, ops = Array.new) ⇒ Array<EnvOp>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Apply this package's environment to the given Environment object

It does not apply the dependencies' environment. Call #resolved_env for that.

Parameters:

  • env (Environment)

    the environment to be updated

  • set (Set) (defaults to: Hash.new)

    a set of environment variable names which have already been set by a #env_set. Autoproj will verify that only one package sets a variable as to avoid unexpected conflicts.

Returns:

  • (Array<EnvOp>)

    list of environment-modifying operations applied so far



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/autobuild/package.rb', line 313

def apply_env(env, set = Hash.new, ops = Array.new)
    self.env.each do |env_op|
        next if ops.last == env_op

        if env_op.type == :set
            if (last = set[env_op.name])
                last_pkg, last_values = *last
                if last_values != env_op.values
                    raise IncompatibleEnvironment, "trying to reset "\
                        "#{env_op.name} to #{env_op.values} in #{name} "\
                        "but this conflicts with #{last_pkg.name} "\
                        "already setting it to #{last_values}"
                end
            else
                set[env_op.name] = [self, env_op.values]
            end
        end
        env.send(env_op.type, env_op.name, *env_op.values)
        ops << env_op
    end
    ops
end

#apply_post_installObject



544
545
546
547
548
549
550
551
552
# File 'lib/autobuild/package.rb', line 544

def apply_post_install
    Autobuild.post_install_handlers.each do |b|
        Autobuild.apply_post_install(self, b)
    end
    @post_install_blocks.each do |b|
        Autobuild.apply_post_install(self, b)
    end
    @applied_post_install = true
end

#checked_out?Boolean

Whether the package's source directory is present on disk

Returns:

  • (Boolean)


207
208
209
# File 'lib/autobuild/package.rb', line 207

def checked_out?
    File.directory?(srcdir)
end

#depends_on(*packages) ⇒ Object

This package depends on packages. It means that its build will always be triggered after the packages listed in packages are built and installed.



721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
# File 'lib/autobuild/package.rb', line 721

def depends_on(*packages)
    packages.each do |p|
        p = p.name if p.respond_to?(:name)
        unless p.respond_to?(:to_str)
            raise ArgumentError, "#{p.inspect} should be a string"
        end

        p = p.to_str
        next if p == name

        unless (pkg = Package[p])
            raise ConfigException.new(self), "package #{p}, "\
                "listed as a dependency of #{name}, is not defined"
        end

        next if @dependencies.include?(pkg.name)

        Autobuild.message "#{name} depends on #{pkg.name}" if Autobuild.verbose

        task "#{name}-import"  => "#{pkg.name}-import"
        task "#{name}-prepare" => "#{pkg.name}-prepare"
        task "#{name}-build"   => "#{pkg.name}-build"
        @dependencies << pkg.name
    end
end

#depends_on?(package_name) ⇒ Boolean

Returns true if this package depends on package_name and false otherwise.

Returns:

  • (Boolean)


714
715
716
# File 'lib/autobuild/package.rb', line 714

def depends_on?(package_name)
    @dependencies.include?(package_name)
end

#disable(_phases = Autobuild.all_phases) ⇒ Object

Make sure that this package will be ignored in the build



842
843
844
# File 'lib/autobuild/package.rb', line 842

def disable(_phases = Autobuild.all_phases)
    @disabled = true
end

#disable_docObject



641
642
643
# File 'lib/autobuild/package.rb', line 641

def disable_doc
    doc_utility.enabled = false
end

#disable_phases(*phases) ⇒ Object

Makes sure that the specified phases of this package will be no-ops



833
834
835
836
837
838
839
# File 'lib/autobuild/package.rb', line 833

def disable_phases(*phases)
    phases.each do |phase|
        task "#{name}-#{phase}"
        t = Rake::Task["#{name}-#{phase}"]
        t.disable
    end
end

#disabled?Boolean

Returns:

  • (Boolean)


828
829
830
# File 'lib/autobuild/package.rb', line 828

def disabled?
    @disabled
end

#doc_dirObject



617
618
619
# File 'lib/autobuild/package.rb', line 617

def doc_dir
    doc_utility.source_dir
end

#doc_dir=(value) ⇒ Object



613
614
615
# File 'lib/autobuild/package.rb', line 613

def doc_dir=(value)
    doc_utility.source_dir = value
end

#doc_disabledObject



649
650
651
# File 'lib/autobuild/package.rb', line 649

def doc_disabled
    doc_utility.disabled
end

#doc_target_dirObject



625
626
627
# File 'lib/autobuild/package.rb', line 625

def doc_target_dir
    doc_utility.target_dir
end

#doc_target_dir=(value) ⇒ Object



621
622
623
# File 'lib/autobuild/package.rb', line 621

def doc_target_dir=(value)
    doc_utility.target_dir = value
end

#doc_task(&block) ⇒ Object



629
630
631
# File 'lib/autobuild/package.rb', line 629

def doc_task(&block)
    doc_utility.task(&block)
end

#enable_docObject



637
638
639
# File 'lib/autobuild/package.rb', line 637

def enable_doc
    doc_utility.enabled = true
end

#env_add(name, *values) ⇒ void

This method returns an undefined value.

Add value(s) to a list-based environment variable

This differs from #env_add_path in that a value can be added multiple times in the list.

Parameters:

  • name (String)

    the environment variable name

  • values (Array<String>)

    list of values to be added



254
255
256
# File 'lib/autobuild/package.rb', line 254

def env_add(name, *values)
    add_env_op EnvOp.new(:add, name, values)
end

#env_add_path(name, *values) ⇒ void

This method returns an undefined value.

Add a new path to a PATH-like environment variable

It differs from #env_add in its handling of duplicate values. Any value already existing will be removed, and re-appended to the value so that it takes priority.

Parameters:

  • name (String)

    the environment variable name

  • values (Array<String>)

    list of values. They will be joined using the platform's standard separator (e.g. : on Unices)



268
269
270
# File 'lib/autobuild/package.rb', line 268

def env_add_path(name, *values)
    add_env_op EnvOp.new(:add_path, name, values)
end

#env_add_prefix(prefix, includes = nil) ⇒ Object

Add a prefix to be resolved into the environment

Autoproj will update all “standard” environment variables based on what it finds as subdirectories from the prefix



286
287
288
# File 'lib/autobuild/package.rb', line 286

def env_add_prefix(prefix, includes = nil)
    add_env_op EnvOp.new(:add_prefix, prefix, [includes])
end

#env_set(name, *values) ⇒ void

This method returns an undefined value.

Set an environment variable to a list of values

Parameters:

  • name (String)

    the environment variable name

  • values (Array<String>)

    list of values. They will be joined using the platform's standard separator (e.g. : on Unices)



278
279
280
# File 'lib/autobuild/package.rb', line 278

def env_set(name, *values)
    add_env_op EnvOp.new(:set, name, values)
end

#error(error_string) ⇒ Object

Display a progress message. %s in the string is replaced by the package name



516
517
518
# File 'lib/autobuild/package.rb', line 516

def error(error_string)
    message("  ERROR: #{error_string}", :red, :bold)
end

#failed?Boolean

Returns true if one of the operations applied on this package failed

Returns:

  • (Boolean)


388
389
390
# File 'lib/autobuild/package.rb', line 388

def failed?
    @failed
end

#file(*args, &block) ⇒ Object

Calls Rake to define a file task and then extends it with TaskExtension



598
599
600
601
602
603
# File 'lib/autobuild/package.rb', line 598

def file(*args, &block)
    task = super
    task.extend TaskExtension
    task.package = self
    task
end

#find_in_path(file, envvar = 'PATH') ⇒ Object

Find a file in a path-like environment variable



359
360
361
# File 'lib/autobuild/package.rb', line 359

def find_in_path(file, envvar = 'PATH')
    full_env.find_in_path(file, envvar)
end

#fingerprint(recursive: true, memo: {}) ⇒ String

Returns a unique hash representing a state of the package and its dependencies, if any dependency can't calculate its own fingerprint the result will be nil

Returns:

  • (String)


675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
# File 'lib/autobuild/package.rb', line 675

def fingerprint(recursive: true, memo: {})
    return memo[name] if memo.key?(name)

    self_fingerprint = self.self_fingerprint
    return unless self_fingerprint
    if dependencies.empty?
        return (memo[name] = self_fingerprint)
    elsif !recursive
        return self_fingerprint
    end

    dependency_fingerprints = dependencies.sort.map do |pkg_name|
        pkg = Autobuild::Package[pkg_name]
        unless (fingerprint = memo[pkg.name])
            fingerprint = pkg.fingerprint(recursive: true, memo: memo)
            break unless fingerprint
        end
        fingerprint
    end
    return unless dependency_fingerprints

    memo[name] = Digest::SHA1.hexdigest(
        self_fingerprint + dependency_fingerprints.join(""))
end

#full_env(root = Autobuild.env) ⇒ Object

This package's environment



349
350
351
352
353
354
355
356
# File 'lib/autobuild/package.rb', line 349

def full_env(root = Autobuild.env)
    set = Hash.new
    env = root.dup
    ops = Array.new
    ops = resolve_dependency_env(env, set, ops)
    apply_env(env, set, ops)
    env
end

#generates_doc?Boolean

Returns:

  • (Boolean)


633
634
635
# File 'lib/autobuild/package.rb', line 633

def generates_doc?
    doc_utility.enabled?
end

#has_doc?Boolean

Returns:

  • (Boolean)


653
654
655
# File 'lib/autobuild/package.rb', line 653

def has_doc?
    doc_utility.has_task?
end

#import(*old_boolean, **options) ⇒ Object

Call the importer if there is one. Autodetection of “provides” should be done there as well.

(see Importer#import)



452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/autobuild/package.rb', line 452

def import(*old_boolean, **options)
    options = { only_local: old_boolean.first } unless old_boolean.empty?

    @import_invoked = true
    if @importer
        result = @importer.import(self, **options)
    elsif update?
        message "%s: no importer defined, doing nothing"
    end
    @imported = true

    # Add the dependencies declared in spec
    depends_on(*@spec_dependencies) if @spec_dependencies
    result
end

#import=(value) ⇒ Object

Sets importer object for this package. Defined for backwards compatibility. Use the #importer attribute instead



54
55
56
# File 'lib/autobuild/package.rb', line 54

def import=(value)
    @importer = value
end

#import_invoked?Boolean

Returns:

  • (Boolean)


211
212
213
# File 'lib/autobuild/package.rb', line 211

def import_invoked?
    @import_invoked
end

#imported?Boolean

Returns:

  • (Boolean)


215
216
217
# File 'lib/autobuild/package.rb', line 215

def imported?
    @imported
end

#in_dir(directory) ⇒ Object



821
822
823
824
825
826
# File 'lib/autobuild/package.rb', line 821

def in_dir(directory)
    @in_dir_stack << directory
    yield
ensure
    @in_dir_stack.pop
end

#inspectObject



231
232
233
# File 'lib/autobuild/package.rb', line 231

def inspect
    to_s
end

#installObject

Install the result in prefix



555
556
557
558
559
560
561
562
563
564
# File 'lib/autobuild/package.rb', line 555

def install
    apply_post_install

    # Safety net for forgotten progress_done
    progress_done

    Autobuild.touch_stamp(installstamp)

    @installed = true
end

#install_docObject



645
646
647
# File 'lib/autobuild/package.rb', line 645

def install_doc
    doc_utility.install
end

#install_invoked?Boolean

Returns:

  • (Boolean)


219
220
221
# File 'lib/autobuild/package.rb', line 219

def install_invoked?
    @install_invoked
end

#installed?Boolean

Returns:

  • (Boolean)


223
224
225
# File 'lib/autobuild/package.rb', line 223

def installed?
    @installed
end

#installstampObject

The file which marks when the last sucessful install has finished. The path is absolute

A package is sucessfully built when it is installed



108
109
110
# File 'lib/autobuild/package.rb', line 108

def installstamp
    File.join(logdir, "#{name}-#{STAMPFILE}")
end

#isolate_errors(options = Hash.new) ⇒ Object

If Autobuild.ignore_errors is set, an exception raised from within the provided block will be filtered out, only displaying a message instead of stopping the build

Moreover, the package will be marked as “failed” and isolate_errors will subsequently be a noop. I.e. if build fails, install will do nothing.



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/autobuild/package.rb', line 403

def isolate_errors(options = Hash.new)
    options = Hash[mark_as_failed: true] unless options.kind_of?(Hash)
    options = validate_options options,
                               mark_as_failed: true,
                               ignore_errors: Autobuild.ignore_errors

    # Don't do anything if we already have failed
    if failed?
        unless options[:ignore_errors]
            raise AlreadyFailedError, "attempting to do an operation "\
                "on a failed package"
        end

        return
    end

    begin
        toplevel = !Thread.current[:isolate_errors]
        Thread.current[:isolate_errors] = true
        yield
    rescue InteractionRequired
        raise
    rescue Interrupt
        raise
    rescue ::Exception => e
        @failures << e
        @failed = true if options[:mark_as_failed]

        if options[:ignore_errors]
            lines = e.to_s.split("\n")
            lines = e.message.split("\n") if lines.empty?
            lines = ["unknown error"] if lines.empty?
            message(lines.shift, :red, :bold)
            lines.each do |line|
                message(line)
            end
            nil
        else
            raise
        end
    ensure
        Thread.current[:isolate_errors] = false if toplevel
    end
end

#message(*args) ⇒ Object

Display a progress message. %s in the string is replaced by the package name



522
523
524
525
# File 'lib/autobuild/package.rb', line 522

def message(*args)
    args[0] = "  #{process_formatting_string(args[0])}" unless args.empty?
    Autobuild.message(*args)
end

#parallel_build_levelObject

Returns the level of parallelism authorized during the build for this particular package. If not set, defaults to the system-wide option (Autobuild.parallel_build_level and Autobuild.parallel_build_level=).

The default value is the number of CPUs on this system.



807
808
809
810
811
812
813
814
815
# File 'lib/autobuild/package.rb', line 807

def parallel_build_level
    if @parallel_build_level.nil?
        Autobuild.parallel_build_level
    elsif !@parallel_build_level || @parallel_build_level <= 0
        1
    else
        @parallel_build_level
    end
end

#parallel_build_level=(value) ⇒ Object

Sets the level of parallelism authorized while building this package

See #parallel_build_level and Autobuild.parallel_build_level for more information.

Note that not all package types use this value



798
799
800
# File 'lib/autobuild/package.rb', line 798

def parallel_build_level=(value)
    @parallel_build_level = Integer(value)
end

#post_install(*args, &block) ⇒ Object



657
658
659
660
661
662
663
664
665
# File 'lib/autobuild/package.rb', line 657

def post_install(*args, &block)
    if args.empty?
        @post_install_blocks << block
    elsif !block
        @post_install_blocks << args
    else
        raise ArgumentError, "cannot set both arguments and block"
    end
end

#prepareObject

Create all the dependencies required to reconfigure and/or rebuild the package when required. The package's build target is called “package_name-build”.



471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/autobuild/package.rb', line 471

def prepare
    super if defined? super

    stamps = dependencies.map { |p| Package[p].installstamp }

    file installstamp => stamps do
        isolate_errors do
            @install_invoked = true
            install
        end
    end
    task "#{name}-build" => installstamp

    @prepared = true
end

#prepare_for_forced_buildObject

Called before a forced build. It should remove all the timestamp and target files so that all the build phases of this package gets retriggered. However, it should not clean the build products.



375
376
377
# File 'lib/autobuild/package.rb', line 375

def prepare_for_forced_build
    FileUtils.rm_f installstamp if File.exist?(installstamp)
end

#prepare_for_rebuildObject

Called when the user asked for a full rebuild. It should delete the build products so that a full build is retriggered.



381
382
383
384
385
# File 'lib/autobuild/package.rb', line 381

def prepare_for_rebuild
    prepare_for_forced_build

    FileUtils.rm_f installstamp if File.exist?(installstamp)
end

#process_formatting_string(msg, *prefix_style) ⇒ Object



487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/autobuild/package.rb', line 487

def process_formatting_string(msg, *prefix_style)
    prefix = []
    suffix = []
    msg.split(" ").each do |token|
        if token =~ /%s/
            suffix << token.gsub(/%s/, name)
        elsif suffix.empty?
            prefix << token
        else suffix << token
        end
    end
    if suffix.empty?
        msg
    elsif prefix_style.empty?
        (prefix + suffix).join(" ")
    else
        colorized_prefix = Autobuild.color(prefix.join(" "), *prefix_style)
        [colorized_prefix, *suffix].join(" ")
    end
end

#progress(*args) ⇒ Object



534
535
536
537
# File 'lib/autobuild/package.rb', line 534

def progress(*args)
    args[0] = process_formatting_string(args[0], :bold)
    Autobuild.progress(self, *args)
end

#progress_done(done_message = nil) ⇒ Object



539
540
541
542
# File 'lib/autobuild/package.rb', line 539

def progress_done(done_message = nil)
    done_message = process_formatting_string(done_message) if done_message
    Autobuild.progress_done(self, message: done_message)
end

#progress_start(*args, done_message: nil, **raw_options, &block) ⇒ Object



527
528
529
530
531
532
# File 'lib/autobuild/package.rb', line 527

def progress_start(*args, done_message: nil, **raw_options, &block)
    args[0] = process_formatting_string(args[0], :bold)
    done_message = process_formatting_string(done_message) if done_message
    Autobuild.progress_start(self, *args,
                             done_message: done_message, **raw_options, &block)
end

#provides(*packages) ⇒ Object

Declare that this package provides packages. In effect, the names listed in packages are aliases for this package.



749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
# File 'lib/autobuild/package.rb', line 749

def provides(*packages)
    packages.each do |p|
        unless p.respond_to?(:to_str)
            raise ArgumentError, "#{p.inspect} should be a string"
        end

        p = p.to_str
        next if p == name
        next if @provides.include?(name)

        @@provides[p] = self

        Autobuild.message "#{name} provides #{p}" if Autobuild.verbose

        task p => name
        task "#{p}-import" => "#{name}-import"
        task "#{p}-prepare" => "#{name}-prepare"
        task "#{p}-build" => "#{name}-build"
        @provides << p
    end
end

#resolve_dependency_env(env, set, ops) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Updates an Environment object with the environment of the package's dependencies



340
341
342
343
344
345
346
# File 'lib/autobuild/package.rb', line 340

def resolve_dependency_env(env, set, ops)
    all_dependencies.each do |pkg_name|
        pkg = Autobuild::Package[pkg_name]
        ops = pkg.apply_env(env, set, ops)
    end
    ops
end

#resolved_env(root = Autobuild.env) ⇒ Hash<String,String>

Resolves this package's environment into Hash form

Parameters:

  • root (Environment) (defaults to: Autobuild.env)

    the base environment object to update

Returns:

  • (Hash<String,String>)

    the full environment

See Also:



368
369
370
# File 'lib/autobuild/package.rb', line 368

def resolved_env(root = Autobuild.env)
    full_env(root).resolved_env
end

#respond_to_missing?(name, _include_all) ⇒ Boolean

Returns:

  • (Boolean)


850
851
852
# File 'lib/autobuild/package.rb', line 850

def respond_to_missing?(name, _include_all)
    utilities.key?(name.to_s)
end

#run(*args, &block) ⇒ Object



566
567
568
569
570
571
572
573
574
575
576
# File 'lib/autobuild/package.rb', line 566

def run(*args, &block)
    options =
        if args.last.kind_of?(Hash)
            args.pop
        else
            Hash.new
        end
    options[:env] = options.delete(:resolved_env) ||
                    (options[:env] || Hash.new).merge(resolved_env)
    Autobuild::Subprocess.run(self, *args, options, &block)
end

#self_fingerprintObject



667
668
669
# File 'lib/autobuild/package.rb', line 667

def self_fingerprint
    importer.fingerprint(self)
end

#source_tree(*args, &block) ⇒ Object



590
591
592
593
594
595
# File 'lib/autobuild/package.rb', line 590

def source_tree(*args, &block)
    task = Autobuild.source_tree(*args, &block)
    task.extend TaskExtension
    task.package = self
    task
end

#task(*args, &block) ⇒ Object

Calls Rake to define a plain task and then extends it with TaskExtension



606
607
608
609
610
611
# File 'lib/autobuild/package.rb', line 606

def task(*args, &block)
    task = super
    task.extend TaskExtension
    task.package = self
    task
end

#to_sObject



227
228
229
# File 'lib/autobuild/package.rb', line 227

def to_s
    "#<#{self.class} name=#{name}>"
end

#update?Boolean

True if this package should update itself when #import is called

Returns:

  • (Boolean)


119
120
121
122
123
124
# File 'lib/autobuild/package.rb', line 119

def update?
    if @update.nil?
        Autobuild.do_update
    else @update
    end
end

#update_environmentObject

Hook called by autoproj to set up the default environment for this package

By default, it calls #env_add_prefix with this package's prefix



294
295
296
# File 'lib/autobuild/package.rb', line 294

def update_environment
    env_add_prefix prefix
end

#updated?Boolean

Returns true if this package has already been updated. It will not be true if the importer has been called while Autobuild.do_update was false.

Returns:

  • (Boolean)


131
132
133
# File 'lib/autobuild/package.rb', line 131

def updated?
    @updated
end

#utility(utility_name) ⇒ Object



846
847
848
# File 'lib/autobuild/package.rb', line 846

def utility(utility_name)
    utilities[utility_name.to_s] ||= Autobuild.create_utility(utility_name, self)
end

#warn(warning_string) ⇒ Object

Display a progress message. %s in the string is replaced by the package name



510
511
512
# File 'lib/autobuild/package.rb', line 510

def warn(warning_string)
    message("  WARN: #{warning_string}", :magenta)
end

#working_directoryObject



817
818
819
# File 'lib/autobuild/package.rb', line 817

def working_directory
    @in_dir_stack.last
end