Class: Autoproj::PackageSet

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

Overview

A package set is a version control repository which contains general information with package version control information (source.yml file), package definitions (.autobuild files), and finally definition of dependencies that are provided by the operating system (.osdeps file).

Direct Known Subclasses

LocalPackageSet

Defined Under Namespace

Classes: NotLoaded

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ws, vcs, name: self.class.name_of(ws, vcs), raw_local_dir: self.class.raw_local_dir_of(ws, vcs)) ⇒ PackageSet

Create this source from a VCSDefinition object



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
# File 'lib/autoproj/package_set.rb', line 155

def initialize(
    ws, vcs,
    name: self.class.name_of(ws, vcs),
    raw_local_dir: self.class.raw_local_dir_of(ws, vcs)
)

    @ws = ws
    @vcs = vcs
    unless vcs
        raise ArgumentError, "cannot create a package set with a nil vcs, create a null VCS using VCSDefinition.none"
    end

    @name = name
    @os_repository_resolver = OSRepositoryResolver.new
    @os_package_resolver = OSPackageResolver.new(
        operating_system: ws.os_package_resolver.operating_system,
        package_managers: ws.os_package_resolver.package_managers,
        os_package_manager: ws.os_package_resolver.os_package_manager
    )
    @importer_definitions_cache = Hash.new
    @all_osdeps = []
    @all_osrepos = []
    @constants_definitions = Hash.new
    @required_autoproj_version = "0"
    @version_control = Array.new
    @overrides = Array.new
    @raw_local_dir = raw_local_dir
    @default_importer = VCSDefinition.from_raw({ type: "none" })

    @imports = Set.new
    @imports_vcs = Array.new
    @imported_from = Array.new
    @explicit = false
    @auto_imports = true
end

Class Attribute Details

.source_filesObject (readonly)

Returns the value of attribute source_files.



21
22
23
# File 'lib/autoproj/package_set.rb', line 21

def source_files
  @source_files
end

Instance Attribute Details

#all_osdepsArray<(String,OSPackageResolver)> (readonly)

The set of OSPackageResolver object that represent the osdeps files available in this package set

Returns:

  • (Array<(String,OSPackageResolver)>)

    the list of osdep files and the corresponding OSPackageResolver object



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

def all_osdeps
  @all_osdeps
end

#all_osreposArray<(String,OSRepositoryResolver)> (readonly)

The set of OSRepositoryResolver object that represent the osrepos files available in this package set

Returns:

  • (Array<(String,OSRepositoryResolver)>)

    the list of osdep files and the corresponding OSRepositoryResolver object



75
76
77
# File 'lib/autoproj/package_set.rb', line 75

def all_osrepos
  @all_osrepos
end

#auto_imports=(value) ⇒ Object (writeonly)

Sets the auto_imports flag

See Also:



118
119
120
# File 'lib/autoproj/package_set.rb', line 118

def auto_imports=(value)
  @auto_imports = value
end

#constants_definitionsObject (readonly)

Definition of key => value mappings used to resolve e.g. $KEY values in the version control sections



98
99
100
# File 'lib/autoproj/package_set.rb', line 98

def constants_definitions
  @constants_definitions
end

#default_importerVCSDefinition

The importer that should be used for packages that have no explicit entry

Returns:



110
111
112
# File 'lib/autoproj/package_set.rb', line 110

def default_importer
  @default_importer
end

#explicit=(value) ⇒ Object (writeonly)

Sets the attribute explicit

Parameters:

  • value

    the value to set the attribute explicit to.



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

def explicit=(value)
  @explicit = value
end

#imported_fromObject

If this package set has been imported from another package set, this is the other package set object



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

def imported_from
  @imported_from
end

#importer_definitions_cacheObject (readonly)

Cached results of #importer_definition_for



104
105
106
# File 'lib/autoproj/package_set.rb', line 104

def importer_definitions_cache
  @importer_definitions_cache
end

#importsObject (readonly)

The package sets that this imports



131
132
133
# File 'lib/autoproj/package_set.rb', line 131

def imports
  @imports
end

#imports_vcsArray<VCSDefinition> (readonly)

The VCS definition entries from the ‘imports’ section of the YAML file

Returns:



128
129
130
# File 'lib/autoproj/package_set.rb', line 128

def imports_vcs
  @imports_vcs
end

#nameString

The package set name

Returns:

  • (String)


55
56
57
# File 'lib/autoproj/package_set.rb', line 55

def name
  @name
end

#os_package_resolverObject (readonly)

The OSPackageResolver which is a merged version of all OSdeps in #all_osdeps



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

def os_package_resolver
  @os_package_resolver
end

#os_repository_resolverObject (readonly)

The OSRepositoryResolver which is a merged version of all OSrepos in #all_osrepos



83
84
85
# File 'lib/autoproj/package_set.rb', line 83

def os_repository_resolver
  @os_repository_resolver
end

#overridesObject (readonly)

The set of overrides defined in this package set



113
114
115
# File 'lib/autoproj/package_set.rb', line 113

def overrides
  @overrides
end

#raw_local_dirObject (readonly)

Remote sources can be accessed through a hidden directory in Workspace#remotes_dir, or through a symbolic link in autoproj/remotes/

This returns the former. See #user_local_dir for the latter.

For local sources, is simply returns the path to the source directory.



152
153
154
# File 'lib/autoproj/package_set.rb', line 152

def raw_local_dir
  @raw_local_dir
end

#required_autoproj_versionString

The minimum autoproj version this package set requires

It defaults to 0

Returns:

  • (String)


50
51
52
# File 'lib/autoproj/package_set.rb', line 50

def required_autoproj_version
  @required_autoproj_version
end

#vcsObject

The VCSDefinition object that defines the version control holding information for this source. Local package sets (i.e. the ones that are not under version control) use the ‘local’ version control name. For them, local? returns true.



61
62
63
# File 'lib/autoproj/package_set.rb', line 61

def vcs
  @vcs
end

#version_controlObject (readonly)

The version control information defined in this package set



101
102
103
# File 'lib/autoproj/package_set.rb', line 101

def version_control
  @version_control
end

#wsWorkspace (readonly)

The underlying workspace

Returns:



36
37
38
# File 'lib/autoproj/package_set.rb', line 36

def ws
  @ws
end

Class Method Details

.add_source_file(name) ⇒ Object



27
28
29
30
# File 'lib/autoproj/package_set.rb', line 27

def add_source_file(name)
    source_files.delete(name)
    source_files << name
end

.default_expansions(ws) ⇒ Object



302
303
304
305
306
307
# File 'lib/autoproj/package_set.rb', line 302

def self.default_expansions(ws)
    ws.config.to_hash
      .merge(ws.manifest.constant_definitions)
      .merge("AUTOPROJ_ROOT" => ws.root_dir,
             "AUTOPROJ_CONFIG" => ws.config_dir)
end

.master_source_fileObject



23
24
25
# File 'lib/autoproj/package_set.rb', line 23

def master_source_file
    source_files.first
end

.name_of(ws, vcs, raw_local_dir: raw_local_dir_of(ws, vcs), ignore_load_errors: false) ⇒ String

Returns the “best” name under which we can refer to the given package set to the user

Mainly, it returns the package set’s name if the package set is checked out, and the vcs (as a string) otherwise

Returns:

  • (String)


275
276
277
278
279
280
281
282
283
284
# File 'lib/autoproj/package_set.rb', line 275

def self.name_of(ws, vcs, raw_local_dir: raw_local_dir_of(ws, vcs), ignore_load_errors: false)
    if File.directory?(raw_local_dir)
        begin
            return raw_description_file(raw_local_dir, package_set_name: "#{vcs.type}:#{vcs.url}")["name"]
        rescue ConfigError
            raise unless ignore_load_errors
        end
    end
    vcs.to_s
end

.raw_description_file(raw_local_dir, package_set_name: nil) ⇒ Hash

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.

Read the description information for a package set in a given directory

Parameters:

  • raw_local_dir (String)

    the package set’s directory

Returns:

  • (Hash)

    the raw description information



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
# File 'lib/autoproj/package_set.rb', line 406

def self.raw_description_file(raw_local_dir, package_set_name: nil)
    master_source_file = File.join(raw_local_dir, PackageSet.master_source_file)
    unless File.exist?(master_source_file)
        raise ConfigError.new, "package set #{package_set_name} present in #{raw_local_dir} should have a source.yml file, but does not"
    end

    source_definition = Hash.new
    PackageSet.source_files.each do |name|
        source_file = File.join(raw_local_dir, name)
        next unless File.file?(source_file)

        newdefs = Autoproj.in_file(source_file, Autoproj::YAML_LOAD_ERROR) do
            YAML.load(File.read(source_file))
        end
        newdefs = validate_and_normalize_source_file(source_file, newdefs || Hash.new)
        source_definition.merge!(newdefs) do |k, old, new|
            if old.respond_to?(:to_ary)
                old + new
            else
                new
            end
        end
    end
    unless source_definition["name"]
        raise ConfigError.new(master_source_file), "#{master_source_file} does not have a 'name' field"
    end

    source_definition
end

.raw_local_dir_of(ws, vcs) ⇒ String

Returns the local directory in which the given package set should be checked out

Parameters:

  • vcs (VCSDefinition)

    the version control information for the package set

Returns:

  • (String)


292
293
294
295
296
297
298
299
300
# File 'lib/autoproj/package_set.rb', line 292

def self.raw_local_dir_of(ws, vcs)
    if vcs.needs_import?
        repository_id = vcs.create_autobuild_importer.repository_id
        path = File.join(ws.remotes_dir, repository_id.gsub(/[^\w]/, "_"))
        File.expand_path(path)
    elsif !vcs.none?
        File.expand_path(vcs.url)
    end
end

.resolve_definition(ws, raw_spec, from: nil, raw: Array.new, vars: default_expansions(ws)) ⇒ Object

Resolve the VCS information for a package set

This parses the information stored in the package_sets section of autoproj/manifest, r the imports section of the source.yml files and returns the corresponding VCSDefinition object



314
315
316
317
318
319
320
321
322
# File 'lib/autoproj/package_set.rb', line 314

def self.resolve_definition(ws, raw_spec, from: nil, raw: Array.new,
    vars: default_expansions(ws))

    spec = VCSDefinition.normalize_vcs_hash(raw_spec, base_dir: ws.config_dir)
    options, vcs_spec = Kernel.filter_options spec, auto_imports: true

    vcs_spec = Autoproj.expand(vcs_spec, vars)
    [VCSDefinition.from_raw(vcs_spec, from: from, raw: raw), options]
end

.validate_and_normalize_source_file(yaml_path, yaml) ⇒ 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.

Validate and normalizes a raw source file



374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/autoproj/package_set.rb', line 374

def self.validate_and_normalize_source_file(yaml_path, yaml)
    yaml = yaml.dup
    %w[imports version_control].each do |entry_name|
        yaml[entry_name] ||= Array.new
        unless yaml[entry_name].respond_to?(:to_ary)
            raise ConfigError.new(yaml_path), "expected the '#{entry_name}' entry to be an array"
        end
    end

    %w[constants].each do |entry_name|
        yaml[entry_name] ||= Hash.new
        unless yaml[entry_name].respond_to?(:to_h)
            raise ConfigError.new(yaml_path), "expected the '#{entry_name}' entry to be a map"
        end
    end

    if yaml.has_key?("overrides")
        yaml["overrides"] ||= Array.new
        unless yaml["overrides"].respond_to?(:to_ary)
            raise ConfigError.new(yaml_path), "expected the 'overrides' entry to be an array"
        end
    end
    yaml
end

Instance Method Details

#add_constant_definition(key, value) ⇒ Object

Add a new constant to be used to resolve e.g. version control entries



459
460
461
# File 'lib/autoproj/package_set.rb', line 459

def add_constant_definition(key, value)
    constants_definitions[key] = value
end

#add_overrides_entry(matcher, vcs_definition, file: "#add_overrides_entry") ⇒ Object

Add a new entry in the list of version control resolutions



486
487
488
489
490
491
492
# File 'lib/autoproj/package_set.rb', line 486

def add_overrides_entry(matcher, vcs_definition, file: "#add_overrides_entry")
    if (last_entry = overrides.last) && last_entry[0] == file
        last_entry[1] << [matcher, vcs_definition]
    else
        overrides << [file, [[matcher, vcs_definition]]]
    end
end

#add_raw_imported_set(vcs, auto_imports: true) ⇒ void

This method returns an undefined value.

Add a new VCS import to the list of imports

Parameters:



467
468
469
# File 'lib/autoproj/package_set.rb', line 467

def add_raw_imported_set(vcs, auto_imports: true)
    imports_vcs << [vcs, Hash[auto_imports: auto_imports]]
end

#add_version_control_entry(matcher, vcs_definition) ⇒ Object

Add a new entry in the list of version control resolutions



480
481
482
483
# File 'lib/autoproj/package_set.rb', line 480

def add_version_control_entry(matcher, vcs_definition)
    invalidate_importer_definitions_cache
    version_control << [matcher, vcs_definition]
end

#auto_imports?Boolean

If true (the default), imports listed in this package set will be automatically loaded by autoproj

Returns:

  • (Boolean)


122
123
124
# File 'lib/autoproj/package_set.rb', line 122

def auto_imports?
    !!@auto_imports
end

#autobuildObject

Defined for coherence with the API on Autoproj::PackageDefinition



247
248
249
# File 'lib/autoproj/package_set.rb', line 247

def autobuild
    create_autobuild_package
end

#create_autobuild_packageObject

Create a stub autobuild package to handle the import of this package set



253
254
255
# File 'lib/autoproj/package_set.rb', line 253

def create_autobuild_package
    Ops::Tools.create_autobuild_package(vcs, name, raw_local_dir)
end

#default_packagesObject

List of the packages that are built if the package set is selected in the layout



141
142
143
# File 'lib/autoproj/package_set.rb', line 141

def default_packages
    metapackage.each_package
end

#each_autobuild_fileObject

List the autobuild files that are part of this package set



807
808
809
810
811
812
813
# File 'lib/autoproj/package_set.rb', line 807

def each_autobuild_file
    return enum_for(__method__) unless block_given?

    Dir.glob(File.join(local_dir, "*.autobuild")).sort.each do |file|
        yield(file)
    end
end

#each_imported_set {|pkg_set| ... } ⇒ Object

Yields the package sets imported by this package set

This information is available only after the whole configuration has been loaded

Yield Parameters:

  • pkg_set (PackageSet)

    a package set imported by this one



454
455
456
# File 'lib/autoproj/package_set.rb', line 454

def each_imported_set(&block)
    @imports.each(&block)
end

#each_osdep(&block) ⇒ Object

Enumerate all osdeps package names from this package set



212
213
214
# File 'lib/autoproj/package_set.rb', line 212

def each_osdep(&block)
    os_package_resolver.all_package_names.each(&block)
end

#each_osdeps_fileObject

Yields each osdeps definition files that are present in this package set



817
818
819
820
821
822
823
# File 'lib/autoproj/package_set.rb', line 817

def each_osdeps_file
    return enum_for(__method__) unless block_given?

    Dir.glob(File.join(local_dir, "*.osdeps")).each do |file|
        yield(file)
    end
end

#each_osrepo(&block) ⇒ Object

Enumerate all osrepos entries from this package set



217
218
219
# File 'lib/autoproj/package_set.rb', line 217

def each_osrepo(&block)
    os_repository_resolver.all_entries.each(&block)
end

#each_osrepos_fileObject

Yields each osdeps definition files that are present in this package set



827
828
829
830
831
832
833
# File 'lib/autoproj/package_set.rb', line 827

def each_osrepos_file
    return enum_for(__method__) unless block_given?

    Dir.glob(File.join(local_dir, "*.osrepos")).each do |file|
        yield(file)
    end
end

#each_packageObject

Enumerates the Autobuild::Package instances that are defined in this source



798
799
800
801
802
803
804
# File 'lib/autoproj/package_set.rb', line 798

def each_package
    return enum_for(:each_package) unless block_given?

    manifest.each_package_definition do |pkg|
        yield(pkg.autobuild) if pkg.package_set == self
    end
end

#each_raw_imported_set {|vcs, options| ... } ⇒ Object

Yields the imports raw information

Yield Parameters:

  • vcs (VCSDefinition)

    the import VCS information

  • options (Hash)

    import options



475
476
477
# File 'lib/autoproj/package_set.rb', line 475

def each_raw_imported_set(&block)
    imports_vcs.each(&block)
end

#empty?Boolean

True if this source defines nothing

Returns:

  • (Boolean)


239
240
241
242
243
244
# File 'lib/autoproj/package_set.rb', line 239

def empty?
    version_control.empty? && overrides.empty?
    !each_package.find { true } &&
        !File.exist?(File.join(raw_local_dir, "overrides.rb")) &&
        !File.exist?(File.join(raw_local_dir, "init.rb"))
end

#expand(data, additional_expansions = Hash.new) ⇒ Object

Expands the given string as much as possible using the expansions listed in the source.yml file, and returns it. Raises if not all variables can be expanded.



605
606
607
608
# File 'lib/autoproj/package_set.rb', line 605

def expand(data, additional_expansions = Hash.new)
    defs = inject_constants_and_config_for_expansion(additional_expansions)
    Autoproj.expand(data, defs)
end

#explicit?Boolean

If true, this package set has been loaded because another set imports it. If false, it is loaded explicitely by the user

Returns:

  • (Boolean)


91
92
93
# File 'lib/autoproj/package_set.rb', line 91

def explicit?
    !!@explicit
end

#importer_definition_for(package, default: default_importer, require_existing: true) ⇒ VCSDefinition

Returns the VCS definition for package_name as defined in this package set, or nil if the source does not have any.

Parameters:

Returns:

  • (VCSDefinition)

    the importer definition, or nil if none could be found



739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
# File 'lib/autoproj/package_set.rb', line 739

def importer_definition_for(package, default: default_importer, require_existing: true)
    package_name = manifest.validate_package_name_argument(
        package, require_existing: require_existing
    )
    importer_definitions_cache[package_name] ||= Autoproj.in_file source_file do
        vcs_spec, raw = version_control_field(
            package_name, version_control,
            file: source_file, section: "version_control"
        )
        if vcs_spec
            VCSDefinition.from_raw(vcs_spec, raw: raw, from: self)
        else
            default
        end
    end
end

#inject_constants_and_config_for_expansion(additional_expansions) ⇒ 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.

Injects the values of #constants_definitions and #manifest.constant_definitions, as well as the available configuration variables, into a hash suitable to be used for variable expansion using Autoproj.expand and Autoproj.single_expansion



582
583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/autoproj/package_set.rb', line 582

def inject_constants_and_config_for_expansion(additional_expansions)
    defs = Hash[
        "AUTOPROJ_ROOT" => ws.root_dir,
        "AUTOPROJ_CONFIG" => ws.config_dir,
        "AUTOPROJ_SOURCE_DIR" => local_dir]
           .merge(manifest.constant_definitions)
           .merge(constants_definitions)
           .merge(additional_expansions)

    config = ws.config
    Hash.new do |h, k|
        config.get(k) if config.has_value_for?(k) || config.declared?(k)
    end.merge(defs)
end

#invalidate_importer_definitions_cacheObject

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.

Invalidate #importer_definitions_cache



729
730
731
# File 'lib/autoproj/package_set.rb', line 729

def invalidate_importer_definitions_cache
    @importer_definitions_cache.clear
end

#load_description_fileObject

Load the source.yml file and resolves all information it contains.



500
501
502
503
504
505
506
507
508
509
510
511
512
# File 'lib/autoproj/package_set.rb', line 500

def load_description_file
    source_definition = raw_description_file
    name = source_definition["name"]
    if name !~ /^[\w.-]+$/
        raise ConfigError.new(source_file),
              "in #{source_file}: invalid source name '#{@name}': source names can only contain alphanumeric characters, and .-_"
    elsif name == "local"
        raise ConfigError.new(source_file),
              "in #{source_file}: the name 'local' is a reserved name"
    end

    parse_source_definition(source_definition)
end

#load_osdeps(file, **options) ⇒ Object

Load a new osdeps file for this package set



192
193
194
195
196
197
198
199
200
201
# File 'lib/autoproj/package_set.rb', line 192

def load_osdeps(file, **options)
    new_osdeps = OSPackageResolver.load(
        file,
        suffixes: ws.osdep_suffixes,
        **options
    )
    all_osdeps << new_osdeps
    os_package_resolver.merge(all_osdeps.last)
    new_osdeps
end

#load_osrepos(file) ⇒ Object

Load a new osrepos file for this package set



204
205
206
207
208
209
# File 'lib/autoproj/package_set.rb', line 204

def load_osrepos(file)
    new_osrepos = OSRepositoryResolver.load(file)
    all_osrepos << new_osrepos
    os_repository_resolver.merge(all_osrepos.last)
    new_osrepos
end

#load_overrides(source_definition) ⇒ Object



514
515
516
517
518
# File 'lib/autoproj/package_set.rb', line 514

def load_overrides(source_definition)
    if (data = source_definition["overrides"])
        [[source_file, data]]
    end
end

#local?Boolean

True if this source is local, i.e. is not under a version control

Returns:

  • (Boolean)


234
235
236
# File 'lib/autoproj/package_set.rb', line 234

def local?
    vcs.local?
end

#local_dirObject

The directory in which data for this source will be checked out



359
360
361
362
363
364
365
366
367
368
369
# File 'lib/autoproj/package_set.rb', line 359

def local_dir
    ugly_dir   = raw_local_dir
    pretty_dir = user_local_dir
    if ugly_dir == pretty_dir
        pretty_dir
    elsif File.symlink?(pretty_dir) && File.readlink(pretty_dir) == ugly_dir
        pretty_dir
    else
        ugly_dir
    end
end

#main?Boolean

True if this is the main package set (i.e. the main autoproj configuration)

Returns:

  • (Boolean)


229
230
231
# File 'lib/autoproj/package_set.rb', line 229

def main?
    false
end

#manifestManifest

The manifest this package set is registered on

Returns:



41
42
43
# File 'lib/autoproj/package_set.rb', line 41

def manifest
    ws.manifest
end

#metapackageObject

Returns the Metapackage object that has the same name than this package set



135
136
137
# File 'lib/autoproj/package_set.rb', line 135

def metapackage
    manifest.metapackage(name)
end

#normalize_vcs_list(section_name, file, list) ⇒ 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.

Validate the format of a VCS list field (formatted in array-of-hashes)



620
621
622
623
624
625
626
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
658
659
660
661
662
663
664
665
666
# File 'lib/autoproj/package_set.rb', line 620

def normalize_vcs_list(section_name, file, list)
    if list.kind_of?(Hash)
        raise InvalidYAMLFormatting, "wrong format for the #{section_name} section of #{file}, you forgot the '-' in front of the package names"
    elsif !list.kind_of?(Array)
        raise InvalidYAMLFormatting, "wrong format for the #{section_name} section of #{file}"
    end

    list.each_with_index.map do |spec, spec_idx|
        spec_nth = number_to_nth(spec_idx + 1)
        unless spec.kind_of?(Hash)
            raise InvalidYAMLFormatting, "wrong format for the #{spec_nth} entry (#{spec.inspect}) of the #{section_name} section of #{file}, expected a package name, followed by a colon, and one importer option per following line"
        end

        spec = spec.dup
        if spec.values.size == 1
            name, spec = spec.to_a.first
            if spec.respond_to?(:to_str)
                if spec == "none"
                    spec = Hash["type" => "none"]
                else
                    raise ConfigError.new, "invalid VCS specification in the #{section_name} section of #{file}: '#{name}: #{spec}'. One can only use this shorthand to declare the absence of a VCS with the 'none' keyword"
                end
            elsif !spec.kind_of?(Hash)
                raise InvalidYAMLFormatting, "expected '#{name}:' followed by version control options, but got nothing, in the #{spec_nth} entry of the #{section_name} section of #{file}"
            end
        else
            # Maybe the user wrote the spec like
            #   - package_name:
            #     type: git
            #     url: blah
            #
            # In that case, we should have the package name as
            # "name => nil". Check that.
            name, = spec.find { |n, v| v.nil? }
            if name
                spec.delete(name)
            else
                raise InvalidYAMLFormatting, "cannot make sense of the #{spec_nth} entry in the #{section_name} section of #{file}: #{spec}"
            end
        end

        name_match = name
        name_match = Regexp.new("^#{name_match}") if name_match =~ /[^\w\/-]/

        [name_match, spec]
    end
end

#number_to_nth(number) ⇒ 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.

Converts a number to an ordinal string representation (i.e. 1st, 25th)



613
614
615
# File 'lib/autoproj/package_set.rb', line 613

def number_to_nth(number)
    Hash[1 => "1st", 2 => "2nd", 3 => "3rd"].fetch(number, "#{number}th")
end

#overrides_for(package, vcs, require_existing: true) ⇒ VCSDefinition

Update a VCS object using the overrides defined in this package set

Parameters:

Returns:



761
762
763
764
765
766
# File 'lib/autoproj/package_set.rb', line 761

def overrides_for(package, vcs, require_existing: true)
    package_name = manifest.validate_package_name_argument(
        package, require_existing: require_existing
    )
    resolve_overrides(package_name, vcs)
end

#parse_source_definition(source_definition) ⇒ Object



520
521
522
523
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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# File 'lib/autoproj/package_set.rb', line 520

def parse_source_definition(source_definition)
    @name = source_definition["name"] || name
    @required_autoproj_version = source_definition.fetch(
        "required_autoproj_version", required_autoproj_version
    )

    # Compute the definition of constants
    if (new_constants = source_definition["constants"])
        Autoproj.in_file(source_file) do
            variables = inject_constants_and_config_for_expansion(Hash.new)
            @constants_definitions = Autoproj.resolve_constant_definitions(
                new_constants, variables
            )
        end
    end

    if (new_imports = source_definition["imports"])
        variables = inject_constants_and_config_for_expansion(Hash.new)
        @imports_vcs = Array(new_imports).map do |set_def|
            if !set_def.kind_of?(Hash) && !set_def.respond_to?(:to_str)
                raise ConfigError.new(source_file), "in #{source_file}: "\
                                                    "wrong format for 'imports' section. Expected an array of "\
                                                    "maps or strings (e.g. - github: my/url)."
            end

            Autoproj.in_file(source_file) do
                PackageSet.resolve_definition(ws, set_def, from: self,
                                                           vars: variables,
                                                           raw: [VCSDefinition::RawEntry.new(self, source_file, set_def)])
            end
        end
    end

    if (new_version_control = source_definition["version_control"])
        invalidate_importer_definitions_cache
        @version_control = normalize_vcs_list("version_control", source_file,
                                              new_version_control)

        Autoproj.in_file(source_file) do
            default_vcs_spec, raw = version_control_field(
                "default", version_control,
                file: source_file, section: "version_control"
            )
            if default_vcs_spec
                @default_importer = VCSDefinition.from_raw(default_vcs_spec,
                                                           raw: raw, from: self)
            end
        end
    end
    if (new_overrides = load_overrides(source_definition))
        @overrides = new_overrides.map do |file, entries|
            [file, normalize_vcs_list("overrides", file, entries)]
        end
    end
end

#present?Boolean

True if this source has already been checked out on the local autoproj installation

Returns:

  • (Boolean)


223
224
225
# File 'lib/autoproj/package_set.rb', line 223

def present?
    File.directory?(raw_local_dir)
end

#raw_description_fileObject

Loads the source.yml file, validates it and returns it as a hash

Raises InternalError if the source has not been checked out yet (it should have), and ConfigError if the source.yml file is not valid.



440
441
442
443
444
445
446
# File 'lib/autoproj/package_set.rb', line 440

def raw_description_file
    unless present?
        raise InternalError, "source #{vcs} has not been fetched yet, cannot load description for it"
    end

    self.class.raw_description_file(raw_local_dir, package_set_name: name)
end

#repository_idObject

Returns a string that uniquely represents the version control information for this package set.

I.e. for two package sets set1 and set2, if set1.repository_id == set2.repository_id, it means that both package sets are checked out from exactly the same source.



330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/autoproj/package_set.rb', line 330

def repository_id
    if local?
        raw_local_dir
    else
        importer = vcs.create_autobuild_importer
        if importer.respond_to?(:repository_id)
            importer.repository_id
        else
            vcs.to_s
        end
    end
end

#resolve_overrides(key, vcs) ⇒ 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.

Apply overrides on a VCS object from its (string) key

This is a helper for #overrides_for



773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
# File 'lib/autoproj/package_set.rb', line 773

def resolve_overrides(key, vcs)
    overrides.each do |file, file_overrides|
        new_spec, new_raw_entry =
            Autoproj.in_file file do
                version_control_field(
                    key, file_overrides,
                    validate: false, file: file, section: "overrides"
                )
            end

        if new_spec
            Autoproj.in_file file do
                vcs = vcs.update(new_spec, raw: new_raw_entry, from: self)
            rescue ConfigError => e
                raise ConfigError.new,
                      "invalid resulting VCS specification in the overrides "\
                      "section for #{key}: #{e.message}"
            end
        end
    end
    vcs
end

#single_expansion(data, additional_expansions = Hash.new) ⇒ Object



597
598
599
600
# File 'lib/autoproj/package_set.rb', line 597

def single_expansion(data, additional_expansions = Hash.new)
    defs = inject_constants_and_config_for_expansion(additional_expansions)
    Autoproj.single_expansion(data, defs)
end

#snapshot(target_dir, options = Hash.new) ⇒ Object



257
258
259
260
261
262
263
264
265
266
# File 'lib/autoproj/package_set.rb', line 257

def snapshot(target_dir, options = Hash.new)
    if local?
        Hash.new
    else
        package = create_autobuild_package
        if package.importer.respond_to?(:snapshot)
            package.importer.snapshot(package, target_dir, **options)
        end
    end
end

#source_fileObject

Path to the source.yml file



495
496
497
# File 'lib/autoproj/package_set.rb', line 495

def source_file
    File.join(local_dir, "source.yml") if local_dir
end

#user_local_dirObject

Remote sources can be accessed through a hidden directory in Workspace#remotes_dir, or through a symbolic link in autoproj/remotes/

This returns the latter. See #raw_local_dir for the former.

For local sources, is simply returns the path to the source directory.



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

def user_local_dir
    if local?
        vcs.url
    else
        File.join(ws.config_dir, "remotes", name)
    end
end

#version_control_field(package_name, entry_list, validate: true, file: source_file, section: nil) ⇒ [(Hash,nil),Array]

Returns a VCS definition for the given package, if one is available. Otherwise returns nil.

Returns:

  • ([(Hash,nil),Array])

    the resolved VCS definition, as well as the “history” of it, that is the list of entries that matched the package in the form (PackageSet,Hash), where PackageSet is self. The Hash part is nil if there are no matching entries. Hash keys are normalized to symbols



676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
# File 'lib/autoproj/package_set.rb', line 676

def version_control_field(package_name, entry_list, validate: true,
    file: source_file, section: nil)
    raw = []
    vcs_spec = entry_list.inject({}) do |resolved_spec, (name_match, spec)|
        next(resolved_spec) unless name_match === package_name

        raw << VCSDefinition::RawEntry.new(self, file, spec)
        begin
            VCSDefinition.update_raw_vcs_spec(resolved_spec, spec)
        rescue ArgumentError => e
            raise ConfigError.new,
                  "invalid VCS definition while resolving package "\
                  "'#{package_name}', entry '#{name_match}' of "\
                  "#{section ? "section '#{section}'" : ''}: "\
                  "#{e.message}", e.backtrace
        end
    end

    return nil, [] if vcs_spec.empty?

    expansions = {
        "PACKAGE" => package_name,
        "PACKAGE_BASENAME" => File.basename(package_name)
    }

    vcs_spec = expand(vcs_spec, expansions)
    vcs_spec.dup.each do |name, value|
        vcs_spec[name] = expand(value, expansions)
    end

    # Resolve relative paths w.r.t. the workspace root dir
    if (url = (vcs_spec.delete("url") || vcs_spec.delete(:url)))
        vcs_spec[:url] = VCSDefinition.to_absolute_url(url, ws.root_dir)
    end

    # If required, verify that the configuration is a valid VCS
    # configuration
    if validate
        begin
            VCSDefinition.from_raw(vcs_spec)
        rescue ArgumentError => e
            raise ConfigError.new,
                  "invalid resulting VCS definition for package "\
                  "'#{package_name}': #{e.message}",
                  e.backtrace
        end
    end
    [vcs_spec, raw]
end