From 4dc1280f685b01fcf1a8ac40c9c2442a7cb85d99 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 28 Jan 2026 11:56:34 -0500 Subject: [PATCH] Add Util.glob() and use from Script --- lib/rscons/script.rb | 10 +--------- lib/rscons/util.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/rscons/script.rb b/lib/rscons/script.rb index 55ee043..a48752d 100644 --- a/lib/rscons/script.rb +++ b/lib/rscons/script.rb @@ -34,15 +34,7 @@ module Rscons # # @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 + Util.glob(*patterns) end # Download a file. diff --git a/lib/rscons/util.rb b/lib/rscons/util.rb index 8bacb73..27a087c 100644 --- a/lib/rscons/util.rb +++ b/lib/rscons/util.rb @@ -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] 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]