rscons 0.0.7 → 0.0.8
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.
- data/lib/rscons/builder.rb +1 -1
- data/lib/rscons/builders/object.rb +1 -1
- data/lib/rscons/cache.rb +31 -0
- data/lib/rscons/environment.rb +0 -1
- data/lib/rscons/version.rb +1 -1
- data/lib/rscons.rb +16 -0
- data/spec/build_tests_spec.rb +29 -0
- metadata +4 -4
data/lib/rscons/builder.rb
CHANGED
@@ -24,7 +24,7 @@ module Rscons
|
|
24
24
|
# Return the name of the target or false on failure.
|
25
25
|
def standard_build(short_cmd_string, target, command, sources, env, cache)
|
26
26
|
unless cache.up_to_date?(target, command, sources)
|
27
|
-
|
27
|
+
cache.mkdir_p(File.dirname(target))
|
28
28
|
FileUtils.rm_f(target)
|
29
29
|
return false unless env.execute(short_cmd_string, command)
|
30
30
|
cache.register_build(target, command, sources)
|
@@ -55,7 +55,7 @@ module Rscons
|
|
55
55
|
end
|
56
56
|
command = env.build_command(env["#{com_prefix}COM"], vars)
|
57
57
|
unless cache.up_to_date?(target, command, sources)
|
58
|
-
|
58
|
+
cache.mkdir_p(File.dirname(target))
|
59
59
|
FileUtils.rm_f(target)
|
60
60
|
return false unless env.execute("#{com_prefix} #{target}", command)
|
61
61
|
deps = sources
|
data/lib/rscons/cache.rb
CHANGED
@@ -36,6 +36,11 @@ module Rscons
|
|
36
36
|
# ]
|
37
37
|
# }
|
38
38
|
# }
|
39
|
+
# directories: {
|
40
|
+
# 'build' => true,
|
41
|
+
# 'build/one' => true,
|
42
|
+
# 'build/two' => true,
|
43
|
+
# }
|
39
44
|
# }
|
40
45
|
class Cache
|
41
46
|
#### Constants
|
@@ -57,6 +62,7 @@ module Rscons
|
|
57
62
|
def initialize
|
58
63
|
@cache = YAML.load(File.read(CACHE_FILE)) rescue {
|
59
64
|
targets: {},
|
65
|
+
directories: {},
|
60
66
|
version: VERSION,
|
61
67
|
}
|
62
68
|
@lookup_checksums = {}
|
@@ -132,6 +138,31 @@ module Rscons
|
|
132
138
|
}
|
133
139
|
end
|
134
140
|
|
141
|
+
# Return a list of targets that have been built
|
142
|
+
def targets
|
143
|
+
@cache[:targets].keys
|
144
|
+
end
|
145
|
+
|
146
|
+
# Make any needed directories and record the ones that are created for
|
147
|
+
# removal upon a "clean" operation.
|
148
|
+
def mkdir_p(path)
|
149
|
+
parts = path.split(/[\\\/]/)
|
150
|
+
(0..parts.size).each do |i|
|
151
|
+
subpath = File.join(*parts[0, i + 1])
|
152
|
+
unless File.exists?(subpath)
|
153
|
+
FileUtils.mkdir(subpath)
|
154
|
+
unless @cache[:directories].include?(subpath)
|
155
|
+
@cache[:directories][subpath] = true
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
# Return a list of directories which were created as a part of the build
|
162
|
+
def directories
|
163
|
+
@cache[:directories].keys
|
164
|
+
end
|
165
|
+
|
135
166
|
# Private Instance Methods
|
136
167
|
private
|
137
168
|
|
data/lib/rscons/environment.rb
CHANGED
data/lib/rscons/version.rb
CHANGED
data/lib/rscons.rb
CHANGED
@@ -22,4 +22,20 @@ module Rscons
|
|
22
22
|
|
23
23
|
class BuildError < Exception
|
24
24
|
end
|
25
|
+
|
26
|
+
# Remove all generated files
|
27
|
+
def self.clean
|
28
|
+
cache = Cache.new
|
29
|
+
# remove all built files
|
30
|
+
cache.targets.each do |target|
|
31
|
+
FileUtils.rm_f(target)
|
32
|
+
end
|
33
|
+
# remove all created directories if they are empty
|
34
|
+
cache.directories.sort {|a, b| b.size <=> a.size}.each do |directory|
|
35
|
+
if (Dir.entries(directory) - ['.', '..']).empty?
|
36
|
+
Dir.rmdir(directory) rescue nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
Cache.clear
|
40
|
+
end
|
25
41
|
end
|
data/spec/build_tests_spec.rb
CHANGED
@@ -120,6 +120,35 @@ describe Rscons do
|
|
120
120
|
File.exists?('build/two/two.o').should be_true
|
121
121
|
end
|
122
122
|
|
123
|
+
it 'cleans built files' do
|
124
|
+
lines = test_dir('build_dir')
|
125
|
+
`./build_dir`.should == "Hello from two()\n"
|
126
|
+
File.exists?('build/one/one.o').should be_true
|
127
|
+
File.exists?('build/two/two.o').should be_true
|
128
|
+
Rscons.clean
|
129
|
+
File.exists?('build/one/one.o').should be_false
|
130
|
+
File.exists?('build/two/two.o').should be_false
|
131
|
+
File.exists?('build/one').should be_false
|
132
|
+
File.exists?('build/two').should be_false
|
133
|
+
File.exists?('build').should be_false
|
134
|
+
File.exists?('src/one/one.c').should be_true
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'does not clean created directories if other non-rscons-generated files reside there' do
|
138
|
+
lines = test_dir('build_dir')
|
139
|
+
`./build_dir`.should == "Hello from two()\n"
|
140
|
+
File.exists?('build/one/one.o').should be_true
|
141
|
+
File.exists?('build/two/two.o').should be_true
|
142
|
+
File.open('build/two/tmp', 'w') { |fh| fh.puts "dum" }
|
143
|
+
Rscons.clean
|
144
|
+
File.exists?('build/one/one.o').should be_false
|
145
|
+
File.exists?('build/two/two.o').should be_false
|
146
|
+
File.exists?('build/one').should be_false
|
147
|
+
File.exists?('build/two').should be_true
|
148
|
+
File.exists?('build').should be_true
|
149
|
+
File.exists?('src/one/one.c').should be_true
|
150
|
+
end
|
151
|
+
|
123
152
|
it 'allows Ruby classes as custom builders to be used to construct files' do
|
124
153
|
lines = test_dir('custom_builder')
|
125
154
|
lines.should == ['CC program.o', 'LD program']
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rscons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
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: 2013-09-
|
12
|
+
date: 2013-09-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec-core
|
@@ -220,7 +220,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
220
220
|
version: '0'
|
221
221
|
segments:
|
222
222
|
- 0
|
223
|
-
hash:
|
223
|
+
hash: 1569804544346672043
|
224
224
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
225
|
none: false
|
226
226
|
requirements:
|
@@ -229,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
229
229
|
version: '0'
|
230
230
|
segments:
|
231
231
|
- 0
|
232
|
-
hash:
|
232
|
+
hash: 1569804544346672043
|
233
233
|
requirements: []
|
234
234
|
rubyforge_project:
|
235
235
|
rubygems_version: 1.8.23
|