Class: Autoproj::Ops::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/autoproj/ops/configuration.rb

Overview

Implementation of the operations to manage the configuration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workspace, update_from: nil) ⇒ Configuration

Returns a new instance of Configuration.

Parameters:

  • manifest (Manifest)
  • loader (Loader)
  • options (Hash)

    a customizable set of options



103
104
105
106
107
# File 'lib/autoproj/ops/configuration.rb', line 103

def initialize(workspace, update_from: nil)
    @ws = workspace
    @update_from = update_from
    @remote_update_message_displayed = false
end

Instance Attribute Details

#update_fromnil, InstallationManifest (readonly)

The autoproj install we should update from (if any)

Returns:



73
74
75
# File 'lib/autoproj/ops/configuration.rb', line 73

def update_from
  @update_from
end

#wsObject (readonly)

Returns the value of attribute ws.



68
69
70
# File 'lib/autoproj/ops/configuration.rb', line 68

def ws
  @ws
end

Instance Method Details

#auto_add_package(name, full_path) ⇒ String?

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.

Attempts to auto-add the package checked out at the given path

Parameters:

  • full_path (String)

Returns:

  • (String, nil)

    either the name of the package handler used to define the package, or nil if no handler could be found



560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/autoproj/ops/configuration.rb', line 560

def auto_add_package(name, full_path)
    manifest = ws.manifest
    handler, _srcdir = Autoproj.package_handler_for(full_path)
    if handler
        ws.set_as_main_workspace do
            ws.in_package_set(manifest.main_package_set, manifest.file) do
                send(handler, name)
            end
        end
        handler
    end
end

#auto_add_packages_from_layoutObject

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.

Attempts to find packages mentioned in the layout but that are not defined, and auto-define them if they can be found on disk

It only warns about packages that can’t be defined that way are on



524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
# File 'lib/autoproj/ops/configuration.rb', line 524

def auto_add_packages_from_layout
    manifest = ws.manifest

    # Auto-add packages that are
    #  * present on disk
    #  * listed in the layout part of the manifest
    #  * but have no definition
    explicit = manifest.normalized_layout
    explicit.each do |pkg_or_set, layout_level|
        next if manifest.find_autobuild_package(pkg_or_set)
        next if manifest.has_package_set?(pkg_or_set)

        full_path = File.expand_path(
            File.join(ws.source_dir, layout_level, pkg_or_set)
        )
        next unless File.directory?(full_path)

        if (handler = auto_add_package(pkg_or_set, full_path))
            handler_name = handler.gsub(/_package/, "")
            layout_level_msg = "in #{layout_level} " if layout_level != "/"
            Autoproj.message "  auto-added #{pkg_or_set} #{layout_level_msg}"\
                             "using the #{handler_name} package handler"
        else
            Autoproj.warn "cannot auto-add #{pkg_or_set}: "\
                          "unknown package type"
        end
    end
end

#cleanup_remotes_dir(package_sets = ws.manifest.package_sets, required_remotes_dirs = Array.new) ⇒ Object

Removes from #remotes_dir the directories that do not match a package set



347
348
349
350
351
352
353
354
355
356
357
# File 'lib/autoproj/ops/configuration.rb', line 347

def cleanup_remotes_dir(package_sets = ws.manifest.package_sets, required_remotes_dirs = Array.new)
    # Cleanup the .remotes and remotes_symlinks_dir directories
    Dir.glob(File.join(remotes_dir, "*")).each do |dir|
        dir = File.expand_path(dir)
        # Once a package set has been checked out during the process,
        # keep it -- so that it won't be checked out again
        if File.directory?(dir) && !required_remotes_dirs.include?(dir)
            FileUtils.rm_rf dir
        end
    end
end

#cleanup_remotes_user_dir(package_sets = ws.manifest.package_sets, required_user_dirs = Array.new) ⇒ Object

Removes from #remotes_user_dir the directories that do not match a package set



361
362
363
364
365
366
367
368
369
# File 'lib/autoproj/ops/configuration.rb', line 361

def cleanup_remotes_user_dir(package_sets = ws.manifest.package_sets, required_user_dirs = Array.new)
    Dir.glob(File.join(remotes_user_dir, "*")).each do |file|
        file = File.expand_path(file)
        user_dir = File.basename(file)
        if File.symlink?(file) && !required_user_dirs.include?(user_dir)
            FileUtils.rm_f file
        end
    end
end

#create_remote_set_user_dir(vcs) ⇒ String

Create the user-visible directory for a remote package set

Parameters:

Returns:

  • (String)

    the full path to the created user dir



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/autoproj/ops/configuration.rb', line 197

def create_remote_set_user_dir(vcs)
    name = PackageSet.name_of(ws, vcs)
    raw_local_dir = PackageSet.raw_local_dir_of(ws, vcs)
    FileUtils.mkdir_p(remotes_user_dir)
    symlink_dest = File.join(remotes_user_dir, name)

    # Check if the current symlink is valid, and recreate it if it
    # is not
    if File.symlink?(symlink_dest)
        dest = File.readlink(symlink_dest)
        if dest != raw_local_dir
            FileUtils.rm_f symlink_dest
            Autoproj.create_symlink(raw_local_dir, symlink_dest)
        end
    else
        FileUtils.rm_f symlink_dest
        Autoproj.create_symlink(raw_local_dir, symlink_dest)
    end

    symlink_dest
end

#handle_keep_going(keep_going, vcs, failures) ⇒ Object



416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/autoproj/ops/configuration.rb', line 416

def handle_keep_going(keep_going, vcs, failures)
    yield
    false
rescue Interrupt
    raise
rescue Exception => failure_reason
    if keep_going
        report_import_failure(vcs, failure_reason)
        failures << failure_reason
        true
    else
        raise
    end
end

#inspectObject



371
372
373
# File 'lib/autoproj/ops/configuration.rb', line 371

def inspect
    to_s
end

#load_and_update_package_sets(root_pkg_set, only_local: false, checkout_only: !Autobuild.do_update,, keep_going: false, reset: false, retry_count: nil) {|osdep| ... } ⇒ Object

Load the package set information

It loads the package set information as required by manifest and makes sure that they are either updated (if Autobuild.do_update is true), or at least checked out.

Yield Parameters:

  • osdep (String)

    the name of an osdep required to import the package sets



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
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
# File 'lib/autoproj/ops/configuration.rb', line 249

def load_and_update_package_sets(root_pkg_set,
    only_local: false,
    checkout_only: !Autobuild.do_update,
    keep_going: false,
    reset: false,
    retry_count: nil)
    package_sets = [root_pkg_set]
    by_repository_id = Hash.new
    by_name = Hash.new
    failures = Array.new

    required_remotes_dirs = Array.new

    queue = queue_auto_imports_if_needed(Array.new, root_pkg_set, root_pkg_set)
    until queue.empty?
        vcs, import_options, imported_from = queue.shift
        repository_id = vcs.overrides_key
        if (already_processed = by_repository_id[repository_id])
            already_processed_vcs, already_processed_from, pkg_set = *already_processed
            if (already_processed_from != root_pkg_set) && (already_processed_vcs != vcs)
                Autoproj.warn "already loaded the package set from #{already_processed_vcs} from #{already_processed_from.name}, this overrides different settings (#{vcs}) found in #{imported_from.name}"
            end

            if imported_from
                pkg_set.imported_from << imported_from
                imported_from.imports << pkg_set
            end
            next
        end
        by_repository_id[repository_id] = [vcs, imported_from]

        # Make sure the package set has been already checked out to
        # retrieve the actual name of the package set
        unless vcs.local?
            failed = handle_keep_going(keep_going, vcs, failures) do
                update_remote_package_set(
                    vcs, checkout_only: checkout_only,
                         only_local: only_local, reset: reset,
                         retry_count: retry_count
                )
            end
            raw_local_dir = PackageSet.raw_local_dir_of(ws, vcs)

            # We really can't continue if the VCS was being checked out
            # and that failed
            raise failures.last if failed && !File.directory?(raw_local_dir)

            required_remotes_dirs << raw_local_dir
        end

        name = PackageSet.name_of(ws, vcs)

        required_user_dirs = by_name.collect { |k, v| k }
        Autoproj.debug "Trying to load package_set: #{name} from definition #{repository_id}"
        Autoproj.debug "Already loaded package_sets are: #{required_user_dirs}"

        if (already_loaded = by_name[name])
            already_loaded_pkg_set, already_loaded_vcs = *already_loaded
            if already_loaded_vcs != vcs
                if imported_from
                    Autoproj.warn "redundant auto-import of package set '#{name}' by package set '#{imported_from.name}'"
                    Autoproj.warn "    A package set with the same name has already been imported from"
                    Autoproj.warn "        #{already_loaded_vcs}"
                    Autoproj.warn "    Skipping the following one: "
                    Autoproj.warn "        #{vcs}"
                else
                    Autoproj.warn "the manifest refers to a package set from #{vcs}, but a package set with the same name (#{name}) has already been imported from #{already_loaded_vcs}, I am skipping this one"
                end
            end

            if imported_from
                already_loaded_pkg_set.imported_from << imported_from
                imported_from.imports << already_loaded_pkg_set
                by_repository_id[repository_id][2] = already_loaded_pkg_set
            end
            next
        end

        create_remote_set_user_dir(vcs) unless vcs.local?
        pkg_set = load_package_set(vcs, import_options, imported_from)
        by_repository_id[repository_id][2] = pkg_set
        package_sets << pkg_set

        by_name[pkg_set.name] = [pkg_set, vcs, import_options, imported_from]

        # Finally, queue the imports
        queue_auto_imports_if_needed(queue, pkg_set, root_pkg_set)
    end

    required_user_dirs = by_name.collect { |k, v| k }
    cleanup_remotes_dir(package_sets, required_remotes_dirs)
    cleanup_remotes_user_dir(package_sets, required_user_dirs)

    [package_sets, failures]
end

#load_osdeps_from_package_setsvoid

This method returns an undefined value.

Load OS dependency information contained in our registered package sets into the provided osdep object

This is included in #load_package_sets



601
602
603
604
605
606
607
608
609
610
# File 'lib/autoproj/ops/configuration.rb', line 601

def load_osdeps_from_package_sets
    ws.manifest.each_package_set do |pkg_set|
        pkg_set.each_osdeps_file do |file|
            file_osdeps = pkg_set.load_osdeps(
                file, operating_system: ws.operating_system
            )
            ws.os_package_resolver.merge(file_osdeps)
        end
    end
end

#load_osrepos_from_package_setsvoid

This method returns an undefined value.

Load OS repository information contained in our registered package sets into the provided osrepo object

This is included in #load_package_sets



618
619
620
621
622
623
624
625
# File 'lib/autoproj/ops/configuration.rb', line 618

def load_osrepos_from_package_sets
    ws.manifest.each_package_set do |pkg_set|
        pkg_set.each_osrepos_file do |file|
            file_osrepos = pkg_set.load_osrepos(file)
            ws.os_repository_resolver.merge(file_osrepos)
        end
    end
end

#load_package_set(vcs, options, imported_from) ⇒ Object



219
220
221
222
223
224
225
226
227
228
# File 'lib/autoproj/ops/configuration.rb', line 219

def load_package_set(vcs, options, imported_from)
    pkg_set = PackageSet.new(ws, vcs)
    pkg_set.auto_imports = options[:auto_imports]
    pkg_set.load_description_file
    if imported_from
        pkg_set.imported_from << imported_from
        imported_from.imports << pkg_set
    end
    pkg_set
end

#load_package_set_information(mainline: nil) ⇒ Object



480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'lib/autoproj/ops/configuration.rb', line 480

def load_package_set_information(mainline: nil)
    manifest = ws.manifest
    manifest.each_package_set do |pkg_set|
        if Gem::Version.new(pkg_set.required_autoproj_version) > Gem::Version.new(Autoproj::VERSION)
            raise ConfigError.new(pkg_set.source_file), "the #{pkg_set.name} package set requires autoproj v#{pkg_set.required_autoproj_version} but this is v#{Autoproj::VERSION}"
        end
    end

    # Loads OS repository definitions once and for all
    load_osrepos_from_package_sets

    # Loads OS package definitions once and for all
    load_osdeps_from_package_sets

    # Load the required autobuild definitions
    manifest.each_package_set do |pkg_set|
        pkg_set.each_autobuild_file do |path|
            ws.import_autobuild_file pkg_set, path
        end
    end

    # Now, load the package's importer configurations (from the various
    # source.yml files)
    mainline = manifest.package_set(mainline) if mainline.respond_to?(:to_str)
    manifest.load_importers(mainline: mainline)

    auto_add_packages_from_layout

    manifest.each_autobuild_package do |pkg|
        Autobuild.each_utility do |uname, _|
            pkg.utility(uname).enabled =
                ws.config.utility_enabled_for?(uname, pkg.name)
        end
    end

    mark_unavailable_osdeps_as_excluded
end

#load_package_sets(only_local: false, checkout_only: true, keep_going: false, reset: false, retry_count: nil, mainline: nil) ⇒ Object



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/autoproj/ops/configuration.rb', line 391

def load_package_sets(
    only_local: false,
    checkout_only: true,
    keep_going: false,
    reset: false,
    retry_count: nil,
    mainline: nil
)
    update_configuration(
        only_local: only_local,
        checkout_only: checkout_only,
        keep_going: keep_going,
        reset: reset,
        retry_count: retry_count,
        mainline: mainline
    )
end

#manifest_pathString

The path to the main manifest file

Returns:

  • (String)


94
95
96
# File 'lib/autoproj/ops/configuration.rb', line 94

def manifest_path
    ws.manifest_file_path
end

#mark_unavailable_osdeps_as_excludedObject



573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# File 'lib/autoproj/ops/configuration.rb', line 573

def mark_unavailable_osdeps_as_excluded
    os_package_resolver = ws.os_package_resolver
    manifest = ws.manifest
    os_package_resolver.all_package_names.each do |osdep_name|
        # If the osdep can be replaced by source packages, there's
        # nothing to do really. The exclusions of the source packages
        # will work as expected
        if manifest.osdeps_overrides[osdep_name] || manifest.find_autobuild_package(osdep_name)
            next
        end

        case os_package_resolver.availability_of(osdep_name)
        when OSPackageResolver::UNKNOWN_OS
            manifest.exclude_package(osdep_name, "the current operating system is unknown to autoproj")
        when OSPackageResolver::WRONG_OS
            manifest.exclude_package(osdep_name, "#{osdep_name} is defined, but not for this operating system")
        when OSPackageResolver::NONEXISTENT
            manifest.exclude_package(osdep_name, "#{osdep_name} is marked as unavailable for this operating system")
        end
    end
end

#queue_auto_imports_if_needed(queue, pkg_set, root_set) ⇒ Object



230
231
232
233
234
235
236
237
238
239
# File 'lib/autoproj/ops/configuration.rb', line 230

def queue_auto_imports_if_needed(queue, pkg_set, root_set)
    if pkg_set.auto_imports?
        pkg_set.each_raw_imported_set do |import_vcs, import_options|
            vcs_overrides_key = import_vcs.overrides_key
            import_vcs = root_set.resolve_overrides("pkg_set:#{vcs_overrides_key}", import_vcs)
            queue << [import_vcs, import_options, pkg_set]
        end
    end
    queue
end

#remotes_dirString

The path in which remote package sets should be exposed to the user

Returns:

  • (String)


79
80
81
# File 'lib/autoproj/ops/configuration.rb', line 79

def remotes_dir
    ws.remotes_dir
end

#remotes_user_dirString

The path in which remote package sets should be exposed to the user

Returns:

  • (String)


87
88
89
# File 'lib/autoproj/ops/configuration.rb', line 87

def remotes_user_dir
    File.join(ws.config_dir, "remotes")
end

#report_import_failure(what, reason) ⇒ Object



409
410
411
412
413
414
# File 'lib/autoproj/ops/configuration.rb', line 409

def report_import_failure(what, reason)
    unless reason.kind_of?(Interrupt)
        Autoproj.message "import of #{what} failed", :red
        Autoproj.message reason.to_s, :red
    end
end

#sort_package_sets_by_import_order(package_sets, root_pkg_set) ⇒ Object

Sort the package sets by dependency order Package sets that have no dependencies come first, the local package set (by main configuration) last



378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/autoproj/ops/configuration.rb', line 378

def sort_package_sets_by_import_order(package_sets, root_pkg_set)
    c = PackageSetHierarchy.new(package_sets, root_pkg_set)
    c.verify_acyclic
    sorted_pkg_sets = c.flatten

    if sorted_pkg_sets.last != root_pkg_set
        raise InternalError, "Failed to sort the package sets: the " \
                             "root package set should be last, but is not #{sorted_pkg_sets.map(&:name)}"
    end

    sorted_pkg_sets
end

#update_configuration(only_local: false, checkout_only: !Autobuild.do_update,, keep_going: false, reset: false, retry_count: nil, mainline: nil) ⇒ Object



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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'lib/autoproj/ops/configuration.rb', line 431

def update_configuration(
    only_local: false,
    checkout_only: !Autobuild.do_update,
    keep_going: false,
    reset: false,
    retry_count: nil,
    mainline: nil
)

    if ws.manifest.vcs.needs_import?
        main_configuration_failure = update_main_configuration(
            keep_going: keep_going,
            checkout_only: checkout_only,
            only_local: only_local,
            reset: reset,
            retry_count: retry_count
        )

        main_configuration_failure.each do |e|
            report_import_failure("main configuration", e)
        end
    else
        main_configuration_failure = []
    end
    ws.load_main_initrb
    ws.manifest.load(manifest_path)
    root_pkg_set = ws.manifest.main_package_set
    root_pkg_set.load_description_file
    root_pkg_set.explicit = true

    package_sets_failure = update_package_sets(
        only_local: only_local,
        checkout_only: checkout_only,
        keep_going: keep_going,
        reset: reset,
        retry_count: retry_count
    )

    load_package_set_information(mainline: mainline)

    if !main_configuration_failure.empty? && !package_sets_failure.empty?
        raise ImportFailed.new(main_configuration_failure + package_sets_failure)
    elsif !main_configuration_failure.empty?
        raise ImportFailed.new(main_configuration_failure)
    elsif !package_sets_failure.empty?
        raise ImportFailed.new(package_sets_failure)
    end
end

#update_configuration_repository(vcs, name, into, only_local: false, reset: false, retry_count: nil) ⇒ Object

Imports or updates a source (remote or otherwise).

See create_autobuild_package for informations about the arguments.



112
113
114
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
# File 'lib/autoproj/ops/configuration.rb', line 112

def update_configuration_repository(vcs, name, into,
    only_local: false,
    reset: false,
    retry_count: nil)

    fake_package = Tools.create_autobuild_package(vcs, name, into)
    if update_from
        # Define a package in the installation manifest that points to
        # the desired folder in other_root
        relative_path = Pathname.new(into)
                                .relative_path_from(Pathname.new(ws.root_dir)).to_s
        other_dir = File.join(update_from.path, relative_path)
        if File.directory?(other_dir)
            update_from.packages.unshift(
                InstallationManifest::Package.new(fake_package.name, other_dir, File.join(other_dir, "install"))
            )
        end

        # Then move the importer there if possible
        if fake_package.importer.respond_to?(:pick_from_autoproj_root)
            unless fake_package.importer.pick_from_autoproj_root(fake_package, update_from)
                fake_package.update = false
            end
        else
            fake_package.update = false
        end
    end
    fake_package.importer.retry_count = retry_count if retry_count
    fake_package.import(only_local: only_local, reset: reset)
rescue Autobuild::ConfigException => e
    raise ConfigError.new, "cannot import #{name}: #{e.message}", e.backtrace
end

#update_main_configuration(keep_going: false, checkout_only: !Autobuild.do_update,, only_local: false, reset: false, retry_count: nil) ⇒ Boolean

Update the main configuration repository

Returns:

  • (Boolean)

    true if something got updated or checked out, and false otherwise



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/autoproj/ops/configuration.rb', line 149

def update_main_configuration(keep_going: false, checkout_only: !Autobuild.do_update, only_local: false, reset: false, retry_count: nil)
    return [] if checkout_only && File.exist?(ws.config_dir)

    update_configuration_repository(
        ws.manifest.vcs, "autoproj main configuration", ws.config_dir,
        only_local: only_local, reset: reset, retry_count: retry_count
    )
    []
rescue Interrupt
    raise
rescue Exception => e
    if keep_going
        [e]
    else
        raise e
    end
end

#update_package_sets(only_local: false, checkout_only: !Autobuild.do_update,, keep_going: false, reset: false, retry_count: nil) ⇒ Object



627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
# File 'lib/autoproj/ops/configuration.rb', line 627

def update_package_sets(only_local: false,
    checkout_only: !Autobuild.do_update,
    keep_going: false,
    reset: false,
    retry_count: nil)
    root_pkg_set = ws.manifest.main_package_set
    package_sets, failures = load_and_update_package_sets(
        root_pkg_set,
        only_local: only_local,
        checkout_only: checkout_only,
        keep_going: keep_going,
        reset: reset,
        retry_count: retry_count
    )
    root_pkg_set.imports.each do |pkg_set|
        pkg_set.explicit = true
    end

    # sort packages, main package is the last
    package_sets = sort_package_sets_by_import_order(package_sets, root_pkg_set)
    ws.manifest.reset_package_sets
    package_sets.each do |pkg_set|
        ws.manifest.register_package_set(pkg_set)
    end

    ws.manifest.each_package_set do |pkg_set|
        ws.load_if_present(pkg_set, pkg_set.local_dir, "init.rb")
    end

    failures
end

#update_remote_package_set(vcs, checkout_only: !Autobuild.do_update,, only_local: false, reset: false, retry_count: nil) ⇒ Boolean

Update or checkout a remote package set, based on its VCS definition

Parameters:

Returns:

  • (Boolean)

    true if something got updated or checked out, and false otherwise



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/autoproj/ops/configuration.rb', line 172

def update_remote_package_set(vcs,
    checkout_only: !Autobuild.do_update,
    only_local: false,
    reset: false,
    retry_count: nil)

    raw_local_dir = PackageSet.raw_local_dir_of(ws, vcs)
    return if checkout_only && File.exist?(raw_local_dir)

    # name_of does minimal validation of source.yml, so do it here
    # even though we don't really need it
    name = PackageSet.name_of(ws, vcs, ignore_load_errors: true)
    ws.install_os_packages([vcs.type], all: nil)
    update_configuration_repository(
        vcs, name, raw_local_dir,
        only_local: only_local,
        reset: reset,
        retry_count: retry_count
    )
end