summaryrefslogtreecommitdiffstats
path: root/scripts/cleanup-workdir
diff options
context:
space:
mode:
authorKang Kai <kai.kang@windriver.com>2012-06-15 03:06:54 (GMT)
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-06-18 12:24:57 (GMT)
commit3360a4f1b3b4b73e01fc4a05ce4b83ffa010a744 (patch)
treee585ca874fcdc21eb3182a3ecbba9e2211a0ef3e /scripts/cleanup-workdir
parent21d84d2fe3ac4a73f6477bd87ef459969d0d8850 (diff)
downloadpoky-3360a4f1b3b4b73e01fc4a05ce4b83ffa010a744.tar.gz
cleanup-workdir: only deal dirs related to current arch
Some users may build for different archs under same workdir, so they don't want to clean the dirs not related to current arch. Run command 'bitbake -e' with selected packages to get the dirs related to current arch then clean them. Update the way to get the WORKDIR by parsing the IMAGE_ROOTFS by the way. (From OE-Core rev: a16727ebc341e0a0ce59a5200dc774cf672593ee) Signed-off-by: Kang Kai <kai.kang@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/cleanup-workdir')
-rwxr-xr-xscripts/cleanup-workdir54
1 files changed, 49 insertions, 5 deletions
diff --git a/scripts/cleanup-workdir b/scripts/cleanup-workdir
index 1e9c56d..156a259 100755
--- a/scripts/cleanup-workdir
+++ b/scripts/cleanup-workdir
@@ -47,6 +47,19 @@ def run_command(cmd):
47 sys.exit(1) 47 sys.exit(1)
48 return output 48 return output
49 49
50def get_cur_arch_dirs(workdir, arch_dirs):
51 pattern = workdir + '/(.*?)/'
52
53 # select thest 5 packages to get the dirs of current arch
54 pkgs = ['hicolor-icon-theme', 'base-files', 'acl-native', 'binutils-crosssdk', 'autoconf-nativesdk']
55
56 for pkg in pkgs:
57 cmd = "bitbake -e " + pkg + " | grep ^IMAGE_ROOTFS="
58 output = run_command(cmd)
59 output = output.split('"')[1]
60 m = re.match(pattern, output)
61 arch_dirs.append(m.group(1))
62
50def main(): 63def main():
51 global parser 64 global parser
52 parser = optparse.OptionParser( 65 parser = optparse.OptionParser(
@@ -87,21 +100,52 @@ This script must be ran under BUILDDIR after source file \"oe-init-build-env\"."
87 version = parse_version(elems[2]) 100 version = parse_version(elems[2])
88 pkg_cur_dirs.append(elems[0] + '-' + version) 101 pkg_cur_dirs.append(elems[0] + '-' + version)
89 102
90 cmd = "bitbake -e | grep ^TMPDIR" 103 cmd = "bitbake -e"
91 output = run_command(cmd) 104 output = run_command(cmd)
92 105
93 tmpdir = output.split('"')[1] 106 tmpdir = None
94 workdir = os.path.join(tmpdir, 'work') 107 image_rootfs = None
95 if not os.path.exists(workdir): 108 output = output.split('\n')
96 print "WORKDIR %s does NOT exist. Quit." % workdir 109 for line in output:
110 if tmpdir and image_rootfs:
111 break
112
113 if not tmpdir:
114 m = re.match('TMPDIR="(.*)"', line)
115 if m:
116 tmpdir = m.group(1)
117
118 if not image_rootfs:
119 m = re.match('IMAGE_ROOTFS="(.*)"', line)
120 if m:
121 image_rootfs = m.group(1)
122
123 # won't fail just in case
124 if not tmpdir or not image_rootfs:
125 print "Can't get TMPDIR or IMAGE_ROOTFS."
126 return 1
127
128 pattern = tmpdir + '/(.*?)/(.*?)/'
129 m = re.match(pattern, image_rootfs)
130 if not m:
131 print "Can't get WORKDIR."
97 return 1 132 return 1
98 133
134 workdir = os.path.join(tmpdir, m.group(1))
135
136 # we only deal the dirs of current arch, total numbers of dirs are 6
137 cur_arch_dirs = [m.group(2)]
138 get_cur_arch_dirs(workdir, cur_arch_dirs)
139
99 for workroot, dirs, files in os.walk(workdir): 140 for workroot, dirs, files in os.walk(workdir):
100 # For the files, they should NOT exist in WORKDIR. Romve them. 141 # For the files, they should NOT exist in WORKDIR. Romve them.
101 for f in files: 142 for f in files:
102 obsolete_dirs.append(os.path.join(workroot, f)) 143 obsolete_dirs.append(os.path.join(workroot, f))
103 144
104 for d in dirs: 145 for d in dirs:
146 if d not in cur_arch_dirs:
147 continue
148
105 for pkgroot, pkgdirs, filenames in os.walk(os.path.join(workroot, d)): 149 for pkgroot, pkgdirs, filenames in os.walk(os.path.join(workroot, d)):
106 for f in filenames: 150 for f in filenames:
107 obsolete_dirs.append(os.path.join(pkgroot, f)) 151 obsolete_dirs.append(os.path.join(pkgroot, f))