Class: Autoproj::CLI::Update

Inherits:
Base
  • Object
show all
Defined in:
lib/autoproj/cli/update.rb

Direct Known Subclasses

Build

Defined Under Namespace

Classes: AskUpdateFilter

Instance Attribute Summary

Attributes inherited from Base

#ws

Instance Method Summary collapse

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

#finish_loading_configuration(selected_packages) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/autoproj/cli/update.rb', line 165

def finish_loading_configuration(selected_packages)
    ws.setup_all_package_directories
    # Call resolve_user_selection once to auto-add packages
    resolve_user_selection(selected_packages)
    # Now we can finalize and re-resolve the selection since the
    # overrides.rb files might have changed it
    ws.finalize_package_setup
    # Finally, filter out exclusions
    resolved_selected_packages, =
        resolve_user_selection(selected_packages)
    validate_user_selection(selected_packages, resolved_selected_packages)

    if selected_packages.empty?
        command_line_selection = Array.new
    else
        command_line_selection = resolved_selected_packages.dup
    end
    [command_line_selection, resolved_selected_packages]
end

#normalize_osdeps_options(checkout_only: false, osdeps: true, osdeps_mode: nil, osdeps_filter_uptodate: true) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/autoproj/cli/update.rb', line 185

def normalize_osdeps_options(
    checkout_only: false, osdeps: true, osdeps_mode: nil,
    osdeps_filter_uptodate: true
)

    osdeps_options = Hash[install_only: checkout_only]
    if osdeps_mode
        osdeps_options[:osdeps_mode] = osdeps_mode
    elsif !osdeps
        osdeps_options[:osdeps_mode] = Array.new
    end
    ws.os_package_installer.filter_uptodate_packages = osdeps_filter_uptodate
    osdeps_options
end

#run(selected_packages, run_hook: false, report: true, ask: false, **options) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
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
102
103
104
105
106
107
108
109
110
111
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/autoproj/cli/update.rb', line 66

def run(selected_packages, run_hook: false, report: true, ask: false, **options)
    ws.manifest.accept_unavailable_osdeps = !options[:osdeps]
    ws.setup
    ws.autodetect_operating_system(force: true)

    if ask
        prompt = TTY::Prompt.new
        options[:bundler] &&= prompt.yes?("Update bundler ?")
        options[:autoproj] &&= prompt.yes?("Update autoproj ?")
    end

    ws.update_bundler if options[:bundler]
    ws.update_autoproj if options[:autoproj]

    begin
        ws.load_package_sets(
            mainline: options[:mainline],
            only_local: options[:only_local],
            checkout_only: !options[:config] || options[:checkout_only],
            reset: options[:reset],
            keep_going: options[:keep_going],
            retry_count: options[:retry_count]
        )
    rescue ImportFailed => configuration_import_failure
        raise unless options[:keep_going]
    ensure
        ws.config.save
    end

    if options[:packages]
        command_line_selection, selected_packages =
            finish_loading_configuration(selected_packages)
    else
        ws.setup_all_package_directories
        ws.finalize_package_setup
        command_line_selection = []
        selected_packages = PackageSelection.new
    end

    osdeps_options = normalize_osdeps_options(
        checkout_only: options[:checkout_only],
        osdeps_mode: options[:osdeps_mode],
        osdeps: options[:osdeps],
        osdeps_filter_uptodate: options[:osdeps_filter_uptodate]
    )

    source_packages, osdep_packages, import_failure =
        update_packages(
            selected_packages,
            osdeps: options[:osdeps],
            osdeps_options: osdeps_options,
            from: options[:from],
            checkout_only: options[:checkout_only],
            only_local: options[:only_local],
            reset: options[:reset],
            deps: options[:deps],
            keep_going: options[:keep_going],
            parallel: options[:parallel] || ws.config.parallel_import_level,
            retry_count: options[:retry_count],
            auto_exclude: options[:auto_exclude],
            ask: ask,
            report: report
        )

    ws.finalize_setup
    ws.export_installation_manifest

    if options[:osdeps] && !osdep_packages.empty?
        ws.install_os_repositories
        ws.install_os_packages(osdep_packages, **osdeps_options)
    end

    if run_hook
        if options[:osdeps]
            CLI::Main.run_post_command_hook(:update, ws,
                                            source_packages: source_packages,
                                            osdep_packages: osdep_packages)
        else
            CLI::Main.run_post_command_hook(:update, ws,
                                            source_packages: source_packages,
                                            osdep_packages: [])
        end
    end

    export_env_sh

    if !options[:auto_exclude] && !options[:ignore_errors]
        if import_failure && configuration_import_failure
            raise ImportFailed.new(configuration_import_failure.original_errors + import_failure.original_errors)
        elsif import_failure
            raise import_failure
        elsif configuration_import_failure
            raise configuration_import_failure
        end
    end

    [command_line_selection, source_packages, osdep_packages]
end

#setup_update_from(other_root) ⇒ Object



283
284
285
286
287
288
289
290
291
292
293
# File 'lib/autoproj/cli/update.rb', line 283

def setup_update_from(other_root)
    manifest.each_autobuild_package do |pkg|
        if pkg.importer.respond_to?(:pick_from_autoproj_root)
            unless pkg.importer.pick_from_autoproj_root(pkg, other_root)
                pkg.update = false
            end
        else
            pkg.update = false
        end
    end
end

#update_packages(selected_packages, from: nil, checkout_only: false, only_local: false, reset: false, deps: true, keep_going: false, parallel: 1, retry_count: 0, osdeps: true, auto_exclude: false, osdeps_options: Hash.new, report: true, ask: false) ⇒ Object



239
240
241
242
243
244
245
246
247
248
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
# File 'lib/autoproj/cli/update.rb', line 239

def update_packages(selected_packages,
    from: nil, checkout_only: false, only_local: false, reset: false,
    deps: true, keep_going: false, parallel: 1,
    retry_count: 0, osdeps: true, auto_exclude: false, osdeps_options: Hash.new,
    report: true, ask: false)

    setup_update_from(from) if from

    filter =
        if ask
            prompt = TTY::Prompt.new
            filter = AskUpdateFilter.new(
                prompt, parallel: parallel, only_local: only_local
            )
        else
            ->(pkg) { true }
        end

    ops = Autoproj::Ops::Import.new(
        ws, report_path: (ws.import_report_path if report)
    )
    source_packages, osdep_packages =
        ops.import_packages(selected_packages,
                            checkout_only: checkout_only,
                            only_local: only_local,
                            reset: reset,
                            recursive: deps,
                            keep_going: keep_going,
                            parallel: parallel,
                            retry_count: retry_count,
                            install_vcs_packages: (osdeps_options if osdeps),
                            auto_exclude: auto_exclude,
                            filter: filter)
    [source_packages, osdep_packages, nil]
rescue ExcludedSelection => e
    raise CLIInvalidSelection, e.message, e.backtrace
rescue PackageImportFailed => import_failure
    raise unless keep_going

    [import_failure.source_packages,
     import_failure.osdep_packages,
     import_failure]
end

#validate_options(selection, options) ⇒ Object



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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/autoproj/cli/update.rb', line 9

def validate_options(selection, options)
    selection, options = super

    if (from = options[:from])
        options[:from] = Autoproj::InstallationManifest.from_workspace_root(from)
    end

    options[:deps] = false if options[:no_deps_shortcut]

    if options[:aup] && !options[:config] && !options[:all] && selection.empty?
        if Dir.pwd == ws.root_dir
            options[:all] = true
        else
            selection = [Dir.pwd]
        end
    end

    options[:reset] = :force if options.delete(:force_reset)

    if (mainline = options[:mainline])
        if mainline == "mainline" || mainline == "true"
            options[:mainline] = true
        end
    end

    has_explicit_selection = !selection.empty?
    selection, config_selected =
        normalize_command_line_package_selection(selection)

    # Autoproj and configuration are updated only if (1) it is
    # explicitely selected or (2) nothing is explicitely selected
    update_autoproj =
        (options[:autoproj] || (
            options[:autoproj] != false &&
            !has_explicit_selection &&
            !options[:config] &&
            !options[:checkout_only])
        )

    update_config =
        (options[:config] || config_selected || (
            options[:config] != false &&
            !has_explicit_selection &&
            !options[:autoproj]))

    update_packages =
        options[:all] ||
        (has_explicit_selection && !selection.empty?) ||
        (!has_explicit_selection && !options[:config] && !options[:autoproj])

    options[:bundler] = update_autoproj
    options[:autoproj] = update_autoproj
    options[:config]   = update_config
    options[:packages] = update_packages
    [selection, options]
end