teapot 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/teapot +15 -13
- data/lib/teapot/build.rb +242 -0
- data/lib/teapot/commands.rb +6 -1
- data/lib/teapot/context.rb +1 -1
- data/lib/teapot/environment.rb +16 -1
- data/lib/teapot/version.rb +1 -1
- data/test/test_environment.rb +1 -1
- metadata +5 -4
data/bin/teapot
CHANGED
@@ -48,6 +48,8 @@ task :fetch do
|
|
48
48
|
|
49
49
|
puts "Fetching #{record}...".color(:cyan)
|
50
50
|
|
51
|
+
branch = record.options.fetch(:version, 'master')
|
52
|
+
|
51
53
|
unless File.exist? destination_path
|
52
54
|
puts "Cloning package at path #{destination_path} ...".color(:cyan)
|
53
55
|
FileUtils.mkdir_p(destination_path.to_s)
|
@@ -62,25 +64,25 @@ task :fetch do
|
|
62
64
|
if source_uri.scheme == "file"
|
63
65
|
source_uri = "file://" + source_uri.path
|
64
66
|
end
|
65
|
-
|
66
|
-
clone_arguments = [
|
67
|
-
"--recursive",
|
68
|
-
source_uri, destination_path,
|
69
|
-
"--depth", 1,
|
70
|
-
]
|
71
67
|
|
72
|
-
|
73
|
-
clone_arguments << "--branch"
|
74
|
-
clone_arguments << record.options[:version]
|
75
|
-
end
|
68
|
+
Teapot::Commands.run("git", "clone", source_uri, destination_path, "--branch", branch)
|
76
69
|
|
77
|
-
|
70
|
+
Dir.chdir(destination_path) do
|
71
|
+
Teapot::Commands.run("git", "submodule", "update", "--init", "--recursive")
|
72
|
+
end
|
78
73
|
else
|
79
74
|
puts "Updating package at path #{destination_path} ...".color(:cyan)
|
80
75
|
|
81
76
|
Dir.chdir(destination_path) do
|
82
|
-
Teapot::Commands.run("git", "
|
83
|
-
|
77
|
+
Teapot::Commands.run("git", "fetch", "origin")
|
78
|
+
|
79
|
+
Teapot::Commands.run("git", "checkout", branch)
|
80
|
+
|
81
|
+
# Pull any changes, if you might get the error from above:
|
82
|
+
# Your branch is behind 'origin/0.1' by 1 commit, and can be fast-forwarded.
|
83
|
+
Teapot::Commands.run("git", "pull")
|
84
|
+
|
85
|
+
Teapot::Commands.run("git", "submodule", "update", "--init", "--recursive")
|
84
86
|
end
|
85
87
|
end
|
86
88
|
end
|
data/lib/teapot/build.rb
ADDED
@@ -0,0 +1,242 @@
|
|
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 'teapot/commands'
|
22
|
+
require 'teapot/environment'
|
23
|
+
|
24
|
+
require 'pathname'
|
25
|
+
require 'rainbow'
|
26
|
+
require 'shellwords'
|
27
|
+
|
28
|
+
module Teapot
|
29
|
+
module Build
|
30
|
+
class Task
|
31
|
+
def initialize(inputs, outputs)
|
32
|
+
@inputs = inputs
|
33
|
+
@outputs = outputs
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Target
|
38
|
+
def initialize(parent)
|
39
|
+
@parent = parent
|
40
|
+
@tasks = []
|
41
|
+
|
42
|
+
@configure = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def root
|
46
|
+
@parent.root
|
47
|
+
end
|
48
|
+
|
49
|
+
def configure(&block)
|
50
|
+
@configure = Proc.new &block
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.target(*args, &block)
|
54
|
+
instance = self.new(*args)
|
55
|
+
|
56
|
+
if block_given?
|
57
|
+
instance.instance_eval(&block)
|
58
|
+
end
|
59
|
+
|
60
|
+
return instance
|
61
|
+
end
|
62
|
+
|
63
|
+
def execute(command, environment, *arguments)
|
64
|
+
if @configure
|
65
|
+
environment = Environment.combine(
|
66
|
+
environment,
|
67
|
+
Environment.new(&@configure),
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
environment = environment.flatten.to_string_hash
|
72
|
+
|
73
|
+
puts YAML::dump(environment).color(:magenta)
|
74
|
+
|
75
|
+
self.send(command, environment, *arguments)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class CompilerTarget < Target
|
80
|
+
def initialize(parent, name, options = {})
|
81
|
+
super parent
|
82
|
+
|
83
|
+
@name = name
|
84
|
+
@options = options
|
85
|
+
end
|
86
|
+
|
87
|
+
def build_prefix!(environment)
|
88
|
+
build_prefix = Pathname.new(environment[:build_prefix]) + @name
|
89
|
+
|
90
|
+
build_prefix.mkpath
|
91
|
+
|
92
|
+
return build_prefix
|
93
|
+
end
|
94
|
+
|
95
|
+
def install_prefix!(environment)
|
96
|
+
install_prefix = Pathname.new(environment[:install_prefix])
|
97
|
+
|
98
|
+
install_prefix.mkpath
|
99
|
+
|
100
|
+
return install_prefix
|
101
|
+
end
|
102
|
+
|
103
|
+
def compile(environment, source_file)
|
104
|
+
object_file = (build_prefix!(environment) + source_file.basename).sub_ext('.o')
|
105
|
+
|
106
|
+
case source_file.extname
|
107
|
+
when ".cpp"
|
108
|
+
Commands.run(
|
109
|
+
Commands.split(environment[:cxx]),
|
110
|
+
Commands.split(environment[:cxxflags]),
|
111
|
+
"-c", source_file, "-o", object_file
|
112
|
+
)
|
113
|
+
when ".c"
|
114
|
+
Commands.run(
|
115
|
+
Commands.split(environment[:cc]),
|
116
|
+
Commands.split(environment[:ccflags]),
|
117
|
+
"-c", source_file, "-o", object_file
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
121
|
+
return Array object_file
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class Library < CompilerTarget
|
126
|
+
def subdirectory
|
127
|
+
"lib"
|
128
|
+
end
|
129
|
+
|
130
|
+
def link(environment, objects)
|
131
|
+
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
|
+
|
139
|
+
return library_file
|
140
|
+
end
|
141
|
+
|
142
|
+
def build(environment)
|
143
|
+
files = sources
|
144
|
+
|
145
|
+
objects = sources.collect do |file|
|
146
|
+
compile(environment, file)
|
147
|
+
end
|
148
|
+
|
149
|
+
return Array link(environment, objects)
|
150
|
+
end
|
151
|
+
|
152
|
+
def install(environment)
|
153
|
+
prefix = install_prefix!(environment)
|
154
|
+
|
155
|
+
build(environment).each do |path|
|
156
|
+
destination_path = prefix + subdirectory + path.basename
|
157
|
+
|
158
|
+
destination_path.dirname.mkpath
|
159
|
+
FileUtils.cp path, destination_path
|
160
|
+
end
|
161
|
+
|
162
|
+
if defined? headers
|
163
|
+
headers.each do |path|
|
164
|
+
relative_path = path.relative_path_from(root)
|
165
|
+
destination_path = prefix + "include" + relative_path
|
166
|
+
|
167
|
+
destination_path.dirname.mkpath
|
168
|
+
FileUtils.cp path, destination_path
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
if defined? files
|
173
|
+
files.each do |path|
|
174
|
+
relative_path = path.relative_path_from(root)
|
175
|
+
destination_path = prefix + relative_path
|
176
|
+
|
177
|
+
destination_path.dirname.mkpath
|
178
|
+
FileUtils.cp path, destination_path
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
class Executable < Library
|
185
|
+
def subdirectory
|
186
|
+
"bin"
|
187
|
+
end
|
188
|
+
|
189
|
+
def link(environment, objects)
|
190
|
+
executable_file = build_prefix!(environment) + "#{@name}"
|
191
|
+
|
192
|
+
Commands.run(
|
193
|
+
Commands.split(environment[:cxx]),
|
194
|
+
Commands.split(environment[:cxxflags]),
|
195
|
+
"-o", executable_file, objects,
|
196
|
+
Commands.split(environment[:ldflags])
|
197
|
+
)
|
198
|
+
|
199
|
+
return executable_file
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
class Directory < Target
|
204
|
+
def initialize(parent, root)
|
205
|
+
@root = root
|
206
|
+
@targets = []
|
207
|
+
end
|
208
|
+
|
209
|
+
attr :root
|
210
|
+
attr :tasks
|
211
|
+
|
212
|
+
def add_library(*args, &block)
|
213
|
+
@targets << Library.target(self, *args, &block)
|
214
|
+
end
|
215
|
+
|
216
|
+
def add_executable(*args, &block)
|
217
|
+
@targets << Executable.target(self, *args, &block)
|
218
|
+
end
|
219
|
+
|
220
|
+
def add_directory(path)
|
221
|
+
directory = Directory.target(self, @root + path)
|
222
|
+
|
223
|
+
$stderr.puts "Loading #{directory.root}..."
|
224
|
+
build_path = (directory.root + "build.rb").to_s
|
225
|
+
directory.instance_eval(File.read(build_path), build_path)
|
226
|
+
|
227
|
+
@targets << directory
|
228
|
+
end
|
229
|
+
|
230
|
+
def execute(command, *arguments)
|
231
|
+
$stderr.puts "Executing #{command} for #{@root}"
|
232
|
+
@targets.each do |target|
|
233
|
+
target.execute(command, *arguments)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
def self.top(path)
|
239
|
+
Directory.target(nil, path)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
data/lib/teapot/commands.rb
CHANGED
@@ -19,14 +19,19 @@
|
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
21
|
require 'rainbow'
|
22
|
+
require 'shellwords'
|
22
23
|
|
23
24
|
module Teapot
|
24
25
|
module Commands
|
25
26
|
class CommandError < StandardError
|
26
27
|
end
|
27
28
|
|
29
|
+
def self.split(arg)
|
30
|
+
Shellwords.split(arg || "")
|
31
|
+
end
|
32
|
+
|
28
33
|
def self.run(*args)
|
29
|
-
args.collect
|
34
|
+
args = args.flatten.collect &:to_s
|
30
35
|
|
31
36
|
puts args.join(' ').color(:blue)
|
32
37
|
|
data/lib/teapot/context.rb
CHANGED
data/lib/teapot/environment.rb
CHANGED
@@ -30,6 +30,17 @@ require 'teapot/commands'
|
|
30
30
|
|
31
31
|
module Teapot
|
32
32
|
class Environment
|
33
|
+
def self.system_environment(env = ENV)
|
34
|
+
self.new(Hash[env.to_hash.collect{|key, value| [key.downcase.to_sym, value]}])
|
35
|
+
end
|
36
|
+
|
37
|
+
def merge(&block)
|
38
|
+
self.class.combine(
|
39
|
+
self,
|
40
|
+
self.class.new(&block)
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
33
44
|
Default = Struct.new(:value)
|
34
45
|
|
35
46
|
class Constructor
|
@@ -153,11 +164,15 @@ module Teapot
|
|
153
164
|
end
|
154
165
|
|
155
166
|
def to_string_hash
|
167
|
+
Hash[@values.map{|key, value| [key, string_value(value)]}]
|
168
|
+
end
|
169
|
+
|
170
|
+
def to_env_hash
|
156
171
|
Hash[@values.map{|key, value| [key.to_s.upcase, string_value(value)]}]
|
157
172
|
end
|
158
173
|
|
159
174
|
def use(options = {}, &block)
|
160
|
-
system_environment = flatten.
|
175
|
+
system_environment = flatten.to_env_hash
|
161
176
|
|
162
177
|
puts YAML::dump(system_environment).color(:magenta)
|
163
178
|
|
data/lib/teapot/version.rb
CHANGED
data/test/test_environment.rb
CHANGED
@@ -29,7 +29,7 @@ class TestEnvironment < Test::Unit::TestCase
|
|
29
29
|
a = Teapot::Environment.new
|
30
30
|
a[:cflags] = ["-std=c++11"]
|
31
31
|
|
32
|
-
b = Teapot::Environment.new(a)
|
32
|
+
b = Teapot::Environment.new(a, {})
|
33
33
|
b[:cflags] = ["-stdlib=libc++"]
|
34
34
|
|
35
35
|
expected = {:cflags => ["-std=c++11", "-stdlib=libc++"]}
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- Rakefile
|
77
77
|
- bin/teapot
|
78
78
|
- lib/teapot.rb
|
79
|
+
- lib/teapot/build.rb
|
79
80
|
- lib/teapot/commands.rb
|
80
81
|
- lib/teapot/config.rb
|
81
82
|
- lib/teapot/context.rb
|
@@ -99,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
100
|
version: '0'
|
100
101
|
segments:
|
101
102
|
- 0
|
102
|
-
hash:
|
103
|
+
hash: -1475380333635225782
|
103
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
105
|
none: false
|
105
106
|
requirements:
|
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
109
|
version: '0'
|
109
110
|
segments:
|
110
111
|
- 0
|
111
|
-
hash:
|
112
|
+
hash: -1475380333635225782
|
112
113
|
requirements: []
|
113
114
|
rubyforge_project:
|
114
115
|
rubygems_version: 1.8.24
|