diff --git a/aux/broccoli b/aux/broccoli index 54f3ff4e66..8843da57dc 160000 --- a/aux/broccoli +++ b/aux/broccoli @@ -1 +1 @@ -Subproject commit 54f3ff4e6627d4a44d1e014e8e581e4e9dfed8c3 +Subproject commit 8843da57dc8aee433550727dcbd1199824ca9da4 diff --git a/aux/broctl b/aux/broctl index d9bfa3e7c2..1bf5407722 160000 --- a/aux/broctl +++ b/aux/broctl @@ -1 +1 @@ -Subproject commit d9bfa3e7c25aa0fdc27a1f8520f2bb474ecd44af +Subproject commit 1bf5407722ef5910bafd513bcec6a51b280eeb10 diff --git a/cmake/ConfigurePackaging.cmake b/cmake/ConfigurePackaging.cmake index f77dcc0fae..6d7cb3d76f 100644 --- a/cmake/ConfigurePackaging.cmake +++ b/cmake/ConfigurePackaging.cmake @@ -63,10 +63,7 @@ endmacro(SetPackageVersion) # # Darwin - PackageMaker # Linux - RPM if the platform has rpmbuild installed -# DEB is ommitted because CPack does not give enough -# control over how the package is created and lacks support -# for automatic dependency detection. -# +# DEB if the platform has dpkg-shlibdeps installed # # CPACK_GENERATOR is set by this macro # CPACK_SOURCE_GENERATOR is set by this macro @@ -77,9 +74,14 @@ macro(SetPackageGenerators) list(APPEND CPACK_GENERATOR PackageMaker) elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") find_program(RPMBUILD_EXE rpmbuild) + find_program(DPKGSHLIB_EXE dpkg-shlibdeps) if (RPMBUILD_EXE) set(CPACK_GENERATOR ${CPACK_GENERATOR} RPM) endif () + if (DPKGSHLIB_EXE) + set(CPACK_GENERATOR ${CPACK_GENERATOR} DEB) + set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS true) + endif () endif () endmacro(SetPackageGenerators) @@ -159,11 +161,27 @@ macro(SetPackageInstallScripts VERSION) endif () if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + # DEB packages can automatically handle configuration files + # if provided in a "conffiles" file in the packaging + set(conffiles_file ${CMAKE_CURRENT_BINARY_DIR}/conffiles) + if (INSTALLED_CONFIG_FILES) + string(REPLACE " " ";" conffiles ${INSTALLED_CONFIG_FILES}) + endif () + file(WRITE ${conffiles_file} "") + foreach (_file ${conffiles}) + file(APPEND ${conffiles_file} "${_file}\n") + endforeach () + + list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA + ${CMAKE_CURRENT_BINARY_DIR}/conffiles) + + # RPMs don't need any explicit direction regarding config files. + # Leaving the set of installed config files empty will just - # bypass the logic in the pre/post install scripts and let - # the RPM do their own thing (regarding backups, etc.) + # bypass the logic in the default pre/post install scripts and let + # the RPMs/DEBs do their own thing (regarding backups, etc.) # when upgrading packages. - set (INSTALLED_CONFIG_FILES "") + set(INSTALLED_CONFIG_FILES "") endif () if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_preinstall.sh.in) @@ -171,10 +189,16 @@ macro(SetPackageInstallScripts VERSION) ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_preinstall.sh.in ${CMAKE_CURRENT_BINARY_DIR}/package_preinstall.sh @ONLY) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_preinstall.sh.in + ${CMAKE_CURRENT_BINARY_DIR}/preinst + @ONLY) set(CPACK_PREFLIGHT_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/package_preinstall.sh) set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/package_preinstall.sh) + list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA + ${CMAKE_CURRENT_BINARY_DIR}/preinst) endif () if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_postupgrade.sh.in) @@ -182,10 +206,16 @@ macro(SetPackageInstallScripts VERSION) ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_postupgrade.sh.in ${CMAKE_CURRENT_BINARY_DIR}/package_postupgrade.sh @ONLY) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/package_postupgrade.sh.in + ${CMAKE_CURRENT_BINARY_DIR}/postinst + @ONLY) set(CPACK_POSTUPGRADE_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/package_postupgrade.sh) set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_CURRENT_BINARY_DIR}/package_postupgrade.sh) + list(APPEND CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA + ${CMAKE_CURRENT_BINARY_DIR}/postinst) endif () endmacro(SetPackageInstallScripts) diff --git a/cmake/package_postupgrade.sh.in b/cmake/package_postupgrade.sh.in index 0ef78413c3..4e199d005c 100755 --- a/cmake/package_postupgrade.sh.in +++ b/cmake/package_postupgrade.sh.in @@ -48,21 +48,13 @@ if [ -n "${sampleFiles}" ]; then EOF fi -# make sure that world-writeable dirs have the sticky bit set -# so that unprivileged can't rename/remove files within - -if [ -d /var/opt/bro/spool ]; then - chmod +t /var/opt/bro/spool -fi - -if [ -d /var/opt/bro/spool/tmp ]; then - chmod +t /var/opt/bro/spool/tmp -fi - -if [ -d /var/opt/bro/spool/policy ]; then - chmod +t /var/opt/bro/spool/policy -fi - -if [ -d /var/opt/bro/logs ]; then - chmod +t /var/opt/bro/logs +# Set up world writeable spool and logs directory for broctl, making sure +# to set the sticky bit so that unprivileged users can't rename/remove files. +# (CMake/CPack is supposed to install them, but has problems with empty dirs) +if [ -n "@EMPTY_WORLD_DIRS@" ]; then + for dir in "@EMPTY_WORLD_DIRS@"; do + mkdir -p ${dir} + chmod 777 ${dir} + chmod +t ${dir} + done fi diff --git a/make-deb-packages b/make-deb-packages new file mode 100755 index 0000000000..c8d501198b --- /dev/null +++ b/make-deb-packages @@ -0,0 +1,52 @@ +#!/bin/sh + +# This script generates binary DEB packages. +# They can be found in build/ after running. + +prefix=/opt/bro + +# CMake/CPack versions before 2.8.2 have bugs that can create bad packages +CMAKE_PACK_REQ=2.8.2 +CMAKE_VER=`cmake -version` + +if [ "${CMAKE_VER}" \< "${CMAKE_PACK_REQ}" ]; then + echo "Package creation requires CMake > 2.8.2" >&2 + exit 1 +fi + +# The DEB CPack generator depends on `dpkg-shlibdeps` to automatically +# determine what dependencies to set for the packages +type dpkg-shlibdeps > /dev/null 2>&1 || { + echo "\ +Creating DEB packages requires the `dpkg-shlibs` command, usually provided by +the 'dpkg-dev' package, please install it first. +" >&2; + exit 1; +} + +# During the packaging process, `dpkg-shlibs` will fail if used on a library +# that links to other internal/project libraries unless an RPATH is used or +# we set LD_LIBRARY_PATH such that it can find the internal/project library +# in the temporary packaging tree. +export LD_LIBRARY_PATH=./${prefix}/lib + +# Minimum Bro +./configure --prefix=${prefix} --disable-broccoli --disable-broctl \ + --pkg-name-prefix=Bro --binary-package +( cd build && make package ) + +# Full Bro package +./configure --prefix=${prefix} --pkg-name-prefix=Bro-all --binary-package +( cd build && make package ) + +# Broccoli +cd aux/broccoli +./configure --prefix=${prefix} --binary-package +( cd build && make package && mv Broccoli*.deb ../../../build/ ) +cd ../.. + +# Broctl +cd aux/broctl +./configure --prefix=${prefix} --binary-package +( cd build && make package && mv Broctl*.deb ../../../build/ ) +cd ../.. diff --git a/src/Var.cc b/src/Var.cc index f265316f17..00ac734c0a 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -242,15 +242,26 @@ void add_type(ID* id, BroType* t, attr_list* attr, int /* is_event */) // t->GetTypeID() is true. if ( generate_documentation ) { - if ( t->Tag() == TYPE_RECORD ) - { - // Only "shallow" copy record types because we want to be able - // to see additions to the original type's list of fields + switch ( t->Tag() ) { + // Only "shallow" copy types that may contain records because + // we want to be able to see additions to the original record type's + // list of fields + case TYPE_RECORD: tnew = new RecordType(t->AsRecordType()->Types()); - } - - else - { + break; + case TYPE_TABLE: + tnew = new TableType(t->AsTableType()->Indices(), + t->AsTableType()->YieldType()); + break; + case TYPE_VECTOR: + tnew = new VectorType(t->AsVectorType()->YieldType()); + break; + case TYPE_FUNC: + tnew = new FuncType(t->AsFuncType()->Args(), + t->AsFuncType()->YieldType(), + t->AsFuncType()->IsEvent()); + break; + default: SerializationFormat* form = new BinarySerializationFormat(); form->StartWrite(); CloneSerializer ss(form); @@ -267,7 +278,7 @@ void add_type(ID* id, BroType* t, attr_list* attr, int /* is_event */) tnew = t->Unserialize(&uinfo); delete [] data; - } + } tnew->SetTypeID(copy_string(id->Name())); } diff --git a/src/parse.y b/src/parse.y index c7cb0dcae0..ba7174a338 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1093,8 +1093,10 @@ decl: new RecordType(fake_type_decl_list); ID* fake = create_dummy_id($3, fake_record); fake_type_decl_list = 0; - current_reST_doc->AddRedef( - new BroDocObj(fake, reST_doc_comments, true)); + BroDocObj* o = + new BroDocObj(fake, reST_doc_comments, true); + o->SetRole(true); + current_reST_doc->AddRedef(o); } else { diff --git a/testing/btest/Baseline/doc.autogen-reST-example/example.rst b/testing/btest/Baseline/doc.autogen-reST-example/example.rst index f1dcd15e52..a7ef21d907 100644 --- a/testing/btest/Baseline/doc.autogen-reST-example/example.rst +++ b/testing/btest/Baseline/doc.autogen-reST-example/example.rst @@ -279,7 +279,7 @@ Redefinitions document the "SimpleEnum" redef here -.. bro:type:: Example::SimpleRecord +:bro:type:`Example::SimpleRecord` :Type: :bro:type:`record` diff --git a/testing/btest/Baseline/doc.autogen-reST-record-add/autogen-reST-record-add.rst b/testing/btest/Baseline/doc.autogen-reST-record-add/autogen-reST-record-add.rst deleted file mode 100644 index 333600f179..0000000000 --- a/testing/btest/Baseline/doc.autogen-reST-record-add/autogen-reST-record-add.rst +++ /dev/null @@ -1,99 +0,0 @@ -.. Automatically generated. Do not edit. - -autogen-reST-record-add.bro -=========================== - -:download:`Original Source File ` - -Overview --------- - - -Summary -~~~~~~~ -State Variables -############### -===================================== = -:bro:id:`a`: :bro:type:`my_record` - -:bro:id:`b`: :bro:type:`super_record` -===================================== = - -Types -##### -============================================ = -:bro:type:`my_record`: :bro:type:`record` - -:bro:type:`super_record`: :bro:type:`record` -============================================ = - -Functions -######### -===================================== = -:bro:id:`test_func`: :bro:type:`func` -===================================== = - -Redefinitions -############# -========================================= = -:bro:type:`my_record`: :bro:type:`record` -========================================= = - -Public Interface ----------------- -State Variables -~~~~~~~~~~~~~~~ -.. bro:id:: a - - :Type: :bro:type:`my_record` - :Default: - - :: - - { - field1= - field2= - field3= - } - -.. bro:id:: b - - :Type: :bro:type:`super_record` - :Default: - - :: - - { - rec=[field1=, field2=, field3=] - } - -Types -~~~~~ -.. bro:type:: my_record - - :Type: :bro:type:`record` - - field1: :bro:type:`bool` - - field2: :bro:type:`string` - -.. bro:type:: super_record - - :Type: :bro:type:`record` - - rec: :bro:type:`my_record` - -Functions -~~~~~~~~~ -.. bro:id:: test_func - - :Type: :bro:type:`function` () : :bro:type:`void` - -Redefinitions -~~~~~~~~~~~~~ -.. bro:type:: my_record - - :Type: :bro:type:`record` - - field3: :bro:type:`count` :bro:attr:`&optional` - diff --git a/testing/btest/doc/autogen-reST-record-add.bro b/testing/btest/doc/record-add.bro similarity index 70% rename from testing/btest/doc/autogen-reST-record-add.bro rename to testing/btest/doc/record-add.bro index 4ad33e68ae..a326314093 100644 --- a/testing/btest/doc/autogen-reST-record-add.bro +++ b/testing/btest/doc/record-add.bro @@ -1,12 +1,11 @@ # @TEST-EXEC: bro --doc-scripts %INPUT -# @TEST-EXEC: btest-diff autogen-reST-record-add.rst # When in doc mode, bro will clone declared types (see add_type() in Var.cc) # in order to keep track of the identifier name associated with the new type. # This test makes sure that the cloning is done in a way that's compatible # with adding fields to a record type -- we want to be sure that cloning -# a record that contains other record fields will correctly see field -# additions to those contained-records. +# a type that contains record types will correctly see field additions to +# those contained-records. type my_record: record { field1: bool; @@ -16,17 +15,22 @@ type my_record: record { type super_record: record { rec: my_record; }; +type my_table: table[count] of my_record; +type my_vector: vector of my_record; redef record my_record += { field3: count &optional; }; global a: my_record; - global b: super_record; +global c: my_table; +global d: my_vector; function test_func() -{ + { a?$field3; b$rec?$field3; -} + c[0]$field3; + d[0]$field3; + }