mirror of
https://gitlab.com/shorewall/code.git
synced 2024-11-15 04:04:10 +01:00
Finish externalization of compiler
git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@6520 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
parent
66c8c0a766
commit
840f2414bd
@ -3,6 +3,8 @@ Changes in 4.0.0 Beta 5
|
||||
1) Fix undefined function call when both an input interface and an
|
||||
output interface are present.
|
||||
|
||||
2) Externalize compiler and Compile.pm.
|
||||
|
||||
Changes in 4.0.0 Beta 4
|
||||
|
||||
1) Fix the 'Modules' output of 'dump'
|
||||
|
@ -27,7 +27,79 @@ Problems corrected in 4.0.0 Beta 5.
|
||||
|
||||
Other changes in Shorewall 4.0.0 Beta 5.
|
||||
|
||||
None.
|
||||
1) The Perl compiler is now externalized. Both the program
|
||||
'compiler.pl' and the Perl Module interface
|
||||
are now documented.
|
||||
|
||||
The compiler program is /usr/share/shorewall-perl/compiler.pl:
|
||||
|
||||
compiler.pl [ <options> ] [ <filename> ]
|
||||
|
||||
If a <filename> is given, then the configuration will be compiled
|
||||
output placed in the named file. If <filename> is not given, then
|
||||
the configuration will simply be syntax checked.
|
||||
|
||||
Options are:
|
||||
|
||||
-v <verbosity>
|
||||
--verbosity=<verbosity>
|
||||
|
||||
The <verbosity> is a number between 0 and 2 and corresponds to
|
||||
the VERBOSITY setting in shorewall.conf. This setting controls
|
||||
the verbosity of the compiler itself.
|
||||
|
||||
-e
|
||||
--export
|
||||
|
||||
If given, the configuration will be compiled for export to
|
||||
another system.
|
||||
|
||||
-d <directory>
|
||||
--directory=<directory>
|
||||
|
||||
If this option is omitted, the configuration in /etc/shorewall
|
||||
is compiled/checked. Otherwise, the configuration in the named
|
||||
directory will be compiled/checked.
|
||||
|
||||
-t
|
||||
--timestamp
|
||||
|
||||
If given, each progress message issued by the compiler and by
|
||||
the compiled program will be timestamped.
|
||||
|
||||
Example (compiles the configuration in the current directory
|
||||
generating a script named 'firewall' and using VERBOSITY
|
||||
2).
|
||||
|
||||
/usr/share/shorewall-perl/compiler.pl -v 2 -d . firewall
|
||||
|
||||
To use the Shorewall::Compiler module:
|
||||
|
||||
use lib '/usr/share/shorewall-perl';
|
||||
use Shorewall::Compiler;
|
||||
|
||||
Two functions are exported:
|
||||
|
||||
configure( $export, $directory, $verbose, $timestamp )
|
||||
|
||||
The arguments corresponding to the similarly-named
|
||||
run-line options. If passed as '', the value will be
|
||||
ignored.
|
||||
|
||||
configure will raise an exception with die if $directory
|
||||
is passed and does not name an existing directory.
|
||||
|
||||
Example: configure( '', '.', 2, '' );
|
||||
|
||||
compiler( $objectfile )
|
||||
|
||||
The compiler function accepts 1 argument. If it corresponds to
|
||||
the <filename> run-line argument. If the argument is
|
||||
false, then a check is performed; otherwise, the
|
||||
configuration is compiled into the named file.
|
||||
|
||||
Compilation errors cause the compiler to raise an exception via
|
||||
die.
|
||||
|
||||
Migration Considerations:
|
||||
|
||||
@ -560,6 +632,7 @@ Migration Considerations:
|
||||
- Perl Cwd Module
|
||||
- Perl File::Basename Module
|
||||
- Perl File::Temp Module
|
||||
- Perl Getopt::Long Module
|
||||
----------------------------------------------------------------------------
|
||||
U S I N G T H E N E W C O M P I L E R
|
||||
----------------------------------------------------------------------------
|
||||
|
@ -42,6 +42,8 @@ our @EXPORT = qw(
|
||||
emit_unindented
|
||||
save_progress_message
|
||||
save_progress_message_short
|
||||
set_timestamp
|
||||
set_verbose
|
||||
progress_message
|
||||
progress_message2
|
||||
progress_message3
|
||||
@ -78,9 +80,7 @@ our $tempfile; # Temporary File Name
|
||||
#
|
||||
sub fatal_error
|
||||
{
|
||||
print STDERR " ERROR: @_\n";
|
||||
|
||||
exit 1;
|
||||
die " ERROR: @_\n";
|
||||
}
|
||||
|
||||
#
|
||||
@ -154,6 +154,20 @@ sub save_progress_message_short( $ ) {
|
||||
emit "progress_message $_[0]" if $object;
|
||||
}
|
||||
|
||||
#
|
||||
# Set $timestamp
|
||||
#
|
||||
sub set_timestamp( $ ) {
|
||||
$timestamp = shift;
|
||||
}
|
||||
|
||||
#
|
||||
# Set $verbose
|
||||
#
|
||||
sub set_verbose( $ ) {
|
||||
$verbose = shift;
|
||||
}
|
||||
|
||||
#
|
||||
# Print the current TOD to STDOUT.
|
||||
#
|
||||
|
@ -43,12 +43,29 @@ use Shorewall::Proc;
|
||||
use Shorewall::Proxyarp;
|
||||
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw( compiler );
|
||||
our @EXPORT = qw( compiler configure );
|
||||
our @EXPORT_OK = qw( $export );
|
||||
our @VERSION = 1.00;
|
||||
|
||||
our $export = 0;
|
||||
|
||||
#
|
||||
# Configure the compiler
|
||||
#
|
||||
sub configure( $$$$ ) {
|
||||
my ( $export_param, $shorewall_dir, $verbose, $timestamp) = @_;
|
||||
|
||||
$export = $export_param if $export_param;
|
||||
|
||||
if ( $shorewall_dir ne '' ) {
|
||||
fatal_error "$shorewall_dir is not an existing directory" unless -d $shorewall_dir;
|
||||
set_shorewall_dir( $shorewall_dir );
|
||||
}
|
||||
|
||||
set_verbose( $verbose ) unless $verbose eq '';
|
||||
set_timestamp( $timestamp ) unless $timestamp eq '';
|
||||
}
|
||||
|
||||
#
|
||||
# First stage of script generation.
|
||||
#
|
||||
|
@ -36,6 +36,7 @@ our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(
|
||||
warning_message
|
||||
fatal_error
|
||||
set_shorewall_dir
|
||||
find_file
|
||||
split_line
|
||||
split_line1
|
||||
@ -281,9 +282,15 @@ sub warning_message
|
||||
sub fatal_error {
|
||||
my $lineinfo = $currentfile ? " : $currentfilename ( line $currentlinenumber )" : '';
|
||||
|
||||
print STDERR " ERROR: @_$lineinfo\n";
|
||||
die " ERROR: @_$lineinfo\n";
|
||||
|
||||
}
|
||||
|
||||
exit 1;
|
||||
#
|
||||
# Set $shorewall_dir
|
||||
#
|
||||
sub set_shorewall_dir( $ ) {
|
||||
$shorewall_dir = shift;
|
||||
}
|
||||
|
||||
#
|
||||
|
@ -25,7 +25,6 @@
|
||||
#
|
||||
use strict;
|
||||
use lib '/usr/share/shorewall-perl';
|
||||
use Shorewall::Config qw( fatal_error );
|
||||
use Shorewall::Compiler;
|
||||
use Getopt::Long;
|
||||
|
||||
@ -38,21 +37,26 @@ sub usage() {
|
||||
#
|
||||
Getopt::Long::Configure ('bundling');
|
||||
|
||||
my $result = GetOptions('export' => \$Shorewall::Compiler::export,
|
||||
'e' => \$Shorewall::Compiler::export,
|
||||
'directory=s' => \$Shorewall::Config::shorewall_dir,
|
||||
'd=s' => \$Shorewall::Config::shorewall_dir,
|
||||
'verbose=i' => \$Shorewall::Common::verbose,
|
||||
'v=i' => \$Shorewall::Common::verbose,
|
||||
'timestamp' => \$Shorewall::Common::timestamp,
|
||||
't' => \$Shorewall::Common::timestamp );
|
||||
my ( $export , $shorewall_dir, $verbose, $timestamp ) = qw( 0 '' '' '' );
|
||||
|
||||
usage unless $result;
|
||||
my $result = GetOptions('export' => \$export,
|
||||
'e' => \$export,
|
||||
'directory=s' => \$shorewall_dir,
|
||||
'd=s' => \$shorewall_dir,
|
||||
'verbose=i' => \$verbose,
|
||||
'v=i' => \$verbose,
|
||||
'timestamp' => \$timestamp,
|
||||
't' => \$timestamp );
|
||||
|
||||
if ( $Shorewall::Config::shorewall_dir ne '' ) {
|
||||
fatal_error "$Shorewall::Config::shorewall_dir is not an existing directory" unless -d $Shorewall::Config::shorewall_dir;
|
||||
usage unless $result && @ARGV < 2;
|
||||
|
||||
eval {
|
||||
configure( $export, $shorewall_dir, $verbose, $timestamp );
|
||||
compiler $ARGV[0];
|
||||
};
|
||||
|
||||
if ( $@ ) {
|
||||
print STDERR $@;
|
||||
exit 1;
|
||||
}
|
||||
|
||||
usage unless @ARGV < 2;
|
||||
|
||||
compiler $ARGV[0];
|
||||
|
Loading…
Reference in New Issue
Block a user