diff --git a/build_tests/d/Rsconscript b/build_tests/d/Rsconscript index 846d4d0..efdef30 100644 --- a/build_tests/d/Rsconscript +++ b/build_tests/d/Rsconscript @@ -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 diff --git a/build_tests/direct/c_program.rb b/build_tests/direct/c_program.rb index 0269e84..cddff17 100644 --- a/build_tests/direct/c_program.rb +++ b/build_tests/direct/c_program.rb @@ -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 diff --git a/build_tests/library/override_arcmd.rb b/build_tests/library/override_arcmd.rb index 10fde32..f14f9d8 100644 --- a/build_tests/library/override_arcmd.rb +++ b/build_tests/library/override_arcmd.rb @@ -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 diff --git a/build_tests/shared_library/Rsconscript b/build_tests/shared_library/Rsconscript index 882bd08..746d1cc 100644 --- a/build_tests/shared_library/Rsconscript +++ b/build_tests/shared_library/Rsconscript @@ -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 diff --git a/build_tests/shared_library/shared_library_cxx.rb b/build_tests/shared_library/shared_library_cxx.rb index 1fce3c3..c148ac3 100644 --- a/build_tests/shared_library/shared_library_cxx.rb +++ b/build_tests/shared_library/shared_library_cxx.rb @@ -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 diff --git a/build_tests/shared_library/shared_library_d.rb b/build_tests/shared_library/shared_library_d.rb index 06d5a57..50e5a93 100644 --- a/build_tests/shared_library/shared_library_d.rb +++ b/build_tests/shared_library/shared_library_d.rb @@ -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) diff --git a/build_tests/shared_library/shared_library_set_shld.rb b/build_tests/shared_library/shared_library_set_shld.rb index 07c54d6..3c44570 100644 --- a/build_tests/shared_library/shared_library_set_shld.rb +++ b/build_tests/shared_library/shared_library_set_shld.rb @@ -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 diff --git a/build_tests/simple/cvar_array.rb b/build_tests/simple/cvar_array.rb index b1b6b3e..f27fc45 100644 --- a/build_tests/simple/cvar_array.rb +++ b/build_tests/simple/cvar_array.rb @@ -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 diff --git a/build_tests/typical/build_hooks.rb b/build_tests/typical/build_hooks.rb index 4c96e24..ceec0ac 100644 --- a/build_tests/typical/build_hooks.rb +++ b/build_tests/typical/build_hooks.rb @@ -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 diff --git a/build_tests/typical/build_hooks_override_vars.rb b/build_tests/typical/build_hooks_override_vars.rb index 023ccee..3dda2cf 100644 --- a/build_tests/typical/build_hooks_override_vars.rb +++ b/build_tests/typical/build_hooks_override_vars.rb @@ -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" diff --git a/build_tests/typical/carat.rb b/build_tests/typical/carat.rb index 65b3c7b..52acf4f 100644 --- a/build_tests/typical/carat.rb +++ b/build_tests/typical/carat.rb @@ -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 diff --git a/build_tests/typical/csuffix.rb b/build_tests/typical/csuffix.rb index 1472293..0c3b30d 100644 --- a/build_tests/typical/csuffix.rb +++ b/build_tests/typical/csuffix.rb @@ -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 diff --git a/lib/rscons.rb b/lib/rscons.rb index 4aed2d7..65fab52 100644 --- a/lib/rscons.rb +++ b/lib/rscons.rb @@ -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] 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 diff --git a/lib/rscons/script.rb b/lib/rscons/script.rb index 09358d2..eba8702 100644 --- a/lib/rscons/script.rb +++ b/lib/rscons/script.rb @@ -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] 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