Skip to content

Add -MMD option #1673

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
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");
}
}

3 changes: 3 additions & 0 deletions t/80_vppreproc_v_hier_top_mmd.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generated by vppreproc

verilog/v_hier_top.v.d: verilog/v_hier_top.v verilog/v_hier_inc.vh
5 changes: 5 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,5 @@
# Generated by vppreproc

verilog/v_hier_top.v.d: verilog/v_hier_top.v verilog/v_hier_inc.vh

verilog/v_hier_inc.vh:
4 changes: 4 additions & 0 deletions t/80_vppreproc_v_res.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by vppreproc

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
61 changes: 61 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 @@ -92,6 +97,54 @@ if ($opt_dump_defines) {
printf "`define %s%s %s\n", $name,$par,$value;
}
}

# MMD MP option
# produces a list of makefile dependency rules suitable for use by a make utility
if ($opt_mmd) {
my $fh = IO::File->new;
if ($opt_output_filename) {
# Create a single .d
my ($filename, $dirs, $suffix) = File::Basename::fileparse($opt_output_filename, qr/\.[^.]*/);
my $opt_output_filename_d = File::Spec->canonpath("$dirs$filename.d"); # .d file
$fh->open(">$opt_output_filename_d") or die "%Error: $! $opt_output_filename_d\n";
printf $fh "# Generated by vppreproc\n\n"
} else {
# Create a .d for each input file
}
my %includes = %{$Opt->{includes}};
foreach my $target (sort (keys %includes)) {
my $dep_file; # MMD target
# Setup dep file
if ($opt_output_filename) {
$dep_file = $opt_output_filename;
} else {
$dep_file = "$target.d";
$fh->open(">$dep_file") or die "%Error: $! $dep_file\n";
printf $fh "# Generated by vppreproc\n\n"
}
# Create mmd dep
printf $fh "$dep_file: $target";
my @deps = (sort (keys %{$includes{$target}}));
foreach my $dep (@deps) {
$dep = File::Spec->canonpath($Opt->file_path($dep));
printf $fh " $dep";
}
printf $fh "\n";
# Create phony dependency targets (MP)
if ($opt_mp) {
foreach my $dep (@deps) {
$dep = File::Spec->canonpath($Opt->file_path($dep));
printf $fh "\n$dep:\n";
}
}
if (!$opt_output_filename){
$fh->close;
}
}
if ($opt_output_filename) {
$fh->close;
}
}

exit(0);

Expand Down Expand Up @@ -201,6 +254,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, similar to "gcc -MMD" behavior.

=item --MP

Create phony dependency targets, similar to "gcc -MP" behavior.

=item --noblank

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