expose glob method directly to Rsconscript - close #97

This commit is contained in:
Josh Holtrop 2019-04-14 12:51:37 -04:00
parent c23426c5aa
commit 921f0d2cb1
14 changed files with 49 additions and 51 deletions

View File

@ -1,5 +1,5 @@
build do
Environment.new(echo: :command) do |env|
env.Program("hello-d.exe", Rscons.glob("*.d"))
env.Program("hello-d.exe", glob("*.d"))
end
end

View File

@ -1,5 +1,5 @@
build do
Environment.new do |env|
env.Program("test.exe", Rscons.glob("*.c"), direct: true)
env.Program("test.exe", glob("*.c"), direct: true)
end
end

View File

@ -1,6 +1,6 @@
build do
Environment.new(echo: :command) do |env|
env["ARCMD"] = %w[ar rcf ${_TARGET} ${_SOURCES}]
env.Library("lib.a", Rscons.glob("*.c"))
env.Library("lib.a", glob("*.c"))
end
end

View File

@ -1,13 +1,13 @@
build do
Environment.new do |env|
env["CPPPATH"] << "src/lib"
libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.c"))
libmine = env.SharedLibrary("mine", glob("src/lib/*.c"))
env.Program("test-shared.exe",
Rscons.glob("src/*.c"),
glob("src/*.c"),
"LIBPATH" => %w[.],
"LIBS" => %w[mine])
env.build_after("test-shared.exe", libmine)
env.Program("test-static.exe",
Rscons.glob("src/**/*.c"))
glob("src/**/*.c"))
end
end

View File

@ -1,13 +1,13 @@
build do
Environment.new do |env|
env["CPPPATH"] << "src/lib"
libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.cc"))
libmine = env.SharedLibrary("mine", glob("src/lib/*.cc"))
env.Program("test-shared.exe",
Rscons.glob("src/*.cc"),
glob("src/*.cc"),
"LIBPATH" => %w[.],
"LIBS" => %w[mine])
env.build_after("test-shared.exe", libmine)
env.Program("test-static.exe",
Rscons.glob("src/**/*.cc"))
glob("src/**/*.cc"))
end
end

View File

@ -1,9 +1,9 @@
build do
Environment.new do |env|
env["CPPPATH"] << "src/lib"
libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.d"))
libmine = env.SharedLibrary("mine", glob("src/lib/*.d"))
env.Program("test-shared.exe",
Rscons.glob("src/*.c"),
glob("src/*.c"),
"LIBPATH" => %w[.],
"LIBS" => %w[mine])
env.build_after("test-shared.exe", libmine)

View File

@ -2,13 +2,13 @@ build do
Environment.new do |env|
env["CPPPATH"] << "src/lib"
env["SHLD"] = "gcc"
libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.c"))
libmine = env.SharedLibrary("mine", glob("src/lib/*.c"))
env.Program("test-shared.exe",
Rscons.glob("src/*.c"),
glob("src/*.c"),
"LIBPATH" => %w[.],
"LIBS" => %w[mine])
env.build_after("test-shared.exe", libmine)
env.Program("test-static.exe",
Rscons.glob("src/**/*.c"))
glob("src/**/*.c"))
end
end

View File

@ -1,6 +1,6 @@
build do
Environment.new do |env|
env["sources"] = Rscons.glob("*.c")
env["sources"] = glob("*.c")
env.Program("simple.exe", "${sources}")
end
end

View File

@ -1,6 +1,6 @@
build do
Environment.new(echo: :command) do |env|
env.append('CPPPATH' => Rscons.glob('src/**/*/'))
env.append('CPPPATH' => glob('src/**/*/'))
env.add_build_hook do |builder|
if File.basename(builder.target) == "one.o"
builder.vars["CFLAGS"] << "-O1"
@ -8,6 +8,6 @@ build do
builder.vars["CFLAGS"] << "-O2"
end
end
env.Program('build_hook.exe', Rscons.glob('src/**/*.c'))
env.Program('build_hook.exe', glob('src/**/*.c'))
end
end

View File

@ -1,6 +1,6 @@
build do
Environment.new(echo: :command) do |env|
env.append('CPPPATH' => Rscons.glob('src/**'))
env.append('CPPPATH' => glob('src/**'))
env.add_build_hook do |builder|
if builder.name == "Object" && builder.sources.first =~ %r{one\.c}
builder.vars["CFLAGS"] << "-O1"

View File

@ -1,9 +1,9 @@
build do
Environment.new(echo: :command) do |env|
env.append('CPPPATH' => Rscons.glob('src/**').sort)
env.append('CPPPATH' => glob('src/**').sort)
FileUtils.mkdir_p(env.build_root)
FileUtils.mv("src/one/one.c", env.build_root)
env.Object("^/one.o", "^/one.c")
env.Program("program.exe", Rscons.glob('src/**/*.c') + ["^/one.o"])
env.Program("program.exe", glob('src/**/*.c') + ["^/one.o"])
end
end

View File

@ -2,7 +2,7 @@ build do
Environment.new do |env|
env["CSUFFIX"] = %w[.yargh .c]
env["CFLAGS"] += %w[-x c]
env["CPPPATH"] += Rscons.glob("src/**")
env.Program("program.exe", Rscons.glob("src/**/*.{c,yargh}"))
env["CPPPATH"] += glob("src/**")
env.Program("program.exe", glob("src/**/*.{c,yargh}"))
end
end

View File

@ -132,35 +132,6 @@ module Rscons
@command_executer = val
end
# Return a list of paths matching the specified pattern(s).
#
# @since 1.16.0
#
# 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
end
end

View File

@ -28,6 +28,33 @@ module Rscons
def configure(&block)
@script.operations["configure"] = block
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
end
class ConfigureDsl