teapot 0.3.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,114 @@
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'pathname'
22
+ require 'test/unit'
23
+ require 'stringio'
24
+
25
+ require 'teapot/dependency'
26
+
27
+ class TestDependency < Test::Unit::TestCase
28
+ class BasicDependency
29
+ include Teapot::Dependency
30
+
31
+ def initialize(name = nil)
32
+ @name = name
33
+ end
34
+
35
+ attr :name
36
+ end
37
+
38
+ def test_chains
39
+ a = BasicDependency.new
40
+
41
+ a.provides 'apple' do
42
+ fruit ['apple']
43
+ end
44
+
45
+ b = BasicDependency.new
46
+
47
+ b.provides 'orange' do
48
+ fruit ['orange']
49
+ end
50
+
51
+ c = BasicDependency.new
52
+
53
+ c.provides 'fruit-juice' do
54
+ juice ['ice', 'cold']
55
+ end
56
+
57
+ c.depends 'apple'
58
+ c.depends 'orange'
59
+
60
+ chain = Teapot::Dependency::chain([], ['fruit-juice'], [a, b, c])
61
+ assert_equal [a, b, c], chain.ordered.collect(&:first)
62
+
63
+ d = BasicDependency.new
64
+
65
+ d.provides 'pie' do
66
+ end
67
+
68
+ d.depends 'apple'
69
+
70
+ chain = Teapot::Dependency::chain([], ['pie'], [a, b, c, d])
71
+ assert_equal [], chain.unresolved
72
+ assert_equal [a, d], chain.ordered.collect(&:first)
73
+ end
74
+
75
+ def test_conflicts
76
+ apple = BasicDependency.new('apple')
77
+ apple.provides 'apple'
78
+ apple.provides 'fruit'
79
+
80
+ bananna = BasicDependency.new('bananna')
81
+ bananna.provides 'fruit'
82
+
83
+ salad = BasicDependency.new('salad')
84
+ salad.depends 'fruit'
85
+ salad.provides 'salad'
86
+
87
+ chain = Teapot::Dependency::chain([], ['salad'], [apple, bananna, salad])
88
+ assert_equal ["fruit", salad], chain.unresolved.first
89
+ assert_equal({"fruit" => [apple, bananna]}, chain.conflicts)
90
+
91
+ chain = Teapot::Dependency::chain(['apple'], ['salad'], [apple, bananna, salad])
92
+ assert_equal([], chain.unresolved)
93
+ assert_equal({}, chain.conflicts)
94
+ end
95
+
96
+ def test_aliases
97
+ apple = BasicDependency.new('apple')
98
+ apple.provides 'apple'
99
+ apple.provides :fruit => 'apple'
100
+
101
+ bananna = BasicDependency.new('bananna')
102
+ bananna.provides 'bananna'
103
+ bananna.provides :fruit => 'bananna'
104
+
105
+ salad = BasicDependency.new('salad')
106
+ salad.depends :fruit
107
+ salad.provides 'salad'
108
+
109
+ chain = Teapot::Dependency::chain(['apple'], ['salad'], [apple, bananna, salad])
110
+ assert_equal([], chain.unresolved)
111
+ assert_equal({}, chain.conflicts)
112
+ assert_equal([[apple, "apple"], [salad, "salad"]], chain.ordered)
113
+ end
114
+ end
@@ -51,12 +51,12 @@ class TestEnvironment < Test::Unit::TestCase
51
51
  cflags ["-pipe"]
52
52
  end
53
53
 
54
- expected = {'SDK' => "bob-2.8", 'CCFLAGS' => "-sdk=bob-2.8"}
54
+ expected = {'SDK' => "bob-2.8", 'CFLAGS' => "-sdk=bob-2.8"}
55
55
 
56
56
  assert_equal [:cflags, :sdk], b.flatten.to_hash.keys.sort
57
- assert_equal expected, b.flatten.to_system_environment_hash
57
+ assert_equal expected, Teapot::Environment::System::convert_to_shell(b.flatten)
58
58
 
59
- assert_equal "-sdk=bob-2.8 -pipe", c.flatten.to_string_hash[:cflags]
59
+ assert_equal %W{-sdk=bob-2.8 -pipe}, c.flatten[:cflags]
60
60
  end
61
61
 
62
62
  def test_environment_nested_lambda
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teapot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,10 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-21 00:00:00.000000000 Z
12
+ date: 2012-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rake
15
+ name: rainbow
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
@@ -28,7 +28,7 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: rainbow
31
+ name: rexec
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
@@ -44,7 +44,7 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: rexec
47
+ name: trollop
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
@@ -77,20 +77,31 @@ files:
77
77
  - bin/teapot
78
78
  - lib/teapot.rb
79
79
  - lib/teapot/build.rb
80
+ - lib/teapot/build/component.rb
81
+ - lib/teapot/build/file_list.rb
80
82
  - lib/teapot/build/linker.rb
83
+ - lib/teapot/build/target.rb
84
+ - lib/teapot/build/targets/application.rb
85
+ - lib/teapot/build/targets/compiler.rb
86
+ - lib/teapot/build/targets/directory.rb
87
+ - lib/teapot/build/targets/executable.rb
88
+ - lib/teapot/build/targets/files.rb
89
+ - lib/teapot/build/targets/library.rb
81
90
  - lib/teapot/commands.rb
82
91
  - lib/teapot/config.rb
83
92
  - lib/teapot/context.rb
93
+ - lib/teapot/dependency.rb
84
94
  - lib/teapot/environment.rb
85
95
  - lib/teapot/environment/base.rb
86
96
  - lib/teapot/environment/constructor.rb
87
97
  - lib/teapot/environment/evaluator.rb
88
98
  - lib/teapot/environment/flatten.rb
89
99
  - lib/teapot/environment/system.rb
90
- - lib/teapot/package.rb
91
- - lib/teapot/platform.rb
100
+ - lib/teapot/target.rb
92
101
  - lib/teapot/version.rb
93
102
  - teapot.gemspec
103
+ - test/test_config.rb
104
+ - test/test_dependency.rb
94
105
  - test/test_environment.rb
95
106
  homepage: ''
96
107
  licenses: []
@@ -106,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
117
  version: '0'
107
118
  segments:
108
119
  - 0
109
- hash: 4295501369315822730
120
+ hash: -1731715330087988580
110
121
  required_rubygems_version: !ruby/object:Gem::Requirement
111
122
  none: false
112
123
  requirements:
@@ -115,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
126
  version: '0'
116
127
  segments:
117
128
  - 0
118
- hash: 4295501369315822730
129
+ hash: -1731715330087988580
119
130
  requirements: []
120
131
  rubyforge_project:
121
132
  rubygems_version: 1.8.24
@@ -123,4 +134,6 @@ signing_key:
123
134
  specification_version: 3
124
135
  summary: Teapot is a tool for managing complex cross-platform builds.
125
136
  test_files:
137
+ - test/test_config.rb
138
+ - test/test_dependency.rb
126
139
  - test/test_environment.rb
@@ -1,164 +0,0 @@
1
- # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'pathname'
22
-
23
- module Teapot
24
- class BuildError < StandardError
25
- end
26
-
27
- class Task
28
- def initialize
29
- @callbacks = {}
30
- end
31
-
32
- def define(name, &callback)
33
- @callbacks[name] = callback
34
- end
35
-
36
- def [](name)
37
- @callbacks[name] || @callbacks[:all]
38
- end
39
- end
40
-
41
- class FakePackage
42
- def initialize(context, record, name)
43
- @context = context
44
- @record = record
45
- @name = name
46
- @version = nil
47
- @path = nil
48
- end
49
-
50
- attr :context
51
- attr :record
52
-
53
- attr :name
54
- attr :version
55
-
56
- attr :path
57
-
58
- def depends
59
- @record.options.fetch(:depends, [])
60
- end
61
-
62
- def build!(platform = :all, config = {})
63
- end
64
-
65
- def to_s
66
- "<FakePackage: #{@name}>"
67
- end
68
- end
69
-
70
- class Package
71
- def initialize(context, record, name)
72
- @context = context
73
- @record = record
74
-
75
- parts = name.split('-')
76
- @name = parts[0..-2].join('-')
77
- @version = parts[-1]
78
-
79
- @build = Task.new
80
-
81
- @depends = []
82
-
83
- @path = @record.destination_path
84
- @source_path = @path + name
85
- end
86
-
87
- attr :context
88
- attr :record
89
-
90
- attr :name
91
- attr :version
92
-
93
- attr :path
94
-
95
- attr :depends, true
96
- attr :source_path, true
97
-
98
- def build(platform, &block)
99
- @build.define(platform, &block)
100
- end
101
-
102
- def build!(platform = :all, config = {})
103
- task = @build[platform.name]
104
-
105
- if task
106
- environment = Environment.combine(
107
- @record.options[:environment],
108
- platform.environment,
109
- config,
110
- )
111
-
112
- local_build = environment.merge do
113
- default build_prefix Pathname.new("build/cache/#{platform.name}-#{config[:variant]}")
114
- default install_prefix platform.prefix
115
-
116
- buildflags [
117
- ->{"-I" + (platform.prefix + "include").to_s},
118
- ]
119
-
120
- linkflags [
121
- ->{"-L" + (platform.prefix + "lib").to_s},
122
- ]
123
- end
124
-
125
- Dir.chdir(@path) do
126
- task.call(platform, local_build)
127
- end
128
- else
129
- raise BuildError.new("Could not find build task for #{platform.name}!")
130
- end
131
- end
132
-
133
- def to_s
134
- "<Package: #{@name}>"
135
- end
136
-
137
- def self.build_order(available, packages)
138
- ordered = []
139
- unresolved = []
140
-
141
- expand = lambda do |name, parent|
142
- package = available[name]
143
-
144
- unless package
145
- unresolved << [name, parent]
146
- else
147
- package.depends.each do |dependency|
148
- expand.call(dependency, package)
149
- end
150
-
151
- unless ordered.include? package
152
- ordered << package
153
- end
154
- end
155
- end
156
-
157
- packages.each do |package|
158
- expand.call(package.name, nil)
159
- end
160
-
161
- return {:ordered => ordered, :unresolved => unresolved}
162
- end
163
- end
164
- end