rscons 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWYzYjNkYTFlM2JlMGE1YWU0MDU0YTI0Zjg5Zjk4NDFiODViMmMyNA==
4
+ NjE2OGU4MDZjYTk0MDhkYWU2NzgxZGJjYjgzZmIxYTI0NTk4YzU2Zg==
5
5
  data.tar.gz: !binary |-
6
- NmEzYWRmNDQ1NTIyZjE2ZTY2ZmU3MTljNDkzNmQxYzNkODcyNGNlYQ==
6
+ OTkwYjJhODI0NjgzZTc2NDg3MGNmMDlhNmE2MjgxOWNmNWY4YjE3ZQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NWE5NGFhMjNhNWM2NTE1ZGNmZDk1ZDUxZjNhMzFhYzQ0Mjk4YzZmNzg0YjJk
10
- NzgzMmVlOWM3ZmFkNTM3ODY0MjBkOWNmMTM0NTdmNGIyZjE1MTg0MWMyZDJm
11
- ZjU1ZWIwMmY0NjE3NTkyYzI1MzMzYTBkYjcwNjcwOWM5ZTE1NzA=
9
+ NTQzMjdjYzkxODUwNjIzNTg0NDI2ZmIxM2QzZTllNWJhNjRiOWRmMDc0OTUz
10
+ ZDJjMmI0MDMxMGE3NWRmZTFmZjA3NmE0YWNkNWYzNmVkY2VmZTIyNTEwOTZl
11
+ YTBkNGZlZjRhYjZlNjgxNDIyZTJlNWJkZjhkMjgwY2E2YTA4Mzc=
12
12
  data.tar.gz: !binary |-
13
- NzdkOWE1Nzk2NzIwZjQ4YTZhNGI5ZjFiZjEzYWJjMDcwN2IzOTJhOGVmNjQy
14
- ZGQ3ZTNkNzIxYTQ1OTI5MTZlMDYzOGU3YThkYmNlNzlkMjM3NDhiMDdiZmIz
15
- NGIyZDZhYzI0ZTdhMzYwODMxMDU3NTcwZTA0Njg2YTI1YjljZmI=
13
+ MjM1ZTY0YmZlNDcwMGRiNTU3ZDQyZWVjMGMwYmM1MGM2YjlmODk0MGRmMjNm
14
+ NjVmOWI5MjUxMTI0ZDA0ZjZhMWU1OWRhOWNjZDMxZjYwMzAyNDQ3ZTY3NDA2
15
+ YzIxYTAwMjExNzMwYjgxMmYxYmEyMTUwZDdhOWNjNTEyNmY3Y2E=
@@ -0,0 +1,12 @@
1
+ Rscons::Environment.new do |env|
2
+ env.append('CPPPATH' => Dir['src/**/*/'])
3
+ env.build_dir(%r{^src/([^/]+)/}, 'build_\\1/')
4
+ env.add_tweaker do |build_op|
5
+ if build_op[:target] =~ %r{build_one/.*\.o}
6
+ build_op[:vars]["CFLAGS"] << "-O1"
7
+ elsif build_op[:target] =~ %r{build_two/.*\.o}
8
+ build_op[:vars]["CFLAGS"] << "-O2"
9
+ end
10
+ end
11
+ env.Program('tweaker', Dir['src/**/*.c'])
12
+ end
@@ -22,6 +22,7 @@ module Rscons
22
22
  @targets = {}
23
23
  @builders = {}
24
24
  @build_dirs = []
25
+ @tweakers = []
25
26
  @varset[:exclude_builders] ||= []
26
27
  unless @varset[:exclude_builders] == :all
27
28
  exclude_builders = Set.new(@varset[:exclude_builders] || [])
@@ -45,7 +46,7 @@ module Rscons
45
46
  # Make a copy of the Environment object.
46
47
  # The cloned environment will contain a copy of all environment options,
47
48
  # construction variables, builders, and build directories. It will not
48
- # contain a copy of the targets.
49
+ # contain a copy of the targets or tweakers.
49
50
  # If a block is given, the Environment object is yielded to the block and
50
51
  # when the block returns, the {#process} method is automatically called.
51
52
  def clone(variables = {})
@@ -74,6 +75,11 @@ module Rscons
74
75
  end
75
76
  end
76
77
 
78
+ # Add a tweaker block to the Environment.
79
+ def add_tweaker(&block)
80
+ @tweakers << block
81
+ end
82
+
77
83
  # Specify a build directory for this Environment.
78
84
  # Source files from src_dir will produce object files under obj_dir.
79
85
  def build_dir(src_dir, obj_dir)
@@ -136,11 +142,11 @@ module Rscons
136
142
  if @targets[target][:source].map do |src|
137
143
  targets_processed.include?(src) or not @targets.include?(src) or process_target.call(src)
138
144
  end.all?
139
- @targets[target][:builder].run(target,
140
- @targets[target][:source],
141
- cache,
142
- self,
143
- @targets[target][:vars] || {})
145
+ run_builder(@targets[target][:builder],
146
+ target,
147
+ @targets[target][:source],
148
+ cache,
149
+ @targets[target][:vars] || {})
144
150
  else
145
151
  false
146
152
  end
@@ -238,6 +244,7 @@ module Rscons
238
244
  # @param sources [Array] List of source files to build.
239
245
  # @param suffixes [Array] List of suffixes to try to convert source files into.
240
246
  # @param cache [Cache] The Cache.
247
+ # @param vars [Hash] Extra variables to pass to the builder.
241
248
  # Return a list of the converted file names.
242
249
  def build_sources(sources, suffixes, cache, vars = {})
243
250
  sources.map do |source|
@@ -249,7 +256,7 @@ module Rscons
249
256
  converted_fname = get_build_fname(source, suffix)
250
257
  builder = @builders.values.find { |b| b.produces?(converted_fname, source, self) }
251
258
  if builder
252
- converted = builder.run(converted_fname, [source], cache, self, vars)
259
+ converted = run_builder(builder, converted_fname, [source], cache, vars)
253
260
  return nil unless converted
254
261
  break
255
262
  end
@@ -258,5 +265,26 @@ module Rscons
258
265
  end
259
266
  end
260
267
  end
268
+
269
+ # Invoke a builder to build the given target based on the given sources.
270
+ # @param builder [Builder] The Builder to use.
271
+ # @param target [String] The target output file.
272
+ # @param sources [Array] List of source files.
273
+ # @param cache [Cache] The Cache.
274
+ # @param vars [Hash] Extra variables to pass to the builder.
275
+ # Return the result of the builder's run() method.
276
+ def run_builder(builder, target, sources, cache, vars)
277
+ vars = @varset.merge(vars)
278
+ @tweakers.each do |tweaker_block|
279
+ build_operation = {
280
+ builder: builder,
281
+ target: target,
282
+ sources: sources,
283
+ vars: vars,
284
+ }
285
+ tweaker_block.call(build_operation)
286
+ end
287
+ builder.run(target, sources, cache, self, vars)
288
+ end
261
289
  end
262
290
  end
@@ -44,7 +44,7 @@ module Rscons
44
44
  # @param values [VarSet, Hash] New set of variables.
45
45
  def append(values)
46
46
  values = values.vars if values.is_a?(VarSet)
47
- @vars.merge!(values)
47
+ @vars.merge!(Marshal.load(Marshal.dump(values)))
48
48
  self
49
49
  end
50
50
 
@@ -1,4 +1,4 @@
1
1
  module Rscons
2
2
  # gem version
3
- VERSION = "0.0.12"
3
+ VERSION = "0.0.13"
4
4
  end
@@ -11,10 +11,10 @@ describe Rscons do
11
11
  FileUtils.rm_rf('build_tests_run')
12
12
  end
13
13
 
14
- def build_testdir
15
- if File.exists?("build.rb")
16
- build_rb = File.read("build.rb")
17
- File.open("build.rb", "w") do |fh|
14
+ def build_testdir(build_script = "build.rb")
15
+ if File.exists?(build_script)
16
+ build_rb = File.read(build_script)
17
+ File.open(build_script, "w") do |fh|
18
18
  fh.puts(<<EOF + build_rb)
19
19
  require "simplecov"
20
20
 
@@ -27,7 +27,7 @@ end
27
27
  require "rscons"
28
28
  EOF
29
29
  end
30
- IO.popen(%{ruby -I #{@owd}/lib build.rb}) do |io|
30
+ IO.popen(%{ruby -I #{@owd}/lib #{build_script}}) do |io|
31
31
  io.readlines.reject do |line|
32
32
  line =~ /^Coverage report/
33
33
  end
@@ -35,11 +35,11 @@ EOF
35
35
  end
36
36
  end
37
37
 
38
- def test_dir(build_test_directory)
38
+ def test_dir(build_test_directory, build_script = "build.rb")
39
39
  @build_test_name = build_test_directory
40
40
  FileUtils.cp_r("build_tests/#{build_test_directory}", 'build_tests_run')
41
41
  Dir.chdir("build_tests_run")
42
- build_testdir
42
+ build_testdir(build_script)
43
43
  end
44
44
 
45
45
  def file_sub(fname)
@@ -207,4 +207,14 @@ EOF
207
207
  File.exists?('library').should be_true
208
208
  `ar t lib.a`.should == "one.o\ntwo.o\n"
209
209
  end
210
+
211
+ it 'supports tweakers to override construction variables' do
212
+ lines = test_dir("build_dir", "tweaker_build.rb")
213
+ `./tweaker`.should == "Hello from two()\n"
214
+ lines.should =~ [
215
+ 'gcc -c -o build_one/one.o -MMD -MF build_one/one.mf -Isrc/one/ -Isrc/two/ -O1 src/one/one.c',
216
+ 'gcc -c -o build_two/two.o -MMD -MF build_two/two.mf -Isrc/one/ -Isrc/two/ -O2 src/two/two.c',
217
+ 'gcc -o tweaker build_one/one.o build_two/two.o',
218
+ ]
219
+ end
210
220
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rscons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Holtrop
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-08 00:00:00.000000000 Z
11
+ date: 2013-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core
@@ -153,6 +153,7 @@ files:
153
153
  - build_tests/build_dir/src/one/one.c
154
154
  - build_tests/build_dir/src/two/two.c
155
155
  - build_tests/build_dir/src/two/two.h
156
+ - build_tests/build_dir/tweaker_build.rb
156
157
  - build_tests/clone_env/build.rb
157
158
  - build_tests/clone_env/src/program.c
158
159
  - build_tests/custom_builder/build.rb