Class: Autoproj::PackageManagers::HomebrewManager

Inherits:
ShellScriptManager show all
Defined in:
lib/autoproj/package_managers/homebrew_manager.rb

Overview

Package manager interface for Mac OS using homebrew as its package manager

Instance Attribute Summary

Attributes inherited from ShellScriptManager

#auto_install_cmd, #needs_locking, #needs_root, #user_install_cmd

Attributes inherited from Manager

#enabled, #silent, #ws

Instance Method Summary collapse

Methods inherited from ShellScriptManager

execute, #generate_auto_os_script, #generate_script, #generate_user_os_script, #needs_locking?, #needs_root?, #osdeps_interaction

Methods inherited from Manager

#call_while_empty?, #configure_manager, #enabled?, #initialize_environment, #os_dependencies, #silent?, #strict?

Constructor Details

#initialize(ws) ⇒ HomebrewManager

Returns a new instance of HomebrewManager.



6
7
8
9
10
11
# File 'lib/autoproj/package_managers/homebrew_manager.rb', line 6

def initialize(ws)
    super(ws, true,
            %w[brew install],
            %w[brew install],
            false)
end

Instance Method Details

#filter_uptodate_packages(packages) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/autoproj/package_managers/homebrew_manager.rb', line 13

def filter_uptodate_packages(packages)
    # TODO there might be duplicates in packages which should be fixed
    # somewhere else
    packages = packages.uniq
    command_line = "brew info --json=v1 #{packages.join(' ')}"
    result = Autoproj.bundler_with_unbundled_env do
        (Autobuild::Subprocess.run "autoproj", "osdeps", command_line).first
    end

    begin
        JSON.parse(result)
    rescue JSON::ParserError
        if result && !result.empty?
            Autoproj.warn "Error while parsing result of brew info --json=v1"
        else
            # one of the packages is unknown fallback to install all
            # packaes which will complain about it
        end
        return packages
    end

    # fall back if something else went wrong
    if packages.size != result.size
        Autoproj.warn "brew info returns less or more packages when requested. Falling back to install all packages"
        return packages
    end

    new_packages = []
    result.each do |pkg|
        new_packages << pkg["name"] if pkg["installed"].empty?
    end
    new_packages
end

#install(packages, filter_uptodate_packages: true, install_only: false) ⇒ Object



47
48
49
50
51
52
# File 'lib/autoproj/package_managers/homebrew_manager.rb', line 47

def install(packages, filter_uptodate_packages: true, install_only: false)
    if filter_uptodate_packages || install_only
        packages = filter_uptodate_packages(packages)
    end
    super(packages)
end