Update to 2.3:

- Added the 'env' command.  This prints a small shell snippet that can be
  imported into the current shell.  The printed code defines a set of
  convenience global variables and functions to work with the source tree.
This commit is contained in:
jmmv 2012-08-25 19:20:53 +00:00
parent 209129b74c
commit b056a4db6c
6 changed files with 315 additions and 8 deletions

View file

@ -1,6 +1,6 @@
# $NetBSD: Makefile,v 1.20 2012/08/23 02:26:56 jmmv Exp $
# $NetBSD: Makefile,v 1.21 2012/08/25 19:20:53 jmmv Exp $
DISTNAME= sysbuild-2.2
DISTNAME= sysbuild-2.3
CATEGORIES= sysutils
MASTER_SITES= # empty
DISTFILES= # empty
@ -18,6 +18,7 @@ NO_CONFIGURE= YES
BUILD_SUBST= -e 's,@SYSBUILD_BINDIR@,${PREFIX}/bin,g'
BUILD_SUBST+= -e 's,@SYSBUILD_EGDIR@,${EGDIR},g'
BUILD_SUBST+= -e 's,@SYSBUILD_ETCDIR@,${PKG_SYSCONFDIR},g'
BUILD_SUBST+= -e 's,@SYSBUILD_SHAREDIR@,${PREFIX}/share/sysbuild,g'
PKG_SYSCONFSUBDIR= sysbuild
EGDIR= ${PREFIX}/share/examples/sysbuild
@ -55,7 +56,8 @@ install-tests:
.endfor
do-test:
cd ${WRKSRC} && PATH="${WRKSRC}:${PATH}" kyua test
cd ${WRKSRC} && PATH="${WRKSRC}:${PATH}" \
SYSBUILD_SHAREDIR="${WRKSRC}" kyua test
.else
PLIST_SUBST+= TESTS=@comment
.endif
@ -69,8 +71,11 @@ do-build:
.for file in sysbuild.1 sysbuild4cron.1 default.conf
sed ${BUILD_SUBST} <${FILESDIR}/${file} >${WRKSRC}/${file}
.endfor
cp ${FILESDIR}/env.sh ${WRKSRC}
chmod +x ${WRKSRC}/env.sh
INSTALLATION_DIRS+= bin ${PKGMANDIR}/man1 share/examples/sysbuild
INSTALLATION_DIRS+= bin ${PKGMANDIR}/man1 \
share/examples/sysbuild share/sysbuild
do-install:
${INSTALL_SCRIPT} ${WRKSRC}/sysbuild ${DESTDIR}${PREFIX}/bin/
@ -82,6 +87,7 @@ do-install:
.for file in default.conf
${INSTALL_DATA} ${WRKSRC}/${file} ${DESTDIR}${EGDIR}
.endfor
${INSTALL_SCRIPT} ${WRKSRC}/env.sh ${DESTDIR}${PREFIX}/share/sysbuild
.include "../../devel/shtk/buildlink3.mk"
.include "../../mk/bsd.pkg.mk"

View file

@ -1,9 +1,10 @@
@comment $NetBSD: PLIST,v 1.5 2012/08/15 21:20:14 jmmv Exp $
@comment $NetBSD: PLIST,v 1.6 2012/08/25 19:20:53 jmmv Exp $
bin/sysbuild
bin/sysbuild4cron
man/man1/sysbuild.1
man/man1/sysbuild4cron.1
share/examples/sysbuild/default.conf
share/sysbuild/env.sh
${TESTS}tests/sysbuild/Kyuafile
${TESTS}tests/sysbuild/sysbuild_test
${TESTS}tests/sysbuild/sysbuild4cron_test

View file

@ -0,0 +1,52 @@
# Copyright 2012 Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Google Inc. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# 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.
# \file env.sh
# Utility functions for interactive shells.
#
# This file is supposed to be loaded automatically when running:
# eval $(sysbuild env)
# Do not load it directly, as it depends on global variables defined by
# the command shown above.
# Locates the object directory that matches the current source directory.
curobj() {
local curdir="$(pwd)"
case "${curdir}" in
${S:-non-existent}*)
echo "${O}${curdir##${S}}"
;;
${XS:-non-existent}*)
echo "${XO}${curdir##${XS}}"
;;
*)
echo "NOT-FOUND"
;;
esac
}

View file

@ -1,4 +1,4 @@
.\" $NetBSD: sysbuild.1,v 1.4 2012/08/23 02:26:57 jmmv Exp $
.\" $NetBSD: sysbuild.1,v 1.5 2012/08/25 19:20:53 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 August 22, 2012
.Dd August 25, 2012
.Dt SYSBUILD 1
.Os
.Sh NAME
@ -46,6 +46,11 @@ config
.Nm
.Op Fl c Ar config_name
.Op Fl o Ar variable=value
env
.Op Ar machine
.Nm
.Op Fl c Ar config_name
.Op Fl o Ar variable=value
fetch
.Sh DESCRIPTION
.Nm
@ -181,6 +186,67 @@ The format of the output is not a script, so it cannot be fed back into
The purpose of this command is to aid in debugging the configuration of the
tool before performing any builds, particularly when the configuration
files use shell logic to determine the value of any variables.
.Ss The env command
The env command prints a shell script snippet that defines environment variables
to simplify working with the directory layout of a
.Nx
build for a particular machine.
If the
.Va MACHINES
variable is not defined, or if it lists more than one machine, then the
.Ar machine
argument is required.
.Pp
The common mechanism to use these variables is by executing
.Nm
in the following way:
.Bd -literal -offset indent
$ eval $(sysbuild env)
.Ed
.Pp
The following variables are defined and/or modified:
.Bl -tag -width PATH
.It Va PATH
The path to the tools is prepended to the path.
Of particular interest is the
.Pa nbmake-<machine>
script made available in this way, which allows you to build arbitrary targets
within the source directory using the tools.
.It Va D
Path to the destdir.
.It Va O
Path to the objects directory for the source tree.
.It Va S
Path to the source tree.
.It Va T
Path to the tools.
Note that this points to the root of the tools, not their
.Pa bin
subdirectory.
.It Va XO
If
.Va XSRCDIR
is defined, path to the objects directory for the X source tree.
.It Va XS
If
.Va XSRCDIR
is defined, path to the X source tree.
.El
.Pp
And the following functions are defined:
.Bl -tag -width curobj
.It Fn curobj
When invoked from a subdirectory of either src or xsrc, prints the path to that
same subdirectory within the objects hierarchy.
You may use this to reference temporary build files easily when you are working
within the source tree as follows:
.Bd -literal -offset indent
$ cd /usr/src/bin/ls
/usr/src/bin/ls$ nbmake-amd64
/usr/src/bin/ls$ cd $(curobj)
/usr/obj/usr/src/bin/ls$
.Ed
.El
.Ss The fetch command
The fetch command downloads or updates the
.Nx

View file

@ -47,6 +47,7 @@ SYSBUILD_CONFIG_VARS="BUILD_ROOT BUILD_TARGETS CVSROOT CVSTAG INCREMENTAL_BUILD
#
# Can be overriden for test purposes only.
: ${SYSBUILD_ETCDIR="@SYSBUILD_ETCDIR@"}
: ${SYSBUILD_SHAREDIR="@SYSBUILD_SHAREDIR@"}
# Sets defaults for configuration variables that need a value.
@ -209,6 +210,51 @@ sysbuild_config() {
}
# Outputs shell configuration commands.
#
# \params ... The options and arguments to the command.
sysbuild_env() {
[ ${#} -lt 2 ] || shtk_cli_usage_error "env takes zero or one arguments"
local machine=
if [ ${#} -eq 1 ]; then
machine="${1}"
else
set -- $(shtk_config_get MACHINES)
[ ${#} -eq 1 ] || shtk_cli_usage_error "No machine name provided as" \
"an argument and MACHINES contains more than one name"
machine="${1}"
fi
local basedir="$(shtk_config_get BUILD_ROOT)/${machine}"
local srcdir="$(shtk_config_get SRCDIR)"
[ -f "${SYSBUILD_SHAREDIR}/env.sh" ] \
|| shtk_cli_error "Cannot open ${SYSBUILD_SHAREDIR}/env.sh"
# The semicolon after the sourcing of env.sh is required to get this output
# working when passed through eval. Running eval on the output collapses
# everything into a single line, and we need to separate the sourcing of
# env.sh from the definition of the global variables.
cat <<EOF
. "${SYSBUILD_SHAREDIR}/env.sh" ;
PATH="${basedir}/tools/bin:\${PATH}"
D="${basedir}/destdir"
O="${basedir}/obj${srcdir}"
S="${srcdir}"
T="${basedir}/tools"
EOF
if shtk_config_has XSRCDIR; then
local xsrcdir="$(shtk_config_get XSRCDIR)"
cat <<EOF
XO="${basedir}/obj${xsrcdir}"
XS="${xsrcdir}"
EOF
fi
}
# Fetches a copy of the source tree, or updates an existing one.
#
# \params ... The options and arguments to the command.
@ -294,7 +340,7 @@ sysbuild_main() {
local command="${1}"; shift
case "${command}" in
build|config|fetch)
build|config|env|fetch)
sysbuild_set_defaults
sysbuild_config_load "${config_name}"
"sysbuild_${command}" "${@}" || exit_code="${?}"

View file

@ -32,6 +32,12 @@
MOCK_CVSROOT=":local:$(pwd)/cvsroot"
# Paths to installed files.
#
# Can be overriden for test purposes only.
: ${SYSBUILD_SHAREDIR="@SYSBUILD_SHAREDIR@"}
# Creates a fake program that records its invocations for later processing.
#
# The fake program, when invoked, will append its arguments to a commands.log
@ -586,6 +592,129 @@ EOF
}
atf_test_case env__src_only
env__src_only_body() {
cat >expout <<EOF
. "${SYSBUILD_SHAREDIR}/env.sh" ;
PATH="/my/root/shark/tools/bin:\${PATH}"
D="/my/root/shark/destdir"
O="/my/root/shark/obj/usr/src"
S="/usr/src"
T="/my/root/shark/tools"
EOF
atf_check -s exit:0 -o file:expout sysbuild -c /dev/null \
-o BUILD_ROOT=/my/root -o MACHINES=shark -o SRCDIR=/usr/src env
}
atf_test_case env__src_and_xsrc
env__src_and_xsrc_body() {
cat >expout <<EOF
. "${SYSBUILD_SHAREDIR}/env.sh" ;
PATH="/my/root/i386/tools/bin:\${PATH}"
D="/my/root/i386/destdir"
O="/my/root/i386/obj/a/b/src"
S="/a/b/src"
T="/my/root/i386/tools"
XO="/my/root/i386/obj/d/xsrc"
XS="/d/xsrc"
EOF
atf_check -s exit:0 -o file:expout sysbuild -c /dev/null \
-o BUILD_ROOT=/my/root -o MACHINES=i386 -o SRCDIR=/a/b/src \
-o XSRCDIR=/d/xsrc env
}
atf_test_case env__explicit_machine
env__explicit_machine_body() {
cat >expout <<EOF
. "${SYSBUILD_SHAREDIR}/env.sh" ;
PATH="/my/root/macppc/tools/bin:\${PATH}"
D="/my/root/macppc/destdir"
O="/my/root/macppc/obj/usr/src"
S="/usr/src"
T="/my/root/macppc/tools"
EOF
atf_check -s exit:0 -o file:expout sysbuild -c /dev/null \
-o BUILD_ROOT=/my/root -o MACHINES="amd64 i386" -o SRCDIR=/usr/src \
env macppc
}
atf_test_case env__eval
env__eval_body() {
make_one() {
mkdir -p "${1}"
touch "${1}/${2}"
}
make_one src src.cookie
make_one xsrc xsrc.cookie
make_one root/mach/destdir destdir.cookie
make_one root/mach/tools tools.cookie
make_one root/mach/"obj$(pwd)"/src src-obj.cookie
make_one root/mach/"obj$(pwd)"/xsrc xsrc-obj.cookie
find src xsrc root
mkdir -p root/mach/tools/bin
cat >root/mach/tools/bin/nbmake-mach <<EOF
#! /bin/sh
echo "This is nbmake!"
EOF
chmod +x root/mach/tools/bin/nbmake-mach
atf_check -s exit:0 -o save:env.sh sysbuild -c /dev/null \
-o BUILD_ROOT="$(pwd)/root" \
-o MACHINES="mach" \
-o SRCDIR="$(pwd)/src" \
-o XSRCDIR="$(pwd)/xsrc" \
env
eval $(cat ./env.sh)
[ -f "${D}/destdir.cookie" ] || atf_fail "D points to the wrong place"
[ -f "${O}/src-obj.cookie" ] || atf_fail "O points to the wrong place"
[ -f "${S}/src.cookie" ] || atf_fail "S points to the wrong place"
[ -f "${T}/tools.cookie" ] || atf_fail "T points to the wrong place"
[ -f "${XO}/xsrc-obj.cookie" ] || atf_fail "XO points to the wrong place"
[ -f "${XS}/xsrc.cookie" ] || atf_fail "XS points to the wrong place"
atf_check -o inline:"This is nbmake!\n" nbmake-mach
mkdir -p src/bin/ls
atf_check_equal '$(pwd)/root/mach/obj$(pwd)/src/bin/ls' \
'$(cd src/bin/ls && curobj)'
mkdir -p xsrc/some/other/dir
atf_check_equal '$(pwd)/root/mach/obj$(pwd)/xsrc/some/other/dir' \
'$(cd xsrc/some/other/dir && curobj)'
mkdir a
atf_check_equal 'NOT-FOUND' '$(cd a && curobj)'
atf_check_equal 'NOT-FOUND' '$(cd /bin && curobj)'
}
atf_test_case env__too_many_machines
env__too_many_machines_body() {
cat >experr <<EOF
sysbuild: E: No machine name provided as an argument and MACHINES contains more than one name
Type 'man sysbuild' for help
EOF
atf_check -s exit:1 -e file:experr sysbuild -c /dev/null \
-o MACHINES="amd64 i386" env
}
atf_test_case env__too_many_args
env__too_many_args_body() {
cat >experr <<EOF
sysbuild: E: env takes zero or one arguments
Type 'man sysbuild' for help
EOF
atf_check -s exit:1 -e file:experr sysbuild -c /dev/null env foo bar
}
atf_test_case fetch__checkout__src_only
fetch__checkout__src_only_body() {
create_mock_cvsroot "${MOCK_CVSROOT}"
@ -753,6 +882,13 @@ atf_init_test_cases() {
atf_add_test_case config__overrides
atf_add_test_case config__too_many_args
atf_add_test_case env__src_only
atf_add_test_case env__src_and_xsrc
atf_add_test_case env__explicit_machine
atf_add_test_case env__eval
atf_add_test_case env__too_many_machines
atf_add_test_case env__too_many_args
atf_add_test_case fetch__checkout__src_only
atf_add_test_case fetch__checkout__src_and_xsrc
atf_add_test_case fetch__update__src_only