rscons 1.4.3 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rscons.rb +75 -5
- data/lib/rscons/build_target.rb +36 -0
- data/lib/rscons/builder.rb +41 -3
- data/lib/rscons/builders/cfile.rb +15 -0
- data/lib/rscons/builders/disassemble.rb +15 -0
- data/lib/rscons/builders/library.rb +17 -2
- data/lib/rscons/builders/object.rb +37 -5
- data/lib/rscons/builders/preprocess.rb +15 -0
- data/lib/rscons/builders/program.rb +42 -2
- data/lib/rscons/cache.rb +26 -6
- data/lib/rscons/environment.rb +259 -19
- data/lib/rscons/varset.rb +33 -10
- data/lib/rscons/version.rb +1 -1
- data/rscons.gemspec +8 -10
- metadata +38 -103
- checksums.yaml +0 -15
- data/.gitignore +0 -18
- data/.rspec +0 -2
- data/Gemfile +0 -4
- data/README.md +0 -384
- data/Rakefile.rb +0 -26
- data/build_tests/build_dir/src/one/one.c +0 -6
- data/build_tests/build_dir/src/two/two.c +0 -7
- data/build_tests/build_dir/src/two/two.h +0 -6
- data/build_tests/clone_env/src/program.c +0 -6
- data/build_tests/custom_builder/program.c +0 -7
- data/build_tests/d/main.d +0 -6
- data/build_tests/header/header.c +0 -7
- data/build_tests/header/header.h +0 -6
- data/build_tests/library/one.c +0 -8
- data/build_tests/library/three.c +0 -0
- data/build_tests/library/two.c +0 -0
- data/build_tests/simple/simple.c +0 -6
- data/build_tests/simple_cc/simple.cc +0 -8
- data/build_tests/two_sources/one.c +0 -8
- data/build_tests/two_sources/two.c +0 -3
- data/spec/build_tests_spec.rb +0 -527
- data/spec/rscons/builders/cfile_spec.rb +0 -28
- data/spec/rscons/builders/disassemble_spec.rb +0 -17
- data/spec/rscons/builders/library_spec.rb +0 -18
- data/spec/rscons/builders/object_spec.rb +0 -23
- data/spec/rscons/builders/preprocess_spec.rb +0 -18
- data/spec/rscons/builders/program_spec.rb +0 -18
- data/spec/rscons/cache_spec.rb +0 -271
- data/spec/rscons/environment_spec.rb +0 -361
- data/spec/rscons/varset_spec.rb +0 -163
- data/spec/rscons_spec.rb +0 -26
- data/spec/spec_helper.rb +0 -7
data/.rspec
DELETED
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,384 +0,0 @@
|
|
1
|
-
# Rscons
|
2
|
-
|
3
|
-
Software construction library inspired by SCons and implemented in Ruby
|
4
|
-
|
5
|
-
[![Gem Version](https://badge.fury.io/rb/rscons.png)](http://badge.fury.io/rb/rscons)
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
gem "rscons"
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle install
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install rscons
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
Rscons is a Ruby library.
|
24
|
-
It can be called from a standalone Ruby script or it can be used with rake and
|
25
|
-
called from your Rakefile.
|
26
|
-
|
27
|
-
### Example: Building a C Program
|
28
|
-
|
29
|
-
```ruby
|
30
|
-
Rscons::Environment.new do |env|
|
31
|
-
env["CFLAGS"] << "-Wall"
|
32
|
-
env.Program("program", Dir["**/*.c"])
|
33
|
-
end
|
34
|
-
```
|
35
|
-
|
36
|
-
### Example: Building a D Program
|
37
|
-
|
38
|
-
```ruby
|
39
|
-
Rscons::Environment.new do |env|
|
40
|
-
env["DFLAGS"] << "-Wall"
|
41
|
-
env.Program("program", Dir["**/*.d"])
|
42
|
-
end
|
43
|
-
```
|
44
|
-
|
45
|
-
### Example: Cloning an Environment
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
main_env = Rscons::Environment.new do |env|
|
49
|
-
# Store object files from sources under "src" in "build/main"
|
50
|
-
env.build_dir("src", "build/main")
|
51
|
-
env["CFLAGS"] = ["-DSOME_DEFINE", "-O3"]
|
52
|
-
env["LIBS"] = ["SDL"]
|
53
|
-
env.Program("program", Dir["src/**/*.cc"])
|
54
|
-
end
|
55
|
-
|
56
|
-
debug_env = main_env.clone do |env|
|
57
|
-
# Store object files from sources under "src" in "build/debug"
|
58
|
-
env.build_dir("src", "build/debug")
|
59
|
-
env["CFLAGS"] -= ["-O3"]
|
60
|
-
env["CFLAGS"] += ["-g", "-O0"]
|
61
|
-
env.Program("program-debug", Dir["src/**/*.cc"])
|
62
|
-
end
|
63
|
-
```
|
64
|
-
|
65
|
-
### Example: Custom Builder
|
66
|
-
|
67
|
-
Custom builders are implemented as classes which extend from `Rscons::Builder`.
|
68
|
-
The builder must have a `run` method which is called to invoke the builder.
|
69
|
-
The `run` method should return the name of the target built on success, and
|
70
|
-
`false` on failure.
|
71
|
-
|
72
|
-
```ruby
|
73
|
-
class GenerateFoo < Rscons::Builder
|
74
|
-
def run(target, sources, cache, env, vars)
|
75
|
-
cache.mkdir_p(File.dirname(target))
|
76
|
-
File.open(target, "w") do |fh|
|
77
|
-
fh.puts <<EOF
|
78
|
-
#define GENERATED 42
|
79
|
-
EOF
|
80
|
-
end
|
81
|
-
target
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
Rscons::Environment.new do |env|
|
86
|
-
env.add_builder(GenerateFoo.new)
|
87
|
-
env.GenerateFoo("foo.h", [])
|
88
|
-
env.Program("a.out", Dir["*.c"])
|
89
|
-
end
|
90
|
-
```
|
91
|
-
|
92
|
-
### Example: Custom Builder That Only Regenerates When Necessary
|
93
|
-
|
94
|
-
```ruby
|
95
|
-
class CmdBuilder < Rscons::Builder
|
96
|
-
def run(target, sources, cache, env, vars)
|
97
|
-
cmd = ["cmd", "-i", sources.first, "-o", target]
|
98
|
-
unless cache.up_to_date?(target, cmd, sources, env)
|
99
|
-
cache.mkdir_p(File.dirname(target))
|
100
|
-
system(cmd)
|
101
|
-
cache.register_build(target, cmd, sources, env)
|
102
|
-
end
|
103
|
-
target
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
Rscons::Environment.new do |env|
|
108
|
-
env.add_builder(CmdBuilder.new)
|
109
|
-
env.CmdBuilder("foo.gen", "foo_gen.cfg")
|
110
|
-
end
|
111
|
-
```
|
112
|
-
|
113
|
-
### Example: Custom Builder That Generates Multiple Output Files
|
114
|
-
|
115
|
-
```ruby
|
116
|
-
class CModuleGenerator < Rscons::Builder
|
117
|
-
def run(target, sources, cache, env, vars)
|
118
|
-
c_fname = target
|
119
|
-
h_fname = target.sub(/\.c$/, ".h")
|
120
|
-
cmd = ["generate_c_and_h", sources.first, c_fname, h_fname]
|
121
|
-
unless cache.up_to_date?([c_fname, h_fname], cmd, sources, env)
|
122
|
-
cache.mkdir_p(File.dirname(target))
|
123
|
-
system(cmd)
|
124
|
-
cache.register_build([c_fname, h_fname], cmd, sources, env)
|
125
|
-
end
|
126
|
-
target
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
Rscons::Environment.new do |env|
|
131
|
-
env.add_builder(CModuleGenerator.new)
|
132
|
-
env.CModuleGenerator("build/foo.c", "foo_gen.cfg")
|
133
|
-
end
|
134
|
-
```
|
135
|
-
|
136
|
-
### Example: Custom Builder Using Builder#standard_build()
|
137
|
-
|
138
|
-
The `standard_build` method from the `Rscons::Builder` base class can be used
|
139
|
-
when the builder needs to execute a system command to produce the target file.
|
140
|
-
The `standard_build` method will return the correct value so its return value
|
141
|
-
can be used as the return value from the `run` method.
|
142
|
-
|
143
|
-
```ruby
|
144
|
-
class CmdBuilder < Rscons::Builder
|
145
|
-
def run(target, sources, cache, env, vars)
|
146
|
-
cmd = ["cmd", "-i", sources.first, "-o", target]
|
147
|
-
standard_build("CmdBld #{target}", target, cmd, sources, env, cache)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
Rscons::Environment.new do |env|
|
152
|
-
env.add_builder(CmdBuilder.new)
|
153
|
-
env.CmdBuilder("foo.gen", "foo_gen.cfg")
|
154
|
-
end
|
155
|
-
```
|
156
|
-
|
157
|
-
### Example: Using different compilation flags for some sources
|
158
|
-
|
159
|
-
```ruby
|
160
|
-
Rscons::Environment.new do |env|
|
161
|
-
env["CFLAGS"] = ["-O3", "-Wall", "-DDEFINE"]
|
162
|
-
env.add_build_hook do |build_op|
|
163
|
-
if build_op[:target] =~ %r{build/third-party}
|
164
|
-
build_op[:vars]["CFLAGS"] -= ["-Wall"]
|
165
|
-
end
|
166
|
-
end
|
167
|
-
env.build_dir("src", "build")
|
168
|
-
env.Program("program", Dir["**/*.cc"])
|
169
|
-
end
|
170
|
-
```
|
171
|
-
|
172
|
-
Each build hook block will be invoked for every build operation, so the block
|
173
|
-
should test the target or sources if its action should only apply to some
|
174
|
-
subset of build targets or source files.
|
175
|
-
|
176
|
-
The `build_op` parameter to the build hook block is a Hash describing the
|
177
|
-
build operation with the following keys:
|
178
|
-
* `:builder` - `Builder` instance in use
|
179
|
-
* `:env` - `Environment` calling the build hook; note that this may be
|
180
|
-
different from the Environment that the build hook was added to in the case
|
181
|
-
that the original Environment was cloned with build hooks!
|
182
|
-
* `:target` - `String` name of the target file
|
183
|
-
* `:sources` - `Array` of the source files
|
184
|
-
* `:vars` - `Rscons::VarSet` containing the construction variables to use.
|
185
|
-
The build hook can overwrite entries in `build_op[:vars]` to alter the
|
186
|
-
construction variables in use for this specific build operation.
|
187
|
-
|
188
|
-
### Example: Creating a static library
|
189
|
-
|
190
|
-
```ruby
|
191
|
-
Rscons::Environment.new do |env|
|
192
|
-
env.Library("mylib.a", Dir["src/**/*.c"])
|
193
|
-
end
|
194
|
-
```
|
195
|
-
|
196
|
-
### Example: Creating a C++ parser source from a Yacc/Bison input file
|
197
|
-
|
198
|
-
```ruby
|
199
|
-
Rscons::Environment.new do |env|
|
200
|
-
env.CFile("#{env.build_root}/parser.tab.cc", "parser.yy")
|
201
|
-
end
|
202
|
-
```
|
203
|
-
|
204
|
-
## Details
|
205
|
-
|
206
|
-
### Builders
|
207
|
-
|
208
|
-
Rscons ships with a number of builders:
|
209
|
-
|
210
|
-
* CFile, which builds a C or C++ source file from a lex or yacc input file
|
211
|
-
* Disassemble, which disassembles an object file to a disassembly listing
|
212
|
-
* Library, which collects object files into a static library archive file
|
213
|
-
* Object, which compiles source files to produce an object file
|
214
|
-
* Preprocess, which invokes the C/C++ preprocessor on a source file
|
215
|
-
* Program, which links object files to produce an executable
|
216
|
-
|
217
|
-
If you want to create an Environment that does not contain any builders,
|
218
|
-
you can use the `exclude_builders` key to the Environment constructor.
|
219
|
-
|
220
|
-
#### CFile
|
221
|
-
|
222
|
-
```ruby
|
223
|
-
env.CFile(target, source)
|
224
|
-
# Example
|
225
|
-
env.CFile("parser.c", "parser.y")
|
226
|
-
```
|
227
|
-
|
228
|
-
The CFile builder will generate a C or C++ source file from a lex (.l, .ll)
|
229
|
-
or yacc (.y, .yy) input file.
|
230
|
-
|
231
|
-
#### Disassemble
|
232
|
-
|
233
|
-
```ruby
|
234
|
-
env.Disassemble(target, source)
|
235
|
-
# Example
|
236
|
-
env.Disassemble("module.dis", "module.o")
|
237
|
-
```
|
238
|
-
|
239
|
-
The Disassemble builder generates a disassembly listing using objdump from
|
240
|
-
and object file.
|
241
|
-
|
242
|
-
#### Library
|
243
|
-
|
244
|
-
```ruby
|
245
|
-
env.Library(target, sources)
|
246
|
-
# Example
|
247
|
-
env.Library("lib.a", Dir["src/**/*.c"])
|
248
|
-
```
|
249
|
-
|
250
|
-
The Library builder creates a static library archive from the given source
|
251
|
-
files.
|
252
|
-
|
253
|
-
#### Object
|
254
|
-
|
255
|
-
```ruby
|
256
|
-
env.Object(target, sources)
|
257
|
-
# Example
|
258
|
-
env.Object("module.o", "module.c")
|
259
|
-
```
|
260
|
-
|
261
|
-
The Object builder compiles the given sources to an object file.
|
262
|
-
|
263
|
-
#### Preprocess
|
264
|
-
|
265
|
-
```ruby
|
266
|
-
env.Preprocess(target, source)
|
267
|
-
# Example
|
268
|
-
env.Preprocess("module-preprocessed.cc", "module.cc")
|
269
|
-
```
|
270
|
-
|
271
|
-
The Preprocess builder invokes either ${CC} or ${CXX} (depending on if the
|
272
|
-
source contains an extension in ${CXXSUFFIX} or not) and writes the
|
273
|
-
preprocessed output to the target file.
|
274
|
-
|
275
|
-
#### Program
|
276
|
-
|
277
|
-
```ruby
|
278
|
-
env.Program(target, sources)
|
279
|
-
# Example
|
280
|
-
env.Program("myprog", Dir["src/**/*.cc"])
|
281
|
-
```
|
282
|
-
|
283
|
-
The Program builder compiles and links the given sources to an executable file.
|
284
|
-
Object files or source files can be given as `sources`.
|
285
|
-
|
286
|
-
### Managing Environments
|
287
|
-
|
288
|
-
An Rscons::Environment consists of:
|
289
|
-
|
290
|
-
* a collection of construction variables
|
291
|
-
* a collection of builders
|
292
|
-
* a mapping of build directories from source directories
|
293
|
-
* a default build root to apply if no build directories are matched
|
294
|
-
* a collection of targets to build
|
295
|
-
* a collection of build hooks
|
296
|
-
|
297
|
-
When cloning an environment, by default the construction variables and builders
|
298
|
-
are cloned, but the new environment does not inherit any of the targets, build
|
299
|
-
hooks, build directories, or the build root from the source environment.
|
300
|
-
|
301
|
-
The set of environment attributes that are cloned is controllable via the
|
302
|
-
`:clone` option to the `#clone` method.
|
303
|
-
For example, `env.clone(clone: :all)` will include construction variables,
|
304
|
-
builders, build hooks, build directories, and the build root.
|
305
|
-
|
306
|
-
The set of pending targets is never cloned.
|
307
|
-
|
308
|
-
Cloned environments contain "deep copies" of construction variables.
|
309
|
-
For example, in:
|
310
|
-
|
311
|
-
```ruby
|
312
|
-
base_env = Rscons::Environment.new
|
313
|
-
base_env["CPPPATH"] = ["one", "two"]
|
314
|
-
cloned_env = base_env.clone
|
315
|
-
cloned_env["CPPPATH"] << "three"
|
316
|
-
```
|
317
|
-
|
318
|
-
`base_env["CPPPATH"]` will not include "three".
|
319
|
-
|
320
|
-
### Construction Variable Naming
|
321
|
-
|
322
|
-
* uppercase strings - the default construction variables that Rscons uses
|
323
|
-
* symbols, lowercase strings - reserved as user-defined construction variables
|
324
|
-
|
325
|
-
### API documentation
|
326
|
-
|
327
|
-
Documentation for the complete Rscons API can be found at
|
328
|
-
http://rubydoc.info/github/holtrop/rscons/frames.
|
329
|
-
|
330
|
-
## Release Notes
|
331
|
-
|
332
|
-
### v1.4.3
|
333
|
-
|
334
|
-
- fix builders properly using construction variable overrides
|
335
|
-
- expand nil construction variables to empty strings
|
336
|
-
|
337
|
-
### v1.4.2
|
338
|
-
|
339
|
-
- add Environment#expand_path
|
340
|
-
- expand construction variable references in builder targets and sources before invoking builder
|
341
|
-
|
342
|
-
### v1.4.1
|
343
|
-
|
344
|
-
- fix invoking a builder with no sources while a build root defined
|
345
|
-
|
346
|
-
### v1.4.0
|
347
|
-
|
348
|
-
- add CFile builder
|
349
|
-
- add Disassemble builder
|
350
|
-
- add Preprocess builder
|
351
|
-
- pass the Environment object to build hooks in the :env key of the build_op parameter
|
352
|
-
- expand target/source paths beginning with "^/" to be relative to the Environment's build root
|
353
|
-
- many performance improvements, including:
|
354
|
-
- use JSON instead of YAML for the cache to improve loading speed (Issue #7)
|
355
|
-
- store a hash of the build command instead of the full command contents in the cache
|
356
|
-
- implement copy-on-write semantics for construction variables when cloning Environments
|
357
|
-
- only load the cache once instead of on each Environment#process
|
358
|
-
- only write the cache when something has changed
|
359
|
-
- fix Cache#mkdir_p to handle relative paths (Issue #5)
|
360
|
-
- flush the cache to disk if a builder raises an exception (Issue #4)
|
361
|
-
|
362
|
-
### v1.3.0
|
363
|
-
|
364
|
-
- change Environment#execute() options parameter to accept the following options keys:
|
365
|
-
- :env to pass an environment Hash to Kernel#system
|
366
|
-
- :options to pass an options Hash to Kernel#system
|
367
|
-
|
368
|
-
### v1.2.0
|
369
|
-
|
370
|
-
- add :clone option to Environment#clone to control exactly which Environment attributes are cloned
|
371
|
-
- allow nil to be passed in to Environment#build_root=
|
372
|
-
|
373
|
-
### v1.1.0
|
374
|
-
|
375
|
-
- Change Cache#up_to_date?() and #register_build() to accept a single target
|
376
|
-
file or an array of target file names
|
377
|
-
|
378
|
-
## Contributing
|
379
|
-
|
380
|
-
1. Fork it
|
381
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
382
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
383
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
384
|
-
5. Create new Pull Request
|
data/Rakefile.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require "bundler"
|
2
|
-
begin
|
3
|
-
Bundler.setup(:default, :development)
|
4
|
-
rescue Bundler::BundlerError => e
|
5
|
-
raise LoadError.new("Unable to setup Bundler; you might need to `bundle install`: #{e.message}")
|
6
|
-
end
|
7
|
-
|
8
|
-
require "bundler/gem_tasks"
|
9
|
-
require "rspec/core/rake_task"
|
10
|
-
require "yard"
|
11
|
-
|
12
|
-
RSpec::Core::RakeTask.new(:spec)
|
13
|
-
|
14
|
-
YARD::Rake::YardocTask.new do |yard|
|
15
|
-
yard.files = ['lib/**/*.rb']
|
16
|
-
end
|
17
|
-
|
18
|
-
task :default => :spec
|
19
|
-
|
20
|
-
task :clean do
|
21
|
-
FileUtils.rm_rf(["build_test_run", "doc", "coverage"])
|
22
|
-
end
|
23
|
-
|
24
|
-
task :clobber => :clean do
|
25
|
-
FileUtils.rm_rf(["pkg"])
|
26
|
-
end
|