wok rev 4996

tazbb: add check-depends
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Feb 27 20:49:37 2010 +0100 (2010-02-27)
parents e01eb29ff29f
children 9554030e83f1
files tazbb/stuff/tazbb
line diff
     1.1 --- a/tazbb/stuff/tazbb	Sat Feb 27 19:35:45 2010 +0000
     1.2 +++ b/tazbb/stuff/tazbb	Sat Feb 27 20:49:37 2010 +0100
     1.3 @@ -47,17 +47,18 @@
     1.4  	echo -e "\nSliTaz developers and build host tool\n
     1.5  \033[1mUsage: \033[0m `basename $0` [command] [--option]
     1.6  \033[1mCommands: \033[0m\n
     1.7 -  usage        Print this short usage and command list.
     1.8 -  list-pkgs    List last cooked packages with date.
     1.9 -  report       Run in report mode and dont cook anything [--verbose].
    1.10 -  cook         Cook, install and log a single package build.
    1.11 -  cook-all     Cook all missing, modified or unbuilt packages.
    1.12 -  cook-commit  Cook all packages affected by a commit in the last update.
    1.13 -  test-pkgs    Execute a test suite on all packages [--verbose].
    1.14 -  [un]block    Block or unblock a package to skip or enable building.
    1.15 -  mail         Send mail to package maintainer with tazbbmail.
    1.16 -  clean-up     Remove old packages [--verbose|--dry-run].
    1.17 -  clean-log    Remove all generated build log files.\n"
    1.18 +  usage           Print this short usage and command list.
    1.19 +  list-pkgs       List last cooked packages with date.
    1.20 +  report          Run in report mode and dont cook anything [--verbose].
    1.21 +  cook            Cook, install and log a single package build.
    1.22 +  cook-all        Cook all missing, modified or unbuilt packages.
    1.23 +  cook-commit     Cook all packages affected by a commit in the last update.
    1.24 +  test-pkgs       Execute a test suite on all packages [--verbose].
    1.25 +  [un]block       Block or unblock a package to skip or enable building.
    1.26 +  mail            Send mail to package maintainer with tazbbmail.
    1.27 +  check-depends   Verify DEPENDS value with library needs [--verbose].
    1.28 +  clean-up        Remove old packages [--verbose|--dry-run].
    1.29 +  clean-log       Remove all generated build log files.\n"
    1.30  }
    1.31  
    1.32  status()
    1.33 @@ -90,6 +91,8 @@
    1.34  	fi
    1.35  }
    1.36  
    1.37 +VERBOSE=""
    1.38 +
    1.39  packages_summary_update()
    1.40  {
    1.41  	sed -i s/"[0-9]* in the wok"/"`ls $BUILD_WOK | wc -l` in the wok"/ \
    1.42 @@ -438,6 +441,20 @@
    1.43  			echo "<a href=\"log.php?package=$(escape $pkg)\">$pkg</a>" >> \
    1.44  				$DB_DIR/unbuilt
    1.45  		fi
    1.46 +		missing_depends="$(check_depends_pkg $pkg)"
    1.47 +		if [ -n "$missing_depends" ]; then
    1.48 +			cat >> $LOG_DIR/$pkg.log <<EOT
    1.49 +
    1.50 +Update $pkg receipt for DEPENDS :
    1.51 +The package $pkg depends on packages $missing_depends
    1.52 +
    1.53 +EOT
    1.54 +			# Unbuild package
    1.55 +			rm -rf $BUILD_WOK/$pkg/taz
    1.56 +			# Link to build log.
    1.57 +			echo "<a href=\"log.php?package=$(escape $pkg)\">$pkg</a>" >> \
    1.58 +				$DB_DIR/unbuilt
    1.59 +		fi
    1.60  		# Remove package from the cooklist and empty lines for HTML <pre>.
    1.61  		sed -i /"^$pkg$"/d $DB_DIR/cooklist
    1.62  		sed -i '/^$/d' $DB_DIR/cooklist
    1.63 @@ -445,6 +462,151 @@
    1.64  	done
    1.65  }
    1.66  
    1.67 +# Build depends_to_skip list with packages to remove from depends_to_add list
    1.68 +# These packages are already present in depends_to_add trees
    1.69 +scan_depends_to_skip()
    1.70 +{
    1.71 +	local i
    1.72 +	case " $depends_to_skip " in
    1.73 +	*\ $1\ *) return;;
    1.74 +	esac
    1.75 +	[ -d $BUILD_WOK/$1 ] || return
    1.76 +	DEPENDS=""
    1.77 +	. $BUILD_WOK/$1/receipt
    1.78 +	for i in $DEPENDS ; do
    1.79 +		case " $depends_to_add " in
    1.80 +		*\ $i\ *) depends_to_skip="$depends_to_skip $i";;
    1.81 +		esac
    1.82 +	done
    1.83 +	for i in $DEPENDS ; do
    1.84 +		scan_depends_to_skip $i
    1.85 +	done
    1.86 +}
    1.87 +
    1.88 +# Reduce depends list by scanning nested depends
    1.89 +show_missing_depends()
    1.90 +{
    1.91 +	local i
    1.92 +	depends_to_add=""
    1.93 +	depends_to_skip="$2"
    1.94 +	for i in $1 ; do
    1.95 +		case " $depends_to_add " in
    1.96 +		*\ $i\ *) continue;;
    1.97 +		esac
    1.98 +		depends_to_add="$depends_to_add$i "
    1.99 +	done
   1.100 +	for i in $depends_to_add ; do
   1.101 +		scan_depends_to_skip $i
   1.102 +	done
   1.103 +	for i in $depends_to_add ; do
   1.104 +		case " $depends_to_skip " in
   1.105 +		*\ $i\ *) continue;;
   1.106 +		esac
   1.107 +		echo -n "$i "
   1.108 +	done
   1.109 +}
   1.110 +
   1.111 +# Build all_depends variable
   1.112 +scan_dep()
   1.113 +{
   1.114 +	local i
   1.115 +	all_depends="$all_depends$PACKAGE "
   1.116 +	for i in $DEPENDS $SUGGESTED ; do
   1.117 +		case " $all_depends " in
   1.118 +		*\ $i\ *) continue;;
   1.119 +		esac
   1.120 +		[ -d $BUILD_WOK/$i ] || {
   1.121 +			all_depends="$all_depends$i "
   1.122 +			continue
   1.123 +		}
   1.124 +		DEPENDS=""
   1.125 +		SUGGESTED=""
   1.126 +		. $BUILD_WOK/$i/receipt
   1.127 +		scan_dep
   1.128 +	done
   1.129 +}
   1.130 +
   1.131 +# Check for ELF file
   1.132 +is_elf()
   1.133 +{
   1.134 +	[ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ]
   1.135 +}
   1.136 +
   1.137 +# Print shared library dependencies
   1.138 +ldd()
   1.139 +{
   1.140 +	LD_PRELOAD="" LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so $1 2> /dev/null
   1.141 +}
   1.142 +
   1.143 +# scan a file for shared libraries and display according package names
   1.144 +check_depends_file()
   1.145 +{
   1.146 +	file=$1
   1.147 +	is_elf $file || continue
   1.148 +	case "$file" in
   1.149 +	*.o|*.ko|*.ko.gz) continue;;
   1.150 +	esac
   1.151 +	[ -s /tmp/files.list.tazbb$$ ] ||
   1.152 +	unlzma -c $PACKAGES_REPOSITORY/files.list.lzma >/tmp/files.list.tazbb$$
   1.153 +	ldd $file | while read lib rem; do
   1.154 +		case "$lib" in
   1.155 +		statically|linux-gate.so*|ld-*.so|*/ld-*.so)
   1.156 +			continue;;
   1.157 +		esac
   1.158 +		for dep in $(grep $lib /tmp/files.list.tazbb$$ | cut -d: -f1); do
   1.159 +			case " $all_depends " in
   1.160 +			*\ $dep\ *) continue 2;;
   1.161 +			esac
   1.162 +			for vdep in $(grep $dep $PACKAGES_REPOSITORY/packages.equiv | cut -d= -f1); do
   1.163 +				case " $all_depends " in
   1.164 +				*\ $vdep\ *) continue 3;;
   1.165 +				esac
   1.166 +			done
   1.167 +		done
   1.168 +		[ -n "$dep" ] || dep="UNKNOWN"
   1.169 +		all_depends="$all_depends $dep"
   1.170 +		if [ -n "$VERBOSE" ]; then
   1.171 +			echo "${file#*fs} depends on package $dep for the shared library $lib" 1>&2
   1.172 +		fi
   1.173 +		echo -n "$dep "
   1.174 +	done
   1.175 +}
   1.176 +
   1.177 +DEFAULT_DEPENDS="glibc-base"
   1.178 +
   1.179 +# scan a package for shared libraries and display missing package in DEPENDS
   1.180 +check_depends_pkg()
   1.181 +{
   1.182 +	pkg=$1
   1.183 +	echo "(checking depends for $pkg)" > $DB_DIR/running
   1.184 +	tmp=/tmp/tazbb$$
   1.185 +	mkdir $tmp
   1.186 +	package=$(basename $pkg)
   1.187 +	if ! cd ${package%%-*}*/taz/${package%.tazpkg}/.. 2> /dev/null; then
   1.188 +		cd $tmp
   1.189 +		tazpkg extract $pkg > /dev/null 2>&1
   1.190 +	fi
   1.191 +	. */receipt
   1.192 +	all_depends="$DEFAULT_DEPENDS "
   1.193 +	scan_dep
   1.194 +	toadd=$(find */fs -type f | while read file ; do
   1.195 +		check_depends_file $file
   1.196 +	done)
   1.197 +	. */receipt
   1.198 +	rm -rf */
   1.199 +	cd - > /dev/null
   1.200 +	rm -rf $tmp
   1.201 +	show_missing_depends "$toadd" "$DEPENDS $SUGGESTED"
   1.202 +}
   1.203 +
   1.204 +check_depends_this_file()
   1.205 +{
   1.206 +	file=$1
   1.207 +	all_depends="$DEFAULT_DEPENDS "
   1.208 +	scan_dep
   1.209 +	check_depends_file $file
   1.210 +}
   1.211 +
   1.212  # Remove old packages in the build wok and clean pkgs repository. The
   1.213  # Hg wok is copied into the build wok so packages removed by hg must be
   1.214  # removed. To remove old packages in the repository we look into the
   1.215 @@ -702,11 +864,40 @@
   1.216  		echo -n "Cleaning: $LOG_DIR... "
   1.217  		rm -rf $LOG_DIR/*
   1.218  		echo "$logs log removed" ;;
   1.219 +	check-depends)
   1.220 +		case "$2" in
   1.221 +		wok)
   1.222 +			for pkg in $PACKAGES_REPOSITORY/*.tazpkg ; do
   1.223 +				missing_depends="$(check_depends_pkg $pkg)"
   1.224 +				[ -n "$missing_depends" ] && 
   1.225 +				echo "The package $pkg depends on $missing_depends."
   1.226 +			done ;;
   1.227 +		package)
   1.228 +			pkg=$3
   1.229 +			VERBOSE=$4
   1.230 +			missing_depends="$(check_depends_pkg $pkg)"
   1.231 +			[ -n "$missing_depends" ] && 
   1.232 +			echo "The package $pkg depends on $missing_depends."
   1.233 +			;;
   1.234 +		file)
   1.235 +			file=3
   1.236 +			VERBOSE=$4
   1.237 +			missing_depends="$(check_depends_this_file $file)"
   1.238 +			[ -n "$missing_depends" ] && 
   1.239 +			echo "The file $file depends on $missing_depends."
   1.240 +			;;
   1.241 +		*)	cat <<EOT
   1.242 +check-depends wok		check every package in wok.
   1.243 +check-depends package <pkg>     check one package.
   1.244 +check-depends file <filename>   check one file only.
   1.245 +EOT
   1.246 +			;;
   1.247 +		esac ;;
   1.248  	*)
   1.249  		usage ;;
   1.250  esac
   1.251  
   1.252  echo "" > $DB_DIR/running
   1.253 -rm -f $LOCK_FILE
   1.254 +rm -f $LOCK_FILE /tmp/files.list.tazbb$$
   1.255  
   1.256  exit 0