]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Python/buildgen/AntTasks.py
Python script for generating build files for platform and modules, which uses the...
[mirror_edk2.git] / Tools / Python / buildgen / AntTasks.py
diff --git a/Tools/Python/buildgen/AntTasks.py b/Tools/Python/buildgen/AntTasks.py
new file mode 100644 (file)
index 0000000..ce694f9
--- /dev/null
@@ -0,0 +1,84 @@
+#!/usr/bin/env python\r
+\r
+# Copyright (c) 2007, Intel Corporation\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+"""Ant Tasks Dom Element"""\r
+\r
+import xml.dom.minidom, os\r
+\r
+class AntTask:\r
+    def __init__(self, document, _name, _body=None, **_attributes):\r
+        """Instantiate an Ant task element\r
+        document, _name=task name, _body=task body, **_attributes=task attributes\r
+        """\r
+        self.Document = document\r
+        self.Root = ""\r
+            \r
+        if _name == None or _name == "":\r
+            raise Exception("No Ant task name")\r
+\r
+        taskElement = self.Document.createElement(_name)\r
+        for name in _attributes:\r
+            taskElement.setAttribute(name, _attributes[name])\r
+\r
+        if _body != None:\r
+            if isinstance(_body, str):\r
+                text = self.Document.createTextNode(_body)\r
+                taskElement.appendChild(text)\r
+            elif isinstance(_body, list):\r
+                for subtask in _body:\r
+                    taskElement.appendChild(subtask)\r
+\r
+        self.Root = taskElement\r
+\r
+    def SubTask(self, _name, _body=None, **_attributes):\r
+        """Insert a sub-task into this task"""\r
+        newTask = AntTask(self.Document, _name , _body, **_attributes)\r
+        self.Root.appendChild(newTask.Root)\r
+        return newTask\r
+\r
+    def AddSubTask(self, subTask):\r
+        """Insert a existing sub-task into this task"""\r
+        self.Root.appendChild(subTask.Root.cloneNode(True))\r
+        return subTask\r
+        \r
+    def Comment(self, string):\r
+        """Generate a XML comment"""\r
+        self.Root.appendChild(self.Document.createComment(string))\r
+\r
+    def Blankline(self):\r
+        """Generate a blank line"""\r
+        self.Root.appendChild(self.Document.createTextNode(""))\r
+\r
+\r
+class AntBuildFile(AntTask):\r
+    _FileComment = "DO NOT EDIT\nThis file is auto-generated by the build utility\n\nAbstract:\nAuto-generated ANT build file for building Framework modules and platforms\n"\r
+    \r
+    def __init__(self, name, basedir=".", default="all"):\r
+        """Instantiate an Ant build.xml\r
+           name=project name, basedir=project default directory, default=default target of this project\r
+        """\r
+        self.Document = xml.dom.minidom.getDOMImplementation().createDocument(None, "project", None)\r
+        self.Root = self.Document.documentElement\r
+        \r
+        self.Document.insertBefore(self.Document.createComment(self._FileComment), self.Root)\r
+        self.Root.setAttribute("name", name)\r
+        self.Root.setAttribute("basedir", basedir)\r
+        self.Root.setAttribute("default", default)\r
+        \r
+    def Create(self, file):\r
+        """Generate the build.xml using given file path"""\r
+        buildFileDir = os.path.dirname(file)\r
+        if not os.path.exists(buildFileDir):\r
+            os.makedirs(buildFileDir)\r
+            \r
+        f = open(file, "w")\r
+        f.write(self.Document.toprettyxml(2*" ", encoding="UTF-8"))\r
+        f.close()\r