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

ExtUtils::CBuilder - print out commands being run in usable form #19701

Merged
merged 2 commits into from
Jun 8, 2022
Merged
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
2 changes: 1 addition & 1 deletion dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use Perl::OSType qw/os_type/;

use warnings;
use strict;
our $VERSION = '0.280236'; # VERSION
our $VERSION = '0.280237'; # VERSION
our @ISA;

# We only use this once - don't waste a symbol table entry on it.
Expand Down
18 changes: 16 additions & 2 deletions dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use Text::ParseWords;
use IPC::Cmd qw(can_run);
use File::Temp qw(tempfile);

our $VERSION = '0.280236'; # VERSION
our $VERSION = '0.280237'; # VERSION

# More details about C/C++ compilers:
# http://developers.sun.com/sunstudio/documentation/product/compiler.jsp
Expand Down Expand Up @@ -335,10 +335,24 @@ sub _do_link {
return wantarray ? ($out, @temp_files) : $out;
}

sub quote_literal {
my ($self, $string) = @_;

if (length $string && $string !~ /[^a-zA-Z0-9,._+@%\/-]/) {
return $string;
}

$string =~ s{'}{'\\''}g;

return "'$string'";
}

sub do_system {
my ($self, @cmd) = @_;
print "@cmd\n" if !$self->{quiet};
if (!$self->{quiet}) {
my $full = join ' ', map $self->quote_literal($_), @cmd;
print $full . "\n";
}
return !system(@cmd);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use warnings;
use strict;
use ExtUtils::CBuilder::Base;

our $VERSION = '0.280236'; # VERSION
our $VERSION = '0.280237'; # VERSION
our @ISA = qw(ExtUtils::CBuilder::Base);

sub link_executable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use warnings;
use strict;
use ExtUtils::CBuilder::Base;

our $VERSION = '0.280236'; # VERSION
our $VERSION = '0.280237'; # VERSION
our @ISA = qw(ExtUtils::CBuilder::Base);

use File::Spec::Functions qw(catfile catdir);
Expand Down
31 changes: 26 additions & 5 deletions dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Platform/Windows.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use File::Spec;
use ExtUtils::CBuilder::Base;
use IO::File;

our $VERSION = '0.280236'; # VERSION
our $VERSION = '0.280237'; # VERSION
our @ISA = qw(ExtUtils::CBuilder::Base);

=begin comment
Expand Down Expand Up @@ -51,6 +51,22 @@ sub _compiler_type {
: 'GCC');
}

# native quoting, not shell quoting
sub quote_literal {
my ($self, $string) = @_;

# some of these characters don't need to be quoted for "native" quoting, but
# quote them anyway so they are more likely to make it through cmd.exe
if (length $string && $string !~ /[ \t\n\x0b"|<>%]/) {
return $string;
}

$string =~ s{(\\*)(?="|\z)}{$1$1}g;
$string =~ s{"}{\\"}g;

return qq{"$string"};
}

sub split_like_shell {
# Since Windows will pass the whole command string (not an argument
# array) to the target program and make the program parse it itself,
Expand All @@ -65,10 +81,15 @@ sub split_like_shell {
sub do_system {
# See above
my $self = shift;
my $cmd = join(" ",
grep length,
map {$a=$_;$a=~s/\t/ /g;$a=~s/^\s+|\s+$//;$a}
grep defined, @_);
my $cmd = join ' ',
grep length,
map {$a=$_;$a=~s/\t/ /g;$a=~s/^\s+|\s+$//;$a}
grep defined, @_;

if (!$self->{quiet}) {
print $cmd . "\n";
}
local $self->{quiet} = 1;
return $self->SUPER::do_system($cmd);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ExtUtils::CBuilder::Platform::Windows::BCC;

our $VERSION = '0.280236'; # VERSION
our $VERSION = '0.280237'; # VERSION

use strict;
use warnings;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ExtUtils::CBuilder::Platform::Windows::GCC;

our $VERSION = '0.280236'; # VERSION
our $VERSION = '0.280237'; # VERSION

use warnings;
use strict;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ExtUtils::CBuilder::Platform::Windows::MSVC;

our $VERSION = '0.280236'; # VERSION
our $VERSION = '0.280237'; # VERSION

use warnings;
use strict;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use strict;
use ExtUtils::CBuilder::Platform::Unix;
use File::Spec;

our $VERSION = '0.280236'; # VERSION
our $VERSION = '0.280237'; # VERSION
our @ISA = qw(ExtUtils::CBuilder::Platform::Unix);

sub need_prelink { 1 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use File::Spec;
use ExtUtils::CBuilder::Platform::Unix;
use Config;

our $VERSION = '0.280236'; # VERSION
our $VERSION = '0.280237'; # VERSION
our @ISA = qw(ExtUtils::CBuilder::Platform::Unix);

# The Android linker will not recognize symbols from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use strict;
use File::Spec;
use ExtUtils::CBuilder::Platform::Unix;

our $VERSION = '0.280236'; # VERSION
our $VERSION = '0.280237'; # VERSION
our @ISA = qw(ExtUtils::CBuilder::Platform::Unix);

# TODO: If a specific exe_file name is requested, if the exe created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use warnings;
use strict;
use ExtUtils::CBuilder::Platform::Unix;

our $VERSION = '0.280236'; # VERSION
our $VERSION = '0.280237'; # VERSION
our @ISA = qw(ExtUtils::CBuilder::Platform::Unix);

sub compile {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use strict;
use ExtUtils::CBuilder::Platform::Unix;
use File::Spec;

our $VERSION = '0.280236'; # VERSION
our $VERSION = '0.280237'; # VERSION
our @ISA = qw(ExtUtils::CBuilder::Platform::Unix);

sub link_executable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use warnings;
use strict;
use ExtUtils::CBuilder::Platform::Unix;

our $VERSION = '0.280236'; # VERSION
our $VERSION = '0.280237'; # VERSION
our @ISA = qw(ExtUtils::CBuilder::Platform::Unix);

sub need_prelink { 1 }
Expand Down