bake 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ module Bake
2
+ VERSION = [ 0, 1, 0 ]
3
+ VERSION_STRING = VERSION.join('.')
4
+ end
5
+
data/test/bake_test.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'configuration_test'
2
+ require 'scheme_test'
3
+ require 'context_test'
4
+ require 'target_test'
5
+
@@ -0,0 +1,102 @@
1
+ $: << File.dirname(__FILE__) + '/../lib'
2
+
3
+ require 'test/unit'
4
+ require 'bake/configuration'
5
+
6
+ class ConfigTree
7
+ include Bake::Configuration
8
+
9
+ def initialize(parent = nil)
10
+ @parent = parent
11
+ parent.children << self if parent
12
+ @children = []
13
+ end
14
+
15
+ protected
16
+ attr_reader :parent, :children
17
+ end
18
+
19
+ class ConfigurationTest < Test::Unit::TestCase
20
+ def setup
21
+ @cfg = ConfigTree.new
22
+ @parent = ConfigTree.new
23
+ @child = ConfigTree.new(@parent)
24
+ end
25
+
26
+ def test_opt
27
+ assert_raise(RuntimeError) { @cfg.opt(:yes => true, :no => false) }
28
+ assert_raise(RuntimeError) { @cfg.opt(:yes => true, :no => false) }
29
+
30
+ @cfg.opt(:defines => 'DEBUG')
31
+ assert_equal(1, @cfg[:defines].size)
32
+ assert(@cfg[:defines].include?('DEBUG'))
33
+
34
+ @cfg.opt(:defines => 'WIN32')
35
+ assert_equal(2, @cfg[:defines].size)
36
+ assert(@cfg[:defines].include?('DEBUG'))
37
+ assert(@cfg[:defines].include?('WIN32'))
38
+
39
+ @cfg.opt(:libtype => 'static')
40
+ assert_equal('static', @cfg[:libtype])
41
+
42
+ @cfg.opt(:libtype => 'dynamic')
43
+ assert_equal('dynamic', @cfg[:libtype])
44
+
45
+ assert_nil(@cfg[:random])
46
+
47
+ assert_equal(0, @child[:defines].size)
48
+
49
+ @parent.opt(:defines => 'DEBUG')
50
+ @child.opt(:defines => 'WIN32')
51
+ assert_equal(1, @parent[:defines].size)
52
+ assert(@child[:defines].include?('DEBUG'))
53
+ assert_equal(2, @child[:defines].size)
54
+ assert(@child[:defines].include?('DEBUG'))
55
+ assert(@child[:defines].include?('WIN32'))
56
+ end
57
+
58
+ def test_req
59
+ assert_raise(RuntimeError) { @cfg.req(:yes => true, :no => false) }
60
+
61
+ assert_raise(RuntimeError) { @cfg.req(:defines) }
62
+ assert_raise(RuntimeError) { @cfg.req(:defines => 'DEBUG') }
63
+
64
+ @cfg.req(:libtype => 'static')
65
+ assert_equal('static', @cfg[:libtype])
66
+
67
+ assert_nothing_raised { @cfg.req(:libtype => 'static') }
68
+ assert_raise(RuntimeError) { @cfg.req(:libtype => 'dynamic') }
69
+
70
+ @parent.req(:libtype => 'static')
71
+ assert_equal('static', @parent[:libtype])
72
+ assert_equal('static', @child[:libtype])
73
+
74
+ assert_nothing_raised { @child.req(:libtype => 'static') }
75
+ assert_raise(RuntimeError) { @child.req(:libtype => 'dynamic') }
76
+
77
+ @child.req(:outdir => 'bin')
78
+ assert_nil(@parent[:outdir])
79
+ assert_equal('bin', @child[:outdir])
80
+ end
81
+
82
+ def test_opt_req
83
+ @cfg.opt(:libtype => 'static')
84
+ assert_equal('static', @cfg[:libtype])
85
+ @cfg.req(:libtype => 'dynamic')
86
+ assert_equal('dynamic', @cfg[:libtype])
87
+
88
+ @parent.req(:outdir => 'bin')
89
+ assert_equal('bin', @parent[:outdir])
90
+ assert_equal('bin', @child[:outdir])
91
+ @child.opt(:outdir => 'output')
92
+ assert_equal('bin', @child[:outdir])
93
+
94
+ @parent.opt(:libtype => 'static')
95
+ assert_equal('static', @parent[:libtype])
96
+ assert_equal('static', @child[:libtype])
97
+ @child.req(:libtype => 'dynamic')
98
+ assert_equal('static', @parent[:libtype])
99
+ assert_equal('dynamic', @child[:libtype])
100
+ end
101
+ end
102
+
@@ -0,0 +1,94 @@
1
+ $: << File.dirname(__FILE__) + '/../lib'
2
+
3
+ require 'test/unit'
4
+ require 'bake/context'
5
+ require 'bake/scheme'
6
+ require 'bake/target'
7
+ require 'bake/toolset'
8
+
9
+ module Cpp
10
+ class Object < Bake::Target
11
+ end
12
+
13
+ class Gcc < Bake::Toolset
14
+ end
15
+
16
+ class Vc6 < Bake::Toolset
17
+ end
18
+ end
19
+
20
+ module Common
21
+ class Directory < Bake::Target
22
+ ACCESSORS = :dir
23
+ end
24
+
25
+ class Toolset < Bake::Toolset
26
+ end
27
+ end
28
+
29
+ class MockSchemeLoader
30
+ def initialize
31
+ @schemes =
32
+ {
33
+ 'cpp' => Bake::Scheme.new(Cpp),
34
+ 'common' => Bake::Scheme.new(Common)
35
+ }
36
+ end
37
+
38
+ def scheme(name)
39
+ return @schemes[name]
40
+ end
41
+
42
+ def schemes
43
+ return @schemes.values
44
+ end
45
+ end
46
+
47
+ class ContextTest < Test::Unit::TestCase
48
+ def setup
49
+ @loader = MockSchemeLoader.new
50
+ @context = Bake::Context.new(@loader)
51
+ end
52
+
53
+ def test_context_eval
54
+ test_case = self
55
+ ctx = @context
56
+ proj = Bake::Project.new(nil)
57
+ @context.context_eval(proj) { test_case.assert_same(ctx, self) }
58
+ @context.context_eval(proj) { name 'a name' }
59
+ assert_equal('a name', proj.name)
60
+ @context.context_eval(proj, "name 'another'")
61
+ assert_equal('another', proj.name)
62
+ end
63
+
64
+ def test_using
65
+ assert_raise(RuntimeError) { @context.using('invalid.gcc') }
66
+ assert_raise(RuntimeError) { @context.using('cpp.invalid') }
67
+ assert_raise(RuntimeError) { @context.using('cpp') }
68
+ assert_raise(RuntimeError) { @context.using(12345) }
69
+ @context.using('cpp.gcc')
70
+ assert_instance_of(Cpp::Gcc, @loader.scheme('cpp').toolset)
71
+ @context.using('cpp.vc6')
72
+ assert_instance_of(Cpp::Vc6, @loader.scheme('cpp').toolset)
73
+ end
74
+
75
+ def test_accessor_calls
76
+ assert_raise(NoMethodError) { @context.no_dir }
77
+
78
+ test_case = self
79
+ assert_instance_of(Common::Directory, @context.dir)
80
+ dir = @context.dir do
81
+ name 'yup'
82
+ end
83
+ assert_equal('yup', dir.name)
84
+
85
+ proj = Bake::Project.new(nil)
86
+ @context.context_eval(proj) do
87
+ dir { name 'a dir' }
88
+ end
89
+ assert_equal(1, proj.children.size)
90
+ assert_instance_of(Common::Directory, proj.children[0])
91
+ assert_equal('a dir', proj.children[0].name)
92
+ end
93
+ end
94
+
@@ -0,0 +1,121 @@
1
+ $: << File.dirname(__FILE__) + '/../lib'
2
+
3
+ require 'test/unit'
4
+ require 'bake/toolset'
5
+ require 'bake/target'
6
+ require 'bake/scheme'
7
+
8
+ module GoodScheme
9
+ class Tool1 < Bake::Toolset
10
+ end
11
+
12
+ class Tool2 < Bake::Toolset
13
+ end
14
+
15
+ class Target1 < Bake::Target
16
+ ACCESSORS = :target1
17
+
18
+ def some_target1_meth
19
+ end
20
+ end
21
+
22
+ class Target2 < Bake::Target
23
+ ACCESSORS = [ :target2_first, :target2_second ]
24
+ end
25
+
26
+ class Target3 < Bake::Target
27
+ attr_reader :some_value
28
+
29
+ def initialize(parent, value)
30
+ super(parent)
31
+ @some_value = value
32
+ end
33
+ end
34
+ end
35
+
36
+ module SomeModule
37
+ module NestedScheme
38
+ class Tool < Bake::Toolset
39
+ end
40
+
41
+ class Target < Bake::Target
42
+ end
43
+ end
44
+ end
45
+
46
+ module NoTargetsScheme
47
+ class TestToolset < Bake::Toolset
48
+ end
49
+ end
50
+
51
+ module NoToolsetsScheme
52
+ class TestTarget < Bake::Toolset
53
+ end
54
+ end
55
+
56
+ class SchemeTest < Test::Unit::TestCase
57
+ def setup
58
+ @good_scheme = Bake::Scheme.new(GoodScheme)
59
+ @nested_scheme = Bake::Scheme.new(SomeModule::NestedScheme)
60
+ end
61
+
62
+ def test_init
63
+ assert_equal('good_scheme', @good_scheme.name)
64
+ assert_equal(2, @good_scheme.toolsets.size)
65
+ assert_equal(3, @good_scheme.targets.size)
66
+ assert_nil(@good_scheme.toolset)
67
+
68
+ assert_equal('some_module/nested_scheme', @nested_scheme.name)
69
+ assert_equal(1, @nested_scheme.toolsets.size)
70
+ assert_equal(1, @nested_scheme.toolsets.size)
71
+ assert_nil(@nested_scheme.toolset)
72
+
73
+ assert_raise(RuntimeError) { Bake::Scheme.new(NoTargetsScheme) }
74
+ assert_raise(RuntimeError) { Bake::Scheme.new(NoToolsetsScheme) }
75
+ end
76
+
77
+ def test_toolset
78
+ assert_raise(RuntimeError) { @good_scheme.toolset = :tool3 }
79
+ assert_raise(RuntimeError) do
80
+ @good_scheme.toolset = SomeModule::NestedScheme::Tool.new
81
+ end
82
+ assert_nil(@good_scheme.toolset)
83
+
84
+ @good_scheme.toolset = :tool1
85
+ assert_instance_of(GoodScheme::Tool1, @good_scheme.toolset)
86
+ @good_scheme.toolset = GoodScheme::Tool2.new
87
+ assert_instance_of(GoodScheme::Tool2, @good_scheme.toolset)
88
+
89
+ @nested_scheme.toolset = :tool
90
+ assert_instance_of(SomeModule::NestedScheme::Tool,
91
+ @nested_scheme.toolset)
92
+ end
93
+
94
+ def test_constructors
95
+ assert(@good_scheme.has_constructor?(:target1))
96
+ assert(@good_scheme.has_constructor?(:target2_first))
97
+ assert(@good_scheme.has_constructor?(:target2_second))
98
+ assert(!@good_scheme.has_constructor?(:random))
99
+ assert(!@nested_scheme.has_constructor?(:anything))
100
+
101
+ assert_raise(RuntimeError) { @good_scheme.construct(:invalid) }
102
+ assert_raise(RuntimeError) do
103
+ @good_scheme.construct(SomeModule::NestedScheme::Tool)
104
+ end
105
+
106
+ root = @good_scheme.construct(:target1, nil)
107
+ assert_instance_of(GoodScheme::Target1, root)
108
+ branch1 = @good_scheme.construct(:target2_first, root)
109
+ assert_instance_of(GoodScheme::Target2, branch1)
110
+ branch1a = @nested_scheme.construct(
111
+ SomeModule::NestedScheme::Target, branch1)
112
+ assert_instance_of(SomeModule::NestedScheme::Target, branch1a)
113
+ assert_same(branch1, branch1a.parent)
114
+ assert_same(root, branch1.parent)
115
+
116
+ branch1b = @good_scheme.construct(GoodScheme::Target3, branch1, 'yeap')
117
+ assert_instance_of(GoodScheme::Target3, branch1b)
118
+ assert_equal('yeap', branch1b.some_value)
119
+ end
120
+ end
121
+
@@ -0,0 +1,93 @@
1
+ $: << File.dirname(__FILE__) + '/../lib'
2
+
3
+ require 'test/unit'
4
+ require 'bake/target'
5
+
6
+ class SimpleProjectLoader
7
+ def load_project(path, from_proj)
8
+ path = path.split('/')
9
+ proj = from_proj
10
+ path.each do |subdir|
11
+ next if subdir == '.'
12
+ proj = proj.child(subdir)
13
+ raise "invalid child #{subdir}" if !proj
14
+ end
15
+ return proj
16
+ end
17
+ end
18
+
19
+ class TargetTest < Test::Unit::TestCase
20
+ def setup
21
+ @loader = SimpleProjectLoader.new
22
+
23
+ @target = Bake::Target.new(nil)
24
+ @parent = Bake::Project.new(nil)
25
+ @parent.name 'parent'
26
+ @parent.loader = @loader
27
+ @child1 = Bake::Target.new(@parent)
28
+ @child1.name 'child1'
29
+ @child2 = Bake::Target.new(@parent)
30
+ @child2.name 'child2'
31
+ @child2a = Bake::Project.new(@child2)
32
+ @child2a.name 'child2a'
33
+ @child2a.loader = @loader
34
+ @child2b = Bake::Target.new(@child2)
35
+ @child2b.name 'child2b'
36
+ @child2c = Bake::Target.new(@child2)
37
+ @child2c.name 'child2c'
38
+ @child2ai = Bake::Target.new(@child2a)
39
+ @child2aii = Bake::Target.new(@child2a)
40
+ end
41
+
42
+ def test_initialize
43
+ assert_nil(@target.parent)
44
+ assert_equal(0, @target.children.size)
45
+
46
+ assert_nil(@parent.parent)
47
+ assert_equal(2, @parent.children.size)
48
+ assert_same(@child1.parent, @child2.parent)
49
+ assert_equal(0, @child1.children.size)
50
+ assert_equal(3, @child2.children.size)
51
+ end
52
+
53
+ def test_name
54
+ assert_nil(@target.name)
55
+ assert_equal('oh no', @target.name('oh no'))
56
+ assert_equal('oh no', @target.name)
57
+ end
58
+
59
+ def test_child
60
+ assert_same(@child1, @parent.child('child1'))
61
+ assert_same(@child2c, @child2.child('child2c'))
62
+ assert_nil(@child1.child('anything'))
63
+ assert_nil(@parent.child('child2a'))
64
+ end
65
+
66
+ def test_project
67
+ assert_same(@parent, @child1.project)
68
+ assert_same(@parent, @child2.project)
69
+ assert_same(@parent, @child2a.project)
70
+ assert_same(@parent, @child2b.project)
71
+ assert_nil(@parent.project)
72
+ assert_same(@child2a, @child2ai.project)
73
+ end
74
+
75
+ def test_dep
76
+ assert(@child2aii.deps.empty?)
77
+ assert_raise(RuntimeError) { @child2aii.dep('child1') }
78
+ @parent.map('child1' => '.')
79
+ @child2aii.dep('child1')
80
+ assert_equal(1, @child2aii.deps.size)
81
+ assert_same(@child1, @child2aii.deps[0])
82
+
83
+ @child1.dep('child2')
84
+ assert_equal(1, @child1.deps.size)
85
+ assert_same(@child2, @child1.deps[0])
86
+ end
87
+
88
+ def test_map
89
+ @parent.map('child1' => '.')
90
+ assert_same(@child1, @parent.mapping('child1'))
91
+ end
92
+ end
93
+
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: bake
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-04-19 00:00:00 -04:00
8
+ summary: Project-based build utility
9
+ require_paths:
10
+ - lib
11
+ email: dylan@dylantrotter.com
12
+ homepage: http://dylantrotter.com/
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: bake
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Dylan Trotter
30
+ files:
31
+ - bin/bake
32
+ - lib/bake
33
+ - lib/bake.rb
34
+ - lib/bake_version.rb
35
+ - lib/bake/common_scheme.rb
36
+ - lib/bake/configuration.rb
37
+ - lib/bake/context.rb
38
+ - lib/bake/cpp_scheme.rb
39
+ - lib/bake/project_loader.rb
40
+ - lib/bake/qt_scheme.rb
41
+ - lib/bake/scheme.rb
42
+ - lib/bake/scheme_loader.rb
43
+ - lib/bake/string_utils.rb
44
+ - lib/bake/target.rb
45
+ - lib/bake/toolset.rb
46
+ - test/bake_test.rb
47
+ - test/configuration_test.rb
48
+ - test/context_test.rb
49
+ - test/scheme_test.rb
50
+ - test/target_test.rb
51
+ - README
52
+ - MIT-LICENSE
53
+ - TUTORIAL
54
+ - CONCEPTS
55
+ - REFERENCE
56
+ test_files: []
57
+
58
+ rdoc_options:
59
+ - --title
60
+ - Bake
61
+ - --main
62
+ - README
63
+ extra_rdoc_files:
64
+ - README
65
+ - MIT-LICENSE
66
+ - TUTORIAL
67
+ - CONCEPTS
68
+ - REFERENCE
69
+ executables:
70
+ - bake
71
+ extensions: []
72
+
73
+ requirements: []
74
+
75
+ dependencies: []
76
+