diff --git a/sysutils/sysbuild/Makefile b/sysutils/sysbuild/Makefile index 08408a28e14b..d320db56a91c 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 20a579147c67..cb2b3e27d686 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 12326c70dd01..792c2db1bda3 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 b13d92d56bc8..c8b167b21da6 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 94af42f2addb..b5f93641421b 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 <exp_order <test.conf <exp_order <test.conf <exp_order <expout <test.conf <exp_order <test.conf <exp_order <test.conf <exp_order <experr <