autoproj 1.13.7 → 2.0.0.b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.gemtest +0 -0
  3. data/Manifest.txt +27 -21
  4. data/Rakefile +4 -6
  5. data/bin/alocate +5 -1
  6. data/bin/amake +3 -53
  7. data/bin/aup +3 -50
  8. data/bin/autoproj +3 -264
  9. data/bin/autoproj_bootstrap +294 -349
  10. data/bin/autoproj_bootstrap.in +27 -3
  11. data/lib/autoproj.rb +23 -1
  12. data/lib/autoproj/autobuild.rb +51 -89
  13. data/lib/autoproj/base.rb +0 -9
  14. data/lib/autoproj/build_option.rb +1 -3
  15. data/lib/autoproj/cli.rb +1 -0
  16. data/lib/autoproj/cli/base.rb +155 -0
  17. data/lib/autoproj/cli/bootstrap.rb +119 -0
  18. data/lib/autoproj/cli/build.rb +72 -0
  19. data/lib/autoproj/cli/cache.rb +31 -0
  20. data/lib/autoproj/cli/clean.rb +37 -0
  21. data/lib/autoproj/cli/commit.rb +41 -0
  22. data/lib/autoproj/cli/doc.rb +22 -0
  23. data/lib/autoproj/cli/envsh.rb +22 -0
  24. data/lib/autoproj/cli/inspection_tool.rb +73 -0
  25. data/lib/autoproj/cli/locate.rb +96 -0
  26. data/lib/autoproj/cli/log.rb +26 -0
  27. data/lib/autoproj/cli/main.rb +249 -0
  28. data/lib/autoproj/cli/main_test.rb +57 -0
  29. data/lib/autoproj/cli/osdeps.rb +30 -0
  30. data/lib/autoproj/cli/query.rb +43 -0
  31. data/lib/autoproj/cli/reconfigure.rb +19 -0
  32. data/lib/autoproj/cli/reset.rb +7 -32
  33. data/lib/autoproj/cli/show.rb +219 -0
  34. data/lib/autoproj/cli/snapshot.rb +1 -1
  35. data/lib/autoproj/cli/status.rb +149 -0
  36. data/lib/autoproj/cli/switch_config.rb +28 -0
  37. data/lib/autoproj/cli/tag.rb +9 -35
  38. data/lib/autoproj/cli/test.rb +34 -55
  39. data/lib/autoproj/cli/update.rb +158 -0
  40. data/lib/autoproj/cli/versions.rb +32 -69
  41. data/lib/autoproj/configuration.rb +95 -34
  42. data/lib/autoproj/default.osdeps +25 -35
  43. data/lib/autoproj/environment.rb +85 -63
  44. data/lib/autoproj/exceptions.rb +50 -0
  45. data/lib/autoproj/gitorious.rb +11 -9
  46. data/lib/autoproj/manifest.rb +199 -231
  47. data/lib/autoproj/metapackage.rb +0 -8
  48. data/lib/autoproj/ops/build.rb +1 -17
  49. data/lib/autoproj/ops/configuration.rb +92 -90
  50. data/lib/autoproj/ops/import.rb +222 -0
  51. data/lib/autoproj/ops/loader.rb +18 -8
  52. data/lib/autoproj/ops/main_config_switcher.rb +45 -73
  53. data/lib/autoproj/ops/snapshot.rb +5 -10
  54. data/lib/autoproj/ops/tools.rb +10 -44
  55. data/lib/autoproj/options.rb +35 -6
  56. data/lib/autoproj/osdeps.rb +97 -68
  57. data/lib/autoproj/package_selection.rb +39 -20
  58. data/lib/autoproj/package_set.rb +26 -24
  59. data/lib/autoproj/reporter.rb +91 -0
  60. data/lib/autoproj/system.rb +50 -149
  61. data/lib/autoproj/variable_expansion.rb +32 -6
  62. data/lib/autoproj/vcs_definition.rb +57 -17
  63. data/lib/autoproj/version.rb +1 -1
  64. data/lib/autoproj/workspace.rb +550 -0
  65. data/test/ops/test_snapshot.rb +26 -0
  66. data/test/test_package.rb +30 -0
  67. data/test/test_vcs_definition.rb +46 -0
  68. metadata +55 -50
  69. data/bin/autolocate +0 -3
  70. data/bin/autoproj-bootstrap +0 -68
  71. data/bin/autoproj-cache +0 -18
  72. data/bin/autoproj-clean +0 -13
  73. data/bin/autoproj-commit +0 -10
  74. data/bin/autoproj-create-set +0 -118
  75. data/bin/autoproj-doc +0 -28
  76. data/bin/autoproj-envsh +0 -14
  77. data/bin/autoproj-list +0 -69
  78. data/bin/autoproj-locate +0 -85
  79. data/bin/autoproj-log +0 -5
  80. data/bin/autoproj-query +0 -82
  81. data/bin/autoproj-reset +0 -13
  82. data/bin/autoproj-show +0 -192
  83. data/bin/autoproj-snapshot +0 -27
  84. data/bin/autoproj-switch-config +0 -24
  85. data/bin/autoproj-tag +0 -13
  86. data/bin/autoproj-test +0 -31
  87. data/bin/autoproj-versions +0 -20
  88. data/bin/autoproj_stress_test +0 -40
  89. data/lib/autoproj/cmdline.rb +0 -1649
@@ -1,192 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- require 'autoproj'
4
- require 'autoproj/cmdline'
5
-
6
- user_selection = ARGV.map do |arg|
7
- if File.directory?(arg)
8
- File.expand_path(arg)
9
- else arg
10
- end
11
- end
12
-
13
- Autoproj.silent = true
14
- Autoproj::CmdLine.initialize_root_directory
15
- Autoproj::CmdLine.initialize_and_load(ARGV)
16
-
17
- default_packages = Autoproj.manifest.default_packages
18
- revdeps = Autoproj.manifest.compute_revdeps
19
-
20
- resolved_selection = Autoproj::CmdLine.resolve_user_selection(user_selection, :filter => false)
21
- packages = resolved_selection.selection.keys
22
-
23
- def find_selection_path(from, to)
24
- path = [from]
25
- if from == to
26
- return path
27
- end
28
-
29
- Autoproj.manifest.resolve_package_set(from).each do |pkg_name|
30
- Autobuild::Package[pkg_name].dependencies.each do |dep_pkg_name|
31
- if result = find_selection_path(dep_pkg_name, to)
32
- return path + result
33
- end
34
- end
35
- end
36
- nil
37
- end
38
-
39
- if packages.empty?
40
- puts "no packages or OS packages match #{user_selection.join(" ")}"
41
- exit 1
42
- end
43
-
44
- def vcs_to_array(vcs)
45
- if vcs.kind_of?(Hash)
46
- options = vcs.dup
47
- type = options.delete('type')
48
- url = options.delete('url')
49
- else
50
- options = vcs.options
51
- type = vcs.type
52
- url = vcs.url
53
- end
54
-
55
- value = []
56
- if type
57
- value << ['type', type]
58
- end
59
- if url
60
- value << ['url', url]
61
- end
62
- value = value.concat(options.to_a.sort_by { |k, _| k.to_s })
63
- value.map do |key, value|
64
- if value.respond_to?(:to_str) && File.file?(value) && value =~ /^\//
65
- value = Pathname.new(value).relative_path_from(Pathname.new(Autoproj.root_dir))
66
- end
67
- [key, value]
68
- end
69
- end
70
-
71
- def compute_all_revdeps(pkg_revdeps, revdeps)
72
- pkg_revdeps = pkg_revdeps.dup
73
- all_revdeps = Array.new
74
- while !pkg_revdeps.empty?
75
- parent_name = pkg_revdeps.shift
76
- next if all_revdeps.include?(parent_name)
77
- all_revdeps << parent_name
78
- pkg_revdeps.concat(revdeps[parent_name].to_a)
79
- end
80
- all_revdeps
81
- end
82
-
83
- packages.each do |name|
84
- result = Autoproj.manifest.resolve_package_name(name, :filter => false)
85
- packages, osdeps = result.partition { |type, name| type == :package }
86
- packages = packages.map(&:last)
87
- osdeps = osdeps.map(&:last)
88
-
89
- packages.each do |pkg_name|
90
- puts Autoproj.color("source package #{pkg_name}", :bold)
91
- puts " source definition"
92
- vcs = Autoproj.manifest.importer_definition_for(pkg_name)
93
-
94
- fragments = []
95
- if !vcs
96
- fragments << ["has no VCS definition", []]
97
- elsif vcs.raw
98
- first = true
99
- fragments << [nil, vcs_to_array(vcs)]
100
- vcs.raw.each do |pkg_set, vcs_info|
101
- title = if first
102
- "first match: in #{pkg_set}"
103
- else "overriden in #{pkg_set}"
104
- end
105
- first = false
106
- fragments << [title, vcs_to_array(vcs_info)]
107
- end
108
- end
109
- fragments.each do |title, elements|
110
- if title
111
- puts " #{title}"
112
- elements.each do |key, value|
113
- puts " #{key}: #{value}"
114
- end
115
- else
116
- elements.each do |key, value|
117
- puts " #{key}: #{value}"
118
- end
119
- end
120
- end
121
-
122
- if default_packages.include?(pkg_name)
123
- selection = default_packages.selection[pkg_name]
124
- if selection.include?(pkg_name) && selection.size == 1
125
- puts " is directly selected by the manifest"
126
- else
127
- selection = selection.dup
128
- selection.delete(pkg_name)
129
- puts " is directly selected by the manifest via #{selection.to_a.join(", ")}"
130
- end
131
- else
132
- puts " is not directly selected by the manifest"
133
- end
134
- if Autoproj.manifest.ignored?(pkg_name)
135
- puts " is ignored"
136
- end
137
- if Autoproj.manifest.excluded?(pkg_name)
138
- puts " is excluded: #{Autoproj.manifest.exclusion_reason(pkg_name)}"
139
- end
140
-
141
- if !File.directory?(Autobuild::Package[pkg_name].srcdir)
142
- puts Autobuild.color(" this package is not checked out yet, the dependency information will probably be incomplete", :magenta)
143
- end
144
-
145
- pkg_revdeps = revdeps[pkg_name].to_a
146
- all_revdeps = compute_all_revdeps(pkg_revdeps, revdeps)
147
- if pkg_revdeps.empty?
148
- puts " no reverse dependencies"
149
- else
150
- puts " direct reverse dependencies: #{pkg_revdeps.sort.join(", ")}"
151
- puts " recursive reverse dependencies: #{all_revdeps.sort.join(", ")}"
152
- end
153
-
154
- selections = Set.new
155
- all_revdeps = all_revdeps.to_a.sort
156
- all_revdeps.each do |revdep_parent_name|
157
- if default_packages.include?(revdep_parent_name)
158
- selections |= default_packages.selection[revdep_parent_name]
159
- end
160
- end
161
-
162
- if !selections.empty?
163
- puts " selected by way of"
164
- selections.each do |root_pkg|
165
- path = find_selection_path(root_pkg, pkg_name)
166
- puts " #{path.join(">")}"
167
- end
168
- end
169
-
170
- pkg = Autobuild::Package[pkg_name]
171
- puts " directly depends on: #{pkg.dependencies.sort.join(", ")}"
172
- puts " optionally depends on: #{pkg.optional_dependencies.sort.join(", ")}"
173
- puts " dependencies on OS packages: #{pkg.os_packages.sort.join(", ")}"
174
- end
175
-
176
- osdeps.each do |pkg_name|
177
- puts Autoproj.color("the osdep '#{pkg_name}'", :bold)
178
- Autoproj.osdeps.resolve_os_dependencies([pkg_name]).each do |manager, packages|
179
- puts " #{manager.names.first}: #{packages.map { |*subnames| subnames.join(" ") }.join(", ")}"
180
- end
181
-
182
- pkg_revdeps = revdeps[pkg_name].dup.to_a
183
- all_revdeps = compute_all_revdeps(pkg_revdeps, revdeps)
184
- if pkg_revdeps.empty?
185
- puts " no reverse dependencies"
186
- else
187
- puts " direct reverse dependencies: #{pkg_revdeps.sort.join(", ")}"
188
- puts " recursive reverse dependencies: #{all_revdeps.sort.join(", ")}"
189
- end
190
- end
191
- end
192
-
@@ -1,27 +0,0 @@
1
- #! /usr/bin/env ruby
2
- require 'autoproj/cli/snapshot'
3
-
4
- args = ARGV.map do |arg|
5
- if File.directory?(arg)
6
- File.expand_path(arg)
7
- else arg
8
- end
9
- end
10
-
11
- Autoproj::CmdLine.report(silent: true) do
12
- Autoproj.silent do
13
- Autoproj::CmdLine.initialize_root_directory
14
- Autoproj::CmdLine.initialize_and_load([])
15
- end
16
-
17
- cli = Autoproj::CLI::Snapshot.new(Autoproj.manifest)
18
- args, options = cli.parse_options(args)
19
- if args.empty?
20
- Autoproj.error "missing target directory on the command line"
21
- exit 1
22
- elsif args.size > 1
23
- Autoproj.error "expected only one argument on the command line specifying the target directory"
24
- exit 1
25
- end
26
- cli.run(args.first, options)
27
- end
@@ -1,24 +0,0 @@
1
- #! /usr/bin/env ruby
2
- require 'autoproj'
3
- require 'autoproj/ops/main_config_switcher'
4
-
5
- Autoproj::CmdLine.report do
6
- Autoproj::CmdLine.initialize
7
-
8
- if Dir.pwd.start_with?(Autoproj.remotes_dir) || Dir.pwd.start_with?(Autoproj.config_dir)
9
- raise ConfigError, "you cannot run autoproj switch-config from autoproj's configuration directory or one of its subdirectories"
10
- end
11
-
12
- # We must switch to the root dir first, as it is required by the
13
- # configuration switch code. This is acceptable as long as we
14
- # quit just after the switch
15
- Dir.chdir(Autoproj.root_dir)
16
- switcher = Autoproj::Ops::MainConfigSwitcher.new(Autoproj.root_dir)
17
- if switcher.switch_config(*ARGV)
18
- manifest = Autoproj::Manifest.load(File.join(Autoproj.config_dir, 'manifest'))
19
- update = Autoproj::Ops::Configuration.new(manifest, Autoproj::Ops.loader)
20
- update.update_configuration
21
- Autoproj.save_config
22
- end
23
- end
24
-
@@ -1,13 +0,0 @@
1
- #! /usr/bin/env ruby
2
- require 'autoproj/cli/tag'
3
-
4
- Autoproj::CmdLine.report(silent: true) do
5
- Autoproj.silent do
6
- Autoproj::CmdLine.initialize_root_directory
7
- Autoproj::CmdLine.initialize_and_load([])
8
- end
9
-
10
- cli = Autoproj::CLI::Tag.new(Autoproj.manifest)
11
- tag_name, options = cli.parse_options(ARGV)
12
- cli.run(tag_name, options)
13
- end
@@ -1,31 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- require 'autoproj'
4
- require 'autoproj/cli/test'
5
-
6
- argv = ARGV.map do |arg|
7
- if File.directory?(arg)
8
- File.expand_path(arg)
9
- else arg
10
- end
11
- end
12
-
13
- Autoproj.silent do
14
- Autoproj::CmdLine.initialize_root_directory
15
- Autoproj::CmdLine.initialize_and_load([])
16
- end
17
-
18
- Autobuild.pass_test_errors = true
19
- Autobuild.ignore_errors = true
20
-
21
- Autoproj::CmdLine.report(silent: true) do
22
- cli = Autoproj::CLI::Test.new(Autoproj.manifest)
23
- mode, user_selection, options = cli.parse_options(argv)
24
-
25
- if mode == 'run'
26
- cli.run(user_selection, options)
27
- elsif mode == 'list'
28
- cli.list(user_selection, options)
29
- end
30
- end
31
-
@@ -1,20 +0,0 @@
1
- #! /usr/bin/env ruby
2
- require 'autoproj/cli/versions'
3
-
4
- args = ARGV.map do |arg|
5
- if File.directory?(arg)
6
- File.expand_path(arg)
7
- else arg
8
- end
9
- end
10
-
11
- Autoproj::CmdLine.report(silent: true) do
12
- Autoproj.silent do
13
- Autoproj::CmdLine.initialize_root_directory
14
- Autoproj::CmdLine.initialize_and_load([])
15
- end
16
-
17
- cli = Autoproj::CLI::Versions.new(Autoproj.manifest)
18
- user_selection, options = cli.parse_options(args)
19
- cli.run(user_selection, options)
20
- end
@@ -1,40 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- require 'autoproj'
4
- require 'autoproj/cmdline'
5
-
6
- root_dir = Autoproj::CmdLine.initialize_root_directory
7
- Autoproj::CmdLine.initialize_and_load([])
8
- manifest = Autoproj.manifest
9
-
10
- manifest_path = File.join(Autoproj.config_dir, 'manifest')
11
- manifest_data = YAML.load(File.read(manifest_path))
12
- manifest_data['layout'] = Array.new
13
-
14
- packages = manifest.each_autobuild_package.map(&:name)
15
-
16
- while !packages.empty?
17
- pkg = packages[rand(packages.size)]
18
- next if !pkg
19
- packages.delete(pkg)
20
-
21
- manifest_data['layout'] << pkg
22
- File.open(manifest_path, 'w') do |io|
23
- io.write YAML.dump(manifest_data)
24
- end
25
-
26
- STDERR.puts
27
- STDERR.puts
28
- STDERR.puts
29
- STDERR.puts "=================================================="
30
- STDERR.puts "==== added #{pkg}"
31
- if !system('autoproj', 'full-build', '--randomize-layout', pkg)
32
- File.open(File.join(root_dir, 'failures.txt'), 'a') do |io|
33
- io.puts "the following layout failed:"
34
- io.puts " - " + manifest_data['layout'].join("\n - ")
35
- end
36
- STDERR.puts "the following layout failed:"
37
- STDERR.puts " - " + manifest_data['layout'].join("\n - ")
38
- end
39
- end
40
-
@@ -1,1649 +0,0 @@
1
- require 'highline'
2
- require 'utilrb/module/attr_predicate'
3
- require 'autoproj/ops/build'
4
- module Autoproj
5
- class << self
6
- attr_accessor :verbose
7
- attr_reader :console
8
- def silent?
9
- Autobuild.silent?
10
- end
11
- def silent=(value)
12
- Autobuild.silent = value
13
- end
14
- end
15
- @verbose = false
16
- @console = HighLine.new
17
- ENV_FILENAME =
18
- if Autobuild.windows? then "env.bat"
19
- else "env.sh"
20
- end
21
-
22
-
23
- def self.silent(&block)
24
- Autobuild.silent(&block)
25
- end
26
-
27
- def self.message(*args)
28
- Autobuild.message(*args)
29
- end
30
-
31
- def self.color(*args)
32
- Autobuild.color(*args)
33
- end
34
-
35
- # Displays an error message
36
- def self.error(message)
37
- Autobuild.error(message)
38
- end
39
-
40
- # Displays a warning message
41
- def self.warn(message, *style)
42
- Autobuild.warn(message, *style)
43
- end
44
-
45
- module CmdLine
46
- def self.argv
47
- if defined? ORIGINAL_ARGV
48
- ORIGINAL_ARGV
49
- else
50
- ARGV
51
- end
52
- end
53
-
54
- def self.config
55
- Autoproj.config
56
- end
57
-
58
- def self.ruby_executable
59
- Autoproj.config.ruby_executable
60
- end
61
-
62
- def self.install_ruby_shims
63
- install_suffix = ""
64
- if match = /ruby(.*)$/.match(RbConfig::CONFIG['RUBY_INSTALL_NAME'])
65
- install_suffix = match[1]
66
- end
67
-
68
- bindir = File.join(Autoproj.build_dir, 'bin')
69
- FileUtils.mkdir_p bindir
70
- Autoproj.env_add 'PATH', bindir
71
-
72
- File.open(File.join(bindir, 'ruby'), 'w') do |io|
73
- io.puts "#! /bin/sh"
74
- io.puts "exec #{ruby_executable} \"$@\""
75
- end
76
- FileUtils.chmod 0755, File.join(bindir, 'ruby')
77
-
78
- ['gem', 'irb', 'testrb'].each do |name|
79
- # Look for the corresponding gem program
80
- prg_name = "#{name}#{install_suffix}"
81
- if File.file?(prg_path = File.join(RbConfig::CONFIG['bindir'], prg_name))
82
- File.open(File.join(bindir, name), 'w') do |io|
83
- io.puts "#! #{ruby_executable}"
84
- io.puts "exec \"#{prg_path}\", *ARGV"
85
- end
86
- FileUtils.chmod 0755, File.join(bindir, name)
87
- end
88
- end
89
- end
90
-
91
- def self.validate_current_root
92
- # Make sure that the currently loaded env.sh is actually us
93
- if ENV['AUTOPROJ_CURRENT_ROOT'] && !ENV['AUTOPROJ_CURRENT_ROOT'].empty? && (ENV['AUTOPROJ_CURRENT_ROOT'] != Autoproj.root_dir)
94
- raise ConfigError.new, "the current environment is for #{ENV['AUTOPROJ_CURRENT_ROOT']}, but you are in #{Autoproj.root_dir}, make sure you are loading the right #{ENV_FILENAME} script !"
95
- end
96
- end
97
-
98
- def self.initialize
99
- Encoding.default_internal = Encoding::UTF_8
100
- Encoding.default_external = Encoding::UTF_8
101
-
102
- Autobuild::Reporting << Autoproj::Reporter.new
103
- if mail_config[:to]
104
- Autobuild::Reporting << Autobuild::MailReporter.new(mail_config)
105
- end
106
-
107
- validate_current_root
108
-
109
- # Remove from LOADED_FEATURES everything that is coming from our
110
- # configuration directory
111
- Autobuild::Package.clear
112
- Autoproj.loaded_autobuild_files.clear
113
- Autoproj.load_config
114
-
115
- config.validate_ruby_executable
116
- install_ruby_shims
117
-
118
- config.apply_autobuild_configuration
119
- config.apply_autoproj_prefix
120
-
121
- manifest = Manifest.new
122
- Autoproj.manifest = manifest
123
- Autoproj.prepare_environment
124
- Autobuild.prefix = Autoproj.build_dir
125
- Autobuild.srcdir = Autoproj.root_dir
126
- Autobuild.logdir = File.join(Autobuild.prefix, 'log')
127
-
128
- Ops::Tools.load_autoprojrc
129
-
130
- config.each_reused_autoproj_installation do |p|
131
- manifest.reuse(p)
132
- end
133
-
134
- # We load the local init.rb first so that the manifest loading
135
- # process can use options defined there for the autoproj version
136
- # control information (for instance)
137
- Ops::Tools.load_main_initrb(manifest)
138
-
139
- manifest_path = File.join(Autoproj.config_dir, 'manifest')
140
- manifest.load(manifest_path)
141
-
142
- # Initialize the Autoproj.osdeps object by loading the default. The
143
- # rest is loaded later
144
- manifest.osdeps.load_default
145
- manifest.osdeps.silent = !osdeps?
146
- manifest.osdeps.filter_uptodate_packages = osdeps_filter_uptodate?
147
- if osdeps_forced_mode
148
- manifest.osdeps.osdeps_mode = osdeps_forced_mode
149
- end
150
-
151
- # Define the option NOW, as update_os_dependencies? needs to know in
152
- # what mode we are.
153
- #
154
- # It might lead to having multiple operating system detections, but
155
- # that's the best I can do for now.
156
- Autoproj::OSDependencies.define_osdeps_mode_option
157
- manifest.osdeps.osdeps_mode
158
-
159
- # Do that AFTER we have properly setup Autoproj.osdeps as to avoid
160
- # unnecessarily redetecting the operating system
161
- if update_os_dependencies? || osdeps?
162
- Autoproj.change_option('operating_system', Autoproj::OSDependencies.operating_system(:force => true), true)
163
- end
164
- end
165
-
166
- def self.load_autoprojrc
167
- Ops::Tools.load_autoprojrc
168
- end
169
-
170
- def self.update_myself(options = Hash.new)
171
- options = Kernel.validate_options options,
172
- force: false, restart_on_update: true
173
- return if !options[:force] && !Autoproj::CmdLine.update_os_dependencies?
174
-
175
- Autoproj.config.validate_ruby_executable
176
-
177
- # This is a guard to avoid infinite recursion in case the user is
178
- # running autoproj osdeps --force
179
- if ENV['AUTOPROJ_RESTARTING'] == '1'
180
- return
181
- end
182
-
183
- did_update =
184
- begin
185
- saved_flag = PackageManagers::GemManager.with_prerelease
186
- PackageManagers::GemManager.with_prerelease = Autoproj.config.use_prerelease?
187
- OSDependencies.load_default.install(%w{autobuild autoproj})
188
- ensure
189
- PackageManagers::GemManager.with_prerelease = saved_flag
190
- end
191
-
192
- # First things first, see if we need to update ourselves
193
- if did_update && options[:restart_on_update]
194
- puts
195
- Autoproj.message 'autoproj and/or autobuild has been updated, restarting autoproj'
196
- puts
197
-
198
- # We updated autobuild or autoproj themselves ... Restart !
199
- #
200
- # ...But first save the configuration (!)
201
- Autoproj.save_config
202
- ENV['AUTOPROJ_RESTARTING'] = '1'
203
- require 'rbconfig'
204
- exec(ruby_executable, $0, *argv)
205
- end
206
- end
207
-
208
- def self.load_configuration(silent = false)
209
- manifest.each_package_set do |pkg_set|
210
- if Gem::Version.new(pkg_set.required_autoproj_version) > Gem::Version.new(Autoproj::VERSION)
211
- raise ConfigError.new(pkg_set.source_file), "the #{pkg_set.name} package set requires autoproj v#{pkg_set.required_autoproj_version} but this is v#{Autoproj::VERSION}"
212
- end
213
- end
214
-
215
- # Loads OS package definitions once and for all
216
- Autoproj.load_osdeps_from_package_sets
217
-
218
- # Load the required autobuild definitions
219
- if !silent
220
- Autoproj.message("autoproj: loading ...", :bold)
221
- if !Autoproj.reconfigure?
222
- Autoproj.message("run 'autoproj reconfigure' to change configuration options", :bold)
223
- Autoproj.message("and use 'autoproj switch-config' to change the remote source for", :bold)
224
- Autoproj.message("autoproj's main build configuration", :bold)
225
- end
226
- end
227
- manifest.each_autobuild_file do |source, name|
228
- Autoproj.import_autobuild_file source, name
229
- end
230
-
231
- # Now, load the package's importer configurations (from the various
232
- # source.yml files)
233
- manifest.load_importers
234
-
235
- # Auto-add packages that are
236
- # * present on disk
237
- # * listed in the layout part of the manifest
238
- # * but have no definition
239
- explicit = manifest.normalized_layout
240
- explicit.each do |pkg_or_set, layout_level|
241
- next if Autobuild::Package[pkg_or_set]
242
- next if manifest.has_package_set?(pkg_or_set)
243
-
244
- # This is not known. Check if we can auto-add it
245
- full_path = File.expand_path(File.join(Autoproj.root_dir, layout_level, pkg_or_set))
246
- next if !File.directory?(full_path)
247
-
248
- handler, srcdir = Autoproj.package_handler_for(full_path)
249
- if handler
250
- Autoproj.message " auto-adding #{pkg_or_set} #{"in #{layout_level} " if layout_level != "/"}using the #{handler.gsub(/_package/, '')} package handler"
251
- Autoproj.in_package_set(manifest.local_package_set, manifest.file) do
252
- send(handler, pkg_or_set)
253
- end
254
- else
255
- Autoproj.warn "cannot auto-add #{pkg_or_set}: unknown package type"
256
- end
257
- end
258
-
259
- manifest.each_autobuild_package do |pkg|
260
- Autobuild.each_utility do |uname, _|
261
- pkg.utility(uname).enabled =
262
- config.utility_enabled_for?(uname, pkg.name)
263
- end
264
- end
265
-
266
- # We finished loading the configuration files. Not all configuration
267
- # is done (since we need to process the package setup blocks), but
268
- # save the current state of the configuration anyway.
269
- Autoproj.save_config
270
- end
271
-
272
- def self.update_configuration
273
- Ops::Configuration.new(manifest, Ops.loader).update_configuration(only_local?)
274
- end
275
-
276
- def self.setup_package_directories(pkg)
277
- pkg_name = pkg.name
278
-
279
- layout =
280
- if config.randomize_layout?
281
- Digest::SHA256.hexdigest(pkg_name)[0, 12]
282
- else manifest.whereis(pkg_name)
283
- end
284
-
285
- place =
286
- if target = manifest.moved_packages[pkg_name]
287
- File.join(layout, target)
288
- else
289
- File.join(layout, pkg_name)
290
- end
291
-
292
- pkg = Autobuild::Package[pkg_name]
293
- pkg.srcdir = File.join(Autoproj.root_dir, place)
294
- pkg.prefix = File.join(Autoproj.build_dir, layout)
295
- pkg.doc_target_dir = File.join(Autoproj.build_dir, 'doc', pkg_name)
296
- pkg.logdir = File.join(pkg.prefix, "log")
297
- end
298
-
299
-
300
- def self.setup_all_package_directories
301
- # Override the package directories from our reused installations
302
- imported_packages = Set.new
303
- manifest.reused_installations.each do |imported_manifest|
304
- imported_manifest.each do |imported_pkg|
305
- imported_packages << imported_pkg.name
306
- if pkg = manifest.find_package(imported_pkg.name)
307
- pkg.autobuild.srcdir = imported_pkg.srcdir
308
- pkg.autobuild.prefix = imported_pkg.prefix
309
- end
310
- end
311
- end
312
-
313
- manifest.packages.each_value do |pkg_def|
314
- pkg = pkg_def.autobuild
315
- next if imported_packages.include?(pkg_def.name)
316
- setup_package_directories(pkg)
317
- end
318
- end
319
-
320
- def self.finalize_package_setup
321
- # Now call the blocks that the user defined in the autobuild files. We do it
322
- # now so that the various package directories are properly setup
323
- manifest.packages.each_value do |pkg|
324
- pkg.user_blocks.each do |blk|
325
- blk[pkg.autobuild]
326
- end
327
- pkg.setup = true
328
- end
329
-
330
- manifest.each_package_set do |source|
331
- Autoproj.load_if_present(source, source.local_dir, "overrides.rb")
332
- end
333
-
334
- # Resolve optional dependencies
335
- manifest.resolve_optional_dependencies
336
-
337
- # And, finally, disable all ignored packages on the autobuild side
338
- manifest.each_ignored_package do |pkg_name|
339
- pkg = Autobuild::Package[pkg_name]
340
- if !pkg
341
- Autoproj.warn "ignore line #{pkg_name} does not match anything"
342
- else
343
- pkg.disable
344
- end
345
- end
346
-
347
- update_environment
348
-
349
- # We now have processed the process setup blocks. All configuration
350
- # should be done and we can save the configuration data.
351
- Autoproj.save_config
352
- end
353
-
354
- # This is a bit of a killer. It loads all available package manifests,
355
- # but simply warns in case of errors. The reasons for that is that the
356
- # only packages that should really block the current processing are the
357
- # ones that are selected on the command line
358
- def self.load_all_available_package_manifests(overwrite_existing = true)
359
- # Load the manifest for packages that are already present on the
360
- # file system
361
- manifest.packages.each_value do |pkg|
362
- next if !overwrite_existing && pkg.autobuild.description
363
- if File.directory?(pkg.autobuild.srcdir)
364
- begin
365
- manifest.load_package_manifest(pkg.autobuild.name)
366
- rescue Interrupt
367
- raise
368
- rescue Exception => e
369
- Autoproj.warn "cannot load package manifest for #{pkg.autobuild.name}: #{e.message}"
370
- end
371
- end
372
- end
373
- end
374
-
375
- def self.update_environment
376
- manifest.reused_installations.each do |reused_manifest|
377
- reused_manifest.each do |pkg|
378
- # The reused installations might have packages we do not
379
- # know about, just ignore them
380
- if pkg = manifest.find_autobuild_package(pkg)
381
- pkg.update_environment
382
- end
383
- end
384
- end
385
-
386
- # Make sure that we have the environment of all selected packages
387
- manifest.all_selected_packages(false).each do |pkg_name|
388
- Autobuild::Package[pkg_name].update_environment
389
- end
390
- end
391
-
392
- def self.display_configuration(manifest, package_list = nil)
393
- # Load the manifest for packages that are already present on the
394
- # file system
395
- manifest.packages.each_value do |pkg|
396
- if File.directory?(pkg.autobuild.srcdir)
397
- manifest.load_package_manifest(pkg.autobuild.name)
398
- end
399
- end
400
-
401
- all_packages = Hash.new
402
- if package_list
403
- all_selected_packages = Set.new
404
- package_list.each do |name|
405
- all_selected_packages << name
406
- Autobuild::Package[name].all_dependencies(all_selected_packages)
407
- end
408
-
409
- package_sets = Set.new
410
- all_selected_packages.each do |name|
411
- pkg_set = manifest.definition_package_set(name)
412
- package_sets << pkg_set
413
- all_packages[name] = [manifest.package(name).autobuild, pkg_set.name]
414
- end
415
-
416
- metapackages = Set.new
417
- manifest.metapackages.each_value do |metap|
418
- if package_list.any? { |pkg_name| metap.include?(pkg_name) }
419
- metapackages << metap
420
- end
421
- end
422
- else
423
- package_sets = manifest.each_package_set
424
- package_sets.each do |pkg_set|
425
- pkg_set.each_package.each do |pkg|
426
- all_packages[pkg.name] = [pkg, pkg_set.name]
427
- end
428
- end
429
-
430
- metapackages = manifest.metapackages.values
431
- end
432
-
433
- if package_sets.empty?
434
- Autoproj.message("autoproj: no package sets defined in autoproj/manifest", :bold, :red)
435
- return
436
- end
437
-
438
- Autoproj.message
439
- Autoproj.message("autoproj: package sets", :bold)
440
- package_sets.sort_by(&:name).each do |pkg_set|
441
- next if pkg_set.empty?
442
- if pkg_set.imported_from
443
- Autoproj.message "#{pkg_set.name} (imported by #{pkg_set.imported_from.map(&:name).join(", ")})"
444
- else
445
- Autoproj.message "#{pkg_set.name} (listed in manifest)"
446
- end
447
- if pkg_set.local?
448
- Autoproj.message " local set in #{pkg_set.local_dir}"
449
- else
450
- Autoproj.message " from: #{pkg_set.vcs}"
451
- Autoproj.message " local: #{pkg_set.local_dir}"
452
- end
453
-
454
- imports = pkg_set.each_imported_set.to_a
455
- if !imports.empty?
456
- Autoproj.message " imports #{imports.size} package sets"
457
- if !pkg_set.auto_imports?
458
- Autoproj.message " automatic imports are DISABLED for this set"
459
- end
460
- imports.each do |imported_set|
461
- Autoproj.message " #{imported_set.name}"
462
- end
463
- end
464
-
465
- set_packages = pkg_set.each_package.sort_by(&:name)
466
- Autoproj.message " defines: #{set_packages.map(&:name).join(", ")}"
467
- end
468
-
469
- Autoproj.message
470
- Autoproj.message("autoproj: metapackages", :bold)
471
- metapackages.sort_by(&:name).each do |metap|
472
- Autoproj.message "#{metap.name}"
473
- Autoproj.message " includes: #{metap.packages.map(&:name).sort.join(", ")}"
474
- end
475
-
476
- packages_not_present = []
477
-
478
- Autoproj.message
479
- Autoproj.message("autoproj: packages", :bold)
480
- all_packages.to_a.sort_by(&:first).map(&:last).each do |pkg, pkg_set|
481
- if File.exists?(File.join(pkg.srcdir, "manifest.xml"))
482
- manifest.load_package_manifest(pkg.name)
483
- manifest.resolve_optional_dependencies
484
- end
485
-
486
- pkg_manifest = pkg.description
487
- vcs_def = manifest.importer_definition_for(pkg.name)
488
- Autoproj.message "#{pkg.name}#{": #{pkg_manifest.short_documentation}" if pkg_manifest && pkg_manifest.short_documentation}", :bold
489
- tags = pkg.tags.to_a
490
- if tags.empty?
491
- Autoproj.message " no tags"
492
- else
493
- Autoproj.message " tags: #{pkg.tags.to_a.sort.join(", ")}"
494
- end
495
- Autoproj.message " defined in package set #{pkg_set}"
496
- if File.directory?(pkg.srcdir)
497
- Autoproj.message " checked out in #{pkg.srcdir}"
498
- else
499
- Autoproj.message " will be checked out in #{pkg.srcdir}"
500
- end
501
- Autoproj.message " #{vcs_def.to_s}"
502
-
503
- if !File.directory?(pkg.srcdir)
504
- packages_not_present << pkg.name
505
- Autoproj.message " NOT checked out yet, reported dependencies will be partial"
506
- end
507
-
508
- optdeps = pkg.optional_dependencies.to_set
509
- real_deps = pkg.dependencies.to_a
510
- actual_real_deps = real_deps.find_all { |dep_name| !optdeps.include?(dep_name) }
511
- if !actual_real_deps.empty?
512
- Autoproj.message " deps: #{actual_real_deps.join(", ")}"
513
- end
514
-
515
- selected_opt_deps, opt_deps = optdeps.partition { |dep_name| real_deps.include?(dep_name) }
516
- if !selected_opt_deps.empty?
517
- Autoproj.message " enabled opt deps: #{selected_opt_deps.join(", ")}"
518
- end
519
- if !opt_deps.empty?
520
- Autoproj.message " disabled opt deps: #{opt_deps.join(", ")}"
521
- end
522
-
523
- if !pkg.os_packages.empty?
524
- Autoproj.message " OSdeps: #{pkg.os_packages.to_a.sort.join(", ")}"
525
- end
526
- end
527
-
528
- if !packages_not_present.empty?
529
- Autoproj.message
530
- Autoproj.warn "the following packages are not yet checked out:"
531
- packages_not_present.each_slice(4) do |*packages|
532
- Autoproj.warn " #{packages.join(", ")}"
533
- end
534
- Autoproj.warn "therefore, the package list above and the listed dependencies are probably not complete"
535
- end
536
- end
537
-
538
- # Returns the set of packages that are actually selected based on what
539
- # the user gave on the command line
540
- def self.resolve_user_selection(selected_packages, options = Hash.new)
541
- if all_known_package?
542
- result = PackageSelection.new
543
- names = manifest.all_packages
544
- names.delete_if { |pkg_name| manifest.excluded?(pkg_name) || manifest.ignored?(pkg_name) }
545
- names.each do |pkg_name|
546
- result.select(pkg_name, pkg_name)
547
- end
548
- return result
549
- #return manifest.metapackages#.collect {|m| m[0] }
550
- end
551
- if selected_packages.empty?
552
- return manifest.default_packages
553
- end
554
- selected_packages = selected_packages.to_set
555
-
556
- selected_packages, nonresolved = manifest.
557
- expand_package_selection(selected_packages, options)
558
-
559
- # Try to auto-add stuff if nonresolved
560
- nonresolved.delete_if do |sel|
561
- next if !File.directory?(sel)
562
- while sel != '/'
563
- handler, srcdir = Autoproj.package_handler_for(sel)
564
- if handler
565
- Autoproj.message " auto-adding #{srcdir} using the #{handler.gsub(/_package/, '')} package handler"
566
- srcdir = File.expand_path(srcdir)
567
- relative_to_root = Pathname.new(srcdir).relative_path_from(Pathname.new(Autoproj.root_dir))
568
- pkg = Autoproj.in_package_set(manifest.local_package_set, manifest.file) do
569
- send(handler, relative_to_root.to_s)
570
- end
571
- setup_package_directories(pkg)
572
- selected_packages.select(sel, pkg.name, true)
573
- break(true)
574
- end
575
-
576
- sel = File.dirname(sel)
577
- end
578
- end
579
-
580
- if Autoproj.verbose
581
- Autoproj.message "will install #{selected_packages.packages.to_a.sort.join(", ")}"
582
- end
583
- selected_packages
584
- end
585
-
586
- def self.validate_user_selection(user_selection, resolved_selection)
587
- not_matched = user_selection.find_all do |pkg_name|
588
- !resolved_selection.has_match_for?(pkg_name)
589
- end
590
- if !not_matched.empty?
591
- raise ConfigError.new, "autoproj: wrong package selection on command line, cannot find a match for #{not_matched.to_a.sort.join(", ")}"
592
- end
593
- end
594
-
595
- def self.mark_exclusion_along_revdeps(pkg_name, revdeps, chain = [], reason = nil)
596
- root = !reason
597
- chain.unshift pkg_name
598
- if root
599
- reason = manifest.exclusion_reason(pkg_name)
600
- else
601
- if chain.size == 1
602
- manifest.add_exclusion(pkg_name, "its dependency #{reason}")
603
- else
604
- manifest.add_exclusion(pkg_name, "#{reason} (dependency chain: #{chain.join(">")})")
605
- end
606
- end
607
-
608
- return if !revdeps.has_key?(pkg_name)
609
- revdeps[pkg_name].each do |dep_name|
610
- if !manifest.excluded?(dep_name)
611
- mark_exclusion_along_revdeps(dep_name, revdeps, chain.dup, reason)
612
- end
613
- end
614
- end
615
-
616
- def self.import_next_step(manifest, pkg, reverse_dependencies)
617
- new_packages = []
618
- pkg.dependencies.each do |dep_name|
619
- reverse_dependencies[dep_name] << pkg.name
620
- new_packages << manifest.find_autobuild_package(dep_name)
621
- end
622
- pkg_opt_deps, _ = pkg.partition_optional_dependencies
623
- pkg_opt_deps.each do |dep_name|
624
- new_packages << manifest.find_autobuild_package(dep_name)
625
- end
626
-
627
- new_packages.delete_if do |new_pkg|
628
- if manifest.excluded?(new_pkg.name)
629
- mark_exclusion_along_revdeps(new_pkg.name, reverse_dependencies)
630
- true
631
- elsif manifest.ignored?(new_pkg.name)
632
- true
633
- end
634
- end
635
- new_packages
636
- end
637
-
638
- def self.import_packages(selection, options = Hash.new)
639
- options, import_options = Kernel.filter_options options,
640
- warn_about_ignored_packages: true,
641
- warn_about_excluded_packages: true
642
- import_options = Hash[only_local: only_local?, reset: reset?, checkout_only: !Autobuild.do_update].
643
- merge(import_options)
644
-
645
- updated_packages = Array.new
646
- selected_packages = selection.packages.
647
- map do |pkg_name|
648
- pkg = manifest.find_autobuild_package(pkg_name)
649
- if !pkg
650
- raise ConfigError.new, "selected package #{pkg_name} does not exist"
651
- end
652
- pkg
653
- end.to_set
654
-
655
- # The set of all packages that are currently selected by +selection+
656
- all_processed_packages = Set.new
657
- # The reverse dependencies for the package tree. It is discovered as
658
- # we go on with the import
659
- #
660
- # It only contains strong dependencies. Optional dependencies are
661
- # not included, as we will use this only to take into account
662
- # package exclusion (and that does not affect optional dependencies)
663
- reverse_dependencies = Hash.new { |h, k| h[k] = Set.new }
664
-
665
- package_queue = selected_packages.to_a.sort_by(&:name)
666
- while !package_queue.empty?
667
- pkg = package_queue.shift
668
- # Remove packages that have already been processed
669
- next if all_processed_packages.include?(pkg.name)
670
- all_processed_packages << pkg.name
671
-
672
- # If the package has no importer, the source directory must
673
- # be there
674
- if !pkg.importer && !File.directory?(pkg.srcdir)
675
- raise ConfigError.new, "#{pkg.name} has no VCS, but is not checked out in #{pkg.srcdir}"
676
- end
677
-
678
- # Try to auto-exclude the package early. If the autobuild file
679
- # contained some information that allows us to exclude it now,
680
- # then let's just do it
681
- import_next_step(manifest, pkg, reverse_dependencies)
682
- if manifest.excluded?(pkg.name)
683
- selection.filter_excluded_and_ignored_packages(manifest)
684
- next
685
- end
686
-
687
- ## COMPLETELY BYPASS RAKE HERE
688
- # The reason is that the ordering of import/prepare between
689
- # packages is not important BUT the ordering of import vs.
690
- # prepare in one package IS important: prepare is the method
691
- # that takes into account dependencies.
692
- pkg.import(import_options)
693
- if pkg.updated?
694
- updated_packages << pkg.name
695
- end
696
- Rake::Task["#{pkg.name}-import"].instance_variable_set(:@already_invoked, true)
697
- manifest.load_package_manifest(pkg.name)
698
-
699
- # The package setup mechanisms might have added an exclusion
700
- # on this package. Handle this.
701
- if manifest.excluded?(pkg.name)
702
- mark_exclusion_along_revdeps(pkg.name, reverse_dependencies)
703
- # Run a filter now, to have errors as early as possible
704
- selection.filter_excluded_and_ignored_packages(manifest)
705
- # Delete this package from the current_packages set
706
- next
707
- end
708
-
709
- Autoproj.each_post_import_block(pkg) do |block|
710
- block.call(pkg)
711
- end
712
- pkg.update_environment
713
-
714
- new_packages = import_next_step(manifest, pkg, reverse_dependencies)
715
- # Excluded dependencies might have caused the package to be
716
- # excluded as well ... do not add any dependency to the
717
- # processing queue if it is the case
718
- if !manifest.excluded?(pkg.name)
719
- package_queue.concat(new_packages.sort_by(&:name))
720
- end
721
-
722
- # Verify that everything is still OK with the new
723
- # exclusions/ignores
724
- selection.filter_excluded_and_ignored_packages(manifest)
725
- end
726
-
727
- all_enabled_packages = Set.new
728
- package_queue = selection.packages.dup
729
- # Run optional dependency resolution until we have a fixed point
730
- while !package_queue.empty?
731
- pkg_name = package_queue.shift
732
- next if all_enabled_packages.include?(pkg_name)
733
- all_enabled_packages << pkg_name
734
-
735
- pkg = Autobuild::Package[pkg_name]
736
- pkg.resolve_optional_dependencies
737
-
738
- pkg.prepare if !pkg.disabled?
739
- Rake::Task["#{pkg.name}-prepare"].instance_variable_set(:@already_invoked, true)
740
-
741
- package_queue.concat(pkg.dependencies)
742
- end
743
-
744
- if Autoproj.verbose
745
- Autoproj.message "autoproj: finished importing packages"
746
- end
747
-
748
- if Autoproj::CmdLine.list_newest?
749
- fields = []
750
- Rake::Task.tasks.each do |task|
751
- if task.kind_of?(Autobuild::SourceTreeTask)
752
- task.timestamp
753
- fields << ["#{task.name}:", task.newest_file, task.newest_time.to_s]
754
- end
755
- end
756
-
757
- field_sizes = fields.inject([0, 0, 0]) do |sizes, line|
758
- 3.times do |i|
759
- sizes[i] = [sizes[i], line[i].length].max
760
- end
761
- sizes
762
- end
763
- format = " %-#{field_sizes[0]}s %-#{field_sizes[1]}s at %-#{field_sizes[2]}s"
764
- fields.each do |line|
765
- Autoproj.message(format % line)
766
- end
767
- end
768
-
769
- if options[:warn_about_excluded_packages]
770
- selection.exclusions.each do |sel, pkg_names|
771
- pkg_names.sort.each do |pkg_name|
772
- Autoproj.warn "#{pkg_name}, which was selected for #{sel}, cannot be built: #{manifest.exclusion_reason(pkg_name)}", :bold
773
- end
774
- end
775
- end
776
- if options[:warn_about_ignored_packages]
777
- selection.ignores.each do |sel, pkg_names|
778
- pkg_names.sort.each do |pkg_name|
779
- Autoproj.warn "#{pkg_name}, which was selected for #{sel}, is ignored", :bold
780
- end
781
- end
782
- end
783
-
784
- return all_enabled_packages
785
-
786
- ensure
787
- if Autoproj.config.import_log_enabled? && !updated_packages.empty? && Autoproj::Ops::Snapshot.update_log_available?(manifest)
788
- failure_message =
789
- if $!
790
- " (#{$!.message.split("\n").first})"
791
- end
792
- ops = Ops::Snapshot.new(manifest, keep_going: true)
793
- ops.update_package_import_state(
794
- "#{$0} #{argv.join(" ")}#{failure_message}",
795
- updated_packages)
796
- end
797
- end
798
-
799
- def self.build_packages(selected_packages, all_enabled_packages, phases = [])
800
- if Autoproj::CmdLine.update_os_dependencies?
801
- manifest.install_os_dependencies(all_enabled_packages)
802
- end
803
-
804
- ops = Ops::Build.new(manifest, update_os_dependencies?)
805
- if Autobuild.do_rebuild || Autobuild.do_forced_build
806
- packages_to_rebuild =
807
- if force_re_build_with_depends? || selected_packages.empty?
808
- all_enabled_packages
809
- else selected_packages
810
- end
811
-
812
- if selected_packages.empty?
813
- # If we don't have an explicit package selection, we want to
814
- # make sure that the user really wants this
815
- mode_name = if Autobuild.do_rebuild then 'rebuild'
816
- else 'force-build'
817
- end
818
- opt = BuildOption.new("", "boolean", {:doc => "this is going to trigger a #{mode_name} of all packages. Is that really what you want ?"}, nil)
819
- if !opt.ask(false)
820
- raise Interrupt
821
- end
822
- if Autobuild.do_rebuild
823
- ops.rebuild_all
824
- else
825
- ops.force_build_all
826
- end
827
- elsif Autobuild.do_rebuild
828
- ops.rebuild_packages(packages_to_rebuild, all_enabled_packages)
829
- else
830
- ops.force_build_packages(packages_to_rebuild, all_enabled_packages)
831
- end
832
- return
833
- end
834
-
835
- if phases.include?('build')
836
- ops.build_packages(all_enabled_packages)
837
- end
838
- Autobuild.apply(all_enabled_packages, "autoproj-build", phases - ['build'])
839
- end
840
-
841
- def self.manifest; Autoproj.manifest end
842
- def self.only_status?; !!@only_status end
843
- def self.only_local?; !!@only_local end
844
- def self.all_known_package?; !!@all_known_package end
845
- def self.reset?; !!@reset end
846
- def self.check?; !!@check end
847
- def self.manifest_update?; !!@manifest_update end
848
- def self.only_config?; !!@only_config end
849
- def self.randomize_layout?; config.randomize_layout? end
850
- def self.update_os_dependencies?
851
- # Check if the mode disables osdeps anyway ...
852
- if !@update_os_dependencies.nil? && !@update_os_dependencies
853
- return false
854
- end
855
-
856
- # Now look for what the user wants
857
- Autoproj.osdeps.osdeps_mode != 'none' || !Autoproj.osdeps.silent?
858
- end
859
- class << self
860
- attr_accessor :update_os_dependencies
861
- attr_accessor :snapshot_dir
862
- attr_writer :list_newest
863
- end
864
- def self.display_configuration?; !!@display_configuration end
865
- def self.force_re_build_with_depends?; !!@force_re_build_with_depends end
866
- def self.mail_config; @mail_config || Hash.new end
867
- def self.update_packages?; @mode == "update" || @mode == "envsh" || build? end
868
- def self.update_envsh?; @mode == "envsh" || build? || @mode == "update" end
869
- def self.build?; @mode =~ /build/ end
870
- def self.doc?; @mode == "doc" end
871
- def self.snapshot?; @mode == "snapshot" end
872
- def self.reconfigure?; @mode == "reconfigure" end
873
- def self.list_unused?; @mode == "list-unused" end
874
-
875
- def self.show_statistics?; !!@show_statistics end
876
- def self.ignore_dependencies?; @ignore_dependencies end
877
-
878
- def self.color?; @color end
879
- def self.color=(flag); @color = flag end
880
-
881
- class << self
882
- attr_accessor :update_from
883
- end
884
- def self.osdeps?; @mode == "osdeps" end
885
- def self.show_osdeps?; @mode == "osdeps" && @show_osdeps end
886
- def self.revshow_osdeps?; @mode == "osdeps" && @revshow_osdeps end
887
- def self.osdeps_forced_mode; @osdeps_forced_mode end
888
- def self.osdeps_filter_uptodate?
889
- if @mode == "osdeps"
890
- @osdeps_filter_uptodate
891
- else true
892
- end
893
- end
894
- def self.status_exit_code?
895
- @status_exit_code
896
- end
897
- def self.list_newest?; @list_newest end
898
- def self.parse_arguments(args, with_mode = true, &additional_options)
899
- @only_status = false
900
- @only_local = false
901
- @all_known_package = false
902
- @show_osdeps = false
903
- @status_exit_code = false
904
- @revshow_osdeps = false
905
- @osdeps_filter_uptodate = true
906
- @osdeps_forced_mode = nil
907
- @check = false
908
- @manifest_update = false
909
- @display_configuration = false
910
- @update_os_dependencies = nil
911
- @force_re_build_with_depends = false
912
- force_re_build_with_depends = nil
913
- @only_config = false
914
- @reset = false
915
- @color = true
916
- Autobuild.color = true
917
- Autobuild.do_update = nil
918
- do_update = nil
919
-
920
- mail_config = Hash.new
921
-
922
- # Parse the configuration options
923
- parser = OptionParser.new do |opts|
924
- opts.banner = <<-EOBANNER
925
- autoproj mode [options]
926
- where 'mode' is one of:
927
-
928
- -- Build
929
- build: import, build and install all packages that need it. A package or package
930
- set name can be given, in which case only this package and its dependencies
931
- will be taken into account. Example:
932
-
933
- autoproj build drivers/hokuyo
934
-
935
- fast-build: builds without updating and without considering OS dependencies
936
- full-build: updates packages and OS dependencies, and then builds
937
- force-build: triggers all build commands, i.e. don't be lazy like in "build".
938
- If packages are selected on the command line, only those packages
939
- will be affected unless the --with-depends option is used.
940
- rebuild: clean and then rebuild. If packages are selected on the command line,
941
- only those packages will be affected unless the --with-depends option
942
- is used.
943
- doc: generate and install documentation for packages that have some
944
-
945
- -- Status & Update
946
- envsh: update the #{ENV_FILENAME} script
947
- osdeps: install the OS-provided packages
948
- status: displays the state of the packages w.r.t. their source VCS
949
- list-config: list all available packages
950
- update: only import/update packages, do not build them
951
- update-config: only update the configuration
952
- reconfigure: change the configuration options. Additionally, the
953
- --reconfigure option can be used in other modes like
954
- update or build
955
-
956
- -- Experimental Features (USE AT YOUR OWN RISK)
957
- check: compares dependencies in manifest.xml with autodetected ones
958
- (valid only for package types that do autodetection, like
959
- orogen packages)
960
- manifest-update: like check, but updates the manifest.xml file
961
- (CAREFUL: optional dependencies will get added as well!!!)
962
- snapshot: create a standalone autoproj configuration where all packages
963
- are pinned to their current version. I.e. building a snapshot
964
- should give you the exact same result.
965
-
966
- -- Autoproj Configuration
967
- bootstrap: starts a new autoproj installation. Usage:
968
- autoproj bootstrap [manifest_url|source_vcs source_url opt1=value1 opt2=value2 ...]
969
-
970
- For example:
971
- autoproj bootstrap git git://gitorious.org/rock/buildconfig.git
972
-
973
- switch-config: change where the configuration should be taken from. Syntax:
974
- autoproj switch-config source_vcs source_url opt1=value1 opt2=value2 ...
975
-
976
- For example:
977
- autoproj switch-config git git://gitorious.org/rock/buildconfig.git
978
-
979
- In case only the options need to be changed, the source_vcs and source_url fields can be omitted:
980
-
981
- For example:
982
- autoproj switch-config branch=next
983
-
984
- -- Additional options:
985
- EOBANNER
986
- opts.on("--reconfigure", "re-ask all configuration options (build modes only)") do
987
- Autoproj.reconfigure = true
988
- end
989
- opts.on('--from PATH', 'in update mode, use this existing autoproj installation to check out the packages (for importers that support this)') do |path|
990
- self.update_from = Autoproj::InstallationManifest.from_root(File.expand_path(path))
991
- end
992
- opts.on("--version", "displays the version and then exits") do
993
- puts "autoproj v#{Autoproj::VERSION}"
994
- exit(0)
995
- end
996
- opts.on("--[no-]update", "[do not] update already checked-out packages (build modes only)") do |value|
997
- do_update = value
998
- end
999
- opts.on("--keep-going", "-k", "continue building even though one package has an error") do
1000
- Autobuild.ignore_errors = true
1001
- end
1002
- opts.on("--os-version", "displays the operating system as detected by autoproj") do
1003
- os_names, os_versions = OSDependencies.operating_system
1004
- if !os_names
1005
- puts "no information about that OS"
1006
- else
1007
- puts "name(s): #{os_names.join(", ")}"
1008
- puts "version(s): #{os_versions.join(", ")}"
1009
- end
1010
- exit 0
1011
- end
1012
- opts.on('--stats', 'displays statistics about each of the phases in the package building process') do
1013
- @show_statistics = true
1014
- end
1015
- opts.on('-p LEVEL', '--parallel=LEVEL', Integer, "override the Autobuild.parallel_build_level level") do |value|
1016
- Autobuild.parallel_build_level = value
1017
- end
1018
-
1019
- opts.on("--with-depends", "apply rebuild and force-build to both packages selected on the command line and their dependencies") do
1020
- force_re_build_with_depends = true
1021
- end
1022
- opts.on("--list-newest", "for each source directory, list what is the newest file used by autoproj for dependency tracking") do
1023
- Autoproj::CmdLine.list_newest = true
1024
- end
1025
- opts.on('-n', '--no-deps', 'completely ignore dependencies') do |value|
1026
- @ignore_dependencies = true
1027
- end
1028
- opts.on("--no-osdeps", "in build and update modes, disable osdeps handling") do |value|
1029
- @osdeps_forced_mode = 'none'
1030
- end
1031
- opts.on("--rshow", "in osdeps mode, shows information for each OS package") do
1032
- @revshow_osdeps = true
1033
- end
1034
- opts.on("--show", "in osdeps mode, show a per-package listing of the OS dependencies instead of installing them") do
1035
- @show_osdeps = true
1036
- end
1037
- opts.on('--version') do
1038
- Autoproj.message "autoproj v#{Autoproj::VERSION}"
1039
- Autoproj.message "autobuild v#{Autobuild::VERSION}"
1040
- end
1041
- opts.on("--all", "in osdeps mode, install both OS packages and RubyGem packages, regardless of the otherwise selected mode") do
1042
- @osdeps_forced_mode = 'all'
1043
- end
1044
- opts.on("--os", "in osdeps mode, install OS packages and display information about the RubyGem packages, regardless of the otherwise selected mode") do
1045
- if @osdeps_forced_mode == 'ruby'
1046
- # Make --ruby --os behave like --all
1047
- @osdeps_forced_mode = 'all'
1048
- else
1049
- @osdeps_forced_mode = 'os'
1050
- end
1051
- end
1052
- opts.on('--force', 'in osdeps mode, do not filter out installed and uptodate packages') do
1053
- @osdeps_filter_uptodate = false
1054
- end
1055
- opts.on("--ruby", "in osdeps mode, install only RubyGem packages and display information about the OS packages, regardless of the otherwise selected mode") do
1056
- if @osdeps_forced_mode == 'os'
1057
- # Make --ruby --os behave like --all
1058
- @osdeps_forced_mode = 'all'
1059
- else
1060
- @osdeps_forced_mode = 'ruby'
1061
- end
1062
- end
1063
- opts.on("--none", "in osdeps mode, do not install any package but display information about them, regardless of the otherwise selected mode") do
1064
- @osdeps_forced_mode = 'none'
1065
- end
1066
- opts.on("--local", "in status and update modes, do not access the network") do
1067
- @only_local = true
1068
- end
1069
- opts.on("--all-known-packages", "handle all known packages that are defined by package-sets") do
1070
- @all_known_package = true
1071
- end
1072
- opts.on("--reset", "in update mode, reset the repositories to the state requested by the VCS configuration") do
1073
- @reset = true
1074
- end
1075
-
1076
- opts.on('--exit-code', 'in status mode, exit with a code that reflects the status of the installation (see documentation for details)') do
1077
- @status_exit_code = true
1078
- end
1079
- opts.on('--randomize-layout', 'in build and full-build, generate a random layout') do
1080
- config.randomize_layout = true
1081
- end
1082
-
1083
- opts.on('--nice NICE', Integer, 'nice the subprocesses to the given value') do |value|
1084
- Autobuild.nice = value
1085
- end
1086
- opts.on("-h", "--help", "Show this message") do
1087
- puts opts
1088
- exit
1089
- end
1090
- opts.on("--mail-from EMAIL", String, "From: field of the sent mails") do |from_email|
1091
- mail_config[:from] = from_email
1092
- end
1093
- opts.on("--mail-to EMAILS", String, "comma-separated list of emails to which the reports should be sent") do |emails|
1094
- mail_config[:to] ||= []
1095
- mail_config[:to] += emails.split(',')
1096
- end
1097
- opts.on("--mail-subject SUBJECT", String, "Subject: field of the sent mails") do |subject_email|
1098
- mail_config[:subject] = subject_email
1099
- end
1100
- opts.on("--mail-smtp HOSTNAME", String, " address of the mail server written as hostname[:port]") do |smtp|
1101
- raise "invalid SMTP specification #{smtp}" unless smtp =~ /^([^:]+)(?::(\d+))?$/
1102
- mail_config[:smtp] = $1
1103
- mail_config[:port] = Integer($2) if $2 && !$2.empty?
1104
- end
1105
- opts.on("--mail-only-errors", "send mail only on errors") do
1106
- mail_config[:only_errors] = true
1107
- end
1108
- Ops::Tools.common_options(opts)
1109
- opts.instance_eval(&additional_options) if block_given?
1110
- end
1111
-
1112
- args = parser.parse(args)
1113
- @mail_config = mail_config
1114
-
1115
- if with_mode
1116
- @mode = args.shift
1117
- unknown_mode = catch(:unknown) do
1118
- handle_mode(@mode, args)
1119
- false
1120
- end
1121
- if unknown_mode
1122
- STDERR.puts "unknown mode #{@mode}"
1123
- STDERR.puts "run autoproj --help for more documentation"
1124
- exit(1)
1125
- end
1126
- end
1127
-
1128
- selection = args.dup
1129
- @force_re_build_with_depends = force_re_build_with_depends if !force_re_build_with_depends.nil?
1130
- Autobuild.do_update = do_update if !do_update.nil?
1131
- selection
1132
-
1133
- rescue OptionParser::InvalidOption => e
1134
- raise ConfigError, e.message, e.backtrace
1135
- end
1136
-
1137
- def self.handle_mode(mode, remaining_args)
1138
- case mode
1139
- when "update-sets"
1140
- Autoproj.warn("update-sets is deprecated. Use update-config instead")
1141
- mode = "update-config"
1142
- when "list-sets"
1143
- Autoproj.warn("list-sets is deprecated. Use list-config instead")
1144
- mode = "list-config"
1145
- end
1146
-
1147
- case mode
1148
- when "reconfigure"
1149
- Autoproj.reconfigure = true
1150
- Autobuild.do_update = false
1151
- Autobuild.do_build = false
1152
- @update_os_dependencies = false
1153
-
1154
- when "fast-build"
1155
- Autobuild.do_update = false
1156
- Autobuild.do_build = true
1157
- @update_os_dependencies = false
1158
- when "build"
1159
- Autobuild.do_update = nil
1160
- Autobuild.do_build = true
1161
- @update_os_dependencies = nil
1162
- when "force-build"
1163
- Autobuild.do_update = nil
1164
- Autobuild.do_build = true
1165
- @update_os_dependencies = nil
1166
- Autobuild.do_forced_build = true
1167
- when "rebuild"
1168
- Autobuild.do_update = nil
1169
- Autobuild.do_build = true
1170
- @update_os_dependencies = nil
1171
- Autobuild.do_rebuild = true
1172
- when "full-build"
1173
- Autobuild.do_update = true
1174
- Autobuild.do_build = true
1175
- @update_os_dependencies = true
1176
- when "update"
1177
- Autobuild.do_update = true
1178
- Autobuild.do_build = false
1179
- @update_os_dependencies = true
1180
- when "check"
1181
- Autobuild.do_update = false
1182
- Autobuild.do_build = false
1183
- @update_os_dependencies = false
1184
- @check = true
1185
- when "manifest-update"
1186
- Autobuild.do_update = false
1187
- Autobuild.do_build = false
1188
- @update_os_dependencies = false
1189
- @manifest_update = true
1190
- when "osdeps"
1191
- Autobuild.do_update = false
1192
- Autobuild.do_build = false
1193
- @update_os_dependencies = true
1194
- when "status"
1195
- Autobuild.do_update = false
1196
- Autobuild.do_build = false
1197
- @update_os_dependencies = false
1198
- @only_status = true
1199
- when "envsh"
1200
- Autobuild.do_update = false
1201
- Autobuild.do_build = false
1202
- @update_os_dependencies = false
1203
- when "update-config"
1204
- Autobuild.do_update = true
1205
- Autobuild.do_build = false
1206
- @update_os_dependencies = false
1207
- @only_config = true
1208
- when "list-config"
1209
- Autobuild.do_update = false
1210
- Autobuild.do_build = false
1211
- @update_os_dependencies = false
1212
- @only_config = true
1213
- @display_configuration = true
1214
- when "doc"
1215
- Autobuild.do_update = false
1216
- Autobuild.do_build = false
1217
- @update_os_dependencies = false
1218
- Autobuild.do_doc = true
1219
- Autobuild.only_doc = true
1220
- when "list-unused"
1221
- Autobuild.do_update = false
1222
- Autobuild.do_build = false
1223
- @update_os_dependencies = false
1224
- else
1225
- throw :unknown, true
1226
- end
1227
- nil
1228
- end
1229
-
1230
- StatusResult = Struct.new :uncommitted, :local, :remote
1231
- def self.display_status(packages)
1232
- result = StatusResult.new
1233
-
1234
- sync_packages = ""
1235
- packages.each do |pkg|
1236
- lines = []
1237
-
1238
- pkg_name = pkg.autoproj_name
1239
-
1240
- if !pkg.importer
1241
- lines << Autoproj.color(" is a local-only package (no VCS)", :bold, :red)
1242
- elsif !pkg.importer.respond_to?(:status)
1243
- lines << Autoproj.color(" the #{pkg.importer.class.name.gsub(/.*::/, '')} importer does not support status display", :bold, :red)
1244
- elsif !File.directory?(pkg.srcdir)
1245
- lines << Autoproj.color(" is not imported yet", :magenta)
1246
- else
1247
- status = begin pkg.importer.status(pkg, only_local?)
1248
- rescue Interrupt
1249
- raise
1250
- rescue Exception
1251
- lines << Autoproj.color(" failed to fetch status information", :red)
1252
- nil
1253
- end
1254
-
1255
- if status
1256
- if status.uncommitted_code
1257
- lines << Autoproj.color(" contains uncommitted modifications", :red)
1258
- result.uncommitted = true
1259
- end
1260
-
1261
- case status.status
1262
- when Autobuild::Importer::Status::UP_TO_DATE
1263
- if !status.uncommitted_code
1264
- if sync_packages.size > 80
1265
- Autoproj.message "#{sync_packages},"
1266
- sync_packages = ""
1267
- end
1268
- msg = if sync_packages.empty?
1269
- pkg_name
1270
- else
1271
- ", #{pkg_name}"
1272
- end
1273
- STDERR.print msg
1274
- sync_packages = "#{sync_packages}#{msg}"
1275
- next
1276
- else
1277
- lines << Autoproj.color(" local and remote are in sync", :green)
1278
- end
1279
- when Autobuild::Importer::Status::ADVANCED
1280
- result.local = true
1281
- lines << Autoproj.color(" local contains #{status.local_commits.size} commit that remote does not have:", :blue)
1282
- status.local_commits.each do |line|
1283
- lines << Autoproj.color(" #{line}", :blue)
1284
- end
1285
- when Autobuild::Importer::Status::SIMPLE_UPDATE
1286
- result.remote = true
1287
- lines << Autoproj.color(" remote contains #{status.remote_commits.size} commit that local does not have:", :magenta)
1288
- status.remote_commits.each do |line|
1289
- lines << Autoproj.color(" #{line}", :magenta)
1290
- end
1291
- when Autobuild::Importer::Status::NEEDS_MERGE
1292
- result.local = true
1293
- result.remote = true
1294
- lines << " local and remote have diverged with respectively #{status.local_commits.size} and #{status.remote_commits.size} commits each"
1295
- lines << Autoproj.color(" -- local commits --", :blue)
1296
- status.local_commits.each do |line|
1297
- lines << Autoproj.color(" #{line}", :blue)
1298
- end
1299
- lines << Autoproj.color(" -- remote commits --", :magenta)
1300
- status.remote_commits.each do |line|
1301
- lines << Autoproj.color(" #{line}", :magenta)
1302
- end
1303
- end
1304
- end
1305
- end
1306
-
1307
- if !sync_packages.empty?
1308
- Autoproj.message("#{sync_packages}: #{color("local and remote are in sync", :green)}")
1309
- sync_packages = ""
1310
- end
1311
-
1312
- STDERR.print
1313
-
1314
- if lines.size == 1
1315
- Autoproj.message "#{pkg_name}: #{lines.first}"
1316
- else
1317
- Autoproj.message "#{pkg_name}:"
1318
- lines.each do |l|
1319
- Autoproj.message l
1320
- end
1321
- end
1322
- end
1323
- if !sync_packages.empty?
1324
- Autoproj.message("#{sync_packages}: #{color("local and remote are in sync", :green)}")
1325
- sync_packages = ""
1326
- end
1327
- return result
1328
- end
1329
-
1330
- def self.status(packages)
1331
- pkg_sets = manifest.each_package_set.map(&:create_autobuild_package)
1332
- if !pkg_sets.empty?
1333
- Autoproj.message("autoproj: displaying status of configuration", :bold)
1334
- display_status(pkg_sets)
1335
- STDERR.puts
1336
- end
1337
-
1338
- Autoproj.message("autoproj: displaying status of packages", :bold)
1339
- packages = packages.sort.map do |pkg_name|
1340
- Autobuild::Package[pkg_name]
1341
- end
1342
- display_status(packages)
1343
- end
1344
-
1345
- def self.missing_dependencies(pkg)
1346
- manifest = manifest.package_manifests[pkg.name]
1347
- all_deps = pkg.dependencies.map do |dep_name|
1348
- dep_pkg = Autobuild::Package[dep_name]
1349
- if dep_pkg then dep_pkg.name
1350
- else dep_name
1351
- end
1352
- end
1353
-
1354
- if manifest
1355
- declared_deps = manifest.each_dependency.to_a
1356
- missing = all_deps - declared_deps
1357
- else
1358
- missing = all_deps
1359
- end
1360
-
1361
- missing.to_set.to_a.sort
1362
- end
1363
-
1364
- # Verifies that each package's manifest is up-to-date w.r.t. the
1365
- # automatically-detected dependencies
1366
- #
1367
- # Only useful for package types that do some automatic dependency
1368
- # detection
1369
- def self.check(packages)
1370
- packages.sort.each do |pkg_name|
1371
- result = []
1372
-
1373
- pkg = Autobuild::Package[pkg_name]
1374
- manifest = manifest.package_manifests[pkg.name]
1375
-
1376
- # Check if the manifest contains rosdep tags
1377
- # if manifest && !manifest.each_os_dependency.to_a.empty?
1378
- # result << "uses rosdep tags, convert them to normal <depend .../> tags"
1379
- # end
1380
-
1381
- missing = missing_dependencies(pkg)
1382
- if !missing.empty?
1383
- result << "missing dependency tags for: #{missing.join(", ")}"
1384
- end
1385
-
1386
- if !result.empty?
1387
- Autoproj.message pkg.name
1388
- Autoproj.message " #{result.join("\n ")}"
1389
- end
1390
- end
1391
- end
1392
-
1393
- def self.manifest_update(packages)
1394
- packages.sort.each do |pkg_name|
1395
- pkg = Autobuild::Package[pkg_name]
1396
- manifest = manifest.package_manifests[pkg.name]
1397
-
1398
- xml =
1399
- if !manifest
1400
- Nokogiri::XML::Document.parse("<package></package>") do |c|
1401
- c.noblanks
1402
- end
1403
- else
1404
- manifest.xml.dup
1405
- end
1406
-
1407
- # Add missing dependencies
1408
- missing = missing_dependencies(pkg)
1409
- if !missing.empty?
1410
- package_node = xml.xpath('/package').to_a.first
1411
- missing.each do |pkg_name|
1412
- node = Nokogiri::XML::Node.new("depend", xml)
1413
- node['package'] = pkg_name
1414
- package_node.add_child(node)
1415
- end
1416
- modified = true
1417
- end
1418
-
1419
- # Save the manifest back
1420
- if modified
1421
- path = File.join(pkg.srcdir, 'manifest.xml')
1422
- File.open(path, 'w') do |io|
1423
- io.write xml.to_xml
1424
- end
1425
- if !manifest
1426
- Autoproj.message "created #{path}"
1427
- else
1428
- Autoproj.message "modified #{path}"
1429
- end
1430
- end
1431
- end
1432
- end
1433
-
1434
- # Displays the reverse OS dependencies (i.e. for each osdeps package,
1435
- # who depends on it and where it is defined)
1436
- def self.revshow_osdeps(packages)
1437
- _, ospkg_to_pkg = manifest.list_os_dependencies(packages)
1438
-
1439
- # A mapping from a package name to
1440
- # [is_os_pkg, is_gem_pkg, definitions, used_by]
1441
- #
1442
- # where
1443
- #
1444
- # +used_by+ is the set of autobuild package names that use this
1445
- # osdeps package
1446
- #
1447
- # +definitions+ is a osdep_name => definition_file mapping
1448
- mapping = Hash.new { |h, k| h[k] = Array.new }
1449
- used_by = Hash.new { |h, k| h[k] = Array.new }
1450
- ospkg_to_pkg.each do |pkg_osdep, pkgs|
1451
- used_by[pkg_osdep].concat(pkgs)
1452
- packages = Autoproj.osdeps.resolve_package(pkg_osdep)
1453
- packages.each do |handler, status, entries|
1454
- entries.each do |entry|
1455
- if entry.respond_to?(:join)
1456
- entry = entry.join(", ")
1457
- end
1458
- mapping[entry] << [pkg_osdep, handler, Autoproj.osdeps.source_of(pkg_osdep)]
1459
- end
1460
- end
1461
- end
1462
-
1463
- mapping = mapping.sort_by(&:first)
1464
- mapping.each do |pkg_name, handlers|
1465
- puts pkg_name
1466
- depended_upon = Array.new
1467
- handlers.each do |osdep_name, handler, source|
1468
- install_state =
1469
- if handler.respond_to?(:installed?)
1470
- !!handler.installed?(pkg_name)
1471
- end
1472
- install_state =
1473
- if install_state == false
1474
- ", currently not installed"
1475
- elsif install_state == true
1476
- ", currently installed"
1477
- end # nil means "don't know"
1478
-
1479
- puts " defined as #{osdep_name} (#{handler.name}) in #{source}#{install_state}"
1480
- depended_upon.concat(used_by[osdep_name])
1481
- end
1482
- puts " depended-upon by #{depended_upon.sort.join(", ")}"
1483
- end
1484
- end
1485
-
1486
- # Displays the OS dependencies required by the given packages
1487
- def self.show_osdeps(packages)
1488
- _, ospkg_to_pkg = manifest.list_os_dependencies(packages)
1489
-
1490
- # ospkg_to_pkg is the reverse mapping to what we want. Invert it
1491
- mapping = Hash.new { |h, k| h[k] = Set.new }
1492
- ospkg_to_pkg.each do |ospkg, pkgs|
1493
- pkgs.each do |pkg_name|
1494
- mapping[pkg_name] << ospkg
1495
- end
1496
- end
1497
-
1498
- # Now sort it by package name (better for display)
1499
- package_osdeps = mapping.to_a.
1500
- sort_by { |name, _| name }
1501
-
1502
- package_osdeps.each do |pkg_name, pkg_osdeps|
1503
- if pkg_osdeps.empty?
1504
- puts " #{pkg_name}: no OS dependencies"
1505
- next
1506
- end
1507
-
1508
- packages = Autoproj.osdeps.resolve_os_dependencies(pkg_osdeps)
1509
- puts pkg_name
1510
- packages.each do |handler, packages|
1511
- puts " #{handler.name}: #{packages.sort.join(", ")}"
1512
- needs_update = handler.filter_uptodate_packages(packages)
1513
- if needs_update.to_set != packages.to_set
1514
- if needs_update.empty?
1515
- puts " all packages are up to date"
1516
- else
1517
- puts " needs updating: #{needs_update.sort.join(", ")}"
1518
- end
1519
- end
1520
- end
1521
- end
1522
- end
1523
-
1524
- # This method sets up autoproj and loads the configuration available in
1525
- # the current autoproj installation. It is meant as a simple way to
1526
- # initialize an autoproj environment for standalone tools
1527
- #
1528
- # Beware, it changes the current directory to the autoproj root dir
1529
- def self.initialize_and_load(cmdline_arguments = ARGV.dup)
1530
- require 'autoproj/autobuild'
1531
- require 'open-uri'
1532
- require 'autoproj/cmdline'
1533
-
1534
- remaining_arguments = Autoproj::CmdLine.
1535
- parse_arguments(cmdline_arguments, false)
1536
- Dir.chdir(Autoproj.root_dir)
1537
-
1538
- Autoproj::CmdLine.update_os_dependencies = false
1539
- Autoproj::CmdLine.initialize
1540
- Autoproj::CmdLine.update_configuration
1541
- Autoproj::CmdLine.load_configuration
1542
- Autoproj::CmdLine.setup_all_package_directories
1543
- Autoproj::CmdLine.finalize_package_setup
1544
-
1545
-
1546
- load_all_available_package_manifests(true)
1547
- update_environment
1548
- remaining_arguments
1549
- end
1550
-
1551
- def self.initialize_root_directory
1552
- Autoproj.root_dir
1553
- rescue Autoproj::UserError => error
1554
- if ENV['AUTOPROJ_CURRENT_ROOT']
1555
- Dir.chdir(ENV['AUTOPROJ_CURRENT_ROOT'])
1556
- begin Autoproj.root_dir
1557
- rescue Autoproj::UserError
1558
- raise error
1559
- end
1560
- else
1561
- raise
1562
- end
1563
- end
1564
-
1565
- def self.list_unused(all_enabled_packages)
1566
- all_enabled_packages = all_enabled_packages.map do |pkg_name|
1567
- Autobuild::Package[pkg_name]
1568
- end
1569
- leaf_dirs = (all_enabled_packages.map(&:srcdir) +
1570
- all_enabled_packages.map(&:prefix)).to_set
1571
- leaf_dirs << Autoproj.config_dir
1572
- leaf_dirs << Autoproj.gem_home
1573
- leaf_dirs << Autoproj.remotes_dir
1574
-
1575
- root = Autoproj.root_dir
1576
- all_dirs = leaf_dirs.dup
1577
- leaf_dirs.each do |dir|
1578
- dir = File.dirname(dir)
1579
- while dir != root
1580
- break if all_dirs.include?(dir)
1581
- all_dirs << dir
1582
- dir = File.dirname(dir)
1583
- end
1584
- end
1585
- all_dirs << Autoproj.root_dir
1586
-
1587
- unused = Set.new
1588
- Find.find(Autoproj.root_dir) do |path|
1589
- next if !File.directory?(path)
1590
- if !all_dirs.include?(path)
1591
- unused << path
1592
- Find.prune
1593
- elsif leaf_dirs.include?(path)
1594
- Find.prune
1595
- end
1596
- end
1597
-
1598
-
1599
- root = Pathname.new(Autoproj.root_dir)
1600
- Autoproj.message
1601
- Autoproj.message "The following directories are not part of a package used in the current autoproj installation", :bold
1602
- unused.to_a.sort.each do |dir|
1603
- puts " #{Pathname.new(dir).relative_path_from(root)}"
1604
- end
1605
- end
1606
-
1607
- def self.export_installation_manifest
1608
- File.open(File.join(Autoproj.root_dir, ".autoproj-installation-manifest"), 'w') do |io|
1609
- manifest.all_selected_packages.each do |pkg_name|
1610
- pkg = Autobuild::Package[pkg_name]
1611
- io.puts "#{pkg_name},#{pkg.srcdir},#{pkg.prefix}"
1612
- end
1613
- end
1614
- end
1615
-
1616
- def self.report(options = Hash.new)
1617
- options = Kernel.validate_options options,
1618
- silent: false
1619
-
1620
- Autobuild::Reporting.report do
1621
- yield
1622
- end
1623
- if !options[:silent]
1624
- Autobuild::Reporting.success
1625
- end
1626
-
1627
- rescue ConfigError => e
1628
- STDERR.puts
1629
- STDERR.puts Autoproj.color(e.message, :red, :bold)
1630
- if Autoproj.in_autoproj_installation?(Dir.pwd)
1631
- root_dir = /#{Regexp.quote(Autoproj.root_dir)}(?!\/\.gems)/
1632
- e.backtrace.find_all { |path| path =~ root_dir }.
1633
- each do |path|
1634
- STDERR.puts Autoproj.color(" in #{path}", :red, :bold)
1635
- end
1636
- end
1637
- if Autobuild.debug then raise
1638
- else exit 1
1639
- end
1640
- rescue Interrupt
1641
- STDERR.puts
1642
- STDERR.puts Autoproj.color("Interrupted by user", :red, :bold)
1643
- if Autobuild.debug then raise
1644
- else exit 1
1645
- end
1646
- end
1647
- end
1648
- end
1649
-