Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 07 Feb 2003 18:17:04 +1300
From:      Andrew Turner <zombie@i4free.co.nz>
To:        arch@freebsd.org
Subject:   Kernel Dependency finding tool
Message-ID:  <3E434150.4070601@i4free.co.nz>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------010606050505090804060806
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hello,

I've beed working on the attached tool to find options/drivers that
depend on other options/drivers.

It currently removes one option at a time from LINT and tryes to build
the kernel sending the output to logs.

I have only tested this script on my one FreeBSD box and would like some
comments and suggestions to improve the script.

Andrew Turner


--------------010606050505090804060806
Content-Type: text/plain;
 name="build_deps.sh"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="build_deps.sh"

#!/bin/sh

# used to find the way home
WD=`pwd`/work
if [ ! -d ${WD} ]
then
  mkdir -p ${WD}
fi

# I_ are the initial settings
I_BASE=""
I_SRCDIR="/usr/src"
I_SYSDIR="/sys"
I_ARCH=`uname -m`
I_LOGDIR=/var/log/bdeps

BASE=""
SRCDIR=""
SUSDIR=""
ARCH=""
CONFDIR=""
SRCBASE=""
LOGDIR=""
BUILDSTART=1
BUILDEND=0

LINES=""

usage () {
  NAME=`basename $0`
  echo "Usage:"
  echo "${NAME} [OPTIONS]"
  echo
  echo "where [OPTIONS] are one or more of:"
  echo
  echo "--prefix=<src-prefix>"
  echo "    Appends src-prefix to start of src-dir"
  echo "--srcdir=<src-dir>"
  echo "    The main source directory DEFAULT: ${I_SRCDIR}"
  echo "--arch=<arch>"
  echo "    Cross build for arch (untested) DEFAULT: ${I_ARCH}"
  echo "--logdir=<log-dir>"
  echo "    Log to log-dir DEFAULT: ${I_LOGDIR}"
  echo "--start=<start-cfg>"
  echo "    Start building on config start-cfg"
  echo "    Intended to be used in a cluster"
  echo "--end=<end-cfg>"
  echo "    End building on config end-cfg"
  echo "--only-build=<build-cfg>"
  echo "    Only build config numbered build-cfg"
  echo "--clean"
  echo "    Clean the temp files and exit"
  echo "--clean-logs"
  echo "    Clean the logs and exit"
}

check_opts () {
  while test "X$1" != "X"
  do
    optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
    case "$1" in
      --prefix=*)
        echo "Using $optarg as src base"
        BASE=$optarg
        shift
        ;;
      --arch=*)
        echo "Building for $optarg"
        ARCH=$optarg
        shift
        ;;
      --srcdir=*)
        echo "Using $optarg as Source dir"
        SRCDIR=$optarg
        shift
        ;;
      --logdir=*)
        echo "Logging to $optarg"
        LOGDIR=$optarg
        shift
        ;;
      --start=*)
        echo "Starting the build with config $optarg"
        BUILDSTART=$optarg
        shift
        ;;
      --end=*)
        echo "Ending the build with config $optarg"
        BUILDEND=$optarg
        shift
        ;;
      --only-build=*)
        echo "Only building config $optarg"
        BUILDSTART=$optarg
        BUILDEND=$optarg
        shift
        ;;
      --clean)
        CLEAN=1
        shift
        ;;
      --clean-logs)
        CLEANLOG=1
        shift
        ;;
      *)
        usage
        exit
        ;;
    esac
  done

  # set the final values to the Initial if are unset
  if test "X$BASE" = "X"
  then
    BASE=${I_BASE}
  fi
  if test "X$ARCH" = "X"
  then
    ARCH=${I_ARCH}
  fi
  if test "X$SRCDIR" = "X"
  then
    SRCDIR=${I_SRCDIR}
  fi
  if test "X${SYSDIR}" = "X"
  then
    SYSDIR=${I_SYSDIR}
  fi
  if test "X${LOGDIR}" = "X"
  then
    LOGDIR=${I_LOGDIR}
  fi

  CONFDIR=${BASEDIR}${SRCDIR}${SYSDIR}/${ARCH}/conf
  SRCBASE=${BASEDIR}${SRCDIR}

  EXIT=0
  if test "X${CLEAN}" != "X"
  then
    do_clean
    # Clean the Workdir
#    rm -fr ${WD}
#    rm -f ${CONFDIR}/CONFIG.*
    EXIT=1
  fi
  if test "X${CLEANLOG}" != "X"
  then
    rm ${LOGDIR}/*
    EXIT=1
  fi
  if [ ${EXIT} -ne 0 ]
  then
    exit 1
  fi
}

# Clean the workdir and config files
do_clean () {
  rm -fr ${WD}
  rm -f ${CONFDIR}/CONFIG.*
}

# Remove all temp files on kill
on_trap () {
  do_clean
  exit 1
}

# Load exit traps on HUP, INT, QUIT and TERM
load_traps () {
  trap on_trap 1 2 3 15
}

# Build the LINT config
make_lint () {
  echo "Building the LINT config from NOTES"
  cd ${CONFDIR}
  make LINT > /dev/null
  cd ${WD}
}

# Copy the LINT config file
copy_lint () {
  echo "Copying LINT file"
  cp ${CONFDIR}/LINT ${WD}
}

# Splitd lint into 2 files:
# 1) the parts that are needed in all config files
# 2) the parts that are changed in each config file
split_lint () {
  echo "Splitting LINT file"
#  rm -f ${WD}/LINT.all
  ALL_OPTS="ident machine profile cpu maxusers makeoptions"
  SOME_OPTS="device options"
  rm -f ${WD}/LINT.*
  for opt in $ALL_OPTS
  do
    awk "{ if ( \$1 == \"$opt\" ) { print \$0 } }" < LINT >> LINT.all
  done
  for opt in $SOME_OPTS
  do
    awk "{ if ( \$1 == \"$opt\" ) { print \$0 } }" < LINT >> LINT.some
  done
}

# Create the n config files
build_configs () {
  if [ -d ${WD}/configure ]
  then
    rm -f ${WD}/configure/CONFIG.*
  else
    mkdir ${WD}/configure
  fi

  LINES=`cat LINT.some | wc -l | xargs echo`

  echo "Creating ${LINES} config files"
  n=0
  while [ $n -lt $LINES ]
  do
    n=`expr $n + 1`
    cp ${WD}/LINT.all ${WD}/configure/CONFIG.$n
    awk "BEGIN { LINE=0 } { LINE++ ; if ( LINE != $n ) { print \$0 } }" < LINT.some >> configure/CONFIG.$n
  done
}

copy_configs () {
  echo "Copying config files to build"
  cp ${WD}/configure/CONFIG.* ${CONFDIR}
}

build_kernels () {
  echo "Building ${LINES} configs"

  n=`expr $BUILDSTART - 1`

  if [ $BUILDEND -eq 0 ]
  then
    BUILDEND=$LINES
  elif [ $BUILDEND -gt $LINES ]
  then
    BUILDEND=$LINES
  fi

  cd ${SRCBASE}
  while [ $n -lt $BUILDEND ]
  do
    n=`expr $n + 1`
    echo "Building config $n starts at `date`"
    date > ${LOGDIR}/buildkernel.$n
    make buildkernel KERNCONF=CONFIG.$n >> ${LOGDIR}/buildkernel.$n 2>&1
    if [ $? -ne 0 ]
    then
      #touch ${LOGDIR}/fail.$n
      head -n $n ${WD}/LINT.some | tail -n 1 > ${LOGDIR}/fail.$n
    else
      head -n $n ${WD}/LINT.some | tail -n 1 > ${LOGDIR}/pass.$n
    fi
    date >> ${LOGDIR}/buildkernel.$n
  done
  cd ${WD}
}

load_traps

check_opts $*

make_lint
copy_lint
split_lint
build_configs
copy_configs
build_kernels


--------------010606050505090804060806--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3E434150.4070601>