Gentoo Archives: gentoo-catalyst

From: Matt Turner <mattst88@g.o>
To: gentoo-catalyst@l.g.o
Cc: Matt Turner <mattst88@g.o>
Subject: [gentoo-catalyst] [PATCH 35/37] targets: Reimplement kerncache support
Date: Wed, 21 Oct 2020 00:24:59
Message-Id: 20201021002344.378131-35-mattst88@gentoo.org
In Reply to: [gentoo-catalyst] [PATCH 01/37] catalyst: Use early return to unindent code by Matt Turner
1 I cannot see how the code added in commit fed3b45b could have possibly
2 worked, and in practice it did not.
3
4 An earlier commit (beb92087) deleted most or all of the uses of the
5 *_MATCH variables but left the code that set them in place.
6
7 Fixes: beb92087 ("Added patches from Joshua Kinard <kumba@g.o>")
8 Fixes: fed3b45b ("Fix and improve kernel build when kerncache is enabled.")
9 Signed-off-by: Matt Turner <mattst88@g.o>
10 ---
11 targets/support/kmerge.sh | 147 ++++++++++++--------------------------
12 1 file changed, 47 insertions(+), 100 deletions(-)
13
14 diff --git a/targets/support/kmerge.sh b/targets/support/kmerge.sh
15 index 6a0137d7..972feb99 100755
16 --- a/targets/support/kmerge.sh
17 +++ b/targets/support/kmerge.sh
18 @@ -85,11 +85,6 @@ genkernel_compile() {
19 else
20 genkernel "${GK_ARGS[@]}" || exit 1
21 fi
22 - if [ -n "${clst_KERNCACHE}" -a -e /var/tmp/${kname}.config ]
23 - then
24 - md5sum /var/tmp/${kname}.config | awk '{print $1}' > \
25 - /tmp/kerncache/${kname}/${kname}-${clst_version_stamp}.CONFIG
26 - fi
27 }
28
29 [ -n "${clst_ENVSCRIPT}" ] && source /tmp/envscript
30 @@ -106,117 +101,69 @@ eval eval kernel_gk_kernargs=( \$clst_boot_kernel_${kname}_gk_kernargs )
31 eval "ksource=\$clst_boot_kernel_${kname}_sources"
32 [[ -z ${ksource} ]] && ksource="sys-kernel/gentoo-sources"
33
34 -# Check if we have a match in kerncach
35 -
36 -if [ -n "${clst_KERNCACHE}" ]
37 -then
38 - USE_MATCH=0
39 - if [ -e /tmp/kerncache/${kname}/${kname}-${clst_version_stamp}.USE ]
40 - then
41 - STR1=$(for i in `cat /tmp/kerncache/${kname}/${kname}-${clst_version_stamp}.USE`; do echo $i; done|sort)
42 - STR2=$(for i in ${kernel_use}; do echo $i; done|sort)
43 - if [ "${STR1}" = "${STR2}" ]
44 - then
45 - USE_MATCH=1
46 - else
47 - [ -e /tmp/kerncache/${kname}/usr/src/linux/.config ] && \
48 - rm /tmp/kerncache/${kname}/usr/src/linux/.config
49 - fi
50 - fi
51 -
52 - EXTRAVERSION_MATCH=0
53 - if [ -e /tmp/kerncache/${kname}/${kname}-${clst_version_stamp}.EXTRAVERSION ]
54 - then
55 - STR1=`cat /tmp/kerncache/${kname}/${kname}-${clst_version_stamp}.EXTRAVERSION`
56 - STR2=${clst_kextraversion}
57 - if [ "${STR1}" = "${STR2}" ]
58 - then
59 - EXTRAVERSION_MATCH=1
60 - fi
61 - fi
62 -
63 - CONFIG_MATCH=0
64 - if [ -e /tmp/kerncache/${kname}/${kname}-${clst_version_stamp}.CONFIG ]
65 - then
66 - if [ ! -e /var/tmp/${kname}.config ]
67 - then
68 - CONFIG_MATCH=1
69 - else
70 - STR1=`cat /tmp/kerncache/${kname}/${kname}-${clst_version_stamp}.CONFIG`
71 - STR2=`md5sum /var/tmp/${kname}.config|awk '{print $1}'`
72 - if [ "${STR1}" = "${STR2}" ]
73 - then
74 - CONFIG_MATCH=1
75 - fi
76 - fi
77 - fi
78 +kernel_version=$(portageq best_visible / "${ksource}")
79
80 - # install dependencies of kernel sources ahead of time in case
81 - # package.provided generated below causes them not to be (re)installed
82 - run_merge --onlydeps "${ksource}"
83 +if [[ -n ${clst_KERNCACHE} ]]; then
84 + mkdir -p "/tmp/kerncache/${kname}"
85 + pushd "/tmp/kerncache/${kname}" >/dev/null
86
87 - # Create the kerncache directory if it doesn't exists
88 - mkdir -p /tmp/kerncache/${kname}
89 + echo "${kernel_use}" > /tmp/USE
90 + echo "${kernel_version}" > /tmp/VERSION
91 + echo "${clst_kextraversion}" > /tmp/EXTRAVERSION
92
93 - if [ -e /tmp/kerncache/${kname}/${kname}-${clst_version_stamp}.KERNELVERSION ]
94 - then
95 - KERNELVERSION=$(</tmp/kerncache/${kname}/${kname}-${clst_version_stamp}.KERNELVERSION)
96 - mkdir -p ${clst_port_conf}/profile
97 - echo "${KERNELVERSION}" > ${clst_port_conf}/profile/package.provided
98 - else
99 - rm -f ${clst_port_conf}/profile/package.provided
100 + if cmp -s {/tmp/,}USE && \
101 + cmp -s {/tmp/,}VERSION && \
102 + cmp -s {/tmp/,}EXTRAVERSION && \
103 + cmp -s /var/tmp/${kname}.config CONFIG; then
104 + cached_kernel_found="true"
105 fi
106
107 - # Don't use package.provided if there's a pending up/downgrade
108 - if [[ "$(portageq best_visible / ${ksource})" == "${KERNELVERSION}" ]]; then
109 - echo "No pending updates for ${ksource}"
110 - else
111 - echo "Pending updates for ${ksource}, removing package.provided"
112 - rm -f ${clst_port_conf}/profile/package.provided
113 - fi
114 + rm -f /tmp/{USE,VERSION,EXTRAVERSION}
115 + popd >/dev/null
116 +fi
117
118 +if [[ ! ${cached_kernel_found} ]]; then
119 USE=symlink run_merge --update "${ksource}"
120 +fi
121
122 +if [[ -n ${clst_KERNCACHE} ]]; then
123 SOURCESDIR="/tmp/kerncache/${kname}/sources"
124 - if [ -L /usr/src/linux ]
125 - then
126 - # A kernel was merged, move it to $SOURCESDIR
127 - [ -e ${SOURCESDIR} ] && rm -Rf ${SOURCESDIR}
128 -
129 - KERNELVERSION=`portageq best_visible / "${ksource}"`
130 - echo "${KERNELVERSION}" > /tmp/kerncache/${kname}/${kname}-${clst_version_stamp}.KERNELVERSION
131 -
132 + if [[ ! ${cached_kernel_found} ]]; then
133 echo "Moving kernel sources to ${SOURCESDIR} ..."
134 - mv `readlink -f /usr/src/linux` ${SOURCESDIR}
135 - fi
136 - ln -sf ${SOURCESDIR} /usr/src/linux
137
138 - # If catalyst has set to a empty string, extraversion wasn't specified so we
139 - # skip this part
140 - if [ "${EXTRAVERSION_MATCH}" = "0" ]
141 - then
142 - if [ ! "${clst_kextraversion}" = "" ]
143 - then
144 - echo "Setting extraversion to ${clst_kextraversion}"
145 - sed -i -e "s:EXTRAVERSION \(=.*\):EXTRAVERSION \1-${clst_kextraversion}:" /usr/src/linux/Makefile
146 - echo ${clst_kextraversion} > /tmp/kerncache/${kname}/${kname}-${clst_version_stamp}.EXTRAVERSION
147 - else
148 - touch /tmp/kerncache/${kname}/${kname}-${clst_version_stamp}.EXTRAVERSION
149 - fi
150 + rm -rf "${SOURCESDIR}"
151 + mv $(readlink -f /usr/src/linux) "${SOURCESDIR}"
152 fi
153 -else
154 - USE=symlink run_merge --update "${ksource}"
155 + ln -snf "${SOURCESDIR}" /usr/src/linux
156 +fi
157
158 - if [ ! "${clst_kextraversion}" = "" ]
159 - then
160 - echo "Setting extraversion to ${clst_kextraversion}"
161 - sed -i -e "s:EXTRAVERSION \(=.*\):EXTRAVERSION \1-${clst_kextraversion}:" /usr/src/linux/Makefile
162 +if [[ -n ${clst_kextraversion} ]]; then
163 + echo "Setting EXTRAVERSION to ${clst_kextraversion}"
164 +
165 + if [[ -e /usr/src/linux/Makefile.bak ]]; then
166 + cp /usr/src/linux/Makefile{.bak,}
167 + else
168 + cp /usr/src/linux/Makefile{,.bak}
169 fi
170 + sed -i -e "s:EXTRAVERSION \(=.*\):EXTRAVERSION \1-${clst_kextraversion}:" \
171 + /usr/src/linux/Makefile
172 fi
173
174 genkernel_compile
175
176 -if [ -n "${clst_KERNCACHE}" ]
177 -then
178 - echo ${kernel_use} > /tmp/kerncache/${kname}/${kname}-${clst_version_stamp}.USE
179 +# Write out CONFIG, USE, VERSION, and EXTRAVERSION files
180 +if [[ -n ${clst_KERNCACHE} && ! ${cached_kernel_found} ]]; then
181 + pushd "/tmp/kerncache/${kname}" >/dev/null
182 +
183 + cp /var/tmp/${kname}.config CONFIG
184 + echo "${kernel_use}" > USE
185 + echo "${kernel_version}" > VERSION
186 + echo "${clst_kextraversion}" > EXTRAVERSION
187 +
188 + popd >/dev/null
189 +fi
190 +
191 +if [[ ! ${cached_kernel_found} ]]; then
192 + run_merge -C "${ksource}"
193 + rm /usr/src/linux
194 fi
195 --
196 2.26.2