summaryrefslogtreecommitdiff
path: root/bin/pack-debug
blob: 312f59e6f81f0889abbc6f9d42d27da9ffff121c (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#!/bin/bash
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# create debuginfo and debugsource packages from LO rpm & deb files
# (generated by using --enable-symbols)

# build path
export BUILD_PATH=$PWD
export BUILD_LOG=$BUILD_PATH/pack-debug.log

if type -P pigz &>/dev/null; then
    GZIP=pigz
else
    GZIP=gzip
fi

if [ $# -gt 0 ]
then
 for i in "$@"
 do
  case $i in
--only-rpm) ONLY_RPM=1;;
--only-deb) ONLY_DEB=1;;
*) echo "Usage: pack-debug [--only-rpm | --only-deb]" && exit 1;;
  esac
 done
fi

# set install dirname and product version
if [ ! -f config.log ]; then
    echo "config.log not found. Run this script from build root."
    exit 1;
fi

# create pack-debug.log file
echo create debug packages >$BUILD_LOG

eval $(grep ^INSTALLDIRNAME config.log)
eval $(grep ^PRODUCTVERSION config.log)

# set package base name, eg. collaboraoffice6.4
DEBUGSRC_PACKAGENAME=$INSTALLDIRNAME$PRODUCTVERSION

#################################
# Function for re-build RPM files
#################################
function repack_rpm {

# set environment based on config.log
# for find-requires-x11.sh used by rpm __find_requires
eval $(grep ^PLATFORMID config.log)
export PLATFORMID
eval $(grep ^build_cpu config.log)
export build_cpu

####################################
echo create RPM debug source package
####################################

DEBUGSRC="$(find workdir -name ${DEBUGSRC_PACKAGENAME}.spec.log)"

# create spec file, based on the spec file of the brand package

cat $DEBUGSRC | awk '
	/^Name:/ { print "Summary: Debug source for package "$2; print $0"-debugsource";next }
	/^Group:/ { print $1" Development/Debug";next }
	/^Brand module/ { print gensub("Brand module", "Source files", "");next }
	/^%attr/ || /^Summary:/ { next }
	{print}
	END {
		print "%defattr(-,root,root)"
	}
 ' > ${DEBUGSRC}-debugsource
 buildroot=$(cat $DEBUGSRC-debugsource | awk '/^BuildRoot/{print$2}')
 topdir=$(dirname $(dirname $buildroot))
 mkdir -p $buildroot $topdir/RPMS/BUILD $topdir/RPMS/RPMS
 rm -rf $buildroot

 # create source file list

 find $BUILD_PATH -name '*[.][hc]xx' -o -name '*[.][hc]' | grep -Ev '/(instdir|qa|DEBS)/' |

 # list all directories for complete rpm remove

 awk -v home=$BUILD_PATH '
	{
		split($0, a, home "/")
		n=split(a[2], b, "/")
		c=home
		for(i=1;i<n;i++) {
			c=c"/"b[i]
			if(mem[c]!=1) print "%dir "c
			mem[c]=1
		}
		print $0
	}' >> ${DEBUGSRC}-debugsource

 # start rpmbuild for debug source package

 ln -s / $buildroot

 # debug build source package

 rpmbuild -bb --define "_unpackaged_files_terminate_build  0" --define "_binary_payload w1T.xzdio" ${DEBUGSRC}-debugsource --target $build_cpu --buildroot=$buildroot

###################################################################
echo create rpm debug info packages by processing logged spec files
###################################################################

for i in $BUILD_PATH/workdir/installation/CollaboraOffice/rpm/logging/*/*.spec.log
do

 # repackage only rpm packages with non-stripped so files

 if grep -q '^%attr.*[.]\(so\|bin\)\([.].*\)\?\"' $i
 then
	echo ================ $i ================
	pack=$(cat $i | awk '/^Name/{print$2}')
	buildroot=$(cat $i | awk '/^BuildRoot/{print$2}')
	topdir=$(dirname $(dirname $buildroot))
	rpmdir=$(echo $topdir | sed 's/_inprogress$//')

	# create empty buildroot directory

	rm -rf $buildroot
	mkdir -p $buildroot $topdir/RPMS/BUILD $topdir/RPMS/RPMS
	cd $buildroot

	echo REBUILD: $rpmdir/RPMS/${pack}-[0-9]*.rpm

	# extract rpm package

	rpm2cpio $rpmdir/RPMS/${pack}-[0-9]*.rpm | cpio -idmv

	# create stripped libraries and linked debug info files

	for j in $(cat $i | awk '/^%attr.*libpython.*[.]so.*-gdb[.]py.*?"$/{next} /^%attr.*[.](so|bin)([.].*)?"$/{print$2}')
	do
		so=$(echo $j | tr -d '"')
		cd ./$(dirname $so)
		so=$(basename $so)
		objcopy --only-keep-debug $so $so.dbg
		objcopy --strip-debug $so
		objcopy --add-gnu-debuglink=$so.dbg $so
		cd $buildroot
	done

	# copy files for double package generation (using hard links)

	cp -rl $buildroot $buildroot.copy

	# stripped package

	rpmbuild -bb --define "_unpackaged_files_terminate_build  0" --define "_binary_payload w1T.xzdio" $i --target $build_cpu --buildroot=$buildroot
	rm -rf $buildroot
	mv $buildroot.copy $buildroot
	mkdir -p $topdir/RPMS/BUILD $topdir/RPMS/RPMS

	# create spec file for the debug info package

	cat $i | awk '
		/^Name:/ { print "Summary: Debug information for package "$2; print $0"-debuginfo";next }
		/^Group:/ { print $1" Development/Debug";next }
		/^%attr.*libpython.*[.]so.*-gdb[.]py.*?"$/ { next }
		/^%attr.*[.](so|bin)([.].*)?"$/ { print substr($0, 1, length($0) - 1)".dbg\""; next }
		/^%attr/ || /^Summary:/ { next }
		{print}
	' > ${i}-debuginfo

	# create debug info package

	rpmbuild -bb --define "_unpackaged_files_terminate_build  0" --define "_binary_payload w1T.xzdio" ${i}-debuginfo --target $build_cpu --buildroot=$buildroot
 fi
done

echo Update RPM download tar.gz

mv $topdir/RPMS/RPMS/*/*.rpm $rpmdir/RPMS/
cd $rpmdir/..
TARGET_RPM=$(ls *_download/*.tar.gz)
TARGET_DEBUG=$(echo $TARGET_RPM | sed 's/.tar.gz$/-debug.tar.gz/')
SOURCE_RPM=$(find *_rpm -type f | grep -v debug)
SOURCE_DEBUG=$(find *_rpm -type f | grep -E '(debug|readme|README)')
tar c $SOURCE_RPM | $GZIP >$TARGET_RPM
tar c $SOURCE_DEBUG | $GZIP >$TARGET_DEBUG
cd $BUILD_PATH
rm -rf $topdir
}

#################################
# Function for re-build DEB files
#################################
function repack_deb {

####################################
echo create DEB debug source package
####################################

DEBUGSRC=$BUILD_PATH/workdir/installation/CollaboraOffice/deb/listfile/en-US/epm_gid_Module_Root_Brand.lst

echo Base spec file: $DEBUGSRC

# create spec file, based on the spec file of the brand package

cat $DEBUGSRC | awk '
	/^%product/ { print gensub("Brand module", "Debug source package", "", $0) ;next }
	/^%description/ { print gensub("Brand module", "Debug source package", "", $0) ;next }
	/^[cdf] / { next }
	{print}
 ' > ${DEBUGSRC}-debugsource

 # create source file list

 find $BUILD_PATH -name '*[.][hc]xx' -o -name '*[.][hc]' | grep -Ev '/(instdir|qa|DEBS)/' |

 # list all directories

 awk -v home=$BUILD_PATH '
	{
		split($0, a, home "/")
		n=split(a[2], b, "/")
		c=home
		for(i=1;i<n;i++) {
			c=c"/"b[i]
			if(mem[c]!=1) print "d 755 root root "c" -"
			mem[c]=1
		}
		print "f 644 root root "$0" "$0
	}' >> ${DEBUGSRC}-debugsource

 echo Spec file of debug source package: ${DEBUGSRC}-debugsource

 # debug build source package

 $BUILD_PATH/workdir/UnpackedTarball/epm/epm -f deb -g ${INSTALLDIRNAME}${PRODUCTVERSION}-debugsource ${DEBUGSRC}-debugsource --output-dir DEBS -v

######################################################################
echo create DEB debug info packages by processing logged EPM lst files
######################################################################

for i in $BUILD_PATH/workdir/installation/CollaboraOffice/deb/listfile/en-US/*.lst
do

 # repackage only deb packages with non-stripped so files

 if grep -q '^f .*[.]\(so\|bin\)\([.].*\)\?$' $i
 then
	echo ================ $i ================
	TARGET_NAME=$INSTALLDIRNAME"$(echo $(basename $i) | awk '
	/epm_gid_Module_Optional_Firebird.lst/{print"basis6.4-firebird"}
	/epm_gid_Module_Optional_Gnome.lst/{print"basis6.4-gnome-integration"}
	/epm_gid_Module_Optional_Grfflt.lst/{print"basis6.4-graphicfilter"}
	/epm_gid_Module_Optional_Kde.lst/{print"basis6.4-kde-integration"}
	/epm_gid_Module_Optional_OGLTrans.lst/{print"basis6.4-ogltrans"}
	/epm_gid_Module_Optional_PostgresqlSdbc.lst/{print"basis6.4-postgresql-sdbc"}
	/epm_gid_Module_Pdfimport.lst/{print"basis6.4-extension-pdf-import"}
	/epm_gid_Module_Prg_Base_Bin.lst/{print"basis6.4-base"}
	/epm_gid_Module_Prg_Calc_Bin.lst/{print"basis6.4-calc"}
	/epm_gid_Module_Prg_Impress_Bin.lst/{print"basis6.4-impress"}
	/epm_gid_Module_Prg_Math_Bin.lst/{print"basis6.4-math"}
	/epm_gid_Module_Prg_Wrt_Bin.lst/{print"basis6.4-writer"}
	/epm_gid_Module_Pyuno.lst/{print"basis6.4-pyuno"}
	/epm_gid_Module_Reportbuilder.lst/{print"basis6.4-extension-report-builder"}
	/epm_gid_Module_Root_Brand.lst/{print"6.4"}
	/epm_gid_Module_Root.lst/{print"basis6.4-core"}
	/epm_gid_Module_Root_Ure_Hidden.lst/{print"6.4-ure"}
	' | sed s/6.4/$PRODUCTVERSION/g)"
	echo TARGET NAME: $TARGET_NAME

	# create stripped libraries and linked debug info files

	for j in $(cat $i | awk '/^f .*libpython.*[.]so.*-gdb[.]py.*$/{next} /^f .*[.](so|bin)([.].*)?$/{print$6}')
	do
		cd $(dirname $j)
		so=$(basename $j)
		# remove old temporary files
		rm -f $so.copy $so.dbg
		# keep original file
		cp $so $so.copy
		objcopy --only-keep-debug $so $so.dbg
		objcopy --strip-debug $so
		objcopy --add-gnu-debuglink=$so.dbg $so
		cd $BUILD_PATH
	done

	# create stripped package

	$BUILD_PATH/workdir/UnpackedTarball/epm/epm -f deb -g $TARGET_NAME $i --output-dir DEBS -v

	# create spec file for the debug info package

	cat $i | awk '
		/^%product/ { print gensub("%product", "%product Debug info package of", "", $0);next }
		/^%description/ { print gensub("%description", "%description Debug info package of", "", $0);next }
		/^f .*libpython.*[.]so.*-gdb[.]py.*$/ { next }
		/^f .*[.](so|bin)([.].*)?$/ { print $1,$2,$3,$4,$5".dbg",$6".dbg"; next }
		/^[cf] / { next }
		{print}
	' > ${i}-debuginfo

	# create debug info package
	$BUILD_PATH/workdir/UnpackedTarball/epm/epm -f deb -g ${TARGET_NAME}-debuginfo $i-debuginfo --output-dir DEBS -v

	# restore original non stripped library files

	for j in $(cat $i | awk '/^f .*libpython.*[.]so.*-gdb[.]py.*$/{next} /^f .*[.](so|bin)([.].*)?$/{print$6}')
	do
		cd $(dirname $j)
		so=$(basename $j)
		rm $so.dbg
		# restore original file
		mv -f $so.copy $so
		cd $BUILD_PATH
	done
 fi
done

echo Update DEB download tar.gz

debdir=$(ls -d $BUILD_PATH/workdir/installation/CollaboraOffice/deb/install/*_deb)
mv $BUILD_PATH/DEBS/*.deb $debdir/DEBS/
cd $debdir/..
TARGET_DEB=$(ls *_download/*.tar.gz)
TARGET_DEBUG=$(echo $TARGET_DEB | sed 's/.tar.gz$/-debug.tar.gz/')
SOURCE_DEB=$(find *_deb -type f | grep -v debug)
SOURCE_DEBUG=$(find *_deb -type f | grep -E '(debug|readme|README)')
tar c $SOURCE_DEB | $GZIP >$TARGET_DEB
tar c $SOURCE_DEBUG | $GZIP >$TARGET_DEBUG

cd $BUILD_PATH
rm -rf DEBS
}

# start deb re-build
test -z "$ONLY_RPM" -a "$(find workdir/installation/CollaboraOffice/deb/listfile -name '*.lst')" != "" && repack_deb >$BUILD_LOG 2>&1 || \
	echo 'Skip DEB debug package generation (--only-rpm or missing EPM lst files).'

# start rpm re-build
test -z "$ONLY_DEB" -a "$(find workdir -name '*spec.log')" != "" && repack_rpm >>$BUILD_LOG 2>&1 || \
	echo 'Skip RPM debug package generation (--only-deb or missing RPM spec files).'