add Rscons.glob - close #50
This commit is contained in:
parent
57de94a3fb
commit
c7f66694ab
@ -1,5 +1,5 @@
|
||||
Rscons::Environment.new do |env|
|
||||
env.append('CPPPATH' => Dir['src/**/*/'].sort)
|
||||
env.append('CPPPATH' => Rscons.glob('src/**'))
|
||||
env.build_dir(%r{^src/([^/]+)/}, 'build_\\1/')
|
||||
env.Program('build_dir.exe', Dir['src/**/*.c'])
|
||||
env.Program('build_dir.exe', Rscons.glob('src/**/*.c'))
|
||||
end
|
||||
|
@ -6,7 +6,7 @@ end
|
||||
|
||||
Rscons::Environment.new(echo: :command) do |env|
|
||||
env.add_builder(MyObject.new)
|
||||
env.append('CPPPATH' => Dir['src/**/*/'].sort)
|
||||
env.append('CPPPATH' => Rscons.glob('src/**'))
|
||||
env.add_build_hook do |build_op|
|
||||
if build_op[:builder].name == "MyObject" && build_op[:sources].first =~ %r{one\.c}
|
||||
build_op[:vars]["CFLAGS"] << "-O1"
|
||||
|
@ -1,6 +1,6 @@
|
||||
env = Rscons::Environment.new do |env|
|
||||
env.append('CPPPATH' => Dir['src/**/*/'].sort)
|
||||
env.append('CPPPATH' => Rscons.glob('src/**/*/'))
|
||||
env.build_dir("src", "build")
|
||||
env.build_root = "build_root"
|
||||
env.Program('build_dir.exe', Dir['src/**/*.c'])
|
||||
env.Program('build_dir.exe', Rscons.glob('src/**/*.c'))
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
Rscons::Environment.new(echo: :command) do |env|
|
||||
env.append('CPPPATH' => Dir['src/**/*/'].sort)
|
||||
env.append('CPPPATH' => Rscons.glob('src/**/*/'))
|
||||
env.build_dir(%r{^src/([^/]+)/}, 'build_\\1/')
|
||||
env.add_build_hook do |build_op|
|
||||
if build_op[:target] =~ %r{build_one/.*\.o}
|
||||
@ -8,5 +8,5 @@ Rscons::Environment.new(echo: :command) do |env|
|
||||
build_op[:vars]["CFLAGS"] << "-O2"
|
||||
end
|
||||
end
|
||||
env.Program('build_hook.exe', Dir['src/**/*.c'].sort)
|
||||
env.Program('build_hook.exe', Rscons.glob('src/**/*.c'))
|
||||
end
|
||||
|
@ -1,8 +1,8 @@
|
||||
Rscons::Environment.new(echo: :command) do |env|
|
||||
env.append('CPPPATH' => Dir['src/**/*/'].sort)
|
||||
env.append('CPPPATH' => Rscons.glob('src/**').sort)
|
||||
env.build_root = "build_root"
|
||||
FileUtils.mkdir_p(env.build_root)
|
||||
FileUtils.mv("src/one/one.c", "build_root")
|
||||
env.Object("^/one.o", "^/one.c")
|
||||
env.Program("build_dir.exe", Dir['src/**/*.c'] + ["^/one.o"])
|
||||
env.Program("build_dir.exe", Rscons.glob('src/**/*.c') + ["^/one.o"])
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
Rscons::Environment.new do |env|
|
||||
env["CSUFFIX"] = %w[.yargh .c]
|
||||
env["CFLAGS"] += %w[-x c]
|
||||
env["CPPPATH"] += Dir["src/**/"]
|
||||
env.Program("build_dir.exe", Dir["src/**/*.{c,yargh}"])
|
||||
env["CPPPATH"] += Rscons.glob("src/**")
|
||||
env.Program("build_dir.exe", Rscons.glob("src/**/*.{c,yargh}"))
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
Rscons::Environment.new do |env|
|
||||
env.append('CPPPATH' => Dir['src/**/*/'].sort)
|
||||
env.append('CPPPATH' => Rscons.glob('src/**'))
|
||||
env.build_dir("src2", "build")
|
||||
env.build_root = "build_root"
|
||||
env.Program('build_dir.exe', Dir['src/**/*.c'])
|
||||
env.Program('build_dir.exe', Rscons.glob('src/**/*.c'))
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
Rscons::Environment.new do |env|
|
||||
env.append("CPPPATH" => Dir["src/**/*/"].sort)
|
||||
env.append("CPPPATH" => Rscons.glob("src/**"))
|
||||
env.build_dir("src/one/", "build_one/")
|
||||
env.build_dir("src/two", "build_two")
|
||||
env.Program("build_dir.exe", Dir["src/**/*.c"])
|
||||
env.Program("build_dir.exe", Rscons.glob("src/**/*.c"))
|
||||
end
|
||||
|
@ -1,3 +1,3 @@
|
||||
Rscons::Environment.new(echo: :command) do |env|
|
||||
env.Program("hello-d.exe", Dir["*.d"].sort)
|
||||
env.Program("hello-d.exe", Rscons.glob("*.d"))
|
||||
end
|
||||
|
@ -1,4 +1,4 @@
|
||||
Rscons::Environment.new(echo: :command) do |env|
|
||||
env["ARCMD"] = %w[ar rcf ${_TARGET} ${_SOURCES}]
|
||||
env.Library("lib.a", Dir["*.c"].sort)
|
||||
env.Library("lib.a", Rscons.glob("*.c"))
|
||||
end
|
||||
|
@ -1,11 +1,11 @@
|
||||
Rscons::Environment.new do |env|
|
||||
env["CPPPATH"] << "src/lib"
|
||||
libmine = env.SharedLibrary("mine", Dir["src/lib/*.c"])
|
||||
libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.c"))
|
||||
env.Program("test-shared.exe",
|
||||
Dir["src/*.c"],
|
||||
Rscons.glob("src/*.c"),
|
||||
"LIBPATH" => %w[.],
|
||||
"LIBS" => %w[mine])
|
||||
env.build_after("test-shared.exe", libmine.to_s)
|
||||
env.Program("test-static.exe",
|
||||
Dir["src/**/*.c"])
|
||||
Rscons.glob("src/**/*.c"))
|
||||
end
|
||||
|
@ -1,11 +1,11 @@
|
||||
Rscons::Environment.new do |env|
|
||||
env["CPPPATH"] << "src/lib"
|
||||
libmine = env.SharedLibrary("mine", Dir["src/lib/*.cc"])
|
||||
libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.cc"))
|
||||
env.Program("test-shared.exe",
|
||||
Dir["src/*.cc"],
|
||||
Rscons.glob("src/*.cc"),
|
||||
"LIBPATH" => %w[.],
|
||||
"LIBS" => %w[mine])
|
||||
env.build_after("test-shared.exe", libmine.to_s)
|
||||
env.Program("test-static.exe",
|
||||
Dir["src/**/*.cc"])
|
||||
Rscons.glob("src/**/*.cc"))
|
||||
end
|
||||
|
@ -1,8 +1,8 @@
|
||||
Rscons::Environment.new do |env|
|
||||
env["CPPPATH"] << "src/lib"
|
||||
libmine = env.SharedLibrary("mine", Dir["src/lib/*.d"])
|
||||
libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.d"))
|
||||
env.Program("test-shared.exe",
|
||||
Dir["src/*.c"],
|
||||
Rscons.glob("src/*.c"),
|
||||
"LIBPATH" => %w[.],
|
||||
"LIBS" => %w[mine])
|
||||
env.build_after("test-shared.exe", libmine.to_s)
|
||||
|
@ -1,12 +1,12 @@
|
||||
Rscons::Environment.new do |env|
|
||||
env["CPPPATH"] << "src/lib"
|
||||
env["SHLD"] = "gcc"
|
||||
libmine = env.SharedLibrary("mine", Dir["src/lib/*.c"])
|
||||
libmine = env.SharedLibrary("mine", Rscons.glob("src/lib/*.c"))
|
||||
env.Program("test-shared.exe",
|
||||
Dir["src/*.c"],
|
||||
Rscons.glob("src/*.c"),
|
||||
"LIBPATH" => %w[.],
|
||||
"LIBS" => %w[mine])
|
||||
env.build_after("test-shared.exe", libmine.to_s)
|
||||
env.Program("test-static.exe",
|
||||
Dir["src/**/*.c"])
|
||||
Rscons.glob("src/**/*.c"))
|
||||
end
|
||||
|
@ -1,4 +1,4 @@
|
||||
Rscons::Environment.new do |env|
|
||||
env["sources"] = Dir["*.c"].sort
|
||||
env["sources"] = Rscons.glob("*.c")
|
||||
env.Program("simple.exe", "${sources}")
|
||||
end
|
||||
|
@ -165,6 +165,35 @@ 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
|
||||
|
||||
private
|
||||
|
||||
# Determine the number of threads to use by default.
|
||||
|
@ -250,8 +250,8 @@ EOF
|
||||
result = run_test(rsconsfile: "carat.rb")
|
||||
expect(result.stderr).to eq ""
|
||||
expect(Set[*lines(result.stdout)]).to eq Set[
|
||||
%q{gcc -c -o build_root/one.o -MMD -MF build_root/one.mf -MT TARGET -Isrc/one/ -Isrc/two/ build_root/one.c},
|
||||
%q{gcc -c -o build_root/src/two/two.o -MMD -MF build_root/src/two/two.mf -MT TARGET -Isrc/one/ -Isrc/two/ src/two/two.c},
|
||||
%q{gcc -c -o build_root/one.o -MMD -MF build_root/one.mf -MT TARGET -Isrc -Isrc/one -Isrc/two build_root/one.c},
|
||||
%q{gcc -c -o build_root/src/two/two.o -MMD -MF build_root/src/two/two.mf -MT TARGET -Isrc -Isrc/one -Isrc/two src/two/two.c},
|
||||
%Q{gcc -o build_dir.exe build_root/src/two/two.o build_root/one.o},
|
||||
]
|
||||
end
|
||||
@ -393,8 +393,8 @@ EOF
|
||||
result = run_test(rsconsfile: "build_hooks.rb")
|
||||
expect(result.stderr).to eq ""
|
||||
expect(Set[*lines(result.stdout)]).to eq Set[
|
||||
'gcc -c -o build_one/one.o -MMD -MF build_one/one.mf -MT TARGET -Isrc/one/ -Isrc/two/ -O1 src/one/one.c',
|
||||
'gcc -c -o build_two/two.o -MMD -MF build_two/two.mf -MT TARGET -Isrc/one/ -Isrc/two/ -O2 src/two/two.c',
|
||||
'gcc -c -o build_one/one.o -MMD -MF build_one/one.mf -MT TARGET -Isrc/one -Isrc/two -O1 src/one/one.c',
|
||||
'gcc -c -o build_two/two.o -MMD -MF build_two/two.mf -MT TARGET -Isrc/one -Isrc/two -O2 src/two/two.c',
|
||||
'gcc -o build_hook.exe build_one/one.o build_two/two.o',
|
||||
]
|
||||
expect(`./build_hook.exe`).to eq "Hello from two()\n"
|
||||
@ -894,8 +894,8 @@ EOF
|
||||
result = run_test(rsconsfile: "backward_compatible_build_hooks.rb")
|
||||
expect(result.stderr).to eq ""
|
||||
expect(Set[*lines(result.stdout)]).to eq Set[
|
||||
'gcc -c -o one.o -MMD -MF one.mf -MT TARGET -Isrc/one/ -Isrc/two/ -O1 src/two/two.c',
|
||||
'gcc -c -o two.o -MMD -MF two.mf -MT TARGET -Isrc/one/ -Isrc/two/ -O2 src/two/two.c'
|
||||
'gcc -c -o one.o -MMD -MF one.mf -MT TARGET -Isrc -Isrc/one -Isrc/two -O1 src/two/two.c',
|
||||
'gcc -c -o two.o -MMD -MF two.mf -MT TARGET -Isrc -Isrc/one -Isrc/two -O2 src/two/two.c'
|
||||
]
|
||||
expect(File.exists?('one.o')).to be_truthy
|
||||
expect(File.exists?('two.o')).to be_truthy
|
||||
|
Loading…
x
Reference in New Issue
Block a user