aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/cleanup-workdir
diff options
context:
space:
mode:
authorKang Kai <kai.kang@windriver.com>2012-06-15 11:06:54 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-06-18 13:16:37 +0100
commita16727ebc341e0a0ce59a5200dc774cf672593ee (patch)
treefbcdeb81c7a663237caa3c46e4c49c56bb0759a7 /scripts/cleanup-workdir
parent33f18965bbeeec47f694f2aa165e5e07eadb7ab7 (diff)
downloadopenembedded-core-contrib-a16727ebc341e0a0ce59a5200dc774cf672593ee.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. Signed-off-by: Kang Kai <kai.kang@windriver.com>
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 1e9c56dcf6..156a2597c1 100755
--- a/scripts/cleanup-workdir
+++ b/scripts/cleanup-workdir
@@ -47,6 +47,19 @@ def run_command(cmd):
sys.exit(1)
return output
+def get_cur_arch_dirs(workdir, arch_dirs):
+ pattern = workdir + '/(.*?)/'
+
+ # select thest 5 packages to get the dirs of current arch
+ pkgs = ['hicolor-icon-theme', 'base-files', 'acl-native', 'binutils-crosssdk', 'autoconf-nativesdk']
+
+ for pkg in pkgs:
+ cmd = "bitbake -e " + pkg + " | grep ^IMAGE_ROOTFS="
+ output = run_command(cmd)
+ output = output.split('"')[1]
+ m = re.match(pattern, output)
+ arch_dirs.append(m.group(1))
+
def main():
global parser
parser = optparse.OptionParser(
@@ -87,21 +100,52 @@ This script must be ran under BUILDDIR after source file \"oe-init-build-env\"."
version = parse_version(elems[2])
pkg_cur_dirs.append(elems[0] + '-' + version)
- cmd = "bitbake -e | grep ^TMPDIR"
+ cmd = "bitbake -e"
output = run_command(cmd)
- tmpdir = output.split('"')[1]
- workdir = os.path.join(tmpdir, 'work')
- if not os.path.exists(workdir):
- print "WORKDIR %s does NOT exist. Quit." % workdir
+ tmpdir = None
+ image_rootfs = None
+ output = output.split('\n')
+ for line in output:
+ if tmpdir and image_rootfs:
+ break
+
+ if not tmpdir:
+ m = re.match('TMPDIR="(.*)"', line)
+ if m:
+ tmpdir = m.group(1)
+
+ if not image_rootfs:
+ m = re.match('IMAGE_ROOTFS="(.*)"', line)
+ if m:
+ image_rootfs = m.group(1)
+
+ # won't fail just in case
+ if not tmpdir or not image_rootfs:
+ print "Can't get TMPDIR or IMAGE_ROOTFS."
+ return 1
+
+ pattern = tmpdir + '/(.*?)/(.*?)/'
+ m = re.match(pattern, image_rootfs)
+ if not m:
+ print "Can't get WORKDIR."
return 1
+ workdir = os.path.join(tmpdir, m.group(1))
+
+ # we only deal the dirs of current arch, total numbers of dirs are 6
+ cur_arch_dirs = [m.group(2)]
+ get_cur_arch_dirs(workdir, cur_arch_dirs)
+
for workroot, dirs, files in os.walk(workdir):
# For the files, they should NOT exist in WORKDIR. Romve them.
for f in files:
obsolete_dirs.append(os.path.join(workroot, f))
for d in dirs:
+ if d not in cur_arch_dirs:
+ continue
+
for pkgroot, pkgdirs, filenames in os.walk(os.path.join(workroot, d)):
for f in filenames:
obsolete_dirs.append(os.path.join(pkgroot, f))
ted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
#
# Copyright (C) 2006 - 2007  Michael 'Mickey' Lauer
# Copyright (C) 2006 - 2007  Richard Purdie
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


"""
Use this class to fork off a thread to recieve event callbacks from the bitbake 
server and queue them for the UI to process. This process must be used to avoid
client/server deadlocks.
"""

import socket, threading, pickle
from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler

class BBUIEventQueue:
    def __init__(self, BBServer):

        self.eventQueue = []
        self.eventQueueLock = threading.Lock()
        self.eventQueueNotify = threading.Event()

        self.BBServer = BBServer

        self.t = threading.Thread()
        self.t.setDaemon(True)
        self.t.run = self.startCallbackHandler
        self.t.start()

    def getEvent(self):

        self.eventQueueLock.acquire()

        if len(self.eventQueue) == 0:
            self.eventQueueLock.release()
            return None

        item = self.eventQueue.pop(0)

        if len(self.eventQueue) == 0:
            self.eventQueueNotify.clear()

        self.eventQueueLock.release()
        return item

    def waitEvent(self, delay):
        self.eventQueueNotify.wait(delay)
        return self.getEvent()

    def queue_event(self, event):
        self.eventQueueLock.acquire()
        self.eventQueue.append(pickle.loads(event))
        self.eventQueueNotify.set()
        self.eventQueueLock.release()

    def startCallbackHandler(self):

        server = UIXMLRPCServer()
        self.host, self.port = server.socket.getsockname()

        server.register_function( self.system_quit, "event.quit" )
        server.register_function( self.queue_event, "event.send" )
        server.socket.settimeout(1)

        self.EventHandle = self.BBServer.registerEventHandler(self.host, self.port)

        self.server = server
        while not server.quit:
            server.handle_request()
        server.server_close()

    def system_quit( self ):
        """
        Shut down the callback thread
        """
        try:
            self.BBServer.unregisterEventHandler(self.EventHandle)
        except:
            pass
        self.server.quit = True

class UIXMLRPCServer (SimpleXMLRPCServer):

    def __init__( self, interface = ("localhost", 0) ):
        self.quit = False
        SimpleXMLRPCServer.__init__( self,
                                    interface,
                                    requestHandler=SimpleXMLRPCRequestHandler,
                                    logRequests=False, allow_none=True)

    def get_request(self):
        while not self.quit:
            try:
                sock, addr = self.socket.accept()
                sock.settimeout(1)
                return (sock, addr)
            except socket.timeout:
                pass
        return (None,None)

    def close_request(self, request):
        if request is None:
            return
        SimpleXMLRPCServer.close_request(self, request)
        
    def process_request(self, request, client_address):
        if request is None:
            return
        SimpleXMLRPCServer.process_request(self, request, client_address)