From f18951a77e3a6ee2be0d0736830c67773bdcd87e Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 16 May 2011 13:51:32 -0500 Subject: [PATCH 1/4] Changes to allow DEB packaging via CPack, addresses #458 --- aux/broccoli | 2 +- aux/broctl | 2 +- cmake/ConfigurePackaging.cmake | 44 +++++++++++++++++++++++----- cmake/package_postupgrade.sh.in | 26 ++++++----------- make-deb-packages | 52 +++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 26 deletions(-) create mode 100755 make-deb-packages diff --git a/aux/broccoli b/aux/broccoli index 54f3ff4e66..12c1f32d65 160000 --- a/aux/broccoli +++ b/aux/broccoli @@ -1 +1 @@ -Subproject commit 54f3ff4e6627d4a44d1e014e8e581e4e9dfed8c3 +Subproject commit 12c1f32d65fdf72d4af1450b0c9c5a5e398bba08 diff --git a/aux/broctl b/aux/broctl index d9bfa3e7c2..e4e49c312a 160000 --- a/aux/broctl +++ b/aux/broctl @@ -1 +1 @@ -Subproject commit d9bfa3e7c25aa0fdc27a1f8520f2bb474ecd44af +Subproject commit e4e49c312a559886f7ec6d6f8efd582bbeb297ad 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 ../.. From d69c3edf211e1a60e15f830df063c7ad0d72044d Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 17 May 2011 15:03:40 -0500 Subject: [PATCH 2/4] Fixes for more doc mode corner cases caused by type cloning. "shallow" copying has to be done for any type that can contain record types in order to accommodate record redefs that add fields. --- src/Var.cc | 28 ++++-- .../autogen-reST-record-add.rst | 99 ------------------- ...gen-reST-record-add.bro => record-add.bro} | 16 +-- 3 files changed, 29 insertions(+), 114 deletions(-) delete mode 100644 testing/btest/Baseline/doc.autogen-reST-record-add/autogen-reST-record-add.rst rename testing/btest/doc/{autogen-reST-record-add.bro => record-add.bro} (70%) diff --git a/src/Var.cc b/src/Var.cc index f265316f17..7880325538 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -242,15 +242,25 @@ 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()); + default: SerializationFormat* form = new BinarySerializationFormat(); form->StartWrite(); CloneSerializer ss(form); @@ -267,7 +277,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/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; + } From 73a18714b3a4cf73e0b5bf87f26ddf74b01d42c5 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 17 May 2011 15:27:45 -0500 Subject: [PATCH 3/4] Fix reST markup generated for record redefs. They should have been using reST roles to xref the original record type instead of a reST directive to declare a new type. --- src/parse.y | 6 ++++-- testing/btest/Baseline/doc.autogen-reST-example/example.rst | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/parse.y b/src/parse.y index a31b47b0bd..8b3f8d64c8 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1092,8 +1092,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 f06c23ba8b..516b7b51aa 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` From e0c05868e36017896dd3ec8c7496fe48c1f88e8b Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Wed, 18 May 2011 09:08:59 -0700 Subject: [PATCH 4/4] Updating submodule(s). --- aux/broccoli | 2 +- aux/broctl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aux/broccoli b/aux/broccoli index 12c1f32d65..8843da57dc 160000 --- a/aux/broccoli +++ b/aux/broccoli @@ -1 +1 @@ -Subproject commit 12c1f32d65fdf72d4af1450b0c9c5a5e398bba08 +Subproject commit 8843da57dc8aee433550727dcbd1199824ca9da4 diff --git a/aux/broctl b/aux/broctl index e4e49c312a..1bf5407722 160000 --- a/aux/broctl +++ b/aux/broctl @@ -1 +1 @@ -Subproject commit e4e49c312a559886f7ec6d6f8efd582bbeb297ad +Subproject commit 1bf5407722ef5910bafd513bcec6a51b280eeb10