Replace CFile builder with Yacc and Lex builders - close #166
This commit is contained in:
1 parent
d4ec07dd7a
commit
ed7408367f
12 files changed
+86
-71
No files matched your search
+4
-2
@@ -23,13 +23,13 @@ module Rscons
|
||||
# Names of the default builders which will be added to all newly created
|
||||
# {Environment} objects.
|
||||
DEFAULT_BUILDERS = [
|
||||
:CFile,
|
||||
:Command,
|
||||
:Copy,
|
||||
:Directory,
|
||||
:Disassemble,
|
||||
:Install,
|
||||
:InstallDirectory,
|
||||
:Lex,
|
||||
:Library,
|
||||
:Object,
|
||||
:Preprocess,
|
||||
@@ -37,6 +37,7 @@ module Rscons
|
||||
:SharedLibrary,
|
||||
:SharedObject,
|
||||
:Size,
|
||||
:Yacc,
|
||||
]
|
||||
|
||||
# Class to represent a fatal error during an Rscons operation.
|
||||
@@ -135,11 +136,11 @@ require_relative "rscons/builders/mixins/object_deps"
|
||||
require_relative "rscons/builders/mixins/program"
|
||||
|
||||
# default builders
|
||||
require_relative "rscons/builders/cfile"
|
||||
require_relative "rscons/builders/command"
|
||||
require_relative "rscons/builders/copy"
|
||||
require_relative "rscons/builders/directory"
|
||||
require_relative "rscons/builders/disassemble"
|
||||
require_relative "rscons/builders/lex"
|
||||
require_relative "rscons/builders/library"
|
||||
require_relative "rscons/builders/object"
|
||||
require_relative "rscons/builders/preprocess"
|
||||
@@ -148,6 +149,7 @@ require_relative "rscons/builders/shared_library"
|
||||
require_relative "rscons/builders/shared_object"
|
||||
require_relative "rscons/builders/simple_builder"
|
||||
require_relative "rscons/builders/size"
|
||||
require_relative "rscons/builders/yacc"
|
||||
|
||||
# language support
|
||||
require_relative "rscons/builders/lang/asm"
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
module Rscons
|
||||
module Builders
|
||||
# Build a C or C++ source file given a lex (.l, .ll) or yacc (.y, .yy)
|
||||
# input file.
|
||||
#
|
||||
# Examples::
|
||||
# env.CFile("parser.tab.cc", "parser.yy")
|
||||
# env.CFile("lex.yy.cc", "parser.ll")
|
||||
class CFile < Builder
|
||||
|
||||
# Run the builder to produce a build target.
|
||||
def run(options)
|
||||
if @command
|
||||
finalize_command
|
||||
else
|
||||
@vars["_TARGET"] = @target
|
||||
@vars["_SOURCES"] = @sources
|
||||
case
|
||||
when @sources.first.end_with?(*@env.expand_varref("${LEXSUFFIX}"))
|
||||
cmd = "LEX"
|
||||
message = "Generating lexer"
|
||||
when @sources.first.end_with?(*@env.expand_varref("${YACCSUFFIX}"))
|
||||
cmd = "YACC"
|
||||
message = "Generating parser"
|
||||
else
|
||||
raise "Unknown source file #{@sources.first.inspect} for CFile builder"
|
||||
end
|
||||
command = @env.build_command("${#{cmd}_CMD}", @vars)
|
||||
standard_command("#{message} from <source>#{Util.short_format_paths(@sources)}<reset> => <target>#{@target}<reset>", command)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,24 @@
|
||||
module Rscons
|
||||
module Builders
|
||||
# Build a source file given a lex input file.
|
||||
#
|
||||
# Examples::
|
||||
# env.Lex("lex.c", "parser.l")
|
||||
# env.Lex("lex.cc", "parser.ll")
|
||||
class Lex < Builder
|
||||
|
||||
# Run the builder to produce a build target.
|
||||
def run(options)
|
||||
if @command
|
||||
finalize_command
|
||||
else
|
||||
@vars["_TARGET"] = @target
|
||||
@vars["_SOURCES"] = @sources
|
||||
command = @env.build_command("${LEX_CMD}", @vars)
|
||||
standard_command("Generating lexer source from <source>#{Util.short_format_paths(@sources)}<reset> => <target>#{@target}<reset>", command)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,24 @@
|
||||
module Rscons
|
||||
module Builders
|
||||
# Build a source file given a yacc input file.
|
||||
#
|
||||
# Examples::
|
||||
# env.Yacc("parser.c", "parser.y")
|
||||
# env.Yacc("parser.cc", "parser.yy")
|
||||
class Yacc < Builder
|
||||
|
||||
# Run the builder to produce a build target.
|
||||
def run(options)
|
||||
if @command
|
||||
finalize_command
|
||||
else
|
||||
@vars["_TARGET"] = @target
|
||||
@vars["_SOURCES"] = @sources
|
||||
command = @env.build_command("${YACC_CMD}", @vars)
|
||||
standard_command("Generating parser source from <source>#{Util.short_format_paths(@sources)}<reset> => <target>#{@target}<reset>", command)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -49,7 +49,6 @@ module Rscons
|
||||
"LDCMD" => %w[${LD} -o ${_TARGET} ${LDFLAGS} ${_SOURCES} ${LIBDIRPREFIX}${LIBPATH} ${LIBLINKPREFIX}${LIBS}],
|
||||
"LDFLAGS" => [],
|
||||
"LEX" => "flex",
|
||||
"LEXSUFFIX" => %w[.l .ll],
|
||||
"LEX_CMD" => %w[${LEX} ${LEX_FLAGS} -o ${_TARGET} ${_SOURCES}],
|
||||
"LEX_FLAGS" => [],
|
||||
"LIBDIRPREFIX" => "-L",
|
||||
@@ -84,7 +83,6 @@ module Rscons
|
||||
"SIZECMD" => %w[${SIZE} ${SIZEFLAGS} ${_SOURCES}],
|
||||
"SIZEFLAGS" => [],
|
||||
"YACC" => "bison",
|
||||
"YACCSUFFIX" => %w[.y .yy],
|
||||
"YACC_CMD" => %w[${YACC} ${YACC_FLAGS} -o ${_TARGET} ${_SOURCES}],
|
||||
"YACC_FLAGS" => %w[-d],
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user