]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow static lua files in any parts of rspamd sources
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 28 May 2016 11:26:49 +0000 (12:26 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 28 May 2016 11:26:49 +0000 (12:26 +0100)
lua_preprocess.pl [new file with mode: 0644]
src/CMakeLists.txt
src/lua/CMakeLists.txt
src/rspamadm/CMakeLists.txt
src/rspamadm/lua_preprocess.pl [deleted file]

diff --git a/lua_preprocess.pl b/lua_preprocess.pl
new file mode 100644 (file)
index 0000000..d1e8f46
--- /dev/null
@@ -0,0 +1,86 @@
+#!/usr/bin/env perl
+
+use warnings FATAL => 'all';
+use strict;
+use Digest::MD5;
+
+my ( $in_dir, $out_dir ) = @ARGV;
+my @files = <$in_dir/*.lua>;
+
+sub quote_file {
+       my ( $in, $out ) = @_;
+
+       while (<$in>) {
+               if (/^--.USE\s*"(\S+)"$/) {
+                       open( my $inc, '<', "$in_dir/$1.lua.in" )
+                         or die "missing include $1";
+                       quote_file( $inc, $out );
+               }
+               else {
+                       s/^\s*//;    # remove unnecessary spaces at the beginning
+                       next if /^--/;      # skip comments
+                       next if /^\s*$/;    # skip empty lines
+                       s/(.)/'$1',/g;          # split as 'c',
+                       s/\'\\\'/\'\\\\'/g;     # escape backslashes
+                       s/\'\'\'/\'\\\'\'/g;    # escape single quotes
+                       print $out "$_'\\n',";
+               }
+       }
+}
+
+sub digest_for_file {
+       my ($file) = @_;
+
+       open( my $in, '<', $file ) or die "file missing";
+       my $digest = Digest::MD5->new->addfile($in)->hexdigest;
+
+       return $digest;
+}
+
+sub changed {
+       my ( $file, $outfile ) = @_;
+
+       open( my $out, '<', $outfile ) or return 1;
+
+       my $in_checksum = digest_for_file($file);
+       my $ln          = <$out>;
+
+       if ( $ln =~ /^.*id:(\S+)\s.*$/ ) {
+               if ( $in_checksum ne $1 ) {
+                       return 1;
+               }
+               else {
+                       return 0;
+               }
+       }
+
+       return 1;
+}
+
+foreach my $file (@files) {
+       if ( $file =~ /([^\/.]+)(.lua)$/ ) {
+               my $fname      = "$1$2";
+               my $varname    = "rspamadm_script_$1";
+               my $definename = uc $varname;
+               my $outfile    = "$out_dir/$fname.h";
+
+               if ( changed( $file, $outfile ) ) {
+                       open( my $in,  '<', $file )    or die "input missing";
+                       open( my $out, '>', $outfile ) or die "output missing";
+                       my $checksum = digest_for_file($file);
+                       print $out <<EOD;
+/* id:$checksum */
+#ifndef ${definename}_GUARD_H
+#define ${definename}_GUARD_H
+
+static const char ${varname}\[\] = {
+EOD
+                       quote_file( $in, $out );
+
+                       print $out <<EOD;
+'\\0'};
+#endif
+EOD
+               }
+       }
+}
index a7b03f55ce997b699c60114ab641db05f73589c6..0c1e31dbe8cbe0cb17525d999b2ff4a9ac327074 100644 (file)
@@ -111,6 +111,8 @@ TARGET_LINK_LIBRARIES(rspamd-server rspamd-cdb)
 TARGET_LINK_LIBRARIES(rspamd-server rspamd-lpeg)
 TARGET_LINK_LIBRARIES(rspamd-server lcbtrie)
 
+ADD_DEPENDENCIES(rspamd-server rspamd_lua_preprocess)
+
 IF (ENABLE_CLANG_PLUGIN MATCHES "ON")
        ADD_DEPENDENCIES(rspamd-server rspamd-clang)
 ENDIF()
index cb97ca3ed6513f77d6f1124ebb4b60a995691795..544fbac3ace7e79a38446f2f3ff7b602a6ce7c97 100644 (file)
@@ -30,3 +30,10 @@ SET(LUASRC                     ${CMAKE_CURRENT_SOURCE_DIR}/lua_common.c
                                          ${CMAKE_CURRENT_SOURCE_DIR}/lua_map.c)
 
 SET(RSPAMD_LUA ${LUASRC} PARENT_SCOPE)
+SET(RSPAMDMLUASRC "")
+ADD_CUSTOM_TARGET(rspamd_lua_preprocess
+        ${PERL_EXECUTABLE}
+            "${CMAKE_SOURCE_DIR}/lua_preprocess.pl"
+            "${CMAKE_CURRENT_SOURCE_DIR}"
+            "${CMAKE_CURRENT_BINARY_DIR}"
+        SOURCES ${RSPAMDMLUASRC} ${CMAKE_SOURCE_DIR}/lua_preprocess.pl)
\ No newline at end of file
index 65b8669bcfb354a71a63f1c4e941a1d513de508b..992e2a3aaef50e10e887ff6e8beb3631c4d99e6c 100644 (file)
@@ -25,10 +25,10 @@ SET(RSPAMADMLUASRC
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
 ADD_CUSTOM_TARGET(rspamadm_lua_preprocess
         ${PERL_EXECUTABLE}
-            "${CMAKE_CURRENT_SOURCE_DIR}/lua_preprocess.pl"
+            "${CMAKE_SOURCE_DIR}/lua_preprocess.pl"
             "${CMAKE_CURRENT_SOURCE_DIR}"
             "${CMAKE_CURRENT_BINARY_DIR}"
-        SOURCES ${RSPAMADMLUASRC} ${CMAKE_CURRENT_SOURCE_DIR}/lua_preprocess.pl)
+        SOURCES ${RSPAMADMLUASRC} ${CMAKE_SOURCE_DIR}/lua_preprocess.pl)
 IF (ENABLE_HYPERSCAN MATCHES "ON")
     LIST(APPEND RSPAMADMSRC "${CMAKE_SOURCE_DIR}/src/hs_helper.c")
 ENDIF()
diff --git a/src/rspamadm/lua_preprocess.pl b/src/rspamadm/lua_preprocess.pl
deleted file mode 100644 (file)
index d1e8f46..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/usr/bin/env perl
-
-use warnings FATAL => 'all';
-use strict;
-use Digest::MD5;
-
-my ( $in_dir, $out_dir ) = @ARGV;
-my @files = <$in_dir/*.lua>;
-
-sub quote_file {
-       my ( $in, $out ) = @_;
-
-       while (<$in>) {
-               if (/^--.USE\s*"(\S+)"$/) {
-                       open( my $inc, '<', "$in_dir/$1.lua.in" )
-                         or die "missing include $1";
-                       quote_file( $inc, $out );
-               }
-               else {
-                       s/^\s*//;    # remove unnecessary spaces at the beginning
-                       next if /^--/;      # skip comments
-                       next if /^\s*$/;    # skip empty lines
-                       s/(.)/'$1',/g;          # split as 'c',
-                       s/\'\\\'/\'\\\\'/g;     # escape backslashes
-                       s/\'\'\'/\'\\\'\'/g;    # escape single quotes
-                       print $out "$_'\\n',";
-               }
-       }
-}
-
-sub digest_for_file {
-       my ($file) = @_;
-
-       open( my $in, '<', $file ) or die "file missing";
-       my $digest = Digest::MD5->new->addfile($in)->hexdigest;
-
-       return $digest;
-}
-
-sub changed {
-       my ( $file, $outfile ) = @_;
-
-       open( my $out, '<', $outfile ) or return 1;
-
-       my $in_checksum = digest_for_file($file);
-       my $ln          = <$out>;
-
-       if ( $ln =~ /^.*id:(\S+)\s.*$/ ) {
-               if ( $in_checksum ne $1 ) {
-                       return 1;
-               }
-               else {
-                       return 0;
-               }
-       }
-
-       return 1;
-}
-
-foreach my $file (@files) {
-       if ( $file =~ /([^\/.]+)(.lua)$/ ) {
-               my $fname      = "$1$2";
-               my $varname    = "rspamadm_script_$1";
-               my $definename = uc $varname;
-               my $outfile    = "$out_dir/$fname.h";
-
-               if ( changed( $file, $outfile ) ) {
-                       open( my $in,  '<', $file )    or die "input missing";
-                       open( my $out, '>', $outfile ) or die "output missing";
-                       my $checksum = digest_for_file($file);
-                       print $out <<EOD;
-/* id:$checksum */
-#ifndef ${definename}_GUARD_H
-#define ${definename}_GUARD_H
-
-static const char ${varname}\[\] = {
-EOD
-                       quote_file( $in, $out );
-
-                       print $out <<EOD;
-'\\0'};
-#endif
-EOD
-               }
-       }
-}