Compare commits

...

2 Commits

Author SHA1 Message Date
4dc1280f68 Add Util.glob() and use from Script 2026-01-28 11:56:34 -05:00
355014def6 Add Precompile builder 2026-01-28 11:49:52 -05:00
5 changed files with 61 additions and 9 deletions

View File

@ -33,6 +33,7 @@ module Rscons
:Lex,
:Library,
:Object,
:Precompile,
:Preprocess,
:Program,
:SharedLibrary,
@ -152,6 +153,7 @@ require_relative "rscons/builders/disassemble"
require_relative "rscons/builders/lex"
require_relative "rscons/builders/library"
require_relative "rscons/builders/object"
require_relative "rscons/builders/precompile"
require_relative "rscons/builders/preprocess"
require_relative "rscons/builders/program"
require_relative "rscons/builders/shared_library"

View File

@ -0,0 +1,29 @@
module Rscons
module Builders
# The Precompile builder generates .di interface files from .d source files
# for D.
class Precompile < Builder
# Run the builder to produce a build target.
def run(options)
if @command
finalize_command
else
if @sources.find {|s| s.end_with?(*@env.expand_varref("${DSUFFIX}", @vars))}
pcc = @env.expand_varref("${DC}")
if pcc =~ /ldc/
dpc_cmd = "${DPC_CMD:ldc}"
else
dpc_cmd = "${DPC_CMD:gdc}"
end
@vars["_TARGET"] = @target
@vars["_SOURCES"] = @sources
command = @env.build_command(dpc_cmd, @vars)
standard_command("Precompile <source>#{Util.short_format_paths(@sources)}<reset>", command)
end
end
end
end
end
end

View File

@ -43,6 +43,8 @@ module Rscons
"DFLAGS" => [],
"DISASM_CMD" => %w[${OBJDUMP} ${DISASM_FLAGS} ${_SOURCES}],
"DISASM_FLAGS" => %w[--disassemble --source],
"DPC_CMD:ldc" => %w[${DC} -H -Hf ${_TARGET} -o- ${INCPREFIX}${D_IMPORT_PATH} ${DFLAGS} ${_SOURCES}],
"DPC_CMD:gdc" => %w[${DC} -H -Hf ${_TARGET} -fsyntax-only ${INCPREFIX}${D_IMPORT_PATH} ${DFLAGS} ${_SOURCES}],
"DSUFFIX" => %w[.d],
"D_IMPORT_PATH" => [],
"INCPREFIX" => "-I",

View File

@ -34,15 +34,7 @@ module Rscons
#
# @return [Array<String>] Paths matching the specified pattern(s).
def glob(*patterns)
require "pathname"
patterns.reduce([]) do |result, pattern|
if pattern.end_with?("/**")
pattern += "/"
end
result += Dir.glob(pattern).map do |path|
Pathname.new(path.gsub("\\", "/")).cleanpath.to_s
end
end.sort
Util.glob(*patterns)
end
# Download a file.

View File

@ -156,6 +156,33 @@ module Rscons
result
end
# Return a list of paths matching the specified pattern(s).
#
# A pattern can contain a "/**" component to recurse through directories.
# If the pattern ends with "/**" then only the recursive list of
# directories will be returned.
#
# Examples:
# - "src/**": return all directories under "src", recursively (including
# "src" itself).
# - "src/**/*": return all files and directories recursively under the src
# directory.
# - "src/**/*.c": return all .c files recursively under the src directory.
# - "dir/*/": return all directories in dir, but no files.
#
# @return [Array<String>] Paths matching the specified pattern(s).
def glob(*patterns)
require "pathname"
patterns.reduce([]) do |result, pattern|
if pattern.end_with?("/**")
pattern += "/"
end
result += Dir.glob(pattern).map do |path|
Pathname.new(path.gsub("\\", "/")).cleanpath.to_s
end
end.sort
end
# Make a relative path corresponding to a possibly absolute one.
#
# @param path [String]