mirror of
				https://codeberg.org/h3xx/simplify_static_dir
				synced 2024-08-14 23:57:24 +00:00 
			
		
		
		
	Use perl-squasher project to create all-in-one script
This commit is contained in:
		
							parent
							
								
									ed9e369069
								
							
						
					
					
						commit
						fd8793787b
					
				
					 5 changed files with 9 additions and 92 deletions
				
			
		|  | @ -12,5 +12,8 @@ indent_size = 4 | ||||||
| [*.md] | [*.md] | ||||||
| indent_size = 2 | indent_size = 2 | ||||||
| 
 | 
 | ||||||
|  | [.gitmodules] | ||||||
|  | indent_style = tab | ||||||
|  | 
 | ||||||
| [{Makefile,*.mak}] | [{Makefile,*.mak}] | ||||||
| indent_style = tab | indent_style = tab | ||||||
|  |  | ||||||
							
								
								
									
										4
									
								
								.gitmodules
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								.gitmodules
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,4 @@ | ||||||
|  | [submodule "perl-squasher"] | ||||||
|  | 	path = util/perl-squasher | ||||||
|  | 	url = https://codeberg.org/h3xx/perl-squasher.git | ||||||
|  | 	branch = main | ||||||
|  | @ -5,7 +5,7 @@ OUT=$WORKDIR/simplify_static_dir.pl | ||||||
| echo "Outputting to $OUT" >&2 | echo "Outputting to $OUT" >&2 | ||||||
| 
 | 
 | ||||||
| shopt -s globstar | shopt -s globstar | ||||||
| "$WORKDIR/util/squash" \ | "$WORKDIR/util/perl-squasher/squash" \ | ||||||
|     "$WORKDIR/simplify_static_dir-main.pl" \ |     "$WORKDIR/simplify_static_dir-main.pl" \ | ||||||
|     "$WORKDIR"/lib/**/*.pm \ |     "$WORKDIR"/lib/**/*.pm \ | ||||||
|     > "$OUT" |     > "$OUT" | ||||||
|  |  | ||||||
							
								
								
									
										1
									
								
								util/perl-squasher
									
										
									
									
									
										Submodule
									
								
							
							
						
						
									
										1
									
								
								util/perl-squasher
									
										
									
									
									
										Submodule
									
								
							|  | @ -0,0 +1 @@ | ||||||
|  | Subproject commit 9d414ab346caed6035db5a0512d6c89912a8826c | ||||||
							
								
								
									
										91
									
								
								util/squash
									
										
									
									
									
								
							
							
						
						
									
										91
									
								
								util/squash
									
										
									
									
									
								
							|  | @ -1,91 +0,0 @@ | ||||||
| #!/usr/bin/perl |  | ||||||
| 
 |  | ||||||
| # Squashes together the parts of the app into the single script. |  | ||||||
| # (Adapted from the script that squashes App::Ack - see https://github.com/beyondgrep/ack3) |  | ||||||
| use warnings; |  | ||||||
| use strict; |  | ||||||
| 
 |  | ||||||
| my $code; |  | ||||||
| for my $arg (@ARGV) { |  | ||||||
|     my $filename = $arg; |  | ||||||
|     if ($arg =~ /::/) { |  | ||||||
|         my $key = "$arg.pm"; |  | ||||||
|         $key =~ s{::}{/}g; |  | ||||||
|         $filename = $INC{$key} or die "Can't find the file for $arg"; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     warn "Reading $filename\n"; |  | ||||||
|     open my $fh, '<', $filename or die "Can't open $filename: $!"; |  | ||||||
|     my $in_pod = 0; |  | ||||||
|     my $in_section = ''; |  | ||||||
|     my $ignore_lines = 0; |  | ||||||
|     my $empty_lines = 0; |  | ||||||
|     while (<$fh>) { |  | ||||||
|         if (/#.*:squash-ignore-start:$/) { |  | ||||||
|             $in_section = 'ignore'; |  | ||||||
|             $ignore_lines = 1; |  | ||||||
|         } elsif (/#.*:squash-ignore-end:$/) { |  | ||||||
|             $in_section = ''; |  | ||||||
|             $ignore_lines = 1; |  | ||||||
|         } |  | ||||||
|         if ($ignore_lines > 0) { |  | ||||||
|             $ignore_lines--; |  | ||||||
|             next; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         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;$/; |  | ||||||
| 
 |  | ||||||
|         if ($filename =~ /\.pm$/) { |  | ||||||
|             # See if we're in module POD blocks |  | ||||||
|             if (/^=(\w+)/) { |  | ||||||
|                 $in_pod = ($1 ne 'cut'); |  | ||||||
|                 next; |  | ||||||
|             } |  | ||||||
|             elsif ($in_pod) { |  | ||||||
|                 next; |  | ||||||
|             } |  | ||||||
|             next if /^# vi:/; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         # Remove Perl::Critic comments. |  | ||||||
|         # I'd like to remove all comments, but this is a start |  | ||||||
|         s{\s*##.+critic.*}{}; |  | ||||||
|         $code .= $_; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     # Warn if there were unterminated :squash-*: sections |  | ||||||
|     warn "$filename: Unterminated :squash-$in_section-start: section" if $in_section; |  | ||||||
| 
 |  | ||||||
|     close $fh; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| print $code; |  | ||||||
| 
 |  | ||||||
| exit 0; |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue