teapot 1.3.1 → 2.0.0.pre.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +0 -1
  3. data/.travis.yml +6 -0
  4. data/Gemfile +1 -1
  5. data/bin/teapot +3 -3
  6. data/lib/teapot/command/build.rb +123 -0
  7. data/lib/teapot/{metadata.rb → command/clean.rb} +19 -20
  8. data/lib/teapot/command/create.rb +112 -0
  9. data/lib/teapot/command/fetch.rb +183 -0
  10. data/lib/teapot/command/list.rb +97 -0
  11. data/lib/teapot/command/status.rb +74 -0
  12. data/lib/teapot/command/visualize.rb +70 -0
  13. data/lib/teapot/command.rb +52 -132
  14. data/lib/teapot/context.rb +27 -11
  15. data/lib/teapot/loader.rb +6 -22
  16. data/lib/teapot/target.rb +2 -2
  17. data/lib/teapot/version.rb +1 -1
  18. data/spec/teapot/command_spec.rb +20 -12
  19. data/spec/teapot/context_spec.rb +13 -16
  20. data/teapot.gemspec +6 -4
  21. metadata +35 -45
  22. data/PLANNING.md +0 -20
  23. data/lib/teapot/controller/build.rb +0 -107
  24. data/lib/teapot/controller/clean.rb +0 -35
  25. data/lib/teapot/controller/create.rb +0 -73
  26. data/lib/teapot/controller/fetch.rb +0 -173
  27. data/lib/teapot/controller/generate.rb +0 -45
  28. data/lib/teapot/controller/list.rb +0 -82
  29. data/lib/teapot/controller/visualize.rb +0 -50
  30. data/lib/teapot/controller.rb +0 -81
  31. data/lib/teapot/dependency.rb +0 -25
  32. data/lib/teapot/generator.rb +0 -138
  33. data/lib/teapot/merge.rb +0 -142
  34. data/lib/teapot/repository.rb +0 -135
  35. data/lib/teapot/substitutions.rb +0 -258
  36. data/spec/teapot/generator_spec/teapot.rb +0 -54
  37. data/spec/teapot/generator_spec/template/$NAME.txt +0 -1
  38. data/spec/teapot/generator_spec.rb +0 -46
  39. data/spec/teapot/merge_spec.rb +0 -50
  40. data/spec/teapot/metadata_spec.rb +0 -31
  41. data/spec/teapot/substitutions_spec.rb +0 -65
  42. data/spec/teapot/wait_spec/teapot.rb +0 -41
  43. data/spec/teapot/wait_spec.rb +0 -53
@@ -1,258 +0,0 @@
1
- # Copyright, 2013, 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
- class Indentation
23
- TAB = "\t".freeze
24
-
25
- def initialize(prefix, level, indent)
26
- @prefix = prefix
27
- @level = level
28
- @indent = indent
29
- end
30
-
31
- def freeze
32
- indentation
33
-
34
- @prefix.freeze
35
- @level.freeze
36
- @indent.freeze
37
-
38
- super
39
- end
40
-
41
- def indentation
42
- @indentation ||= @prefix + (@indent * @level)
43
- end
44
-
45
- def + other
46
- indentation + other
47
- end
48
-
49
- def << text
50
- text.gsub(/^/){|m| m + indentation}
51
- end
52
-
53
- def by(depth)
54
- Indentation.new(@prefix, @level + depth, @indent)
55
- end
56
-
57
- def with_prefix(prefix)
58
- Indentation.new(prefix, @level, @indent)
59
- end
60
-
61
- def self.none
62
- self.new('', 0, TAB)
63
- end
64
- end
65
-
66
- class Substitutions
67
- def initialize(ordered = [])
68
- @ordered = ordered
69
- end
70
-
71
- def freeze
72
- @ordered.freeze
73
-
74
- super
75
- end
76
-
77
- def []= keyword, value
78
- if Array === value
79
- open, close = *value.each_slice(value.length / 2)
80
- @ordered << NestedSubstitution.new(keyword, open, close)
81
- else
82
- @ordered << SymbolicSubstitution.new('$' + keyword, value.to_s)
83
- end
84
- end
85
-
86
- def << substitution
87
- @ordered << substition
88
- end
89
-
90
- def + other
91
- Substitutions.new(@ordered + other.ordered)
92
- end
93
-
94
- attr :ordered
95
-
96
- def call(text)
97
- apply(text)
98
- end
99
-
100
- def apply(text)
101
- return text unless @ordered.count > 0
102
-
103
- grouped = [[@ordered.first]]
104
-
105
- @ordered.drop(1).each do |substitution|
106
- if grouped.last[0].class == substitution.class
107
- grouped.last << substitution
108
- else
109
- grouped << [substitution]
110
- end
111
- end
112
-
113
- grouped.each do |group|
114
- text = group.first.class.apply(text, group)
115
- end
116
-
117
- return text
118
- end
119
-
120
- class SymbolicSubstitution
121
- def initialize(keyword, value)
122
- @keyword = keyword
123
- @value = value
124
- end
125
-
126
- attr :keyword
127
- attr :value
128
-
129
- def freeze
130
- @keyword.freeze
131
- @value.freeze
132
-
133
- super
134
- end
135
-
136
- def apply(text)
137
- text.gsub(@keyword, @value)
138
- end
139
-
140
- def self.apply(text, group)
141
- substitutions = Hash[group.collect{|substitution| [substitution.keyword, substitution.value]}]
142
-
143
- pattern = Regexp.new(substitutions.keys.map{|key| Regexp.escape(key)}.join('|'))
144
-
145
- text.gsub(pattern) {|key| substitutions[key]}
146
- end
147
- end
148
-
149
- class NestedSubstitution
150
- def initialize(keyword, open, close, indent = "\t")
151
- @keyword = keyword
152
-
153
- @open = open
154
- @close = close
155
-
156
- @indent = indent
157
- end
158
-
159
- def freeze
160
- @keyword.freeze
161
- @open.freeze
162
- @close.freeze
163
- @indent.freeze
164
-
165
- super
166
- end
167
-
168
- def line_pattern(prefix = '')
169
- tag_pattern = Regexp.escape('<' + prefix + @keyword + '>')
170
-
171
- # Line matching pattern:
172
- Regexp.new('^(.*?)' + tag_pattern + '(.*)$', Regexp::MULTILINE | Regexp::EXTENDED)
173
- end
174
-
175
- def write_open(prefix, postfix, output, indentation)
176
- depth = @open.size
177
- indentation = indentation.with_prefix(prefix)
178
-
179
- #output.write(prefix)
180
- (0...depth).each do |i|
181
- chunk = @open[i]
182
- chunk.chomp! if i == depth-1
183
-
184
- output.write(indentation.by(i) << chunk)
185
- end
186
- output.write(postfix)
187
- end
188
-
189
- def write_close(prefix, postfix, output, indentation)
190
- depth = @close.size
191
- indentation = indentation.with_prefix(prefix)
192
-
193
- #output.write(prefix)
194
- (0...depth).reverse_each do |i|
195
- chunk = @close[-1 - i]
196
- chunk.chomp! if i == 0
197
-
198
- output.write(indentation.by(i) << chunk)
199
- end
200
- output.write(postfix)
201
- end
202
-
203
- def apply(text, level = 0)
204
- open_pattern = line_pattern
205
- close_pattern = line_pattern('/')
206
-
207
- lines = text.each_line
208
- output = StringIO.new
209
-
210
- indent = lambda do |level, indentation|
211
- while line = lines.next rescue nil
212
- if line =~ open_pattern
213
- write_open($1, $2, output, indentation)
214
-
215
- indent[level + @open.count, indentation.by(@open.count)]
216
-
217
- write_close($1, $2, output, indentation)
218
- elsif line =~ close_pattern
219
- break
220
- else
221
- output.write(indentation + line)
222
- end
223
- end
224
- end
225
-
226
- indent[0, Indentation.none]
227
-
228
- return output.string
229
- end
230
-
231
- def self.apply(text, group)
232
- group.each do |substitution|
233
- text = substitution.apply(text)
234
- end
235
-
236
- return text
237
- end
238
- end
239
-
240
- # Create a set of substitutions from the given context which includes a set of useful defaults.
241
- def self.for_context(context)
242
- substitutions = self.new
243
-
244
- # The user's current name:
245
- substitutions['AUTHOR_NAME'] = context.metadata.user.name
246
- substitutions['AUTHOR_EMAIL'] = context.metadata.user.email
247
-
248
- substitutions['PROJECT_NAME'] = context.project.name
249
- substitutions['LICENSE'] = context.project.license
250
-
251
- current_date = Time.new
252
- substitutions['DATE'] = current_date.strftime("%-d/%-m/%Y")
253
- substitutions['YEAR'] = current_date.strftime("%Y")
254
-
255
- return substitutions
256
- end
257
- end
258
- end
@@ -1,54 +0,0 @@
1
-
2
- #
3
- # This file is part of the "Teapot" project, and is released under the MIT license.
4
- #
5
-
6
- teapot_version "1.0.0"
7
-
8
- define_configuration 'test' do |configuration|
9
- configuration.public!
10
-
11
- configuration[:source] = "../kurocha"
12
-
13
- configuration.require "variants"
14
-
15
- configuration.require "platform-darwin-osx"
16
- configuration.require "platform-darwin-ios"
17
-
18
- configuration.require "unit-test"
19
- configuration.require "euclid"
20
-
21
- configuration.require "ogg"
22
- configuration.require "vorbis"
23
-
24
- configuration.require "jpeg"
25
- configuration.require "png"
26
-
27
- configuration.require "freetype"
28
-
29
- configuration.require "dream"
30
- configuration.require "tagged-format"
31
-
32
- configuration.require "opencv"
33
- end
34
-
35
- define_generator "generator_spec" do |generator|
36
- generator.generate do
37
- directory = context.root + 'tmp'
38
-
39
- directory.mkpath
40
-
41
- substitutions = Substitutions.new
42
-
43
- substitutions['NAME'] = 'Alice'
44
- substitutions['VARIABLE'] = '42'
45
-
46
- generator.copy('template', directory, substitutions)
47
- end
48
- end
49
-
50
- define_target "target_spec" do |target|
51
- target.provides "Test/TargetSpec" do
52
- append targets 'target_spec'
53
- end
54
- end
@@ -1 +0,0 @@
1
- This $VARIABLE will be substituted.
@@ -1,46 +0,0 @@
1
- # Copyright, 2015, 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/context'
22
- require 'build/files/system'
23
-
24
- module Teapot::GeneratorSpec
25
- ROOT = Build::Files::Path.new(__dir__) + "generator_spec"
26
- TMP_PATH = ROOT + 'tmp'
27
- ALICE_PATH = TMP_PATH + 'Alice.txt'
28
-
29
- describe Teapot::Generator do
30
- after do
31
- TMP_PATH.delete
32
- end
33
-
34
- it "should rename files and expand variables" do
35
- context = Teapot::Context.new(ROOT)
36
-
37
- generator = context.generators["generator_spec"]
38
-
39
- generator.generate!
40
-
41
- expect(TMP_PATH).to be_exist
42
- expect(ALICE_PATH).to be_exist
43
- expect(ALICE_PATH.read).to be =~ /42/
44
- end
45
- end
46
- end
@@ -1,50 +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/merge'
22
-
23
- module Teapot::MergeSpec
24
- describe Teapot::Merge do
25
- TARGET_FILE = <<-EOF
26
- class Bob {
27
- int alice();
28
- }
29
- EOF
30
-
31
- TEMPLATE = <<-EOF
32
- class Bob {
33
- int bob();
34
- }
35
- EOF
36
-
37
- MERGED = <<-EOF
38
- class Bob {
39
- int alice();
40
- int bob();
41
- }
42
- EOF
43
-
44
- it "can merge two files" do
45
- merged = Teapot::Merge.combine(TARGET_FILE.lines, TEMPLATE.lines)
46
-
47
- expect(merged).to be == MERGED.lines
48
- end
49
- end
50
- end
@@ -1,31 +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/metadata'
22
-
23
- module Teapot::MetadataSpec
24
- describe Teapot::Metadata do
25
- let(:metadata) {Teapot::Metadata.new(nil)}
26
- it "can provide user name" do
27
- expect(metadata.user.name).to_not be nil
28
- expect(metadata.user.name.length).to be > 0
29
- end
30
- end
31
- end
@@ -1,65 +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/substitutions'
22
-
23
- module Teapot::SubstitutionsSpec
24
- describe Teapot::Substitutions do
25
- it "should substitute symbolic expressions" do
26
- input = <<-EOF
27
- $FOO $BAR
28
- EOF
29
-
30
- output = <<-EOF
31
- baz bar
32
- EOF
33
-
34
- substitutions = Teapot::Substitutions.new
35
- substitutions['FOO'] = 'baz'
36
- substitutions['BAR'] = 'bar'
37
-
38
- expect(substitutions.apply(input)).to be == output
39
- end
40
-
41
- it "should indent nestest expressions" do
42
- input = <<-EOF
43
- <FOO>
44
- $BAR
45
- </FOO>
46
- EOF
47
-
48
- output = <<-EOF
49
- enter
50
- {
51
- foo
52
- Hello World
53
- bar
54
- }
55
- exit
56
- EOF
57
-
58
- substitutions = Teapot::Substitutions.new
59
- substitutions['FOO'] = ["enter\n{\n", "foo\n", "bar\n", "}\nexit\n"]
60
- substitutions['BAR'] = 'Hello World'
61
-
62
- expect(substitutions.apply(input)).to be == output
63
- end
64
- end
65
- end
@@ -1,41 +0,0 @@
1
-
2
- teapot_version "1.0"
3
-
4
- $log = []
5
-
6
- define_target "A" do |target|
7
- target.build do
8
- $log << :a_enter
9
- run! "sleep 1"
10
- $log << :a_exit
11
- end
12
-
13
- target.provides "Teapot/A"
14
- end
15
-
16
- define_target "B" do |target|
17
- target.build do
18
- $log << :b_enter
19
- run! "sleep 1"
20
- $log << :b_exit
21
- end
22
-
23
- target.provides "Teapot/B"
24
- end
25
-
26
- define_target "C" do |target|
27
- target.build do
28
- $log << :c_enter
29
- # This should not execute until A and B have completed.
30
- run! "sleep 1"
31
- $log << :c_exit
32
- end
33
-
34
- target.depends "Teapot/A"
35
- target.depends "Teapot/B"
36
-
37
- target.provides "Teapot/C"
38
- end
39
-
40
- define_configuration "wait_spec" do |configuration|
41
- end
@@ -1,53 +0,0 @@
1
- # Copyright, 2016, 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/context'
22
- require 'build/controller'
23
-
24
- module Teapot::WaitSpec
25
- ROOT = Build::Files::Path.join(__dir__, "wait_spec")
26
-
27
- describe Teapot::Target do
28
- let(:logger) {Logger.new($stdout).tap{|logger| logger.level = Logger::DEBUG; logger.formatter = Build::CompactFormatter.new}}
29
-
30
- it "should wait on completion of dependent targets" do
31
- context = Teapot::Context.new(ROOT)
32
-
33
- a, b, c = context.targets.values_at('A', 'B', 'C')
34
-
35
- chain = context.dependency_chain(["Teapot/C"])
36
- ordered = chain.ordered
37
-
38
- controller = Build::Controller.new(logger: logger) do |controller|
39
- ordered.each do |resolution|
40
- target = resolution.provider
41
-
42
- environment = target.environment(context.configuration, chain)
43
-
44
- if target.build
45
- controller.add_target(target, environment.flatten)
46
- end
47
- end
48
- end
49
-
50
- controller.update
51
- end
52
- end
53
- end