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:



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
205
# File 'lib/autobuild/package.rb', line 136

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



865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
# File 'lib/autobuild/package.rb', line 865

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



404
405
406
# File 'lib/autobuild/package.rb', line 404

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.



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

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



793
794
795
# File 'lib/autobuild/package.rb', line 793

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

.clearObject

Removes all package definitions



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

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



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

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:



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

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



712
713
714
715
716
717
718
719
720
721
# File 'lib/autobuild/package.rb', line 712

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



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/autobuild/package.rb', line 319

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
        if env_op.type == :source_after
            env.send(env_op.type, env_op.name, **env_op.values)
        else
            env.send(env_op.type, env_op.name, *env_op.values)
        end
        ops << env_op
    end
    ops
end

#apply_post_installObject



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

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)


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

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.



732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
# File 'lib/autobuild/package.rb', line 732

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)


725
726
727
# File 'lib/autobuild/package.rb', line 725

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



853
854
855
# File 'lib/autobuild/package.rb', line 853

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

#disable_docObject



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

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



844
845
846
847
848
849
850
# File 'lib/autobuild/package.rb', line 844

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

#disabled?Boolean

Returns:

  • (Boolean)


839
840
841
# File 'lib/autobuild/package.rb', line 839

def disabled?
    @disabled
end

#doc_dirObject



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

def doc_dir
    doc_utility.source_dir
end

#doc_dir=(value) ⇒ Object



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

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

#doc_disabledObject



660
661
662
# File 'lib/autobuild/package.rb', line 660

def doc_disabled
    doc_utility.disabled
end

#doc_target_dirObject



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

def doc_target_dir
    doc_utility.target_dir
end

#doc_target_dir=(value) ⇒ Object



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

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

#doc_task(&block) ⇒ Object



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

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

#enable_docObject



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

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



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

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)



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

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



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

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)



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

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

#env_source_after(file, shell: "sh") ⇒ Object

Add a file to be sourced at the end of the generated env file



292
293
294
# File 'lib/autobuild/package.rb', line 292

def env_source_after(file, shell: "sh")
    add_env_op EnvOp.new(:source_after, file, shell: shell)
end

#error(error_string) ⇒ Object

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



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

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)


398
399
400
# File 'lib/autobuild/package.rb', line 398

def failed?
    @failed
end

#file(*args, &block) ⇒ Object

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



609
610
611
612
613
614
# File 'lib/autobuild/package.rb', line 609

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



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

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)


686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
# File 'lib/autobuild/package.rb', line 686

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



359
360
361
362
363
364
365
366
# File 'lib/autobuild/package.rb', line 359

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)


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

def generates_doc?
    doc_utility.enabled?
end

#has_doc?Boolean

Returns:

  • (Boolean)


664
665
666
# File 'lib/autobuild/package.rb', line 664

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)



462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
# File 'lib/autobuild/package.rb', line 462

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)


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

def import_invoked?
    @import_invoked
end

#imported?Boolean

Returns:

  • (Boolean)


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

def imported?
    @imported
end

#in_dir(directory) ⇒ Object



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

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

#inspectObject



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

def inspect
    to_s
end

#installObject

Install the result in prefix



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

def install
    apply_post_install

    # Safety net for forgotten progress_done
    progress_done

    Autobuild.touch_stamp(installstamp)

    @installed = true
end

#install_docObject



656
657
658
# File 'lib/autobuild/package.rb', line 656

def install_doc
    doc_utility.install
end

#install_invoked?Boolean

Returns:

  • (Boolean)


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

def install_invoked?
    @install_invoked
end

#installed?Boolean

Returns:

  • (Boolean)


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

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.



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
447
448
449
450
451
452
453
454
455
456
# File 'lib/autobuild/package.rb', line 413

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



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

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.



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

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



809
810
811
# File 'lib/autobuild/package.rb', line 809

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

#post_install(*args, &block) ⇒ Object



668
669
670
671
672
673
674
675
676
# File 'lib/autobuild/package.rb', line 668

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”.



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# File 'lib/autobuild/package.rb', line 481

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.



385
386
387
# File 'lib/autobuild/package.rb', line 385

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.



391
392
393
394
395
# File 'lib/autobuild/package.rb', line 391

def prepare_for_rebuild
    prepare_for_forced_build

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

#process_formatting_string(msg, *prefix_style) ⇒ Object



497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
# File 'lib/autobuild/package.rb', line 497

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



545
546
547
548
# File 'lib/autobuild/package.rb', line 545

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

#progress_done(done_message = nil) ⇒ Object



550
551
552
553
# File 'lib/autobuild/package.rb', line 550

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



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

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.



760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
# File 'lib/autobuild/package.rb', line 760

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



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

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:



378
379
380
# File 'lib/autobuild/package.rb', line 378

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

#respond_to_missing?(name, _include_all) ⇒ Boolean

Returns:

  • (Boolean)


861
862
863
# File 'lib/autobuild/package.rb', line 861

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

#run(*args, &block) ⇒ Object



577
578
579
580
581
582
583
584
585
586
587
# File 'lib/autobuild/package.rb', line 577

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



678
679
680
# File 'lib/autobuild/package.rb', line 678

def self_fingerprint
    importer.fingerprint(self)
end

#source_tree(*args, &block) ⇒ Object



601
602
603
604
605
606
# File 'lib/autobuild/package.rb', line 601

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



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

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

#to_sObject



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

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
125
# 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



300
301
302
# File 'lib/autobuild/package.rb', line 300

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)


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

def updated?
    @updated
end

#utility(utility_name) ⇒ Object



857
858
859
# File 'lib/autobuild/package.rb', line 857

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



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

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

#working_directoryObject



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

def working_directory
    @in_dir_stack.last
end