summaryrefslogtreecommitdiffstats
path: root/Documentation/scripts/test_separate_compilation.sh
blob: 75b980f182e9b0a726f7d4d4d884baa427c3649e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# !!!WARNING!!! use with caution 
#
# This script suppose the kdelibs to be installed
# how to use :
# dependecies_test_compilation <package![use[,use]...] [...]

die() {
	echo '!!! $@'
	exit -100500
}


RESULT_DIR="/tmp/test-build-$(date +%Y-%m-%d_%H-%M)"
SUCCESS_LIST="${RESULT_DIR}/success_list"
FAIL_LIST="${RESULT_DIR}/fail_list"
LOGS_DIR="${RESULT_DIR}/logs/"
CONFIG_BAK="${RESULT_DIR}/portage_bak.tar.gz"
PORTAGE_CONFIG="/etc/portage"
EMERGE_AUTOUNMASK_OPTS="--autounmask y --autounmask-keep-masks y --autounmask-write y"
mkdir -p "${RESULT_DIR}" "${LOGS_DIR}";

for pkguse in "$@"; do
done

# backup config
tar -cf "${CONFIG_BAK}" -C / "${PORTAGE_CONFIG#/}" || die "backup config failed"

# initial cleanup
( emerge -NuD world && 
  emerge --depclean && 
  emerge -NuD world && 
  revdep-rebuild && 
  rm -rf /var/tmp/portage ) || die "initial cleaning failed"

for pkguse in "$@"; do
	pkg="${pkguse%!*}"
	use="${pkguse#*!}"
	use="${use/,// }"
	pkg_use_file="${PORTAGE_CONFIG}/package.use"
	[ -d ${pkg_use_file} ] && pkg_use_file="${pkg_use_file}/test.use"
	echo "$pkg $use" >>"$pkg_use_file"
	pkg_failed=no
	# check for it can be emerged due to depenencies uses
	emerge -p "$pkg"
	if [ "$?" != 0 ]; then
		#try unmask uses
		CONFIG_PROTECT_MASK="/etc/portage" emerge ${EMERGE_AUTOUNMASK_OPTS} "$pkg"
		emerge -p "$pkg"
		if [ "$?" != 0 ]; then
			# we can't emerge the package
			mkdir -p "${LOGS_DIR}/${pkg}"
			emerge -p "$pkg" >"${LOGS_DIR}/${pkg}/emerge_failed" 2>&1
			pkg_failed=yes
		fi
	fi

	if [ "$pkg_failed" == no ]; then
		emerge -1 "$pkg" 
		if [ "$?" != 0 ]; then
			mkdir -p "${LOGS_DIR}/${pkg}"
			for f_pkg in $(cd /var/tmp/portage/ && ls -d */*); do
				cp "/var/tmp/portage/${f_pkg}/temp/build.log" "${LOGS_DIR}/${pkg}/${f_pkg/\//_}.build"
			done
			pkg_failed=yes
		fi
	fi

	if [ "$pkg_failed" == no ]; then
		echo "$pkg" >>"${SUCCESS_LIST}"
	else
		echo "$pkg" >>"${FAIL_LIST}"
	fi
	
	# restoring config
	rm -rf ${PORTAGE_CONFIG}
	tar -xf "${CONFIG_BAK}" -C /

	# let's clean system
    ( emerge -NuD world && 
	  emerge --depclean && 
	  emerge -NuD world && 
	  revdep-rebuild && 
	  rm -rf /var/tmp/portage ) || die "cleaning failed"
done