Add Size builder - close #143
This commit is contained in:
parent
a316c4f922
commit
610b8f1266
6
build_tests/simple/size.rb
Normal file
6
build_tests/simple/size.rb
Normal file
@ -0,0 +1,6 @@
|
||||
build do
|
||||
Environment.new do |env|
|
||||
env.Program("simple.exe", glob("*.c"))
|
||||
env.Size("simple.size", "simple.exe")
|
||||
end
|
||||
end
|
@ -625,6 +625,7 @@ There are several default builders that are built-in to Rscons:
|
||||
library.
|
||||
* `SharedObject`, which compiles source files to produce an object file, in a
|
||||
way that is able to be used to create a shared library.
|
||||
* `Size`, which runs the 'size' utility on an executable file.
|
||||
|
||||
####> The Command Builder
|
||||
|
||||
@ -840,6 +841,20 @@ allows it to be used to create a shared library are added.
|
||||
Although it can be called explicitly, it is more commonly implicitly called by
|
||||
the `SharedLibrary` builder.
|
||||
|
||||
####> The Size Builder
|
||||
|
||||
```ruby
|
||||
env.Size(target, sources)
|
||||
# Example
|
||||
env.Program("program.exe", glob("*.c"))
|
||||
env.Size("program.size", "program.exe")
|
||||
```
|
||||
|
||||
The `Size` builder runs the "size" executable on the given source file and
|
||||
stores its output in the target file.
|
||||
The size executable can be specified with the `SIZE` construction variable,
|
||||
and flags can be specified with `SIZEFLAGS`.
|
||||
|
||||
###> Phony Targets
|
||||
|
||||
rscons supports phony build targets.
|
||||
|
@ -33,6 +33,7 @@ module Rscons
|
||||
:Program,
|
||||
:SharedLibrary,
|
||||
:SharedObject,
|
||||
:Size,
|
||||
]
|
||||
|
||||
# Class to represent a fatal error during an Rscons operation.
|
||||
@ -146,6 +147,7 @@ require_relative "rscons/builders/program"
|
||||
require_relative "rscons/builders/shared_library"
|
||||
require_relative "rscons/builders/shared_object"
|
||||
require_relative "rscons/builders/simple_builder"
|
||||
require_relative "rscons/builders/size"
|
||||
|
||||
# language support
|
||||
require_relative "rscons/builders/lang/asm"
|
||||
|
24
lib/rscons/builders/size.rb
Normal file
24
lib/rscons/builders/size.rb
Normal file
@ -0,0 +1,24 @@
|
||||
module Rscons
|
||||
module Builders
|
||||
# Run the "size" utility on an executable and store its results in the
|
||||
# target file.
|
||||
# input file.
|
||||
#
|
||||
# Examples::
|
||||
# env.Size("^/project.size", "^/project.elf")
|
||||
class Size < Builder
|
||||
|
||||
# Run the builder to produce a build target.
|
||||
def run(options)
|
||||
if @command
|
||||
finalize_command
|
||||
else
|
||||
@vars["_SOURCES"] = @sources
|
||||
command = @env.build_command("${SIZECMD}", @vars)
|
||||
standard_command("Size <source>#{Util.short_format_paths(@sources)}<reset> => <target>#{@target}<reset>", command, stdout: @target)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
@ -80,6 +80,9 @@ module Rscons
|
||||
"SHLIBLINKPREFIX" => "-l",
|
||||
"SHLIBPREFIX" => on_windows ? "" : "lib",
|
||||
"SHLIBSUFFIX" => on_windows ? ".dll" : ".so",
|
||||
"SIZE" => "size",
|
||||
"SIZECMD" => %w[${SIZE} ${SIZEFLAGS} ${_SOURCES}],
|
||||
"SIZEFLAGS" => [],
|
||||
"YACC" => "bison",
|
||||
"YACCSUFFIX" => %w[.y .yy],
|
||||
"YACC_CMD" => %w[${YACC} ${YACC_FLAGS} -o ${_TARGET} ${_SOURCES}],
|
||||
|
@ -1672,6 +1672,21 @@ EOF
|
||||
end
|
||||
end
|
||||
|
||||
context "Size builder" do
|
||||
it "generates a size file" do
|
||||
test_dir "simple"
|
||||
|
||||
result = run_rscons(rsconscript: "size.rb")
|
||||
verify_lines(lines(result.stdout), [
|
||||
/Linking .*simple\.exe/,
|
||||
/Size .*simple\.exe .*simple\.size/,
|
||||
])
|
||||
expect(File.exist?("simple.exe")).to be_truthy
|
||||
expect(File.exist?("simple.size")).to be_truthy
|
||||
expect(File.read("simple.size")).to match /text.*data.*bss/
|
||||
end
|
||||
end
|
||||
|
||||
context "multi-threading" do
|
||||
it "waits for subcommands in threads for builders that support threaded commands" do
|
||||
test_dir("simple")
|
||||
|
Loading…
x
Reference in New Issue
Block a user