autoproj 1.12.6 → 1.13.0.b1

Sign up to get free protection for your applications and to get access to all the features.
@@ -180,7 +180,7 @@ rescue Autoproj::ConfigError => e
180
180
  end
181
181
 
182
182
  # Now try to find out the name of the gem binary
183
- PACKAGES = []
183
+ PACKAGES = ['build-essential', 'sudo']
184
184
 
185
185
  STDERR.puts "autoproj: installing autoproj and its dependencies (this can take a long time)"
186
186
  # First install the dependencies of autoproj, as we don't want them to be
@@ -213,7 +213,6 @@ if ARGV.first != "localdev"
213
213
  ARGV.shift
214
214
  end
215
215
  begin
216
- osdeps_management.install(['build-essential'])
217
216
  osdeps_management.install(['autobuild'])
218
217
  osdeps_management.install(['autoproj'])
219
218
  rescue Autoproj::ConfigError => e
data/lib/autoproj.rb CHANGED
@@ -17,6 +17,8 @@ require 'autoproj/system'
17
17
  require 'autoproj/build_option'
18
18
  require 'autoproj/configuration'
19
19
  require 'autoproj/options'
20
+ # Required for auto-saving in import_packages
21
+ require 'autoproj/ops/snapshot'
20
22
  require 'autoproj/cmdline'
21
23
  require 'autoproj/query'
22
24
 
@@ -222,14 +222,14 @@ module Autoproj
222
222
  class Reporter < Autobuild::Reporter
223
223
  def error(error)
224
224
  error_lines = error.to_s.split("\n")
225
- Autoproj.message("Build failed", :bold, :red)
226
- Autoproj.message("#{error_lines.shift}", :bold, :red)
225
+ Autoproj.message("Command failed", :bold, :red, STDERR)
226
+ Autoproj.message("#{error_lines.shift}", :bold, :red, STDERR)
227
227
  error_lines.each do |line|
228
- Autoproj.message line
228
+ Autoproj.message line, STDERR
229
229
  end
230
230
  end
231
231
  def success
232
- Autoproj.message("Build finished successfully at #{Time.now}", :bold, :green)
232
+ Autoproj.message("Command finished successfully at #{Time.now}", :bold, :green)
233
233
  if Autobuild.post_success_message
234
234
  Autoproj.message Autobuild.post_success_message
235
235
  end
@@ -405,8 +405,8 @@ end
405
405
  def cmake_package(options, &block)
406
406
  package_common(:cmake, options) do |pkg|
407
407
  pkg.depends_on 'cmake'
408
- yield(pkg) if block_given?
409
408
  common_make_based_package_setup(pkg)
409
+ yield(pkg) if block_given?
410
410
  end
411
411
  end
412
412
 
@@ -422,8 +422,8 @@ end
422
422
  def autotools_package(options, &block)
423
423
  package_common(:autotools, options) do |pkg|
424
424
  pkg.depends_on 'autotools'
425
- yield(pkg) if block_given?
426
425
  common_make_based_package_setup(pkg)
426
+ yield(pkg) if block_given?
427
427
  end
428
428
  end
429
429
 
@@ -447,8 +447,6 @@ end
447
447
  # information.
448
448
  def ruby_package(options)
449
449
  package_common(:ruby, options) do |pkg|
450
- yield(pkg) if block_given?
451
-
452
450
  # Documentation code. Ignore if the user provided its own documentation
453
451
  # task, or disabled the documentation generation altogether by setting
454
452
  # rake_doc_task to nil
@@ -467,6 +465,8 @@ def ruby_package(options)
467
465
  pkg.with_tests
468
466
  end
469
467
  end
468
+
469
+ yield(pkg) if block_given?
470
470
  end
471
471
  end
472
472
 
@@ -483,6 +483,7 @@ end
483
483
  # information.
484
484
  def orogen_package(options, &block)
485
485
  package_common(:orogen, options) do |pkg|
486
+ common_make_based_package_setup(pkg)
486
487
  yield(pkg) if block_given?
487
488
  end
488
489
  end
@@ -569,21 +570,44 @@ def user_config(key)
569
570
  end
570
571
 
571
572
  class Autobuild::Git
572
- def snapshot(package, target_dir)
573
- Dir.chdir(package.srcdir) do
574
- head_commit = `git rev-parse #{branch}`.chomp
575
- { 'commit' => head_commit }
573
+ # get version information from the importer
574
+ def snapshot(package, target_dir = nil)
575
+ info = Hash.new
576
+ if local_branch != remote_branch
577
+ info['local_branch'] = local_branch
578
+ info['remote_branch'] = remote_branch
579
+ else
580
+ info['branch'] = branch
581
+ end
582
+
583
+ begin
584
+ tag = run_git_bare(package, 'describe', '--tags', '--exact-match', 'HEAD').first.strip
585
+ info.merge('tag' => tag.encode('UTF-8'), 'commit' => nil)
586
+ rescue Autobuild::SubcommandFailed
587
+ head_commit = rev_parse(package, 'HEAD')
588
+ info.merge('tag' => nil, 'commit' => head_commit.encode('UTF-8'))
576
589
  end
577
590
  end
578
591
  end
579
592
 
593
+ class Autobuild::SVN
594
+ def snapshot(package, target_dir = nil)
595
+ version = svn_revision(package)
596
+ Hash['revision' => version]
597
+ end
598
+ end
599
+
580
600
  class Autobuild::ArchiveImporter
581
- def snapshot(package, target_dir)
582
- archive_dir = File.join(target_dir, 'archives')
583
- FileUtils.mkdir_p archive_dir
584
- FileUtils.cp @cachefile, archive_dir
601
+ def snapshot(package, target_dir = nil)
602
+ if target_dir
603
+ archive_dir = File.join(target_dir, 'archives')
604
+ FileUtils.mkdir_p archive_dir
605
+ FileUtils.cp @cachefile, archive_dir
585
606
 
586
- { 'url' => "file://$AUTOPROJ_SOURCE_DIR/archives/#{File.basename(@cachefile)}" }
607
+ { 'url' => "file://$AUTOPROJ_SOURCE_DIR/archives/#{File.basename(@cachefile)}" }
608
+ else
609
+ { 'url' => @url.to_s }
610
+ end
587
611
  end
588
612
  end
589
613
 
@@ -0,0 +1,7 @@
1
+ module Autoproj
2
+ module CLI
3
+ class InvalidArguments < Autobuild::Exception
4
+ end
5
+ end
6
+ end
7
+
@@ -0,0 +1,79 @@
1
+ require 'autoproj/cli'
2
+ require 'autoproj/cli/versions'
3
+
4
+ module Autoproj
5
+ module CLI
6
+ class Reset
7
+ include Ops::Tools
8
+
9
+ attr_reader :manifest
10
+
11
+ def initialize(manifest)
12
+ @manifest = manifest
13
+ end
14
+
15
+ def parse_options(args)
16
+ options = Hash[]
17
+ parser = OptionParser.new do |opt|
18
+ opt.banner = ["autoproj reset COMMIT_ID", "resets the current autoproj installation to the state saved in the given commit ID"].join("\n")
19
+ opt.on "--freeze", "freezes the project at the requested version" do
20
+ options[:freeze] = true
21
+ end
22
+ end
23
+ common_options(parser)
24
+ remaining = parser.parse(args)
25
+ if remaining.empty?
26
+ puts parser
27
+ raise InvalidArguments, "expected a reference (tag or log ID) as argument and got nothing"
28
+ elsif remaining.size > 1
29
+ puts parser
30
+ raise InvalidArguments, "expected only the tag name as argument"
31
+ end
32
+ return remaining.first, options
33
+ end
34
+
35
+ def run(ref_name, options)
36
+ pkg = manifest.main_package_set.create_autobuild_package
37
+ importer = pkg.importer
38
+ if !importer || !importer.kind_of?(Autobuild::Git)
39
+ raise ConfigError, "cannot use autoproj reset if the main configuration is not managed by git"
40
+ end
41
+
42
+ # Check if the reflog entry exists
43
+ begin
44
+ importer.rev_parse(pkg, ref_name)
45
+ rescue Autobuild::PackageException
46
+ raise InvalidArguments, "#{ref_name} does not exist, run autoproj log for log entries and autoproj tag without arguments for the tags"
47
+ end
48
+
49
+ # Checkout the version file
50
+ versions_file = File.join(
51
+ OVERRIDES_DIR,
52
+ Versions::DEFAULT_VERSIONS_FILE_BASENAME)
53
+ begin
54
+ file_data = importer.show(pkg, ref_name, versions_file)
55
+ versions_path = File.join(Autoproj.config_dir, versions_file)
56
+ if File.file?(versions_path)
57
+ old_versions_path = "#{versions_path}.old"
58
+ FileUtils.rm_f old_versions_path
59
+ FileUtils.cp versions_path, old_versions_path
60
+ end
61
+ FileUtils.mkdir_p File.join(Autoproj.config_dir, OVERRIDES_DIR)
62
+ File.open(versions_path, 'w') do |io|
63
+ io.write file_data
64
+ end
65
+ system("autoproj", "update", '--reset')
66
+
67
+ ensure
68
+ if !options[:freeze]
69
+ FileUtils.rm_f versions_path
70
+ if old_versions_path
71
+ FileUtils.mv old_versions_path, versions_path
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+
@@ -0,0 +1,63 @@
1
+ require 'autoproj'
2
+ require 'autoproj/cli/versions'
3
+
4
+ module Autoproj
5
+ module CLI
6
+ class Snapshot
7
+ include Ops::Tools
8
+
9
+ attr_reader :manifest
10
+
11
+ def initialize(manifest)
12
+ @manifest = manifest
13
+ end
14
+
15
+ def parse_options(args)
16
+ options = Hash.new
17
+ parser = OptionParser.new do |opt|
18
+ opt.on '-k', '--keep-going', "ignore packages that can't be snapshotted (the default is to terminate with an error)" do
19
+ options[:keep_going] = true
20
+ end
21
+ end
22
+ common_options(parser)
23
+ remaining_args = parser.parse(args)
24
+ return remaining_args, options
25
+ end
26
+
27
+ def run(target_dir, options)
28
+ # First, copy the configuration directory to create target_dir
29
+ #
30
+ # This must be done first as the snapshot calls might copy stuff in
31
+ # there
32
+ if File.exists?(target_dir)
33
+ raise ArgumentError, "#{target_dir} already exists"
34
+ end
35
+ FileUtils.cp_r Autoproj.config_dir, target_dir
36
+
37
+ begin
38
+ versions = Versions.new(manifest)
39
+ versions_file = File.join(
40
+ target_dir,
41
+ OVERRIDES_DIR,
42
+ Versions::DEFAULT_VERSIONS_FILE_BASENAME)
43
+
44
+ versions.run([],
45
+ replace: true,
46
+ package_sets: true,
47
+ keep_going: options[:keep_going],
48
+ output_file: versions_file)
49
+ rescue ::Exception
50
+ FileUtils.rm_rf target_dir
51
+ raise
52
+ end
53
+
54
+ # Finally, remove the remotes/ directory from the generated
55
+ # buildconf, it is obsolete now
56
+ FileUtils.rm_rf File.join(target_dir, 'remotes')
57
+
58
+ Autoproj.message "successfully created a snapshot of the current autoproj configuration in #{target_dir}"
59
+ end
60
+ end
61
+ end
62
+ end
63
+
@@ -0,0 +1,82 @@
1
+ require 'autoproj/cli'
2
+ require 'autoproj/cli/versions'
3
+ module Autoproj
4
+ module CLI
5
+ class Tag
6
+ include Ops::Tools
7
+
8
+ attr_reader :manifest
9
+
10
+ def initialize(manifest)
11
+ @manifest = manifest
12
+ end
13
+
14
+ def parse_options(args)
15
+ options = Hash[package_sets: true, keep_going: false]
16
+ parser = OptionParser.new do |opt|
17
+ opt.on '--[no-]package-sets', 'commit the package set state as well (enabled by default)' do |flag|
18
+ options[:package_sets] = flag
19
+ end
20
+ opt.on '-k', '--keep-going', "ignore packages that can't be snapshotted (the default is to terminate with an error)" do
21
+ options[:keep_going] = true
22
+ end
23
+ opt.on '-m MESSAGE', '--message=MESSAGE', String, "the message to use for the new commit (defaults to mentioning the tag creation)" do |message|
24
+ options[:message] = message
25
+ end
26
+ end
27
+ common_options(parser)
28
+ remaining = parser.parse(args)
29
+ if remaining.size > 1
30
+ raise InvalidArguments, "expected only the tag name as argument"
31
+ end
32
+ return remaining.first, options
33
+ end
34
+
35
+ def run(tag_name, options)
36
+ pkg = manifest.main_package_set.create_autobuild_package
37
+ importer = pkg.importer
38
+ if !importer || !importer.kind_of?(Autobuild::Git)
39
+ raise ConfigError, "cannot use autoproj tag if the main configuration is not managed by git"
40
+ end
41
+
42
+ versions_file = File.join(
43
+ OVERRIDES_DIR,
44
+ Versions::DEFAULT_VERSIONS_FILE_BASENAME)
45
+
46
+ if tag_name.nil?
47
+ importer = pkg.importer
48
+ all_tags = importer.run_git_bare(pkg, 'tag')
49
+ all_tags.sort.each do |tag|
50
+ begin importer.show(pkg, "refs/tags/#{tag}", versions_file)
51
+ puts tag
52
+ rescue Autobuild::PackageException
53
+ end
54
+ end
55
+ return
56
+ end
57
+
58
+ # Check if the tag already exists
59
+ begin
60
+ importer.rev_parse(pkg, "refs/tags/#{tag_name}")
61
+ raise InvalidArguments, "tag #{tag_name} already exists"
62
+ rescue Autobuild::PackageException
63
+ end
64
+
65
+ message = options[:message] ||
66
+ "autoproj created tag #{tag_name}"
67
+ commit_id = Ops::Snapshot.create_commit(pkg, versions_file, message) do |io|
68
+ versions = CLI::Versions.new(manifest)
69
+ Autoproj.message "creating versions file, this may take a while"
70
+ versions.run(Array.new,
71
+ package_sets: options[:package_sets],
72
+ output_file: io.path,
73
+ replace: true,
74
+ keep_going: options[:keep_going])
75
+ end
76
+
77
+ importer.run_git_bare(pkg, 'tag', tag_name, commit_id)
78
+ end
79
+ end
80
+ end
81
+ end
82
+
@@ -0,0 +1,90 @@
1
+ require 'autoproj/ops/tools'
2
+
3
+ module Autoproj
4
+ module CLI
5
+ class Test
6
+ include Ops::Tools
7
+
8
+ attr_reader :manifest
9
+
10
+ def initialize(manifest)
11
+ @manifest = manifest
12
+ end
13
+
14
+ def parse_options(args)
15
+ Autoproj.load_config
16
+
17
+ modified_config = false
18
+ mode = nil
19
+ options = Hash.new
20
+ option_parser = OptionParser.new do |opt|
21
+ opt.on '--enable[=PACKAGE,PACKAGE]', Array, 'enable tests for all packages or for specific packages (does not run the tests)' do |packages|
22
+ if !packages
23
+ Autoproj.config.utility_enable_all('test')
24
+ else
25
+ Autoproj.config.utility_enable_for('test', *packages)
26
+ end
27
+ modified_config = true
28
+ end
29
+ opt.on '--disable[=PACKAGE,PACKAGE]', Array, 'disable tests for all packages or for specific packages (does not run the tests)' do |packages|
30
+ if !packages
31
+ Autoproj.config.utility_disable_all('test')
32
+ else
33
+ Autoproj.config.utility_disable_for('test', *packages)
34
+ end
35
+ modified_config = true
36
+ end
37
+ opt.on '--list', 'list the test availability and enabled/disabled state information' do
38
+ mode = 'list'
39
+ end
40
+ opt.on '--[no-]recursion', '(do not) run or list the tests of the dependencies of the packages given on the command line (the default is false)' do |flag|
41
+ options[:recursive] = flag
42
+ end
43
+ end
44
+
45
+ user_selection = option_parser.parse(ARGV)
46
+ if !mode && !(modified_config && user_selection.empty?)
47
+ mode = 'run'
48
+ end
49
+
50
+ if modified_config
51
+ Autoproj.save_config
52
+ end
53
+ return mode, user_selection, options
54
+ end
55
+
56
+ def list(user_selection, options = Hash.new)
57
+ resolved_selection = resolve_selection(
58
+ user_selection,
59
+ recursive: options[:recursive],
60
+ ignore_non_imported_packages: true)
61
+
62
+ lines = Array.new
63
+ resolved_selection.each do |pkg_name|
64
+ pkg = manifest.find_package(pkg_name).autobuild
65
+ lines << [pkg.name, pkg.test_utility.enabled?, pkg.test_utility.available?]
66
+ end
67
+ lines = lines.sort_by { |name, _| name }
68
+ w = lines.map { |name, _| name.length }.max
69
+ format = "%-#{w}s %-7s %-9s"
70
+ puts format % ["Package Name", "Enabled", "Available"]
71
+ lines.each do |name, enabled, available|
72
+ puts(format % [name, (!!enabled).to_s, (!!available).to_s])
73
+ end
74
+ end
75
+
76
+ def run(user_selection, options = Hash.new)
77
+ packages = resolve_selection(
78
+ user_selection,
79
+ recursive: options[:recursive],
80
+ ignore_non_imported_packages: true)
81
+ # This calls #prepare, which is required to run build_packages
82
+ packages.each do |pkg|
83
+ Autobuild::Package[pkg].disable_phases('import', 'prepare', 'install')
84
+ end
85
+ Autobuild.apply(packages, "autoproj-test", ['test'])
86
+ end
87
+ end
88
+ end
89
+ end
90
+