python: fixes for out of tree build

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.
pull/3384/head
Jason Ish 7 years ago committed by Victor Julien
parent 4f48927c44
commit 7e06e765f3

@ -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}

2
python/.gitignore vendored

@ -3,7 +3,5 @@
build
lib/
scripts-*/
bin/suricatasc
!bin/suricatasc.in
suricata/config/defaults.py
!suricata/config/defaults.py.in

@ -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:

@ -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},
)

@ -1,2 +1,3 @@
sysconfdir = "@e_sysconfdir@"
datarulesdir = "@e_datarulesdir@"
localstatedir = "@e_localstatedir@"

Loading…
Cancel
Save