expose glob method directly to Rsconscript - close #97
This commit is contained in:
parent
c23426c5aa
commit
921f0d2cb1
@ -1,5 +1,5 @@
|
|||||||
build do
|
build do
|
||||||
Environment.new(echo: :command) do |env|
|
Environment.new(echo: :command) do |env|
|
||||||
env.Program("hello-d.exe", Rscons.glob("*.d"))
|
env.Program("hello-d.exe", glob("*.d"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
build do
|
build do
|
||||||
Environment.new do |env|
|
Environment.new do |env|
|
||||||
env.Program("test.exe", Rscons.glob("*.c"), direct: true)
|
env.Program("test.exe", glob("*.c"), direct: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
build do
|
build do
|
||||||
Environment.new(echo: :command) do |env|
|
Environment.new(echo: :command) do |env|
|
||||||
env["ARCMD"] = %w[ar rcf ${_TARGET} ${_SOURCES}]
|
env["ARCMD"] = %w[ar rcf ${_TARGET} ${_SOURCES}]
|
||||||
env.Library("lib.a", Rscons.glob("*.c"))
|
env.Library("lib.a", glob("*.c"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
build do
|
build do
|
||||||
Environment.new do |env|
|
Environment.new do |env|
|
||||||
env["CPPPATH"] << "src/lib"
|
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",
|
env.Program("test-shared.exe",
|
||||||
Rscons.glob("src/*.c"),
|
glob("src/*.c"),
|
||||||
"LIBPATH" => %w[.],
|
"LIBPATH" => %w[.],
|
||||||
"LIBS" => %w[mine])
|
"LIBS" => %w[mine])
|
||||||
env.build_after("test-shared.exe", libmine)
|
env.build_after("test-shared.exe", libmine)
|
||||||
env.Program("test-static.exe",
|
env.Program("test-static.exe",
|
||||||
Rscons.glob("src/**/*.c"))
|
glob("src/**/*.c"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
build do
|
build do
|
||||||
Environment.new do |env|
|
Environment.new do |env|
|
||||||
env["CPPPATH"] << "src/lib"
|
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",
|
env.Program("test-shared.exe",
|
||||||
Rscons.glob("src/*.cc"),
|
glob("src/*.cc"),
|
||||||
"LIBPATH" => %w[.],
|
"LIBPATH" => %w[.],
|
||||||
"LIBS" => %w[mine])
|
"LIBS" => %w[mine])
|
||||||
env.build_after("test-shared.exe", libmine)
|
env.build_after("test-shared.exe", libmine)
|
||||||
env.Program("test-static.exe",
|
env.Program("test-static.exe",
|
||||||
Rscons.glob("src/**/*.cc"))
|
glob("src/**/*.cc"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
build do
|
build do
|
||||||
Environment.new do |env|
|
Environment.new do |env|
|
||||||
env["CPPPATH"] << "src/lib"
|
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",
|
env.Program("test-shared.exe",
|
||||||
Rscons.glob("src/*.c"),
|
glob("src/*.c"),
|
||||||
"LIBPATH" => %w[.],
|
"LIBPATH" => %w[.],
|
||||||
"LIBS" => %w[mine])
|
"LIBS" => %w[mine])
|
||||||
env.build_after("test-shared.exe", libmine)
|
env.build_after("test-shared.exe", libmine)
|
||||||
|
@ -2,13 +2,13 @@ build do
|
|||||||
Environment.new do |env|
|
Environment.new do |env|
|
||||||
env["CPPPATH"] << "src/lib"
|
env["CPPPATH"] << "src/lib"
|
||||||
env["SHLD"] = "gcc"
|
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",
|
env.Program("test-shared.exe",
|
||||||
Rscons.glob("src/*.c"),
|
glob("src/*.c"),
|
||||||
"LIBPATH" => %w[.],
|
"LIBPATH" => %w[.],
|
||||||
"LIBS" => %w[mine])
|
"LIBS" => %w[mine])
|
||||||
env.build_after("test-shared.exe", libmine)
|
env.build_after("test-shared.exe", libmine)
|
||||||
env.Program("test-static.exe",
|
env.Program("test-static.exe",
|
||||||
Rscons.glob("src/**/*.c"))
|
glob("src/**/*.c"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
build do
|
build do
|
||||||
Environment.new do |env|
|
Environment.new do |env|
|
||||||
env["sources"] = Rscons.glob("*.c")
|
env["sources"] = glob("*.c")
|
||||||
env.Program("simple.exe", "${sources}")
|
env.Program("simple.exe", "${sources}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
build do
|
build do
|
||||||
Environment.new(echo: :command) do |env|
|
Environment.new(echo: :command) do |env|
|
||||||
env.append('CPPPATH' => Rscons.glob('src/**/*/'))
|
env.append('CPPPATH' => glob('src/**/*/'))
|
||||||
env.add_build_hook do |builder|
|
env.add_build_hook do |builder|
|
||||||
if File.basename(builder.target) == "one.o"
|
if File.basename(builder.target) == "one.o"
|
||||||
builder.vars["CFLAGS"] << "-O1"
|
builder.vars["CFLAGS"] << "-O1"
|
||||||
@ -8,6 +8,6 @@ build do
|
|||||||
builder.vars["CFLAGS"] << "-O2"
|
builder.vars["CFLAGS"] << "-O2"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
env.Program('build_hook.exe', Rscons.glob('src/**/*.c'))
|
env.Program('build_hook.exe', glob('src/**/*.c'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
build do
|
build do
|
||||||
Environment.new(echo: :command) do |env|
|
Environment.new(echo: :command) do |env|
|
||||||
env.append('CPPPATH' => Rscons.glob('src/**'))
|
env.append('CPPPATH' => glob('src/**'))
|
||||||
env.add_build_hook do |builder|
|
env.add_build_hook do |builder|
|
||||||
if builder.name == "Object" && builder.sources.first =~ %r{one\.c}
|
if builder.name == "Object" && builder.sources.first =~ %r{one\.c}
|
||||||
builder.vars["CFLAGS"] << "-O1"
|
builder.vars["CFLAGS"] << "-O1"
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
build do
|
build do
|
||||||
Environment.new(echo: :command) do |env|
|
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.mkdir_p(env.build_root)
|
||||||
FileUtils.mv("src/one/one.c", env.build_root)
|
FileUtils.mv("src/one/one.c", env.build_root)
|
||||||
env.Object("^/one.o", "^/one.c")
|
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
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,7 @@ build do
|
|||||||
Environment.new do |env|
|
Environment.new do |env|
|
||||||
env["CSUFFIX"] = %w[.yargh .c]
|
env["CSUFFIX"] = %w[.yargh .c]
|
||||||
env["CFLAGS"] += %w[-x c]
|
env["CFLAGS"] += %w[-x c]
|
||||||
env["CPPPATH"] += Rscons.glob("src/**")
|
env["CPPPATH"] += glob("src/**")
|
||||||
env.Program("program.exe", Rscons.glob("src/**/*.{c,yargh}"))
|
env.Program("program.exe", glob("src/**/*.{c,yargh}"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -132,35 +132,6 @@ module Rscons
|
|||||||
@command_executer = val
|
@command_executer = val
|
||||||
end
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -28,6 +28,33 @@ module Rscons
|
|||||||
def configure(&block)
|
def configure(&block)
|
||||||
@script.operations["configure"] = block
|
@script.operations["configure"] = block
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class ConfigureDsl
|
class ConfigureDsl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user