]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
python: fixes for out of tree build
authorJason Ish <ish@unx.ca>
Mon, 21 May 2018 14:55:19 +0000 (08:55 -0600)
committerVictor Julien <victor@inliniac.net>
Wed, 23 May 2018 12:47:57 +0000 (14:47 +0200)
Autoconf/automake and python setup.py don't play that well
together with out of tree builds.

Makes suricatasc not an autoconf input file, instead use the
defaults module that is already being created.

In the case of an out of tree build, copy the generated defaults.py
to the build directory manually.

configure.ac
python/.gitignore
python/bin/suricatasc [moved from python/bin/suricatasc.in with 90% similarity]
python/setup.py
python/suricata/config/defaults.py.in

index deabdb7219b81537f17811cbb97602798187e3c5..bb1821c38ceb04053a80b0f98bd18b65ba45a786 100644 (file)
@@ -2296,7 +2296,7 @@ AC_SUBST(CONFIGURE_SYSCONDIR)
 AC_SUBST(CONFIGURE_LOCALSTATEDIR)
 AC_SUBST(PACKAGE_VERSION)
 
-AC_OUTPUT(Makefile src/Makefile rust/Makefile rust/Cargo.toml rust/.cargo/config qa/Makefile qa/coccinelle/Makefile rules/Makefile doc/Makefile doc/userguide/Makefile contrib/Makefile contrib/file_processor/Makefile contrib/file_processor/Action/Makefile contrib/file_processor/Processor/Makefile contrib/tile_pcie_logd/Makefile suricata.yaml etc/Makefile etc/suricata.logrotate etc/suricata.service python/Makefile python/suricata/config/defaults.py python/bin/suricatasc ebpf/Makefile)
+AC_OUTPUT(Makefile src/Makefile rust/Makefile rust/Cargo.toml rust/.cargo/config qa/Makefile qa/coccinelle/Makefile rules/Makefile doc/Makefile doc/userguide/Makefile contrib/Makefile contrib/file_processor/Makefile contrib/file_processor/Action/Makefile contrib/file_processor/Processor/Makefile contrib/tile_pcie_logd/Makefile suricata.yaml etc/Makefile etc/suricata.logrotate etc/suricata.service python/Makefile python/suricata/config/defaults.py ebpf/Makefile)
 
 SURICATA_BUILD_CONF="Suricata Configuration:
   AF_PACKET support:                       ${enable_af_packet}
index 21cc772571dc9ceaac960069f907f5f11d55d57f..25a040f658385ca22f2bafd0757f9ec45f4423db 100644 (file)
@@ -3,7 +3,5 @@
 build
 lib/
 scripts-*/
-bin/suricatasc
-!bin/suricatasc.in
 suricata/config/defaults.py
 !suricata/config/defaults.py.in
similarity index 90%
rename from python/bin/suricatasc.in
rename to python/bin/suricatasc
index 0027469cc215c7179f1127c73c64c0b3ce69e860..99af497779c663298511e9d4297e6269082b0b22 100755 (executable)
@@ -38,6 +38,12 @@ else:
 
 from suricata.sc import *
 
+try:
+    from suricata.config import defaults
+    has_defaults = True
+except:
+    has_defaults = False
+
 parser = argparse.ArgumentParser(prog='suricatasc', description='Client for Suricata unix socket')
 parser.add_argument('-v', '--verbose', action='store_const', const=True, help='verbose output (including JSON dump)')
 parser.add_argument('-c', '--command', default=None, help='execute on single command and return JSON')
@@ -46,8 +52,11 @@ args = parser.parse_args()
 
 if args.socket != None:
     SOCKET_PATH = args.socket
+elif has_defaults:
+    SOCKET_PATH = os.path.join(defaults.localstatedir, "suricata-command.socket")
 else:
-    SOCKET_PATH = "@e_localstatedir@/suricata-command.socket"
+    print("Unable to determine path to suricata-command.socket.", file=sys.stderr)
+    sys.exit(1)
 
 sc = SuricataSC(SOCKET_PATH, verbose=args.verbose)
 try:
index 08f43bf6eecd96b01462c3562e6c1706a8b62124..16c5572d335fa38c58735cab6076cadc4bd0d72f 100644 (file)
@@ -3,8 +3,10 @@ from __future__ import print_function
 import os
 import re
 import sys
+import shutil
 
 from distutils.core import setup
+from distutils.command.build_py import build_py
 
 version = None
 if os.path.exists("../configure.ac"):
@@ -18,7 +20,22 @@ if version is None:
     print("error: failed to parse Suricata version, will use 0.0.0",
           file=sys.stderr)
     version = "0.0.0"
-    
+
+class do_build(build_py):
+    def run(self):
+        build_py.run(self)
+        defaults_py_out = os.path.join(
+            self.build_lib, "suricata", "config", "defaults.py")
+        if not os.path.exists(defaults_py_out):
+            # Must be an out of tree build, find defaults.py.
+            defaults_py_in = os.path.join(
+                self.build_lib, "..", "suricata", "config", "defaults.py")
+            if os.path.exists(defaults_py_in):
+                shutil.copy(defaults_py_in, defaults_py_out)
+            else:
+                print("error: failed to find defaults.py")
+                sys.exit(1)
+
 setup(
     name="suricata",
     description="Suricata control tools",
@@ -48,4 +65,5 @@ setup(
         'Programming Language :: Python',
         'Topic :: System :: Systems Administration',
     ],
+    cmdclass={'build_py': do_build},
 )
index 3156e816890de50e125101033d7bb3ffc8d7d0c5..f46935189a96227b7eeea4028fa8e783cb667009 100644 (file)
@@ -1,2 +1,3 @@
 sysconfdir = "@e_sysconfdir@"
 datarulesdir = "@e_datarulesdir@"
+localstatedir = "@e_localstatedir@"