[zorg] r232835 - It seems we have quite some conditional steps in our builders. Instead of separate steps to set a property and then use the property in the doStepIf condition, we can use the FileExisys or FileDoesNotExist directly with doStepIf.

Galina Kistanova gkistanova at gmail.com
Fri Mar 20 12:29:34 PDT 2015


Author: gkistanova
Date: Fri Mar 20 14:29:34 2015
New Revision: 232835

URL: http://llvm.org/viewvc/llvm-project?rev=232835&view=rev
Log:
It seems we have quite some conditional steps in our builders. Instead of separate steps to set a property and then use the property in the doStepIf condition, we can use the FileExisys or FileDoesNotExist directly with doStepIf.

Added:
    zorg/trunk/zorg/buildbot/conditions/
    zorg/trunk/zorg/buildbot/conditions/FileConditions.py
    zorg/trunk/zorg/buildbot/conditions/__init__.py
Modified:
    zorg/trunk/zorg/buildbot/__init__.py

Modified: zorg/trunk/zorg/buildbot/__init__.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/zorg/buildbot/__init__.py?rev=232835&r1=232834&r2=232835&view=diff
==============================================================================
--- zorg/trunk/zorg/buildbot/__init__.py (original)
+++ zorg/trunk/zorg/buildbot/__init__.py Fri Mar 20 14:29:34 2015
@@ -1,5 +1,6 @@
 import builders
 import commands
 import changes
+import conditions
 
 __all__ = []

Added: zorg/trunk/zorg/buildbot/conditions/FileConditions.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/zorg/buildbot/conditions/FileConditions.py?rev=232835&view=auto
==============================================================================
--- zorg/trunk/zorg/buildbot/conditions/FileConditions.py (added)
+++ zorg/trunk/zorg/buildbot/conditions/FileConditions.py Fri Mar 20 14:29:34 2015
@@ -0,0 +1,72 @@
+from buildbot.process.buildstep import LoggedRemoteCommand
+from buildbot.interfaces import BuildSlaveTooOldError
+import stat
+
+from twisted.python import log
+
+class FileExists(object):
+    """I check a file existence on the buildslave. I return True if the file
+    with the given name exists, False if the file does not exist or that is
+    a directory.
+
+    Use me with doStepIf to make a build step conditional to existence of some
+    file. For example
+
+    doStepIf=FileExists('build/configure')
+    """
+
+    def __init__(self, filename):
+        self.filename = filename
+
+    def __call__(self, step):
+        slavever = step.slaveVersion('stat')
+        if not slavever:
+            raise BuildSlaveTooOldError("slave is too old, does not know "
+                                        "about stat")
+
+        def commandComplete(cmd):
+            if cmd.rc != 0:
+                return False
+
+            s = cmd.updates["stat"][-1]
+            filemode = s[stat.ST_MODE]
+            if stat.S_ISREG(filemode) or stat.S_ISLNK(filemode):
+                # True only if this is a file or a link and not any other file
+                # system object.
+                return True
+            else:
+                return False
+
+        cmd = LoggedRemoteCommand('stat', {'file': self.filename})
+        d = step.runCommand(cmd)
+        d.addCallback(lambda res: commandComplete(cmd))
+        return d
+
+class FileDoesNotExist(object):
+    """I check a file existence on the buildslave. I return False if
+    the file with the given name exists or that is a directory, True if the
+    file does not exist.
+
+    Use me with doStepIf to make a build step conditional to nonexistence
+    of some file. For example
+
+    doStepIf=FileDoesNotExist('build/configure')
+    """
+
+    def __init__(self, filename):
+        self.filename = filename
+
+    def __call__(self, step):
+        slavever = step.slaveVersion('stat')
+        if not slavever:
+            raise BuildSlaveTooOldError("slave is too old, does not know "
+                                        "about stat")
+
+        def commandComplete(cmd):
+            # False if any filesystem object with the given name exists.
+            return (cmd.rc != 0)
+
+        cmd = LoggedRemoteCommand('stat', {'file': self.filename})
+        d = step.runCommand(cmd)
+        d.addCallback(lambda res: commandComplete(cmd))
+        return d
\ No newline at end of file

Added: zorg/trunk/zorg/buildbot/conditions/__init__.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/zorg/buildbot/conditions/__init__.py?rev=232835&view=auto
==============================================================================
--- zorg/trunk/zorg/buildbot/conditions/__init__.py (added)
+++ zorg/trunk/zorg/buildbot/conditions/__init__.py Fri Mar 20 14:29:34 2015
@@ -0,0 +1,3 @@
+import FileConditions
+
+__all__ = []





More information about the llvm-commits mailing list