]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Python/buildgen/AntTasks.py
3 # Copyright (c) 2007, Intel Corporation
4 # All rights reserved. This program and the accompanying materials
5 # are licensed and made available under the terms and conditions of the BSD License
6 # which accompanies this distribution. The full text of the license may be found at
7 # http://opensource.org/licenses/bsd-license.php
9 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 """Ant Tasks Dom Element"""
14 import xml
. dom
. minidom
, os
17 def __init__ ( self
, document
, _name
, _body
= None , ** _attributes
):
18 """Instantiate an Ant task element
19 document, _name=task name, _body=task body, **_attributes=task attributes
21 self
. Document
= document
24 if _name
== None or _name
== "" :
25 raise Exception ( "No Ant task name" )
27 taskElement
= self
. Document
. createElement ( _name
)
28 for name
in _attributes
:
29 taskElement
. setAttribute ( name
, _attributes
[ name
])
32 if isinstance ( _body
, str ):
33 text
= self
. Document
. createTextNode ( _body
)
34 taskElement
. appendChild ( text
)
35 elif isinstance ( _body
, list ):
37 taskElement
. appendChild ( subtask
)
39 self
. Root
= taskElement
41 def SubTask ( self
, _name
, _body
= None , ** _attributes
):
42 """Insert a sub-task into this task"""
43 newTask
= AntTask ( self
. Document
, _name
, _body
, ** _attributes
)
44 self
. Root
. appendChild ( newTask
. Root
)
47 def AddSubTask ( self
, subTask
):
48 """Insert a existing sub-task into this task"""
49 self
. Root
. appendChild ( subTask
. Root
. cloneNode ( True ))
52 def Comment ( self
, string
):
53 """Generate a XML comment"""
54 self
. Root
. appendChild ( self
. Document
. createComment ( string
))
57 """Generate a blank line"""
58 self
. Root
. appendChild ( self
. Document
. createTextNode ( "" ))
61 class AntBuildFile ( AntTask
):
62 _FileComment
= "DO NOT EDIT \n This file is auto-generated by the build utility \n\n Abstract: \n Auto-generated ANT build file for building Framework modules and platforms \n "
64 def __init__ ( self
, name
, basedir
= "." , default
= "all" ):
65 """Instantiate an Ant build.xml
66 name=project name, basedir=project default directory, default=default target of this project
68 self
. Document
= xml
. dom
. minidom
. getDOMImplementation (). createDocument ( None , "project" , None )
69 self
. Root
= self
. Document
. documentElement
71 self
. Document
. insertBefore ( self
. Document
. createComment ( self
._ FileComment
), self
. Root
)
72 self
. Root
. setAttribute ( "name" , name
)
73 self
. Root
. setAttribute ( "basedir" , basedir
)
74 self
. Root
. setAttribute ( "default" , default
)
76 def Create ( self
, file ):
77 """Generate the build.xml using given file path"""
78 buildFileDir
= os
. path
. dirname ( file )
79 if not os
. path
. exists ( buildFileDir
):
80 os
. makedirs ( buildFileDir
)
83 f
. write ( self
. Document
. toprettyxml ( 2 * " " , encoding
= "UTF-8" ))