Compare commits

...

3 Commits

Author SHA1 Message Date
Dan Church a26764fd2f
Fix squasher stripping repeated newlines in ignored sections 2023-06-29 13:28:03 -05:00
Dan Church 4d4edd5e9d
Move library code to lib/
Fixes accidental inclusion of test instrumentation into the all-in-one
script.
2023-06-29 13:01:29 -05:00
Dan Church 9dc3e4578c
Re-write squasher
Add ability to skip over sections (ignore) vs. completely remove them
(remove).
2023-06-29 12:57:15 -05:00
9 changed files with 53 additions and 21 deletions

View File

@ -8,9 +8,9 @@ Object for abstracting management of a hashed filesystem
=cut
# :squash-ignore-start:
# :squash-remove-start:
require Directory::Simplify::File;
# :squash-ignore-end:
# :squash-remove-end:
sub new {
my $class = shift;

View File

@ -4,9 +4,9 @@ use strict;
use warnings;
use overload '""' => 'as_string';
# :squash-ignore-start:
# :squash-remove-start:
require Directory::Simplify::Utils;
# :squash-ignore-end:
# :squash-remove-end:
sub new {
my $class = shift;

View File

@ -6,10 +6,10 @@ use overload '""' => 'as_string';
use File::Basename qw/ dirname /;
use File::Compare qw/ compare /;
# :squash-ignore-start:
# :squash-remove-start:
require Directory::Simplify::Instruction::CopyTimestamp;
require Directory::Simplify::Instruction::Hardlink;
# :squash-ignore-end:
# :squash-remove-end:
sub new {
my $class = shift;

View File

@ -4,9 +4,9 @@ use strict;
use warnings;
use overload '""' => 'as_string';
# :squash-ignore-start:
# :squash-remove-start:
require Directory::Simplify::Utils;
# :squash-ignore-end:
# :squash-remove-end:
sub new {
my $class = shift;

View File

@ -8,6 +8,6 @@ echo "Outputting to $OUT" >&2
shopt -s globstar
"$WORKDIR/util/squash" \
"$WORKDIR/simplify_static_dir-main.pl" \
"$WORKDIR"/**/*.pm \
"$WORKDIR"/lib/**/*.pm \
> "$OUT"
chmod +x -- "$OUT"

View File

@ -104,16 +104,16 @@ use File::Find qw/ find /;
use Getopt::Std qw/ getopts /;
use Pod::Usage qw/ pod2usage /;
# :squash-ignore-start:
# :squash-remove-start:
# (this prepends to the load path)
use FindBin qw//;
use lib $FindBin::RealBin;
use lib "$FindBin::RealBin/lib";
require Directory::Simplify::File;
require Directory::Simplify::FileHash;
require Directory::Simplify::Instruction::Generator;
require Directory::Simplify::Utils;
# :squash-ignore-end:
# :squash-remove-end:
sub HELP_MESSAGE {
my $fh = shift;

View File

@ -18,17 +18,48 @@ for my $arg (@ARGV) {
warn "Reading $filename\n";
open my $fh, '<', $filename or die "Can't open $filename: $!";
my $in_pod = 0;
my $in_ignore_section = 0;
my $in_section = '';
my $ignore_lines = 0;
my $empty_lines = 0;
while (<$fh>) {
if (/#.*:squash-ignore-start:$/) {
$in_ignore_section = 1;
next;
$in_section = 'ignore';
$ignore_lines = 1;
} elsif (/#.*:squash-ignore-end:$/) {
$in_ignore_section = 0;
$in_section = '';
$ignore_lines = 1;
}
if ($ignore_lines > 0) {
$ignore_lines--;
next;
}
next if $in_ignore_section;
next if /#.*:squash-ignore-line:$/;
if ($in_section eq 'ignore') {
$empty_lines = 0 unless /^$/;
$code .= $_;
next;
}
# Remove repeated newlines between paragraphs
# (Provided of course we're not in an 'ignore' section)
if (/^$/) {
++$empty_lines;
if ($empty_lines > 1) {
next;
}
} else {
$empty_lines = 0;
}
if (/#.*:squash-remove-start:$/) {
$in_section = 'remove';
next;
} elsif (/#.*:squash-remove-end:$/) {
$in_section = '';
next;
}
next if $in_section eq 'remove';
next if /#.*:squash-remove-line:$/;
next if /^\s*1;$/;
@ -49,12 +80,13 @@ for my $arg (@ARGV) {
s{\s*##.+critic.*}{};
$code .= $_;
}
# Warn if there were unterminated :squash-*: sections
warn "$filename: Unterminated :squash-$in_section-start: section" if $in_section;
close $fh;
}
# Remove repeated newlines between paragraphs
$code =~ s/\n\n+/\n\n/gs;
print $code;
exit 0;