Class: Autoproj::InstallationManifest

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

Overview

Manifest of installed packages imported from another autoproj installation

Defined Under Namespace

Classes: Package, PackageSet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ InstallationManifest

Returns a new instance of InstallationManifest.



12
13
14
15
16
# File 'lib/autoproj/installation_manifest.rb', line 12

def initialize(path = nil)
    @path = path
    @packages = Hash.new
    @package_sets = Hash.new
end

Instance Attribute Details

#package_setsObject (readonly)

Returns the value of attribute package_sets.



10
11
12
# File 'lib/autoproj/installation_manifest.rb', line 10

def package_sets
  @package_sets
end

#packagesObject (readonly)

Returns the value of attribute packages.



9
10
11
# File 'lib/autoproj/installation_manifest.rb', line 9

def packages
  @packages
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/autoproj/installation_manifest.rb', line 8

def path
  @path
end

Class Method Details

.from_workspace_root(root_dir) ⇒ Object



132
133
134
135
136
137
138
139
140
141
# File 'lib/autoproj/installation_manifest.rb', line 132

def self.from_workspace_root(root_dir)
    path = path_for_workspace_root(root_dir)
    manifest = InstallationManifest.new(path)
    unless manifest.exist?
        raise ConfigError.new, "no #{path} file found. You should probably rerun autoproj envsh in that folder first"
    end

    manifest.load
    manifest
end

.path_for_workspace_root(root_dir) ⇒ String

Returns the default Autoproj installation manifest path for a given autoproj workspace root

Parameters:

  • root_dir (String)

Returns:

  • (String)


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

def self.path_for_workspace_root(root_dir)
    File.join(root_dir, ".autoproj", "installation-manifest")
end

Instance Method Details

#add_package(pkg) ⇒ Package

Add a PackageDefinition to this manifest

Returns:

  • (Package)

    the package in the installation manifest format



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/autoproj/installation_manifest.rb', line 25

def add_package(pkg)
    packages[pkg.name] =
        case pkg
        when PackageDefinition
            v = pkg.autobuild
            Package.new(
                v.name, v.class.name, pkg.vcs.to_hash, v.srcdir,
                (v.importdir if v.respond_to?(:importdir)),
                v.prefix,
                (v.builddir if v.respond_to?(:builddir)),
                v.logdir, v.dependencies
            )
        else
            pkg
        end
end

#add_package_set(pkg_set) ⇒ PackageSet

Add a PackageSet to this manifest

Returns:

  • (PackageSet)

    the package set in the installation manifest format



45
46
47
48
49
50
# File 'lib/autoproj/installation_manifest.rb', line 45

def add_package_set(pkg_set)
    package_sets[pkg_set.name] = PackageSet.new(
        pkg_set.name, pkg_set.vcs.to_hash,
        pkg_set.raw_local_dir, pkg_set.user_local_dir
    )
end

#each_package {|| ... } ⇒ Object

Enumerate this Autoproj::InstallationManifest‘s packages

Yield Parameters:



62
63
64
# File 'lib/autoproj/installation_manifest.rb', line 62

def each_package(&block)
    packages.each_value(&block)
end

#each_package_set {|| ... } ⇒ Object

Enumerate this Autoproj::InstallationManifest‘s package sets

Yield Parameters:



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

def each_package_set(&block)
    package_sets.each_value(&block)
end

#exist?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/autoproj/installation_manifest.rb', line 18

def exist?
    File.exist?(path) if path
end

#find_package_by_name(name) ⇒ Package

Resolve a package by name

Returns:



76
77
78
# File 'lib/autoproj/installation_manifest.rb', line 76

def find_package_by_name(name)
    @packages[name]
end

#find_package_set_by_name(name) ⇒ Package

Resolve a package set by name

Returns:



69
70
71
# File 'lib/autoproj/installation_manifest.rb', line 69

def find_package_set_by_name(name)
    @package_sets[name]
end

#load(path = @path) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/autoproj/installation_manifest.rb', line 80

def load(path = @path)
    @packages = Hash.new
    raw = YAML.load(File.open(path))
    if raw.respond_to?(:to_str) # old CSV-based format
        CSV.read(path).map do |row|
            name, srcdir, prefix, builddir = *row
            builddir = nil if builddir && builddir.empty?
            packages[name] = Package.new(name, srcdir, prefix, builddir, [])
        end
        save(path)
    else
        raw.each do |entry|
            if entry["package_set"]
                pkg_set = PackageSet.new(
                    entry["package_set"], entry["vcs"], entry["raw_local_dir"], entry["user_local_dir"]
                )
                package_sets[pkg_set.name] = pkg_set
            else
                pkg = Package.new(
                    entry["name"], entry["type"], entry["vcs"], entry["srcdir"], entry["importdir"],
                    entry["prefix"], entry["builddir"], entry["logdir"], entry["dependencies"]
                )
                packages[pkg.name] = pkg
            end
        end
    end
end

#save(path = @path) ⇒ Object

Save the installation manifest



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/autoproj/installation_manifest.rb', line 109

def save(path = @path)
    Ops.atomic_write(path) do |io|
        marshalled_package_sets = each_package_set.map do |pkg_set|
            set = pkg_set.to_h.transform_keys(&:to_s)
            set["package_set"] = set["name"]
            set
        end
        marshalled_packages = each_package.map do |pkg|
            pkg.to_h.transform_keys(&:to_s)
        end
        io.write YAML.dump(marshalled_package_sets + marshalled_packages)
    end
end