Thu Sep 9 15:00:01 2021 UTC ()
Add a new operation "mkrepro-timestamp" to extract the timestamp a
build with -P would use. Example usage:

	./build.sh -T /usr/tools -P mkrepro-timestamp

This allows us to extract this information once, make other use of it,
and replicate it on other machines with -V MKREPRO=yes -V MKREPRO_TIMESTAMP=..


(martin)
diff -r1.355 -r1.356 src/build.sh

cvs diff -r1.355 -r1.356 src/build.sh (expand / switch to unified diff)

--- src/build.sh 2021/08/29 09:02:01 1.355
+++ src/build.sh 2021/09/09 15:00:01 1.356
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1#! /usr/bin/env sh 1#! /usr/bin/env sh
2# $NetBSD: build.sh,v 1.355 2021/08/29 09:02:01 christos Exp $ 2# $NetBSD: build.sh,v 1.356 2021/09/09 15:00:01 martin Exp $
3# 3#
4# Copyright (c) 2001-2011 The NetBSD Foundation, Inc. 4# Copyright (c) 2001-2011 The NetBSD Foundation, Inc.
5# All rights reserved. 5# All rights reserved.
6# 6#
7# This code is derived from software contributed to The NetBSD Foundation 7# This code is derived from software contributed to The NetBSD Foundation
8# by Todd Vierling and Luke Mewburn. 8# by Todd Vierling and Luke Mewburn.
9# 9#
10# Redistribution and use in source and binary forms, with or without 10# Redistribution and use in source and binary forms, with or without
11# modification, are permitted provided that the following conditions 11# modification, are permitted provided that the following conditions
12# are met: 12# are met:
13# 1. Redistributions of source code must retain the above copyright 13# 1. Redistributions of source code must retain the above copyright
14# notice, this list of conditions and the following disclaimer. 14# notice, this list of conditions and the following disclaimer.
15# 2. Redistributions in binary form must reproduce the above copyright 15# 2. Redistributions in binary form must reproduce the above copyright
@@ -1061,26 +1061,28 @@ Usage: ${progname} [-EhnoPRrUuxy] [-a ar @@ -1061,26 +1061,28 @@ Usage: ${progname} [-EhnoPRrUuxy] [-a ar
1061 RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs. 1061 RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.
1062 iso-image Create CD-ROM image in RELEASEDIR/images. 1062 iso-image Create CD-ROM image in RELEASEDIR/images.
1063 iso-image-source Create CD-ROM image with source in RELEASEDIR/images. 1063 iso-image-source Create CD-ROM image with source in RELEASEDIR/images.
1064 live-image Create bootable live image in 1064 live-image Create bootable live image in
1065 RELEASEDIR/RELEASEMACHINEDIR/installation/liveimage. 1065 RELEASEDIR/RELEASEMACHINEDIR/installation/liveimage.
1066 install-image Create bootable installation image in 1066 install-image Create bootable installation image in
1067 RELEASEDIR/RELEASEMACHINEDIR/installation/installimage. 1067 RELEASEDIR/RELEASEMACHINEDIR/installation/installimage.
1068 disk-image=target Create bootable disk image in 1068 disk-image=target Create bootable disk image in
1069 RELEASEDIR/RELEASEMACHINEDIR/binary/gzimg/target.img.gz. 1069 RELEASEDIR/RELEASEMACHINEDIR/binary/gzimg/target.img.gz.
1070 params Display various make(1) parameters. 1070 params Display various make(1) parameters.
1071 list-arch Display a list of valid MACHINE/MACHINE_ARCH values, 1071 list-arch Display a list of valid MACHINE/MACHINE_ARCH values,
1072 and exit. The list may be narrowed by passing glob 1072 and exit. The list may be narrowed by passing glob
1073 patterns or exact values in MACHINE or MACHINE_ARCH. 1073 patterns or exact values in MACHINE or MACHINE_ARCH.
 1074 mkrepro-timestamp Show the latest source timestamp used for reproducable
 1075 builds and exit. Requires -P or -V MKREPRO=yes.
1074 1076
1075 Options: 1077 Options:
1076 -a arch Set MACHINE_ARCH to arch. [Default: deduced from MACHINE] 1078 -a arch Set MACHINE_ARCH to arch. [Default: deduced from MACHINE]
1077 -B buildid Set BUILDID to buildid. 1079 -B buildid Set BUILDID to buildid.
1078 -C cdextras Append cdextras to CDEXTRA variable for inclusion on CD-ROM. 1080 -C cdextras Append cdextras to CDEXTRA variable for inclusion on CD-ROM.
1079 -c compiler Select compiler: 1081 -c compiler Select compiler:
1080 clang 1082 clang
1081 gcc 1083 gcc
1082 [Default: gcc] 1084 [Default: gcc]
1083 -D dest Set DESTDIR to dest. [Default: destdir.MACHINE] 1085 -D dest Set DESTDIR to dest. [Default: destdir.MACHINE]
1084 -E Set "expert" mode; disables various safety checks. 1086 -E Set "expert" mode; disables various safety checks.
1085 Should not be used without expert knowledge of the build 1087 Should not be used without expert knowledge of the build
1086 system. 1088 system.
@@ -1356,27 +1358,32 @@ parseoptions() @@ -1356,27 +1358,32 @@ parseoptions()
1356 eval ${optremcmd} 1358 eval ${optremcmd}
1357 while [ $# -gt 0 ]; do 1359 while [ $# -gt 0 ]; do
1358 op=$1; shift 1360 op=$1; shift
1359 operations="${operations} ${op}" 1361 operations="${operations} ${op}"
1360 1362
1361 case "${op}" in 1363 case "${op}" in
1362 1364
1363 help) 1365 help)
1364 usage 1366 usage
1365 ;; 1367 ;;
1366 1368
1367 list-arch) 1369 list-arch)
1368 listarch "${MACHINE}" "${MACHINE_ARCH}" 1370 listarch "${MACHINE}" "${MACHINE_ARCH}"
1369 exit $? 1371 exit
 1372 ;;
 1373 mkrepro-timestamp)
 1374 setup_mkrepro quiet
 1375 echo ${MKREPRO_TIMESTAMP:-0}
 1376 [ ${MKREPRO_TIMESTAMP:-0} -ne 0 ]; exit
1370 ;; 1377 ;;
1371 1378
1372 kernel=*|releasekernel=*|kernel.gdb=*) 1379 kernel=*|releasekernel=*|kernel.gdb=*)
1373 arg=${op#*=} 1380 arg=${op#*=}
1374 op=${op%%=*} 1381 op=${op%%=*}
1375 [ -n "${arg}" ] || 1382 [ -n "${arg}" ] ||
1376 bomb "Must supply a kernel name with \`${op}=...'" 1383 bomb "Must supply a kernel name with \`${op}=...'"
1377 ;; 1384 ;;
1378 1385
1379 disk-image=*) 1386 disk-image=*)
1380 arg=${op#*=} 1387 arg=${op#*=}
1381 op=disk_image 1388 op=disk_image
1382 [ -n "${arg}" ] || 1389 [ -n "${arg}" ] ||
@@ -1955,27 +1962,27 @@ createmakewrapper() @@ -1955,27 +1962,27 @@ createmakewrapper()
1955 else 1962 else
1956 makewrapout=">>\${makewrapper}" 1963 makewrapout=">>\${makewrapper}"
1957 fi 1964 fi
1958 1965
1959 case "${KSH_VERSION:-${SH_VERSION}}" in 1966 case "${KSH_VERSION:-${SH_VERSION}}" in
1960 *PD\ KSH*|*MIRBSD\ KSH*) 1967 *PD\ KSH*|*MIRBSD\ KSH*)
1961 set +o braceexpand 1968 set +o braceexpand
1962 ;; 1969 ;;
1963 esac 1970 esac
1964 1971
1965 eval cat <<EOF ${makewrapout} 1972 eval cat <<EOF ${makewrapout}
1966#! ${HOST_SH} 1973#! ${HOST_SH}
1967# Set proper variables to allow easy "make" building of a NetBSD subtree. 1974# Set proper variables to allow easy "make" building of a NetBSD subtree.
1968# Generated from: \$NetBSD: build.sh,v 1.355 2021/08/29 09:02:01 christos Exp $ 1975# Generated from: \$NetBSD: build.sh,v 1.356 2021/09/09 15:00:01 martin Exp $
1969# with these arguments: ${_args} 1976# with these arguments: ${_args}
1970# 1977#
1971 1978
1972EOF 1979EOF
1973 { 1980 {
1974 sorted_vars="$(for var in ${makeenv}; do echo "${var}" ; done \ 1981 sorted_vars="$(for var in ${makeenv}; do echo "${var}" ; done \
1975 | sort -u )" 1982 | sort -u )"
1976 for var in ${sorted_vars}; do 1983 for var in ${sorted_vars}; do
1977 eval val=\"\${${var}}\" 1984 eval val=\"\${${var}}\"
1978 eval is_set=\"\${${var}+set}\" 1985 eval is_set=\"\${${var}+set}\"
1979 if [ -z "${is_set}" ]; then 1986 if [ -z "${is_set}" ]; then
1980 echo "unset ${var}" 1987 echo "unset ${var}"
1981 else 1988 else
@@ -2284,29 +2291,34 @@ dorump() @@ -2284,29 +2291,34 @@ dorump()
2284 }' 2291 }'
2285 [ $? -ne 0 ] && bomb "Testlink of rump failed: ${set}" 2292 [ $? -ne 0 ] && bomb "Testlink of rump failed: ${set}"
2286 done 2293 done
2287 statusmsg "Rump build&link tests successful" 2294 statusmsg "Rump build&link tests successful"
2288} 2295}
2289 2296
2290repro_date() { 2297repro_date() {
2291 # try the bsd date fail back the the linux one 2298 # try the bsd date fail back the the linux one
2292 date -u -r "$1" 2> /dev/null || date -u -d "@$1" 2299 date -u -r "$1" 2> /dev/null || date -u -d "@$1"
2293} 2300}
2294 2301
2295setup_mkrepro() 2302setup_mkrepro()
2296{ 2303{
 2304 local quiet="$1"
 2305
2297 if [ ${MKREPRO-no} != "yes" ]; then 2306 if [ ${MKREPRO-no} != "yes" ]; then
2298 return 2307 return
2299 fi 2308 fi
 2309 if [ ${MKREPRO_TIMESTAMP-0} -ne 0 ]; then
 2310 return;
 2311 fi
2300 2312
2301 local dirs=${NETBSDSRCDIR-/usr/src}/ 2313 local dirs=${NETBSDSRCDIR-/usr/src}/
2302 if [ ${MKX11-no} = "yes" ]; then 2314 if [ ${MKX11-no} = "yes" ]; then
2303 dirs="$dirs ${X11SRCDIR-/usr/xsrc}/" 2315 dirs="$dirs ${X11SRCDIR-/usr/xsrc}/"
2304 fi 2316 fi
2305 2317
2306 local cvslatest=$(print_tooldir_program cvslatest) 2318 local cvslatest=$(print_tooldir_program cvslatest)
2307 if [ ! -x "${cvslatest}" ]; then 2319 if [ ! -x "${cvslatest}" ]; then
2308 buildtools 2320 buildtools
2309 fi 2321 fi
2310 2322
2311 local cvslatestflags= 2323 local cvslatestflags=
2312 if ${do_expertmode}; then 2324 if ${do_expertmode}; then
@@ -2333,27 +2345,30 @@ setup_mkrepro() @@ -2333,27 +2345,30 @@ setup_mkrepro()
2333 fi 2345 fi
2334 2346
2335 if [ -z "$t" ]; then 2347 if [ -z "$t" ]; then
2336 bomb "Failed to get timestamp for vcs=$vcs in '$d'" 2348 bomb "Failed to get timestamp for vcs=$vcs in '$d'"
2337 fi 2349 fi
2338 2350
2339 #echo "latest $d $vcs $t" 2351 #echo "latest $d $vcs $t"
2340 if [ "$t" -gt "$MKREPRO_TIMESTAMP" ]; then 2352 if [ "$t" -gt "$MKREPRO_TIMESTAMP" ]; then
2341 MKREPRO_TIMESTAMP="$t" 2353 MKREPRO_TIMESTAMP="$t"
2342 fi 2354 fi
2343 done 2355 done
2344 2356
2345 [ "${MKREPRO_TIMESTAMP}" != "0" ] || bomb "Failed to compute timestamp" 2357 [ "${MKREPRO_TIMESTAMP}" != "0" ] || bomb "Failed to compute timestamp"
2346 statusmsg2 "MKREPRO_TIMESTAMP" "$(repro_date "${MKREPRO_TIMESTAMP}")" 2358 if [ -z "${quiet}" ]; then
 2359 statusmsg2 "MKREPRO_TIMESTAMP" \
 2360 "$(repro_date "${MKREPRO_TIMESTAMP}")"
 2361 fi
2347 export MKREPRO MKREPRO_TIMESTAMP 2362 export MKREPRO MKREPRO_TIMESTAMP
2348} 2363}
2349 2364
2350main() 2365main()
2351{ 2366{
2352 initdefaults 2367 initdefaults
2353 _args=$@ 2368 _args=$@
2354 parseoptions "$@" 2369 parseoptions "$@"
2355 2370
2356 sanitycheck 2371 sanitycheck
2357 2372
2358 build_start=$(date) 2373 build_start=$(date)
2359 statusmsg2 "${progname} command:" "$0 $*" 2374 statusmsg2 "${progname} command:" "$0 $*"