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

Add -MMD option #1673

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
63 changes: 54 additions & 9 deletions t/80_vppreproc.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ use IO::File;
use strict;
use Test::More;

BEGIN { plan tests => 15 }
BEGIN { plan tests => 24 }
BEGIN { require "./t/test_utils.pl"; }

print "Checking vppreproc...\n";

vppreproc ("t/80_vppreproc_none.out", "test_dir/vppreproc_none.v", "");
vppreproc ("t/80_vppreproc_cmped.out", "test_dir/vppreproc_cmped.v", "--nocomment --pedantic");
vppreproc ("t/80_vppreproc_none.out", "test_dir/vppreproc_none.v", "");
vppreproc ("t/80_vppreproc_cmped.out", "test_dir/vppreproc_cmped.v", "--nocomment --pedantic");
vppreproc ("t/80_vppreproc_simple.out", "test_dir/vppreproc_simple.v", "--simple");
vppreproc ("t/80_vppreproc_defines.out", "test_dir/vppreproc_defines.v", "--dump-defines");
vppreproc ("t/80_vppreproc_rel_file.out", "test_dir/vppreproc_rel_file.v", "-f verilog/t_80_foo.f");
Expand All @@ -28,12 +28,57 @@ sub vppreproc {
my $cmd = "${PERL} ./vppreproc ${flags} -y verilog inc2.v > $out";

if (0 == run_system_no_die ($cmd)) {
pass("run command");
ok(-r $out, "vppreproc output from: $cmd");
ok(files_identical ($out, $checkname), "diff");
pass("run command");
ok(-r $out, "vppreproc output from: $cmd");
ok(files_identical ($out, $checkname), "diff");
} else {
fail ("run command");
fail ("no output file created");
fail ("no output file to compare");
fail ("run command");
fail ("no output file created");
fail ("no output file to compare");
}
}



# Test -MMD -MP
vppreproc_d ("t/80_vppreproc_v_hier_top_mmd_mp.d", "-MMD -MP");
vppreproc_d ("t/80_vppreproc_v_hier_top_mmd.d", "-MMD");
vppreproc_d_o();

sub vppreproc_d {
my $checkname = shift;
my $flags = shift;
my $defaultcfg = "verilog/v_hier_top.v verilog/v_sv_intf.v +incdir+verilog";
my $cmd = "${PERL} ./vppreproc $flags $defaultcfg";
my $dotd = "verilog/v_hier_top.v.d";
if (0 == run_system_no_die ($cmd)) {
pass("run command");
ok(-r $dotd, "vppreproc .d from: $cmd");
ok(files_identical ($dotd, $checkname), "diff");
} else {
fail ("run command");
fail ("no output file created");
fail ("no output file to compare");
}
system ("/bin/rm -f verilog/v_hier_top.v.d verilog/v_sv_intf.v.d");
}

sub vppreproc_d_o {
my $obasename = "res";
my $checkname = "t/80_vppreproc_v_res.d";
my $defaultcfg = "verilog/v_hier_top.v verilog/v_sv_intf.v +incdir+verilog";
my $cmd = "${PERL} ./vppreproc -MMD -o test_dir/$obasename.vpp $defaultcfg";
my $dotd = "test_dir/$obasename.d";

system ("/bin/rm -f $dotd");
if (0 == run_system_no_die ($cmd)) {
pass("run command");
ok(-r $dotd, "vppreproc .d from: $cmd");
ok(files_identical ($dotd, $checkname), "diff");
} else {
fail ("run command");
fail ("no output file created");
fail ("no output file to compare");
}
}

1 change: 1 addition & 0 deletions t/80_vppreproc_v_hier_top_mmd.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
verilog/v_hier_top.v.d: verilog/v_hier_top.v verilog/v_hier_inc.vh
3 changes: 3 additions & 0 deletions t/80_vppreproc_v_hier_top_mmd_mp.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
verilog/v_hier_top.v.d: verilog/v_hier_top.v verilog/v_hier_inc.vh

verilog/v_hier_inc.vh:
2 changes: 2 additions & 0 deletions t/80_vppreproc_v_res.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test_dir/res.vpp: verilog/v_hier_top.v verilog/v_hier_inc.vh
test_dir/res.vpp: verilog/v_sv_intf.v verilog/v_sv_pkg.v
60 changes: 60 additions & 0 deletions vppreproc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use lib "$RealBin";
use Getopt::Long;
use IO::File;
use Pod::Usage;
use File::Basename;

use Verilog::Preproc;
use Verilog::Getopt;
Expand All @@ -25,6 +26,8 @@ $Debug = 0;
my $opt_output_filename = undef;
my $opt_blank=1;
my $opt_dump_defines;
my $opt_mmd;
my $opt_mp;
my @opt_files;
my @opt_pp_flags;

Expand All @@ -45,6 +48,8 @@ if (! GetOptions (
"blank!" => \$opt_blank,
"comment!" => sub { push @opt_pp_flags, (keep_comments=>$_[1]); },
"dump-defines!" => \$opt_dump_defines,
"MMD!" => \$opt_mmd,
"MP!" => \$opt_mp,
"line!" => sub { push @opt_pp_flags, (line_directives=>$_[1]); },
"P!" => sub { $opt_blank=0; push @opt_pp_flags, (line_directives=>$_[1]); },
"pedantic!" => sub { push @opt_pp_flags, (pedantic=>$_[1]); },
Expand Down Expand Up @@ -93,6 +98,53 @@ if ($opt_dump_defines) {
}
}


# MMD MP option
# produces a list of makefile dependency rules suitable for use by a make utility
if ($opt_mmd) {
my $opt_output_filename_d; # .d file
my $dep_file; # MMD target
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to inside foreach, just before set

if ($opt_output_filename) {
# Create a single .d
my($filename, $dirs, $suffix) = File::Basename::fileparse($opt_output_filename, qr/\.[^.]*/);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
my($filename, $dirs, $suffix) = File::Basename::fileparse($opt_output_filename, qr/\.[^.]*/);
my ($filename, $dirs, $suffix) = File::Basename::fileparse($opt_output_filename, qr/\.[^.]*/);

$opt_output_filename_d = File::Spec->canonpath("$dirs$filename.d");
open(TARGET_D, '>', $opt_output_filename_d) or die "%Error: $! $opt_output_filename\n";
} else {
# Create a .d for each input file
}
my %includes = %{$Opt->{includes}};
foreach my $target (sort (keys %includes)) {
# Setup dep file
if($opt_output_filename){
$dep_file = $opt_output_filename;
} else {
$dep_file = "$target.d";
open(TARGET_D, '>', $dep_file) or die $!;
}
# Create mmd dep
printf TARGET_D "$dep_file: $target";
my @deps = (sort (keys %{$includes{$target}}));
foreach my $dep (@deps) {
$dep = File::Spec->canonpath($Opt->file_path($dep));
printf TARGET_D " $dep";
}
printf TARGET_D "\n";
# Create phony dependency targets (MP)
if ($opt_mp) {
foreach my $dep (@deps) {
$dep = File::Spec->canonpath($Opt->file_path($dep));
printf TARGET_D "\n$dep:\n";
}
}
if (!$opt_output_filename){
close(TARGET_D);
}
}
if ($opt_output_filename) {
close(TARGET_D);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!$opt_output_filename){
close(TARGET_D);
}
}
if ($opt_output_filename) {
close(TARGET_D);
}
}

Close not needed once use handles.

}

exit(0);

######################################################################
Expand Down Expand Up @@ -201,6 +253,14 @@ Use the given filename for output instead of stdout.
Suppress normal output, and instead print a list of all defines existing at
the end of processing the input file.

=item --MMD

Create .d dependency files.

=item --MP

Create phony dependency targets.

=item --noblank

Removes empty lines from the output. Should be used with --noline, as if
Expand Down