autobuild 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,83 +0,0 @@
1
- #! /usr/bin/ruby -w
2
-
3
- # :main: README
4
-
5
- require 'rake'
6
- require 'ostruct'
7
- require 'optparse'
8
-
9
- require 'autobuild/options'
10
- require 'autobuild/config'
11
- require 'autobuild/reporting'
12
- require 'daemons'
13
-
14
- DEFAULT_HTTP_PORT = 2000
15
-
16
- def parse_options(args)
17
- options = Options.default
18
-
19
- parser = OptionParser.new do |opts|
20
- opts.banner = "Usage: autobuild [options] config.yml"
21
- opts.separator ""
22
-
23
- opts.on("--srcdir PATH", "Find or imports sources in PATH") do |options.srcdir| end
24
- opts.on("--prefix PATH", "Packages are installed in PATH") do |options.prefix|
25
- options.logdir = "#{options.prefix}/autobuild"
26
- end
27
- opts.on("--logdir", "Where logs are saved (default: <prefix>/autobuild)") do |options.logdir| end
28
-
29
- opts.on("--[no-]update", "Update already checked-out sources") do |options.update| end
30
-
31
- opts.on('--nice NICE', Integer, 'Nice the subprocesses to the given value') do |options.nice| end
32
- opts.on("--[no-]daemon", "Go into daemon mode") do |options.daemonize| end
33
- #opts.on("--http [PORT]", Integer,
34
- # "Display a HTTP information page on PORT (PORT default: #{DEFAULT_HTTP_PORT})") do |port|
35
- # options.http = (port || DEFAULT_HTTP_PORT)
36
- #end
37
- opts.on("--[no-]verbose", "Display output of commands on stdout") do |options.verbose| end
38
- opts.on("--[no-]debug", "Verbose information (for debugging purposes)") do |options.debug| end
39
-
40
- opts.on_tail("-h", "--help", "Show this message") do
41
- puts opts
42
- exit
43
- end
44
- end
45
-
46
- parser.parse!(args)
47
- if !args[0]
48
- puts parser
49
- exit
50
- end
51
-
52
- [ options, args[0], args[1..-1] ]
53
- end
54
-
55
- # Load the command line options
56
- options, conffile, targets = parse_options(ARGV)
57
-
58
- # make conffile an absolute path since daemonize mode makes
59
- # / the current directory
60
- conffile = File.expand_path(conffile, Dir.pwd)
61
- if options.daemonize
62
- puts "Going into daemon mode ..."
63
- Daemons.daemonize
64
- end
65
-
66
- Reporting.report do
67
- begin
68
- File.open(conffile) do |f|
69
- Config.load(f, options)
70
- end
71
-
72
- if targets.empty?
73
- Rake::Task[:default].invoke
74
- else
75
- targets.each { |t| Rake::Task[t.to_sym].invoke }
76
- end
77
- rescue ConfigException => e
78
- e.target = conffile
79
- raise
80
- end
81
- Reporting.success
82
- end
83
-
@@ -1,8 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('..', File.dirname(__FILE__))
2
- $LOAD_PATH << File.expand_path('../lib', File.dirname(__FILE__))
3
- require 'rubygems'
4
- require 'test/unit'
5
- require 'test/tc_config_interpolation.rb'
6
- require 'test/tc_config.rb'
7
- require 'test/tc_subcommand.rb'
8
- require 'test/tc_import.rb'
@@ -1,40 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('..', File.dirname(__FILE__))
2
- $LOAD_PATH << File.expand_path('../lib', File.dirname(__FILE__))
3
- require 'test/unit'
4
- require 'test/tools'
5
- require 'autobuild/options'
6
- require 'autobuild/config'
7
-
8
- class TC_Config < Test::Unit::TestCase
9
- def setup
10
- @conffile = TestTools.build_config(binding, 'dummy')
11
- @options_hash = File.open(@conffile) { |f| YAML.load(f) }
12
- @options = File.open(@conffile) { |f| Config.load(f, Options.default) }
13
- end
14
-
15
- def teardown
16
- TestTools.clean
17
- end
18
-
19
- def test_keys_to_sym
20
- symed = @options_hash.keys_to_sym
21
-
22
- pass_through = {}
23
- symed.each_recursive { |k, v|
24
- assert_kind_of(Symbol, k)
25
- pass_through[k] = true
26
- }
27
-
28
- assert(pass_through[:PATH])
29
- assert(pass_through[:prefix])
30
- assert(pass_through[:autobuild])
31
- assert_kind_of(String, symed[:autobuild][:srcdir])
32
- end
33
-
34
- def test_value_type
35
- assert_kind_of(String, $SRCDIR)
36
- assert_kind_of(Fixnum, $NICE)
37
- assert_equal(0, $NICE)
38
- end
39
- end
40
-
@@ -1,57 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('..', File.dirname(__FILE__))
2
- $LOAD_PATH << File.expand_path('../lib', File.dirname(__FILE__))
3
-
4
- require 'test/unit'
5
- require 'autobuild/config-interpolator'
6
-
7
- require 'yaml'
8
- require 'stringio'
9
-
10
- class TC_ConfigInterpolation < Test::Unit::TestCase
11
- WELL_FORMED = <<EOF
12
- defines:
13
- global_prefix: /home/doudou
14
- srcdir: ${global_prefix}/src
15
- prefix: ${global_prefix}/build
16
- nice: 10
17
-
18
- autobuild:
19
- srcdir: $srcdir
20
- prefix: $prefix
21
- nice: $nice
22
- envvar: $ENVVAR
23
-
24
- EOF
25
-
26
- def setup
27
- @wellformed = StringIO.open(WELL_FORMED, 'r') { |d| YAML.load(d) }
28
- end
29
-
30
- def teardown
31
- @wellformed = nil
32
- end
33
-
34
- # Check that interpolation matches both forms ${var} and $var
35
- def test_match
36
- data = @wellformed['defines']['srcdir']
37
- all_matches = []
38
- Interpolator::PartialMatch.each_match(data) { |m| all_matches << m[1] }
39
- assert_equal( ['global_prefix'], all_matches )
40
-
41
- data = @wellformed['autobuild']['srcdir']
42
- all_matches = []
43
- Interpolator::PartialMatch.each_match(data) { |m| all_matches << m[2] }
44
- assert_equal( ['srcdir'], all_matches )
45
- end
46
-
47
- def test_interpolation
48
- ENV['ENVVAR'] = 'envvar'
49
- data = Interpolator.interpolate(@wellformed)
50
- assert_equal('/home/doudou/src', data["autobuild"]["srcdir"])
51
- assert_equal('/home/doudou/build', data["autobuild"]["prefix"])
52
- assert_equal('envvar', data["autobuild"]["envvar"])
53
- assert_equal(10, data["autobuild"]["nice"])
54
- assert_kind_of(Fixnum, data["autobuild"]["nice"])
55
- end
56
- end
57
-
@@ -1,77 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('..', File.dirname(__FILE__))
2
- $LOAD_PATH << File.expand_path('../lib', File.dirname(__FILE__))
3
- require 'test/unit'
4
- require 'test/tools'
5
- require 'autobuild/import/cvs'
6
- require 'autobuild/import/svn'
7
-
8
- class TC_Import < Test::Unit::TestCase
9
- Package = Struct.new :srcdir, :target
10
-
11
- def setup
12
- $PROGRAMS = {}
13
- $UPDATE = true
14
- $LOGDIR = "#{TestTools.tempdir}/log"
15
- FileUtils.mkdir_p($LOGDIR)
16
-
17
- end
18
-
19
- def teardown
20
- $PROGRAMS = nil
21
- $UPDATE = true
22
- $LOGDIR = nil
23
- TestTools.clean
24
- end
25
-
26
- def test_cvs
27
- TestTools.untar('cvsroot.tar')
28
- cvsroot = File.join(TestTools.tempdir, 'cvsroot')
29
- pkg_cvs = Package.new File.join(TestTools.tempdir, 'cvs'), :cvs
30
-
31
- # Make a checkout
32
- importer = Import.cvs [ cvsroot, 'cvs' ], {}
33
- importer.import(pkg_cvs)
34
- assert( File.exists?(File.join(pkg_cvs.srcdir, 'test')) )
35
-
36
- # Make an update
37
- importer.import(pkg_cvs)
38
-
39
- # Make an update fail
40
- FileUtils.rm_rf cvsroot
41
- assert_raise(ImportException) { importer.import pkg_cvs }
42
-
43
- # Make a checkout fail
44
- FileUtils.rm_rf pkg_cvs.srcdir
45
- assert_raise(ImportException) { importer.import pkg_cvs }
46
- end
47
-
48
- def test_svn
49
- TestTools.untar('svnroot.tar')
50
- svnrepo = File.join(TestTools.tempdir, 'svnroot')
51
- svnroot = "file:///#{svnrepo}"
52
- pkg_svn = Package.new File.join(TestTools.tempdir, 'svn'), :svn
53
-
54
- # Make a checkout with a splitted URL
55
- importer = Import.svn [ svnroot, 'svn' ], {}
56
- importer.import(pkg_svn)
57
- assert( File.exists?(File.join(pkg_svn.srcdir, 'test')) )
58
-
59
- # Make a checkout with an URL as a string
60
- FileUtils.rm_rf pkg_svn.srcdir
61
- importer = Import.svn File.join(svnroot, 'svn'), {}
62
- importer.import(pkg_svn)
63
- assert( File.exists?(File.join(pkg_svn.srcdir, 'test')) )
64
-
65
- # Make an update
66
- importer.import(pkg_svn)
67
-
68
- # Make an update fail
69
- FileUtils.rm_rf svnrepo
70
- assert_raise(ImportException) { importer.import(pkg_svn) }
71
-
72
- # Make a checkout fail
73
- FileUtils.rm_rf pkg_svn.srcdir
74
- assert_raise(ImportException) { importer.import(pkg_svn) }
75
- end
76
- end
77
-
@@ -1,61 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('..', File.dirname(__FILE__))
2
- $LOAD_PATH << File.expand_path('../lib', File.dirname(__FILE__))
3
- require 'test/unit'
4
- require 'test/tools'
5
- require 'autobuild/options'
6
- require 'autobuild/config'
7
-
8
- require 'tmpdir'
9
- require 'fileutils'
10
-
11
- class TC_Subcommand < Test::Unit::TestCase
12
- EXAMPLE_1 = <<EOF
13
- This is a file
14
- It will be the first part of the two-part cat
15
- EOF
16
-
17
- EXAMPLE_2 = <<EOF
18
- This is another file
19
- It will be the second part of the two-part cat
20
- EOF
21
-
22
- attr_reader :tmpdir
23
- attr_reader :source1, :source2
24
- def setup
25
- conffile = TestTools.build_config(binding, 'dummy')
26
- @tmpdir = File.dirname(conffile)
27
-
28
- options = Options.default
29
- options.logdir = tmpdir
30
- File.open(conffile) do |confstream|
31
- Config.load confstream, options
32
- end
33
-
34
- # Write example files
35
- @source1 = File.join(tmpdir, 'source1')
36
- @source2 = File.join(tmpdir, 'source2')
37
- File.open(source1, 'w+') { |f| f.write(EXAMPLE_1) }
38
- File.open(source2, 'w+') { |f| f.write(EXAMPLE_2) }
39
- end
40
-
41
- def teardown
42
- TestTools.clean
43
- end
44
-
45
- def test_subcommand
46
- assert_raise(SubcommandFailed) { || subcommand('test', 'copy', 'cat', 'bla') }
47
-
48
- subcommand('test', 'simple', 'cat', nil, '', source1)
49
- assert( FileUtils.identical?(source1, File.join(tmpdir, 'test-simple.log')) )
50
-
51
- subcommand('test', 'use-lt', 'cat', "<#{source1}")
52
- assert( FileUtils.identical?(source1, File.join(tmpdir, 'test-use-lt.log')) )
53
-
54
- subcommand('test', 'use-both', 'cat', source1, '-', "<#{source2}")
55
- result = File.open( File.join(tmpdir, 'test-use-both.log') ) do |f|
56
- f.readlines
57
- end
58
- assert_equal(EXAMPLE_1 + EXAMPLE_2, result.join(""))
59
- end
60
- end
61
-
@@ -1,39 +0,0 @@
1
- require 'tmpdir'
2
- require 'erb'
3
- require 'fileutils'
4
-
5
- module TestTools
6
- DATADIR = File.join(File.dirname(__FILE__), 'data')
7
-
8
- def self.tempdir
9
- @tmpdir = File.join(Dir::tmpdir, "/autobuild-test-#{Process.uid}")
10
- FileUtils.mkdir_p(@tmpdir, :mode => 0700)
11
- end
12
-
13
- def self.clean
14
- FileUtils.rm_rf tempdir
15
- end
16
-
17
- def self.build_config(bind, template)
18
- eval "basedir = '#{self.tempdir}'", bind
19
- ryml = File.open(File.join(DATADIR, "#{template}.ryml")) { |f| f.readlines }.join('')
20
- result = ERB.new(ryml).result(bind)
21
-
22
- yml = File.join(tempdir, "#{template}.yml")
23
- File.open(yml, 'w+') { |f| f.write(result) }
24
-
25
- return yml
26
- end
27
-
28
- def self.untar(file)
29
- file = File.expand_path(file, DATADIR)
30
- dir = self.tempdir
31
- Dir.chdir(dir) do
32
- system("tar xf #{file}")
33
- end
34
-
35
- dir
36
- end
37
- end
38
-
39
-