Class: Autoproj::CLI::Cache

Inherits:
InspectionTool show all
Defined in:
lib/autoproj/cli/cache.rb

Instance Attribute Summary

Attributes inherited from Base

#ws

Instance Method Summary collapse

Methods inherited from InspectionTool

#finalize_setup, #initialize_and_load

Methods inherited from Base

#export_env_sh, #initialize, #normalize_command_line_package_selection, #notify_env_sh_updated, #resolve_selection, #resolve_user_selection, validate_options, #validate_user_selection

Methods included from Ops::Tools

#common_options, #create_autobuild_package, #load_autoprojrc, #load_main_initrb

Constructor Details

This class inherits a constructor from Autoproj::CLI::Base

Instance Method Details

#parse_gem_compile(string) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
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
46
47
48
49
50
# File 'lib/autoproj/cli/cache.rb', line 9

def parse_gem_compile(string)
    scanner = StringScanner.new(string)
    name = scanner.scan(/[^\[]+/)

    level = 0
    artifacts = []
    artifact_include = nil
    artifact_name = "".dup
    until scanner.eos?
        c = scanner.getch
        if level == 0
            raise ArgumentError, "expected '[' but got '#{c}'" unless c == "["

            level = 1
            include_c = scanner.getch
            if %w[+ -].include?(include_c)
                artifact_include = (include_c == "+")
            elsif include_c == "]"
                raise ArgumentError, "empty [] found in '#{string}'"
            else
                raise ArgumentError,
                      "expected '+' or '-' but got '#{c}' in '#{string}'"
            end
            next
        end

        if c == "]"
            level -= 1
            if level == 0
                artifacts << [artifact_include, artifact_name]
                artifact_name = "".dup
                next
            end
        end

        artifact_name << c
    end

    raise ArgumentError, "missing closing ']' in #{string}" if level != 0

    [name, artifacts: artifacts]
end

#run(cache_dir, *package_names, keep_going: false, packages: true, all: true, checkout_only: false, gems: false, gems_compile: [], gems_compile_force: false) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/autoproj/cli/cache.rb', line 77

def run(cache_dir, *package_names,
    keep_going: false,
    packages: true, all: true, checkout_only: false,
    gems: false, gems_compile: [], gems_compile_force: false)
    initialize_and_load
    finalize_setup

    cache_op = Autoproj::Ops::Cache.new(cache_dir, ws)
    if packages
        cache_op.create_or_update(
            *package_names,
            all: all, keep_going: keep_going,
            checkout_only: checkout_only
        )
    end

    if gems
        Autoproj.message "caching gems in #{cache_op.gems_cache_dir}"
        cache_op.create_or_update_gems(
            keep_going: keep_going,
            compile: gems_compile,
            compile_force: gems_compile_force
        )
    end
end

#validate_options(argv, options = Hash.new) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/autoproj/cli/cache.rb', line 52

def validate_options(argv, options = Hash.new)
    argv, options = super

    if argv.empty?
        default_cache_dirs = Autobuild::Importer.default_cache_dirs
        if !default_cache_dirs || default_cache_dirs.empty?
            raise CLIInvalidArguments,
                  "no cache directory defined with e.g. the "\
                  "AUTOBUILD_CACHE_DIR environment variable, "\
                  "expected one cache directory as argument"
        end
        Autoproj.warn "using cache directory #{default_cache_dirs.first} "\
                      "from the autoproj configuration"
        argv << default_cache_dirs.first
    end

    if (compile = options[:gems_compile])
        options[:gems_compile] = compile.map do |name|
            parse_gem_compile(name)
        end
    end

    [File.expand_path(argv.first, ws.root_dir), *argv[1..-1], options]
end