Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1519 cpan: prevent MakeMaker user prompts #1520

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/fpm/package/cpan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ def input(package)
cpanm_flags += ["--force"] if attributes[:cpan_cpanm_force?]
cpanm_flags += ["--verbose"] if attributes[:cpan_verbose?]

safesystem(attributes[:cpan_cpanm_bin], *cpanm_flags)

# Run cpanm with stdin enabled so that ExtUtils::MakeMaker does not prompt user for input
safesystemin("", attributes[:cpan_cpanm_bin], *cpanm_flags)

if !attributes[:no_auto_depends?]
found_dependencies = {}
if metadata["requires"]
Expand Down Expand Up @@ -233,13 +234,13 @@ def input(package)
elsif File.exist?("Makefile.PL")
if attributes[:cpan_perl_lib_path]
perl_lib_path = attributes[:cpan_perl_lib_path]
safesystem(attributes[:cpan_perl_bin],
safesystemin("", attributes[:cpan_perl_bin],
"-Mlocal::lib=#{build_path("cpan")}",
"Makefile.PL", "PREFIX=#{prefix}", "LIB=#{perl_lib_path}",
# Empty install_base to avoid local::lib being used.
"INSTALL_BASE=")
else
safesystem(attributes[:cpan_perl_bin],
safesystemin("", attributes[:cpan_perl_bin],
"-Mlocal::lib=#{build_path("cpan")}",
"Makefile.PL", "PREFIX=#{prefix}",
# Empty install_base to avoid local::lib being used.
Expand Down
42 changes: 38 additions & 4 deletions lib/fpm/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def execmd(*args)
opts[:stdin] = true unless opts.include?(:stdin)
opts[:stdout] = true unless opts.include?(:stdout)
opts[:stderr] = true unless opts.include?(:stderr)
opts[:suppress_output] = false unless opts.include?(:suppress_output)

if !program.include?("/") and !program_in_path?(program)
raise ExecutableNotFound.new(program)
Expand Down Expand Up @@ -165,14 +166,14 @@ def execmd(*args)
args3 = []
args3.push(process) if opts[:process]
args3.push(process.io.stdin) if opts[:stdin]
args3.push(stdout_r) if opts[:stdout]
args3.push(stderr_r) if opts[:stderr]
args3.push(stdout_r) if opts[:stdout] && !opts[:suppress_output]
args3.push(stderr_r) if opts[:stderr] && !opts[:suppress_output]

yield(*args3)

process.io.stdin.close if opts[:stdin] and not process.io.stdin.closed?
stdout_r.close unless stdout_r.closed?
stderr_r.close unless stderr_r.closed?
stdout_r.close unless stdout_r.closed? || opts[:suppress_output]
stderr_r.close unless stderr_r.closed? || opts[:suppress_output]
else
# Log both stdout and stderr as 'info' because nobody uses stderr for
# actually reporting errors and as a result 'stderr' is a misnomer.
Expand Down Expand Up @@ -208,6 +209,39 @@ def safesystem(*args)
return success
end # def safesystem

# Run a command safely in a way that pushes stdin to command
def safesystemin(*args)
# Our first argument is our stdin
safe_stdin = args.shift()

if args.size == 1
args = [ default_shell, "-c", args[0] ]
end

if args[0].kind_of?(Hash)
env = args.shift()
logger.info("foo")
exit_code = execmd(env, args, :suppress_output=>true) do |stdin,stdout,stderr|
stdin.write(safe_stdin)
stdin.close
end
else
logger.info("bar")
exit_code = execmd(args, :suppress_output=>true) do |stdin,stdout,stderr|
stdin.write(safe_stdin)
stdin.close
end
end
program = args[0]
success = (exit_code == 0)

if !success
raise ProcessFailed.new("#{program} failed (exit code #{exit_code})" \
". Full command was:#{args.inspect}")
end
return success
end # def safesystemin

# Run a command safely in a way that captures output and status.
def safesystemout(*args)
if args.size == 1
Expand Down