Skip to content
This repository has been archived by the owner on Mar 7, 2019. It is now read-only.

Fix verbose output being captured as command output #147

Closed
wants to merge 1 commit into from

Conversation

salva
Copy link
Contributor

@salva salva commented Jan 8, 2016

Alien::Base::ModuleBuild::do_command captures the output from
Module::Build::Base::do_command, but the later may introduce debugging
output when Module::Build verbose mode is set.

This patch disables Mode::Build verbose mode before calling its
do_command method.

Alien::Base::ModuleBuild::do_command captures the output from
Module::Build::Base::do_command, but the later may introduce debugging
output when Module::Build verbose mode is set.

This patch disables Mode::Build verbose mode before calling its
do_command method.
@salva
Copy link
Contributor Author

salva commented Jan 8, 2016

This bug appears when calling perl Build.PL verbose=1.

@plicease
Copy link
Contributor

plicease commented Jan 8, 2016

Is stuff breaking because there is extra diagnostics in the captured output?

@salva
Copy link
Contributor Author

salva commented Jan 8, 2016

That extra output appears later on the value of version stored in PkgConfig.pm and it would probably also break the version check performed inside Alien::Base.

In general, any code calling do_command in order to get the output from some external command would probably expect that output to be unaltered and may be confused by any extra data.

@plicease
Copy link
Contributor

plicease commented Jan 8, 2016

It is sometimes hard to completely avoid contamination of output, for example if PkgConfig.pm throws a warning, or if a LD_PRELOADd library starts spewing debug messages or something. Anything parsing the output should make some effort to contend with that possibility, although it probably doesn't.

I'm a little leery of turning off verbosity, but not totally against it. If you can show actual breakage then there would be a stronger case for it.

@salva
Copy link
Contributor Author

salva commented Jan 8, 2016

Note that this patch only disables verbose mode when calling do_command and afterwards, immediately restores it. As currently implemented in Module::Build, the only message actually suppressed is the command to be run and it is dumped anyway by Alien::Base::ModuleBuild::do_method.

@mohawk2
Copy link
Contributor

mohawk2 commented Jan 9, 2016

I'm going with Graham on this one: when he's happy, I'm happy, not before.

@plicease
Copy link
Contributor

I looked at the code and my read is that turning of verbose will probably produce some false positives, in that AB::MB may think that a library is installed when it isn't if you run in verbose mode. I haven't been able to test this myself yet. Easy fix is the one that is proposed, and as @salva mentioned, the current implementation only prints out the command.

  • (aside) alien_check_installed_version should check the return status of the command that it executes. This probably doesn't solve the issue completely because the version stored on true positives will include the command executed which we don't want.

I think the more complicated, but more future proof answer is to override the log_* methods so that we can save any output and print them out after the capture. This way users expecting verbosity will get it and if future verbosity is added we don't silence it.

@plicease
Copy link
Contributor

To be sure I am not super crazy about either and am open to alternatives.

@salva
Copy link
Contributor Author

salva commented Jan 12, 2016

Another solution would be to duplicate STDOUT and STDERR when the Module::Build/Alien::Base object is initialized and use those new file handles for logging.

@plicease
Copy link
Contributor

That could work, have to make sure it is bullet proof on both windows and unix, but probably doable.

@salva
Copy link
Contributor Author

salva commented Jan 12, 2016

IIRC, Test::More or Test::Builder do something similar.

@plicease
Copy link
Contributor

We'd need to replicate the logic in Module::Build::Base of log_* for either of these alternatives. I am beginning to think that the original PR may actually be the lesser of all evils.

plicease added a commit that referenced this pull request Jan 13, 2016
If the command fails, but there is some output we get a false positive.
This problem was discovered when using perl Build.PL verbose=1
(and demonstrated with Alien::LibYAML).  While this exact problem
will hopefully be fixed with PR #147, there are other strangeisms
that could infect the captured output with bogus data.
@plicease
Copy link
Contributor

Confirmed that this causes breakage on Alien::LibYAML when you set verbose=1. While I'd like a better solution, there seem to be only more complicated and at least as fragile solutions. Aye.

@jberger
Copy link
Member

jberger commented Jan 13, 2016

The only other thing I can think of would be to default ABMB::Verbose to MB's verbose, though that's from a sanity argument; from looking at the proposed patch I don't suppose that that would fix the noted problems. I'm ok with the proposed fix: if MB is getting info that it shouldn't be, then don't hand it to it. Aye

@plicease
Copy link
Contributor

rebased and merged.

@plicease plicease closed this Jan 14, 2016
plicease added a commit that referenced this pull request Jan 18, 2016
If the command fails, but there is some output we get a false positive.
This problem was discovered when using perl Build.PL verbose=1
(and demonstrated with Alien::LibYAML).  While this exact problem
will hopefully be fixed with PR #147, there are other strangeisms
that could infect the captured output with bogus data.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants