teapot 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
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
+ module Teapot
22
+ module Build
23
+ module Linker
24
+ def self.link_static(environment, library_file, objects)
25
+ if RUBY_PLATFORM =~ /darwin/
26
+ Teapot::Commands.run(
27
+ Commands.split(environment[:libtool] || "libtool"),
28
+ "-static", "-o", library_file, objects,
29
+ )
30
+ elsif RUBY_PLATFORM =~ /linux/
31
+ Commands.run(
32
+ Commands.split(environment[:ar] || 'ar'),
33
+ Commands.split(environment[:arflags] || "-cru"),
34
+ library_file, objects
35
+ )
36
+ else
37
+ raise UnsupportedPlatform.new("Cannot determine linker for #{RUBY_PLATFORM}!")
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
data/lib/teapot/build.rb CHANGED
@@ -25,8 +25,13 @@ require 'pathname'
25
25
  require 'rainbow'
26
26
  require 'shellwords'
27
27
 
28
+ require 'teapot/build/linker'
29
+
28
30
  module Teapot
29
31
  module Build
32
+ class UnsupportedPlatform < StandardError
33
+ end
34
+
30
35
  class Task
31
36
  def initialize(inputs, outputs)
32
37
  @inputs = inputs
@@ -129,13 +134,9 @@ module Teapot
129
134
 
130
135
  def link(environment, objects)
131
136
  library_file = build_prefix!(environment) + "lib#{@name}.a"
132
-
133
- Commands.run(
134
- Commands.split(environment[:libtool] || "libtool"),
135
- "-static", "-o", library_file, objects,
136
- Commands.split(environment[:ldflags])
137
- )
138
-
137
+
138
+ Linker.link_static(environment, library_file, objects)
139
+
139
140
  return library_file
140
141
  end
141
142
 
@@ -42,6 +42,7 @@ module Teapot
42
42
  end
43
43
 
44
44
  Default = Struct.new(:value)
45
+ Replace = Struct.new(:value)
45
46
 
46
47
  class Constructor
47
48
  def initialize(environment)
@@ -65,6 +66,10 @@ module Teapot
65
66
  def default(name)
66
67
  @environment[name] = Default.new(@environment[name])
67
68
  end
69
+
70
+ def replace(name)
71
+ @environment[name] = Replace.new(@environment[name])
72
+ end
68
73
  end
69
74
 
70
75
  class Evaluator
@@ -86,9 +91,11 @@ module Teapot
86
91
  when Symbol
87
92
  object_value(@values[value])
88
93
  when Proc
89
- object_value(instance_eval(&value))
94
+ object_value(instance_exec(&value))
90
95
  when Default
91
96
  object_value(value.value)
97
+ when Replace
98
+ object_value(value.value)
92
99
  else
93
100
  value
94
101
  end
@@ -116,10 +123,7 @@ module Teapot
116
123
  return top
117
124
  end
118
125
 
119
- def initialize(*args, &block)
120
- parent = args.shift if args.size == 2
121
- values = args.shift
122
-
126
+ def initialize(parent = nil, values = {}, &block)
123
127
  @values = (values || {}).to_hash
124
128
  @parent = parent
125
129
 
@@ -131,7 +135,7 @@ module Teapot
131
135
  end
132
136
 
133
137
  def construct(&block)
134
- Constructor.new(self).instance_eval(&block)
138
+ Constructor.new(self).instance_exec(&block)
135
139
  end
136
140
 
137
141
  def dup
@@ -141,6 +145,14 @@ module Teapot
141
145
  attr :values
142
146
  attr :parent
143
147
 
148
+ def lookup(name)
149
+ if @values.include? name
150
+ self
151
+ elsif @parent
152
+ @parent.lookup(name)
153
+ end
154
+ end
155
+
144
156
  def [] (key)
145
157
  environment = lookup(key)
146
158
 
@@ -167,12 +179,12 @@ module Teapot
167
179
  Hash[@values.map{|key, value| [key, string_value(value)]}]
168
180
  end
169
181
 
170
- def to_env_hash
182
+ def to_system_environment_hash
171
183
  Hash[@values.map{|key, value| [key.to_s.upcase, string_value(value)]}]
172
184
  end
173
185
 
174
186
  def use(options = {}, &block)
175
- system_environment = flatten.to_env_hash
187
+ system_environment = flatten.to_system_environment_hash
176
188
 
177
189
  puts YAML::dump(system_environment).color(:magenta)
178
190
 
@@ -213,10 +225,15 @@ module Teapot
213
225
  @values.each do |key, value|
214
226
  previous = hash[key]
215
227
 
216
- if Array === previous
228
+ if Replace === value
229
+ # Replace the parent value
230
+ hash[key] = value
231
+ elsif Array === previous
232
+ # Merge with the parent value
217
233
  hash[key] = previous + Array(value)
218
- elsif Default == previous
219
- hash[key] ||= previous
234
+ elsif Default === value
235
+ # Update the parent value if not defined.
236
+ hash[key] = previous || value
220
237
  else
221
238
  hash[key] = value
222
239
  end
@@ -231,20 +248,12 @@ module Teapot
231
248
  when Symbol
232
249
  string_value(@values[value])
233
250
  when Proc
234
- string_value(@evaluator.instance_eval(&value))
251
+ string_value(@evaluator.instance_exec(&value))
235
252
  when Default
236
253
  string_value(value.value)
237
254
  else
238
255
  value.to_s
239
256
  end
240
257
  end
241
-
242
- def lookup(name)
243
- if @values.include? name
244
- self
245
- elsif @parent
246
- @parent.lookup(name)
247
- end
248
- end
249
258
  end
250
259
  end
@@ -109,8 +109,21 @@ module Teapot
109
109
  config,
110
110
  )
111
111
 
112
+ local_build = environment.merge do
113
+ default build_prefix "build-#{platform.name}-#{variant}"
114
+ default install_prefix platform.prefix
115
+
116
+ buildflags [
117
+ "-I", ->{platform.prefix + "include"},
118
+ ]
119
+
120
+ linkflags [
121
+ "-L", ->{platform.prefix + "lib"},
122
+ ]
123
+ end
124
+
112
125
  Dir.chdir(@path) do
113
- task.call(platform, environment)
126
+ task.call(platform, local_build)
114
127
  end
115
128
  else
116
129
  raise BuildError.new("Could not find build task for #{platform.name}!")
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Teapot
22
- VERSION = "0.2.1"
22
+ VERSION = "0.2.2"
23
23
  end
@@ -40,17 +40,34 @@ class TestEnvironment < Test::Unit::TestCase
40
40
  def test_environment_lambda
41
41
  a = Teapot::Environment.new do
42
42
  sdk "bob-2.6"
43
- cflags {"-sdk=#{sdk}"}
43
+ ccflags [->{"-sdk=#{sdk}"}]
44
44
  end
45
45
 
46
46
  b = Teapot::Environment.new(a) do
47
47
  sdk "bob-2.8"
48
48
  end
49
-
50
- expected = {'SDK' => "bob-2.8", 'CFLAGS' => "-sdk=bob-2.8"}
51
49
 
52
- assert_equal [:cflags, :sdk], b.flatten.to_hash.keys.sort
53
- assert_equal expected, b.flatten.to_env_hash
50
+ c = Teapot::Environment.new(b) do
51
+ ccflags ["-pipe"]
52
+ end
53
+
54
+ expected = {'SDK' => "bob-2.8", 'CCFLAGS' => "-sdk=bob-2.8"}
55
+
56
+ assert_equal [:ccflags, :sdk], b.flatten.to_hash.keys.sort
57
+ assert_equal expected, b.flatten.to_system_environment_hash
58
+
59
+ assert_equal "-sdk=bob-2.8 -pipe", c.flatten.to_string_hash[:ccflags]
60
+ end
61
+
62
+ def test_environment_nested_lambda
63
+ a = Teapot::Environment.new do
64
+ sdk "bob-2.6"
65
+ ccflags [->{"-sdk=#{sdk}"}]
66
+ end
67
+
68
+ b = Teapot::Environment.new(a) do
69
+ sdk "bob-2.8"
70
+ end
54
71
  end
55
72
 
56
73
  def test_combine
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.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -77,6 +77,7 @@ files:
77
77
  - bin/teapot
78
78
  - lib/teapot.rb
79
79
  - lib/teapot/build.rb
80
+ - lib/teapot/build/linker.rb
80
81
  - lib/teapot/commands.rb
81
82
  - lib/teapot/config.rb
82
83
  - lib/teapot/context.rb
@@ -100,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
101
  version: '0'
101
102
  segments:
102
103
  - 0
103
- hash: -3652039777535418332
104
+ hash: -4088469736954378212
104
105
  required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  none: false
106
107
  requirements:
@@ -109,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
110
  version: '0'
110
111
  segments:
111
112
  - 0
112
- hash: -3652039777535418332
113
+ hash: -4088469736954378212
113
114
  requirements: []
114
115
  rubyforge_project:
115
116
  rubygems_version: 1.8.24