add Environment#shell - close #11
This commit is contained in:
1 parent
a1a4cc18cd
commit
ae9021a505
4 files changed
+120
No files matched your search
@@ -54,4 +54,33 @@ module Rscons
|
||||
def self.set_suffix(path, suffix)
|
||||
path.sub(/\.[^.]*$/, suffix)
|
||||
end
|
||||
|
||||
# Return the system shell and arguments for executing a shell command.
|
||||
# @return [Array<String>] The shell and flag.
|
||||
def self.get_system_shell
|
||||
@@shell ||=
|
||||
begin
|
||||
test_shell = lambda do |*args|
|
||||
begin
|
||||
"success" == IO.popen([*args, "echo success"]) do |io|
|
||||
io.read.strip
|
||||
end
|
||||
rescue
|
||||
false
|
||||
end
|
||||
end
|
||||
if ENV["SHELL"] and ENV["SHELL"] != "" and test_shell[ENV["SHELL"], "-c"]
|
||||
[ENV["SHELL"], "-c"]
|
||||
elsif Object.const_get("RUBY_PLATFORM") =~ /mingw/
|
||||
if test_shell["sh", "-c"]
|
||||
# Using Rscons from MSYS should use MSYS's shell.
|
||||
["sh", "-c"]
|
||||
else
|
||||
["cmd", "/c"]
|
||||
end
|
||||
else
|
||||
["sh", "-c"]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -349,6 +349,35 @@ module Rscons
|
||||
path.sub(%r{^\^(?=[\\/])}, @build_root)
|
||||
end
|
||||
|
||||
# Execute a command using the system shell.
|
||||
#
|
||||
# The shell is automatically determined but can be overridden by the SHELL
|
||||
# construction variable. If the SHELL construction variable is specified,
|
||||
# the flag to pass to the shell is automatically dtermined but can be
|
||||
# overridden by the SHELLFLAG construction variable.
|
||||
#
|
||||
# @param command [String] Command to execute.
|
||||
#
|
||||
# @return [String] The command's standard output.
|
||||
def shell(command)
|
||||
shell_cmd =
|
||||
if self["SHELL"]
|
||||
flag = self["SHELLFLAG"] || begin
|
||||
if self["SHELL"] == "cmd"
|
||||
"/c"
|
||||
else
|
||||
"-c"
|
||||
end
|
||||
end
|
||||
[self["SHELL"], flag]
|
||||
else
|
||||
Rscons.get_system_shell
|
||||
end
|
||||
IO.popen([*shell_cmd, command]) do |io|
|
||||
io.read
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Expand target and source paths before invoking builders.
|
||||
|
||||
Reference in new issue
Block a user