Class: Autoproj::CLI::Utility
Instance Attribute Summary collapse
Attributes inherited from Base
#ws
Instance Method Summary
collapse
#finalize_setup, #initialize_and_load
Methods inherited from Base
#export_env_sh, #normalize_command_line_package_selection, #notify_env_sh_updated, #resolve_selection, #resolve_user_selection, #validate_options, validate_options, #validate_user_selection
Methods included from Ops::Tools
#common_options, #create_autobuild_package, #load_autoprojrc, #load_main_initrb
Constructor Details
#initialize(ws, name: nil, report_path: nil) ⇒ Utility
Returns a new instance of Utility.
6
7
8
9
10
|
# File 'lib/autoproj/cli/utility.rb', line 6
def initialize(ws, name: nil, report_path: nil)
@utility_name = name
@report_path = report_path
super(ws)
end
|
Instance Attribute Details
#utility_name ⇒ Object
Returns the value of attribute utility_name.
12
13
14
|
# File 'lib/autoproj/cli/utility.rb', line 12
def utility_name
@utility_name
end
|
Instance Method Details
#apply_to_packages(packages, parallel: ws.config.parallel_build_level) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/autoproj/cli/utility.rb', line 102
def apply_to_packages(packages, parallel: ws.config.parallel_build_level)
if @report_path
reporting = Ops::PhaseReporting.new(
@utility_name, @report_path,
method(:package_metadata)
)
end
reporting&.initialize_incremental_report
Autobuild.apply(
packages.map(&:name), "autoproj-#{@utility_name}",
[@utility_name], parallel: parallel
) do |pkg, phase|
reporting&.report_incremental(pkg) if phase == utility_name
end
ensure
reporting&.create_report(packages.map(&:autobuild))
end
|
#default(enabled) ⇒ Object
14
15
16
17
18
|
# File 'lib/autoproj/cli/utility.rb', line 14
def default(enabled)
ws.load_config
ws.config.utility_default(utility_name, enabled)
ws.config.save
end
|
#disable(user_selection, options = {}) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/autoproj/cli/utility.rb', line 36
def disable(user_selection, options = {})
if user_selection.empty?
ws.load_config
ws.config.utility_disable_all(utility_name)
else
initialize_and_load
selection, = finalize_setup(
user_selection,
recursive: options[:deps],
non_imported_packages: :return
)
ws.config.utility_disable(utility_name, *selection)
end
ws.config.save
end
|
#enable(user_selection, options = {}) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/autoproj/cli/utility.rb', line 20
def enable(user_selection, options = {})
if user_selection.empty?
ws.load_config
ws.config.utility_enable_all(utility_name)
else
initialize_and_load
selection, = finalize_setup(
user_selection,
recursive: options[:deps],
non_imported_packages: :return
)
ws.config.utility_enable(utility_name, *selection)
end
ws.config.save
end
|
#list(user_selection, options = {}) ⇒ 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
76
|
# File 'lib/autoproj/cli/utility.rb', line 52
def list(user_selection, options = {})
initialize_and_load
resolved_selection, = finalize_setup(
user_selection,
recursive: options[:deps],
non_imported_packages: :return
)
lines = []
resolved_selection.each do |pkg_name|
pkg = ws.manifest.find_package_definition(pkg_name).autobuild
lines << [
pkg.name,
pkg.send("#{utility_name}_utility").enabled?,
pkg.send("#{utility_name}_utility").available?
]
end
lines = lines.sort_by { |name, _| name }
w = lines.map { |name, _| name.length }.max
out_format = "%-#{w}s %-7s %-9s"
puts format(out_format, "Package Name", "Enabled", "Available")
lines.each do |name, enabled, available|
puts(format(out_format, name, (!!enabled).to_s, (!!available).to_s)) end
end
|
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/autoproj/cli/utility.rb', line 121
def package_metadata(autobuild_package)
u = autobuild_package.utility(@utility_name)
{
"source_dir" => u.source_dir,
"target_dir" => u.target_dir,
"available" => !!u.available?,
"enabled" => !!u.enabled?,
"invoked" => !!u.invoked?,
"success" => !!u.success?,
"installed" => !!u.installed?
}
end
|
#run(user_selection, options = {}) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/autoproj/cli/utility.rb', line 78
def run(user_selection, options = {})
options[:parallel] ||= ws.config.parallel_build_level
initialize_and_load
user_selection, = normalize_command_line_package_selection(user_selection)
package_names, _, resolved_selection = finalize_setup(
user_selection,
recursive: user_selection.empty? || options[:deps]
)
validate_user_selection(user_selection, resolved_selection)
if package_names.empty?
raise CLIInvalidArguments, "autoproj: the provided package "\
"is not selected for build"
end
return if package_names.empty?
packages = package_names.map do |pkg_name|
ws.manifest.find_package_definition(pkg_name)
end
apply_to_packages(packages, parallel: options[:parallel])
end
|