add Rscons.glob - close #50

This commit is contained in:
josh committed 2018-08-23 11:26:20 -04:00
1 parent 57de94a3fb
commit c7f66694ab
17 files changed
+64 -35

No files matched your search

+29
View File
@@ -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.