diff options
author | jmmv <jmmv> | 2013-03-08 17:47:25 +0000 |
---|---|---|
committer | jmmv <jmmv> | 2013-03-08 17:47:25 +0000 |
commit | eea9208dcd1dbd11f24b84a66647f3cd114b325d (patch) | |
tree | 2e32cf07bd594a5fac0bc0c5e4d8d81f5b477c3b /sysutils | |
parent | 1d2f2bc858b4b9c03b0f048e62f083ca1baef88c (diff) | |
download | pkgsrc-eea9208dcd1dbd11f24b84a66647f3cd114b325d.tar.gz |
Update to 2.5:
- Added support for pre/post fetch/build hooks so that, for example, rsync
can be used to push the results of a successful build to a remote server.
Diffstat (limited to 'sysutils')
-rw-r--r-- | sysutils/sysbuild/Makefile | 5 | ||||
-rw-r--r-- | sysutils/sysbuild/files/sysbuild.1 | 9 | ||||
-rw-r--r-- | sysutils/sysbuild/files/sysbuild.conf.5 | 43 | ||||
-rw-r--r-- | sysutils/sysbuild/files/sysbuild.sh | 13 | ||||
-rw-r--r-- | sysutils/sysbuild/files/sysbuild_test.sh | 213 |
5 files changed, 272 insertions, 11 deletions
diff --git a/sysutils/sysbuild/Makefile b/sysutils/sysbuild/Makefile index 08408a28e14..d320db56a91 100644 --- a/sysutils/sysbuild/Makefile +++ b/sysutils/sysbuild/Makefile @@ -1,6 +1,6 @@ -# $NetBSD: Makefile,v 1.23 2012/10/23 19:51:25 asau Exp $ +# $NetBSD: Makefile,v 1.24 2013/03/08 17:47:25 jmmv Exp $ -DISTNAME= sysbuild-2.4 +DISTNAME= sysbuild-2.5 CATEGORIES= sysutils MASTER_SITES= # empty DISTFILES= # empty @@ -90,5 +90,6 @@ do-install: .endfor ${INSTALL_SCRIPT} ${WRKSRC}/env.sh ${DESTDIR}${PREFIX}/share/sysbuild +BUILDLINK_API_DEPENDS.shtk+= shtk>=1.1 .include "../../devel/shtk/buildlink3.mk" .include "../../mk/bsd.pkg.mk" diff --git a/sysutils/sysbuild/files/sysbuild.1 b/sysutils/sysbuild/files/sysbuild.1 index 20a579147c6..cb2b3e27d68 100644 --- a/sysutils/sysbuild/files/sysbuild.1 +++ b/sysutils/sysbuild/files/sysbuild.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: sysbuild.1,v 1.6 2012/10/13 18:40:33 jmmv Exp $ +.\" $NetBSD: sysbuild.1,v 1.7 2013/03/08 17:47:26 jmmv Exp $ .\" Copyright 2012 Google Inc. .\" All rights reserved. .\" @@ -26,7 +26,7 @@ .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE .\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.Dd October 13, 2012 +.Dd March 8, 2013 .Dt SYSBUILD 1 .Os .Sh NAME @@ -95,6 +95,11 @@ Trivially set up periodic .Nx rebuilds by adding a single line to your .Xr crontab 5 . +.It +Hooks to plug other components into the build procedure. +For example: use +.Xr rsync 1 +to push the results of a successful build to a file server. .El .Pp As you can see in the diff --git a/sysutils/sysbuild/files/sysbuild.conf.5 b/sysutils/sysbuild/files/sysbuild.conf.5 index 12326c70dd0..792c2db1bda 100644 --- a/sysutils/sysbuild/files/sysbuild.conf.5 +++ b/sysutils/sysbuild/files/sysbuild.conf.5 @@ -1,4 +1,4 @@ -.\" $NetBSD: sysbuild.conf.5,v 1.1 2012/10/13 18:40:33 jmmv Exp $ +.\" $NetBSD: sysbuild.conf.5,v 1.2 2013/03/08 17:47:26 jmmv Exp $ .\" Copyright 2012 Google Inc. .\" All rights reserved. .\" @@ -26,7 +26,7 @@ .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE .\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.Dd October 13, 2012 +.Dd March 8, 2013 .Dt SYSBUILD.CONF 5 .Os .Sh NAME @@ -35,10 +35,11 @@ .Sh DESCRIPTION Configuration files for .Xr sysbuild 1 -are plain shell scripts that define a set of recognized variables. -.Pp -As scripts, they can perform any magic they desire to deduce the value of -the configuration variables. +are plain shell scripts that define a set of recognized variables and can +optionally fill in a set of hooks provided as shell functions. +.Ss Configuration variables +As scripts, configuration files can perform any magic they desire to deduce +the value of configuration variables. For example, the default configuration file shipped with .Xr sysbuild 1 automatically deduces the value of the @@ -157,5 +158,35 @@ semantics, is not the same as setting this to 1). .Pp Default: not defined. .El +.Ss Hooks +Hooks are user-provided routines invoked at particular points during the +build process. +These are defined as shell functions and have access to the configuration +variables in the file. +Hooks must return a success error code and they cannot contain unprotected +shell commands. +In other words, they are run under a shell configured with +.Sq set -e . +.Pp +The following hooks can be defined: +.Bl -tag -width post_build_hookXX +.It Fn pre_build_hook +Function executed before invoking +.Nm build.sh +for any of the provided build targets and platforms. +.It Fn post_build_hook +Function executed at the end of all build operations. +In other words: if the system is being built for multiple machine targets, +this hook will only be run once. +.It Fn pre_fetch_hook +Function executed at the beginning of the +.Sq fetch +command before any operations are performed. +This cannot assume that the source directories exist yet. +.It Fn post_fetch_hook +Function executed right after all source trees have been updated by the +.Sq fetch +command. +.El .Sh SEE ALSO .Xr sysbuild 1 diff --git a/sysutils/sysbuild/files/sysbuild.sh b/sysutils/sysbuild/files/sysbuild.sh index b13d92d56bc..c8b167b21da 100644 --- a/sysutils/sysbuild/files/sysbuild.sh +++ b/sysutils/sysbuild/files/sysbuild.sh @@ -51,7 +51,7 @@ SYSBUILD_CONFIG_VARS="BUILD_ROOT BUILD_TARGETS CVSROOT CVSTAG INCREMENTAL_BUILD : ${SYSBUILD_SHAREDIR="@SYSBUILD_SHAREDIR@"} -# Sets defaults for configuration variables that need a value. +# Sets defaults for configuration variables and hooks that need to exist. # # This function should be before the configuration file has been loaded. This # means that the user can undefine a required configuration variable, but we let @@ -66,6 +66,11 @@ sysbuild_set_defaults() { shtk_config_set RELEASEDIR "${HOME}/sysbuild/release" shtk_config_set SRCDIR "${HOME}/sysbuild/src" shtk_config_set UPDATE_SOURCES "true" + + pre_build_hook() { true; } + post_build_hook() { true; } + pre_fetch_hook() { true; } + post_fetch_hook() { true; } } @@ -195,9 +200,11 @@ sysbuild_build() { sysbuild_fetch fi + shtk_config_run_hook pre_build_hook for machine in ${machines}; do do_one_build "${machine}" done + shtk_config_run_hook post_build_hook } @@ -268,6 +275,8 @@ EOF sysbuild_fetch() { [ ${#} -eq 0 ] || shtk_cli_usage_error "fetch does not take any arguments" + shtk_config_run_hook pre_fetch_hook + local cvsroot="$(shtk_config_get CVSROOT)" shtk_cli_info "Updating base source tree" @@ -279,6 +288,8 @@ sysbuild_fetch() { shtk_cvs_fetch "${cvsroot}" xsrc \ "$(shtk_config_get_default CVSTAG '')" "$(shtk_config_get XSRCDIR)" fi + + shtk_config_run_hook post_fetch_hook } diff --git a/sysutils/sysbuild/files/sysbuild_test.sh b/sysutils/sysbuild/files/sysbuild_test.sh index 94af42f2add..b5f93641421 100644 --- a/sysutils/sysbuild/files/sysbuild_test.sh +++ b/sysutils/sysbuild/files/sysbuild_test.sh @@ -508,6 +508,117 @@ EOF } +atf_test_case build__hooks__ok +build__hooks__ok_body() { + create_mock_cvsroot "${MOCK_CVSROOT}" + + create_mock_binary cvs yes + PATH="$(pwd):${PATH}" + + cat >test.conf <<EOF +CVSROOT="${MOCK_CVSROOT}" +MACHINES="one two" # Build hooks are only supposed to be called once. +SRCDIR="$(pwd)/checkout/src" + +pre_fetch_hook() { + echo "Hook before fetch: \${SRCDIR}" +} + +post_fetch_hook() { + echo "Hook after fetch" +} + +pre_build_hook() { + echo "Hook before build: \${MACHINES}" +} + +post_build_hook() { + echo "Hook after build" +} +EOF + + atf_check -o save:stdout -e save:stderr sysbuild -c test.conf build + grep 'Command: build.sh' commands.log || atf_fail "build.sh not run" + + cat >exp_order <<EOF +Hook before fetch: $(pwd)/checkout/src +Hook after fetch +Hook before build: one two +Hook after build +EOF + atf_check -o file:exp_order grep '^Hook' stdout +} + + +atf_test_case build__hooks__pre_fail +build__hooks__pre_fail_body() { + create_mock_cvsroot "${MOCK_CVSROOT}" + cat >test.conf <<EOF +CVSROOT="${MOCK_CVSROOT}" +SRCDIR="$(pwd)/checkout/src" + +pre_fetch_hook() { + echo "Hook before fetch" +} + +post_fetch_hook() { + echo "Hook after fetch" +} + +pre_build_hook() { + echo "Hook before build" + false +} + +post_build_hook() { + echo "Hook after build" +} +EOF + + atf_check -s exit:1 -o save:stdout -e save:stderr \ + sysbuild -c test.conf build + if grep 'Command: build.sh' commands.log; then + atf_fail "build.sh should not have been run" + fi + + cat >exp_order <<EOF +Hook before fetch +Hook after fetch +Hook before build +EOF + atf_check -o file:exp_order grep '^Hook' stdout +} + + +atf_test_case build__hooks__post_fail +build__hooks__post_fail_body() { + create_mock_cvsroot "${MOCK_CVSROOT}" + cat >test.conf <<EOF +CVSROOT="${MOCK_CVSROOT}" +SRCDIR="$(pwd)/checkout/src" + +pre_build_hook() { + echo "Hook before build" +} + +post_build_hook() { + echo "Hook after build" + false +} +EOF + + atf_check -s exit:1 -o save:stdout -e save:stderr \ + sysbuild -c test.conf build + grep 'Command: build.sh' commands.log || atf_fail "build.sh not run" + + cat >exp_order <<EOF +Hook before build +Hook after build +EOF + atf_check -o file:exp_order grep '^Hook' stdout +} + + atf_test_case config__builtins config__builtins_body() { cat >expout <<EOF @@ -853,6 +964,102 @@ EOF } +atf_test_case fetch__hooks__ok +fetch__hooks__ok_body() { + create_mock_cvsroot "${MOCK_CVSROOT}" + cat >test.conf <<EOF +CVSROOT="${MOCK_CVSROOT}" +SRCDIR="$(pwd)/checkout/src" +XSRCDIR="$(pwd)/checkout/xsrc" + +pre_fetch_hook() { + echo "Hook before fetch: \${CVSROOT}" + test ! -d "${SRCDIR}" +} + +post_fetch_hook() { + test -d "${SRCDIR}" + echo "Hook after fetch" +} +EOF + + atf_check -o save:stdout -e ignore sysbuild -c test.conf fetch + test -f checkout/src/file-in-src || atf_fail "src not checked out" + test -f checkout/xsrc/file-in-xsrc || atf_fail "xsrc not checked out" + + cat >exp_order <<EOF +Hook before fetch: ${MOCK_CVSROOT} +Hook after fetch +EOF + atf_check -o file:exp_order grep '^Hook' stdout +} + + +atf_test_case fetch__hooks__pre_fail +fetch__hooks__pre_fail_body() { + create_mock_cvsroot "${MOCK_CVSROOT}" + cat >test.conf <<EOF +CVSROOT="${MOCK_CVSROOT}" +SRCDIR="$(pwd)/checkout/src" +XSRCDIR="$(pwd)/checkout/xsrc" + +pre_fetch_hook() { + echo "Hook before fetch" + false +} + +post_fetch_hook() { + echo "Hook after fetch" +} +EOF + + atf_check -s exit:1 -o save:stdout -e save:stderr \ + sysbuild -c test.conf fetch + grep 'pre_fetch_hook returned an error' stderr || \ + atf_fail "pre_fetch_hook didn't seem to fail" + test ! -f checkout/src/file-in-src || atf_fail "src checked out" + test ! -f checkout/xsrc/file-in-xsrc || atf_fail "xsrc checked out" + + cat >exp_order <<EOF +Hook before fetch +EOF + atf_check -o file:exp_order grep '^Hook' stdout +} + + +atf_test_case fetch__hooks__post_fail +fetch__hooks__post_fail_body() { + create_mock_cvsroot "${MOCK_CVSROOT}" + cat >test.conf <<EOF +CVSROOT="${MOCK_CVSROOT}" +SRCDIR="$(pwd)/checkout/src" +XSRCDIR="$(pwd)/checkout/xsrc" + +pre_fetch_hook() { + echo "Hook before fetch" +} + +post_fetch_hook() { + echo "Hook after fetch" + false +} +EOF + + atf_check -s exit:1 -o save:stdout -e save:stderr \ + sysbuild -c test.conf fetch + test -f checkout/src/file-in-src || atf_fail "src not checked out" + test -f checkout/xsrc/file-in-xsrc || atf_fail "xsrc not checked out" + grep 'post_fetch_hook returned an error' stderr || \ + atf_fail "post_fetch_hook didn't seem to fail" + + cat >exp_order <<EOF +Hook before fetch +Hook after fetch +EOF + atf_check -o file:exp_order grep '^Hook' stdout +} + + atf_test_case fetch__too_many_args fetch__too_many_args_body() { cat >experr <<EOF @@ -904,6 +1111,9 @@ atf_init_test_cases() { atf_add_test_case build__mkvars atf_add_test_case build__with_x11 atf_add_test_case build__some_args + atf_add_test_case build__hooks__ok + atf_add_test_case build__hooks__pre_fail + atf_add_test_case build__hooks__post_fail atf_add_test_case config__builtins atf_add_test_case config__path__components @@ -925,6 +1135,9 @@ atf_init_test_cases() { atf_add_test_case fetch__checkout__src_and_xsrc atf_add_test_case fetch__update__src_only atf_add_test_case fetch__update__src_and_xsrc + atf_add_test_case fetch__hooks__ok + atf_add_test_case fetch__hooks__pre_fail + atf_add_test_case fetch__hooks__post_fail atf_add_test_case fetch__too_many_args atf_add_test_case no_command |