summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2017-04-10 17:00:37 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-04-10 23:00:44 +0100
commit684eefd7a3ab473c4fcada981fbecd92a8f3c3cc (patch)
tree08aed41a2f1f445209bfaf80446561b0279a6c04 /scripts
parent503009b8313082d71da4c23273dca25fbbb22d79 (diff)
downloadpoky-684eefd7a3ab473c4fcada981fbecd92a8f3c3cc.tar.gz
scripts: Drop cleanup-workdir
This script appears broken and is actively breaking build directories. For example, binutils-cross-i586 gets run do_fetch to do_populate_sysroot by: $ oe-selftest -r devtool.DevtoolTests.test_devtool_virtual_kernel_modify then: $ oe-selftest -r oescripts.BuildhistoryDiffTests.test_buildhistory_diff wipes out the contents of tmp/work/x86_64-linux/binutils-cross-i586/2.28-r0/ but does not wipe out the corresponding stamps, then: $ oe-selftest -r runtime-test.Postinst.test_postinst_rootfs_and_boot needs binutils-cross-i586:do_populate_lic and if and only if this is unavailable from sstate, it fails since it thinks the source is already unpacked when it isn't resulting in: WARNING: binutils-cross-i586-2.28-r0 do_populate_lic: Could not copy license file /home/pokybuild/yocto-autobuilder/yocto-worker/nigh tly-oe-selftest/build/build/tmp/work/x86_64-linux/binutils-cross-i586/2.28-r0/git/COPYING3.LIB to /home/pokybuild/yocto-autobuilder/yocto -worker/nightly-oe-selftest/build/build/tmp/work/x86_64-linux/binutils-cross-i586/2.28-r0/license-destdir/binutils-cross-i586/COPYING3.LI B: [Errno 2] No such file or directory: '/home/pokybuild/yocto-autobuilder/yocto-worker/nightly-oe-selftest/build/build/tmp/work/x86_64-l inux/binutils-cross-i586/2.28-r0/git/COPYING3.LIB' ERROR: binutils-cross-i586-2.28-r0 do_populate_lic: QA Issue: binutils-cross-i586: LIC_FILES_CHKSUM points to an invalid file: /home/ pokybuild/yocto-autobuilder/yocto-worker/nightly-oe-selftest/build/build/tmp/work/x86_64-linux/binutils-cross-i586/2.28-r0/git/COPYING3 [license-checksum] and similar errors. Its safer for users to wipe tmp than try and maintain scripts which try to remove pieces of tmp and get it wrong so remove the script. (From OE-Core rev: 809b23c829f352c0eae455ea89f53e2a9ee87f06) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/cleanup-workdir198
1 files changed, 0 insertions, 198 deletions
diff --git a/scripts/cleanup-workdir b/scripts/cleanup-workdir
deleted file mode 100755
index 98769f6b32..0000000000
--- a/scripts/cleanup-workdir
+++ /dev/null
@@ -1,198 +0,0 @@
1#!/usr/bin/env python3
2
3# Copyright (c) 2012 Wind River Systems, Inc.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12# See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18import os
19import sys
20import optparse
21import re
22import subprocess
23import shutil
24
25pkg_cur_dirs = {}
26obsolete_dirs = []
27parser = None
28
29def err_quit(msg):
30 print(msg)
31 parser.print_usage()
32 sys.exit(1)
33
34def parse_version(verstr):
35 elems = verstr.split(':')
36 epoch = elems[0]
37 if len(epoch) == 0:
38 return elems[1]
39 else:
40 return epoch + '_' + elems[1]
41
42def run_command(cmd):
43 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
44 output = pipe.communicate()[0]
45 if pipe.returncode != 0:
46 print("Execute command '%s' failed." % cmd)
47 sys.exit(1)
48 return output.decode('utf-8')
49
50def get_cur_arch_dirs(workdir, arch_dirs):
51 pattern = workdir + '/(.*?)/'
52
53 cmd = "bitbake -e | grep ^SDK_SYS="
54 output = run_command(cmd)
55 sdk_sys = output.split('"')[1]
56
57 # select thest 5 packages to get the dirs of current arch
58 pkgs = ['hicolor-icon-theme', 'base-files', 'acl-native', 'binutils-crosssdk-' + sdk_sys, 'nativesdk-autoconf']
59
60 for pkg in pkgs:
61 cmd = "bitbake -e " + pkg + " | grep ^IMAGE_ROOTFS="
62 output = run_command(cmd)
63 output = output.split('"')[1]
64 m = re.match(pattern, output)
65 arch_dirs.append(m.group(1))
66
67def main():
68 global parser
69 parser = optparse.OptionParser(
70 usage = """%prog
71
72%prog removes the obsolete packages' build directories in WORKDIR.
73This script must be ran under BUILDDIR after source file \"oe-init-build-env\".
74
75Any file or directory under WORKDIR which is not created by Yocto
76will be deleted. Be CAUTIOUS.""")
77
78 options, args = parser.parse_args(sys.argv)
79
80 builddir = run_command('echo $BUILDDIR').strip()
81 if len(builddir) == 0:
82 err_quit("Please source file \"oe-init-build-env\" first.\n")
83
84 if os.getcwd() != builddir:
85 err_quit("Please run %s under: %s\n" % (os.path.basename(args[0]), builddir))
86
87 print('Updating bitbake caches...')
88 cmd = "bitbake -s"
89 output = run_command(cmd)
90
91 output = output.split('\n')
92 index = 0
93 while len(output[index]) > 0:
94 index += 1
95 alllines = output[index+1:]
96
97 for line in alllines:
98 # empty again means end of the versions output
99 if len(line) == 0:
100 break
101 line = line.strip()
102 line = re.sub('\s+', ' ', line)
103 elems = line.split(' ')
104 if len(elems) == 2:
105 version = parse_version(elems[1])
106 else:
107 version = parse_version(elems[2])
108 pkg_cur_dirs[elems[0]] = version
109
110 cmd = "bitbake -e"
111 output = run_command(cmd)
112
113 tmpdir = None
114 image_rootfs = None
115 output = output.split('\n')
116 for line in output:
117 if tmpdir and image_rootfs:
118 break
119
120 if not tmpdir:
121 m = re.match('TMPDIR="(.*)"', line)
122 if m:
123 tmpdir = m.group(1)
124
125 if not image_rootfs:
126 m = re.match('IMAGE_ROOTFS="(.*)"', line)
127 if m:
128 image_rootfs = m.group(1)
129
130 # won't fail just in case
131 if not tmpdir or not image_rootfs:
132 print("Can't get TMPDIR or IMAGE_ROOTFS.")
133 return 1
134
135 pattern = tmpdir + '/(.*?)/(.*?)/'
136 m = re.match(pattern, image_rootfs)
137 if not m:
138 print("Can't get WORKDIR.")
139 return 1
140
141 workdir = os.path.join(tmpdir, m.group(1))
142
143 # we only deal the dirs of current arch, total numbers of dirs are 6
144 cur_arch_dirs = [m.group(2)]
145 get_cur_arch_dirs(workdir, cur_arch_dirs)
146
147 for workroot, dirs, files in os.walk(workdir):
148 # For the files, they should NOT exist in WORKDIR. Remove them.
149 for f in files:
150 obsolete_dirs.append(os.path.join(workroot, f))
151
152 for d in dirs:
153 if d not in cur_arch_dirs:
154 continue
155
156 for pkgroot, pkgdirs, filenames in os.walk(os.path.join(workroot, d)):
157 for f in filenames:
158 obsolete_dirs.append(os.path.join(pkgroot, f))
159
160 for pkgdir in sorted(pkgdirs):
161 if pkgdir not in pkg_cur_dirs:
162 obsolete_dirs.append(os.path.join(pkgroot, pkgdir))
163 else:
164 for verroot, verdirs, verfiles in os.walk(os.path.join(pkgroot, pkgdir)):
165 for f in verfiles:
166 obsolete_dirs.append(os.path.join(pkgroot, f))
167 for v in sorted(verdirs):
168 if v not in pkg_cur_dirs[pkgdir]:
169 obsolete_dirs.append(os.path.join(pkgroot, pkgdir, v))
170 break
171
172 # just process the top dir of every package under tmp/work/*/,
173 # then jump out of the above os.walk()
174 break
175
176 # it is convenient to use os.walk() to get dirs and files at same time
177 # both of them have been dealed in the loop, so jump out
178 break
179
180 for d in obsolete_dirs:
181 print("Deleting %s" % d)
182 shutil.rmtree(d, True)
183
184 if len(obsolete_dirs):
185 print('\nTotal %d items.' % len(obsolete_dirs))
186 else:
187 print('\nNo obsolete directory found under %s.' % workdir)
188
189 return 0
190
191if __name__ == '__main__':
192 try:
193 ret = main()
194 except Exception:
195 ret = 2
196 import traceback
197 traceback.print_exc()
198 sys.exit(ret)