teapot 0.9.10 → 1.0.0.pre.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -3
- data/README.md +3 -4
- data/Rakefile +3 -6
- data/bin/teapot +3 -7
- data/lib/teapot/build.rb +166 -18
- data/lib/teapot/configuration.rb +0 -1
- data/lib/teapot/context.rb +37 -21
- data/lib/teapot/controller/build.rb +24 -7
- data/lib/teapot/controller/fetch.rb +1 -1
- data/lib/teapot/controller.rb +1 -0
- data/lib/teapot/definition.rb +1 -1
- data/lib/teapot/dependency.rb +2 -6
- data/lib/teapot/environment/base.rb +7 -15
- data/lib/teapot/environment/constructor.rb +28 -0
- data/lib/teapot/environment/flatten.rb +42 -1
- data/lib/teapot/environment/system.rb +3 -3
- data/lib/teapot/extractors/linker_extractor.rb +2 -2
- data/lib/teapot/loader.rb +9 -11
- data/lib/teapot/name.rb +4 -0
- data/lib/teapot/package.rb +5 -4
- data/lib/teapot/repository.rb +29 -1
- data/lib/teapot/rule.rb +196 -0
- data/lib/teapot/rulebook.rb +91 -0
- data/lib/teapot/target.rb +15 -40
- data/lib/teapot/version.rb +1 -1
- data/{lib/teapot/build/targets/application.rb → spec/teapot/build_spec.rb} +26 -29
- data/{test/test_teapot.rb → spec/teapot/context_spec.rb} +13 -13
- data/spec/teapot/dependency_spec.rb +113 -0
- data/spec/teapot/environment_spec.rb +91 -0
- data/{lib/teapot/build/graph.rb → spec/teapot/name_spec.rb} +26 -26
- data/{test/test_substitutions.rb → spec/teapot/substitutions_spec.rb} +36 -36
- data/{test → spec/teapot}/teapot.rb +1 -1
- data/teapot.gemspec +16 -9
- metadata +98 -51
- data/lib/teapot/build/component.rb +0 -69
- data/lib/teapot/build/file_list.rb +0 -67
- data/lib/teapot/build/linker.rb +0 -49
- data/lib/teapot/build/target.rb +0 -76
- data/lib/teapot/build/targets/compiler.rb +0 -83
- data/lib/teapot/build/targets/directory.rb +0 -63
- data/lib/teapot/build/targets/executable.rb +0 -56
- data/lib/teapot/build/targets/external.rb +0 -91
- data/lib/teapot/build/targets/files.rb +0 -82
- data/lib/teapot/build/targets/library.rb +0 -117
- data/lib/teapot/commands.rb +0 -139
- data/lib/teapot/controller/run.rb +0 -43
- data/lib/teapot/graph.rb +0 -136
- data/test/test_dependency.rb +0 -112
- data/test/test_environment.rb +0 -102
@@ -1,117 +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 'teapot/build/target'
|
22
|
-
require 'teapot/build/targets/directory'
|
23
|
-
require 'teapot/build/targets/files'
|
24
|
-
require 'teapot/build/targets/compiler'
|
25
|
-
|
26
|
-
require 'teapot/build/graph'
|
27
|
-
require 'teapot/extractors/linker_extractor'
|
28
|
-
|
29
|
-
require 'fileutils'
|
30
|
-
|
31
|
-
module Teapot
|
32
|
-
module Build
|
33
|
-
module Targets
|
34
|
-
class Library < Build::Target
|
35
|
-
include Compiler
|
36
|
-
include Installation
|
37
|
-
|
38
|
-
def initialize(parent, name, options = {})
|
39
|
-
super parent
|
40
|
-
|
41
|
-
@name = name
|
42
|
-
@options = options
|
43
|
-
end
|
44
|
-
|
45
|
-
attr :options
|
46
|
-
|
47
|
-
def subdirectory
|
48
|
-
options[:subdirectory] || "lib"
|
49
|
-
end
|
50
|
-
|
51
|
-
def dependent_libraries(environment)
|
52
|
-
Extractors::LinkerExtractor.libraries(environment[:ldflags])
|
53
|
-
end
|
54
|
-
|
55
|
-
def link(environment, objects)
|
56
|
-
library_file = link_prefix!(environment) + "lib#{@name}.a"
|
57
|
-
|
58
|
-
graph = Build::dependency_graph(environment)
|
59
|
-
|
60
|
-
if graph.regenerate?(library_file, objects + dependent_libraries(environment))
|
61
|
-
Linker.link_static(environment, library_file, objects)
|
62
|
-
end
|
63
|
-
|
64
|
-
return library_file
|
65
|
-
end
|
66
|
-
|
67
|
-
def compile_and_link(environment)
|
68
|
-
file_list = self.source_files(environment)
|
69
|
-
|
70
|
-
pool = Commands::Pool.new
|
71
|
-
|
72
|
-
objects = file_list.collect do |source_file|
|
73
|
-
relative_path = source_file.relative_path_from(file_list.root)
|
74
|
-
|
75
|
-
compile(environment, file_list.root, relative_path, pool)
|
76
|
-
end
|
77
|
-
|
78
|
-
pool.wait
|
79
|
-
|
80
|
-
return Array link(environment, objects)
|
81
|
-
end
|
82
|
-
|
83
|
-
def install_file_list(file_list, prefix)
|
84
|
-
file_list.each do |path|
|
85
|
-
relative_path = path.relative_path_from(file_list.root)
|
86
|
-
destination_path = prefix + file_list.prefix + relative_path
|
87
|
-
|
88
|
-
destination_path.dirname.mkpath
|
89
|
-
FileUtils.cp(path, destination_path, :preserve => true)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def build(environment)
|
94
|
-
prefix = install_prefix!(environment)
|
95
|
-
|
96
|
-
compile_and_link(environment).each do |path|
|
97
|
-
destination_path = prefix + subdirectory + path.basename
|
98
|
-
|
99
|
-
destination_path.dirname.mkpath
|
100
|
-
|
101
|
-
FileUtils.cp(path, destination_path, :preserve => true)
|
102
|
-
end
|
103
|
-
|
104
|
-
if self.respond_to? :headers
|
105
|
-
install_file_list(self.headers(environment), prefix + "include")
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
class Directory
|
111
|
-
def compile_library(*args, &block)
|
112
|
-
self << Library.target(self, *args, &block)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
data/lib/teapot/commands.rb
DELETED
@@ -1,139 +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 'set'
|
22
|
-
require 'rainbow'
|
23
|
-
require 'shellwords'
|
24
|
-
|
25
|
-
require 'system'
|
26
|
-
require 'rexec/task'
|
27
|
-
|
28
|
-
module Teapot
|
29
|
-
module Commands
|
30
|
-
module Helpers
|
31
|
-
def run_executable(path, environment)
|
32
|
-
environment = environment.flatten
|
33
|
-
|
34
|
-
executable = environment[:install_prefix] + path
|
35
|
-
|
36
|
-
Commands.run(executable)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class CommandError < StandardError
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.split(arg)
|
44
|
-
Shellwords.split(arg || "")
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.run(*args, &block)
|
48
|
-
options = Hash === args.last ? args.pop : {}
|
49
|
-
options[:passthrough] ||= :all
|
50
|
-
|
51
|
-
args = args.flatten.compact.collect &:to_s
|
52
|
-
|
53
|
-
puts args.join(' ').color(:blue) + " in #{options[:chdir] || Dir.getwd}"
|
54
|
-
|
55
|
-
task = RExec::Task.open(args, options, &block)
|
56
|
-
|
57
|
-
if task.wait == 0
|
58
|
-
true
|
59
|
-
else
|
60
|
-
raise CommandError.new("Non-zero exit status: #{args.join(' ')}!")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.run!(*args, &block)
|
65
|
-
run(*args, &block)
|
66
|
-
rescue CommandError
|
67
|
-
false
|
68
|
-
end
|
69
|
-
|
70
|
-
def wait
|
71
|
-
# No parallel execution supported by default.
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.make(*args)
|
75
|
-
run("make", args, "-j", System::CPU.count)
|
76
|
-
end
|
77
|
-
|
78
|
-
def self.make_install
|
79
|
-
make("install")
|
80
|
-
end
|
81
|
-
|
82
|
-
class Pool
|
83
|
-
def self.concurrent_process_count
|
84
|
-
System::CPU.count * 2
|
85
|
-
end
|
86
|
-
|
87
|
-
def initialize(options = {})
|
88
|
-
@commands = []
|
89
|
-
|
90
|
-
@limit = options[:limit] || Pool.concurrent_process_count
|
91
|
-
|
92
|
-
@running = Set.new
|
93
|
-
end
|
94
|
-
|
95
|
-
def run(*args)
|
96
|
-
args = args.flatten.compact.collect &:to_s
|
97
|
-
|
98
|
-
@commands << args
|
99
|
-
|
100
|
-
schedule!
|
101
|
-
end
|
102
|
-
|
103
|
-
def schedule!
|
104
|
-
while @running.size < @limit and @commands.size > 0
|
105
|
-
command = @commands.shift
|
106
|
-
|
107
|
-
puts command.join(' ').color(:blue)
|
108
|
-
|
109
|
-
pid = Process.fork do
|
110
|
-
exec(*command)
|
111
|
-
|
112
|
-
exit!(0)
|
113
|
-
end
|
114
|
-
|
115
|
-
@running << pid
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def wait
|
120
|
-
while @running.size > 0
|
121
|
-
pid = Process.wait(0)
|
122
|
-
@running.delete(pid)
|
123
|
-
|
124
|
-
schedule!
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
def self.pipeline(parallel = false)
|
130
|
-
if parallel == false
|
131
|
-
# Non-parallel execution pipeline
|
132
|
-
Commands
|
133
|
-
else
|
134
|
-
# Pool based parallel execution pipeline
|
135
|
-
Pool.new(parallel == true ? {} : parallel)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
@@ -1,43 +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 'teapot/controller'
|
22
|
-
|
23
|
-
module Teapot
|
24
|
-
class Controller
|
25
|
-
def run(dependency_names = [])
|
26
|
-
configuration = context.configuration
|
27
|
-
|
28
|
-
dependency_names += configuration[:run] || []
|
29
|
-
|
30
|
-
log "Running dependencies: #{dependency_names}"
|
31
|
-
|
32
|
-
chain, ordered = build(dependency_names)
|
33
|
-
|
34
|
-
ordered.each do |(target, dependency)|
|
35
|
-
if target.respond_to?(:run!) and !@options[:dry]
|
36
|
-
log "Running #{target.name} for dependency #{dependency}...".color(:cyan)
|
37
|
-
|
38
|
-
target.run!(configuration)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
data/lib/teapot/graph.rb
DELETED
@@ -1,136 +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 'set'
|
22
|
-
require 'pathname'
|
23
|
-
|
24
|
-
module Teapot
|
25
|
-
class Graph
|
26
|
-
def initialize
|
27
|
-
@nodes = {}
|
28
|
-
|
29
|
-
@extractors = []
|
30
|
-
end
|
31
|
-
|
32
|
-
attr :root
|
33
|
-
attr :nodes
|
34
|
-
attr :extractors
|
35
|
-
|
36
|
-
def << node
|
37
|
-
@nodes[node.path] = node
|
38
|
-
end
|
39
|
-
|
40
|
-
def regenerate?(output_path, input_paths)
|
41
|
-
return true unless output_path.exist?
|
42
|
-
|
43
|
-
output_modified_time = output_path.mtime
|
44
|
-
|
45
|
-
Array(input_paths).each do |path|
|
46
|
-
node = fetch(path)
|
47
|
-
|
48
|
-
return true if node.changed_since?(output_modified_time)
|
49
|
-
end
|
50
|
-
|
51
|
-
return false
|
52
|
-
end
|
53
|
-
|
54
|
-
def extract(source_path)
|
55
|
-
dependencies = Set.new
|
56
|
-
|
57
|
-
@extractors.each do |extractor|
|
58
|
-
extractor.call(source_path) do |path|
|
59
|
-
dependencies << path
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
nodes = dependencies.map{|path| fetch(path)}
|
64
|
-
end
|
65
|
-
|
66
|
-
def fetch(path)
|
67
|
-
@nodes.fetch(path) do
|
68
|
-
node = @nodes[path] = Node.new(self, path)
|
69
|
-
node.extract_dependencies!
|
70
|
-
|
71
|
-
node
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
class Node
|
76
|
-
def initialize(graph, path)
|
77
|
-
@graph = graph
|
78
|
-
|
79
|
-
@path = Pathname(path)
|
80
|
-
|
81
|
-
@dependencies = []
|
82
|
-
|
83
|
-
@changed = nil
|
84
|
-
end
|
85
|
-
|
86
|
-
attr :path
|
87
|
-
attr :dependencies
|
88
|
-
|
89
|
-
def changed_since?(modified_time)
|
90
|
-
return true unless @path.exist?
|
91
|
-
|
92
|
-
if @changed == nil
|
93
|
-
# If the file was modified in the future relative to old modified_time:
|
94
|
-
if @path.mtime > modified_time
|
95
|
-
puts "Changed: #{path.to_s.inspect}"
|
96
|
-
return @changed = true
|
97
|
-
else
|
98
|
-
@changed = false
|
99
|
-
end
|
100
|
-
|
101
|
-
# If any of the file's dependencies have changed relative to the old modified_time:
|
102
|
-
@dependencies.each do |dependency|
|
103
|
-
if dependency.changed_since?(modified_time)
|
104
|
-
return @changed = true
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
return @changed
|
110
|
-
end
|
111
|
-
|
112
|
-
def extract_dependencies!
|
113
|
-
@dependencies = @graph.extract(path)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
class Extractor
|
118
|
-
def initialize(patterns = [])
|
119
|
-
@patterns = Array(patterns)
|
120
|
-
end
|
121
|
-
|
122
|
-
def extract(path)
|
123
|
-
end
|
124
|
-
|
125
|
-
def call(path, &block)
|
126
|
-
return unless path.exist?
|
127
|
-
|
128
|
-
basename = path.basename.to_s
|
129
|
-
|
130
|
-
if @patterns.find{|pattern| pattern.match(basename)}
|
131
|
-
extract(path, &block)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
data/test/test_dependency.rb
DELETED
@@ -1,112 +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 "minitest/autorun"
|
22
|
-
|
23
|
-
require 'teapot/dependency'
|
24
|
-
|
25
|
-
class TestDependency < MiniTest::Test
|
26
|
-
class BasicDependency
|
27
|
-
include Teapot::Dependency
|
28
|
-
|
29
|
-
def initialize(name = nil)
|
30
|
-
@name = name
|
31
|
-
end
|
32
|
-
|
33
|
-
attr :name
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_chains
|
37
|
-
a = BasicDependency.new
|
38
|
-
|
39
|
-
a.provides 'apple' do
|
40
|
-
fruit ['apple']
|
41
|
-
end
|
42
|
-
|
43
|
-
b = BasicDependency.new
|
44
|
-
|
45
|
-
b.provides 'orange' do
|
46
|
-
fruit ['orange']
|
47
|
-
end
|
48
|
-
|
49
|
-
c = BasicDependency.new
|
50
|
-
|
51
|
-
c.provides 'fruit-juice' do
|
52
|
-
juice ['ice', 'cold']
|
53
|
-
end
|
54
|
-
|
55
|
-
c.depends 'apple'
|
56
|
-
c.depends 'orange'
|
57
|
-
|
58
|
-
chain = Teapot::Dependency::chain([], ['fruit-juice'], [a, b, c])
|
59
|
-
assert_equal [a, b, c], chain.ordered.collect(&:first)
|
60
|
-
|
61
|
-
d = BasicDependency.new
|
62
|
-
|
63
|
-
d.provides 'pie' do
|
64
|
-
end
|
65
|
-
|
66
|
-
d.depends 'apple'
|
67
|
-
|
68
|
-
chain = Teapot::Dependency::chain([], ['pie'], [a, b, c, d])
|
69
|
-
assert_equal [], chain.unresolved
|
70
|
-
assert_equal [a, d], chain.ordered.collect(&:first)
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_conflicts
|
74
|
-
apple = BasicDependency.new('apple')
|
75
|
-
apple.provides 'apple'
|
76
|
-
apple.provides 'fruit'
|
77
|
-
|
78
|
-
bananna = BasicDependency.new('bananna')
|
79
|
-
bananna.provides 'fruit'
|
80
|
-
|
81
|
-
salad = BasicDependency.new('salad')
|
82
|
-
salad.depends 'fruit'
|
83
|
-
salad.provides 'salad'
|
84
|
-
|
85
|
-
chain = Teapot::Dependency::Chain.new([], ['salad'], [apple, bananna, salad])
|
86
|
-
assert_equal ["fruit", salad], chain.unresolved.first
|
87
|
-
assert_equal({"fruit" => [apple, bananna]}, chain.conflicts)
|
88
|
-
|
89
|
-
chain = Teapot::Dependency::Chain.new(['apple'], ['salad'], [apple, bananna, salad])
|
90
|
-
assert_equal([], chain.unresolved)
|
91
|
-
assert_equal({}, chain.conflicts)
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_aliases
|
95
|
-
apple = BasicDependency.new('apple')
|
96
|
-
apple.provides 'apple'
|
97
|
-
apple.provides :fruit => 'apple'
|
98
|
-
|
99
|
-
bananna = BasicDependency.new('bananna')
|
100
|
-
bananna.provides 'bananna'
|
101
|
-
bananna.provides :fruit => 'bananna'
|
102
|
-
|
103
|
-
salad = BasicDependency.new('salad')
|
104
|
-
salad.depends :fruit
|
105
|
-
salad.provides 'salad'
|
106
|
-
|
107
|
-
chain = Teapot::Dependency::chain(['apple'], ['salad'], [apple, bananna, salad])
|
108
|
-
assert_equal([], chain.unresolved)
|
109
|
-
assert_equal({}, chain.conflicts)
|
110
|
-
assert_equal([[apple, "apple"], [salad, "salad"]], chain.ordered)
|
111
|
-
end
|
112
|
-
end
|
data/test/test_environment.rb
DELETED
@@ -1,102 +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 "minitest/autorun"
|
22
|
-
|
23
|
-
require 'teapot/environment'
|
24
|
-
|
25
|
-
class TestEnvironment < MiniTest::Test
|
26
|
-
def test_environment_chaining
|
27
|
-
a = Teapot::Environment.new
|
28
|
-
a[:cflags] = ["-std=c++11"]
|
29
|
-
|
30
|
-
b = Teapot::Environment.new(a, {})
|
31
|
-
b[:cflags] = ["-stdlib=libc++"]
|
32
|
-
b[:rcflags] = lambda {cflags.reverse}
|
33
|
-
|
34
|
-
expected = {:cflags => ["-std=c++11", "-stdlib=libc++"], :rcflags => ["-stdlib=libc++", "-std=c++11"]}
|
35
|
-
|
36
|
-
assert_equal expected, b.flatten.to_hash
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_environment_lambda
|
40
|
-
a = Teapot::Environment.new do
|
41
|
-
sdk "bob-2.6"
|
42
|
-
cflags [->{"-sdk=#{sdk}"}]
|
43
|
-
end
|
44
|
-
|
45
|
-
b = Teapot::Environment.new(a) do
|
46
|
-
sdk "bob-2.8"
|
47
|
-
end
|
48
|
-
|
49
|
-
c = Teapot::Environment.new(b) do
|
50
|
-
cflags ["-pipe"]
|
51
|
-
end
|
52
|
-
|
53
|
-
expected = {'SDK' => "bob-2.8", 'CFLAGS' => "-sdk=bob-2.8"}
|
54
|
-
|
55
|
-
assert_equal [:cflags, :sdk], b.flatten.to_hash.keys.sort
|
56
|
-
assert_equal expected, Teapot::Environment::System::convert_to_shell(b.flatten)
|
57
|
-
|
58
|
-
assert_equal %W{-sdk=bob-2.8 -pipe}, c.flatten[:cflags]
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_environment_nested_lambda
|
62
|
-
a = Teapot::Environment.new do
|
63
|
-
sdk "bob-2.6"
|
64
|
-
cflags [->{"-sdk=#{sdk}"}]
|
65
|
-
end
|
66
|
-
|
67
|
-
b = Teapot::Environment.new(a) do
|
68
|
-
sdk "bob-2.8"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_combine
|
73
|
-
a = Teapot::Environment.new(nil, {:name => 'a'})
|
74
|
-
b = Teapot::Environment.new(a, {:name => 'b'})
|
75
|
-
c = Teapot::Environment.new(nil, {:name => 'c'})
|
76
|
-
d = Teapot::Environment.new(c, {:name => 'd'})
|
77
|
-
|
78
|
-
top = Teapot::Environment.combine(b, d)
|
79
|
-
|
80
|
-
assert_equal d.values, top.values
|
81
|
-
assert_equal c.values, top.parent.values
|
82
|
-
assert_equal b.values, top.parent.parent.values
|
83
|
-
assert_equal a.values, top.parent.parent.parent.values
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_combine_defaults
|
87
|
-
local = Teapot::Environment.new do
|
88
|
-
architectures ["-m64"]
|
89
|
-
end
|
90
|
-
|
91
|
-
platform = Teapot::Environment.new do
|
92
|
-
default architectures ["-arch", "i386"]
|
93
|
-
end
|
94
|
-
|
95
|
-
combined = Teapot::Environment.combine(
|
96
|
-
platform,
|
97
|
-
local
|
98
|
-
)
|
99
|
-
|
100
|
-
assert_equal ["-m64"], combined[:architectures]
|
101
|
-
end
|
102
|
-
end
|