]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Python/MkFar.py
3 import os
, sys
, re
, getopt
, string
, glob
, xml
.dom
.minidom
, pprint
, zipfile
, tempfile
4 from XmlRoutines
import *
5 from WorkspaceRoutines
import *
7 def parseMsa(msaFile
, spdDir
):
11 msaDir
= os
.path
.dirname(msaFile
)
13 msa
= xml
.dom
.minidom
.parse(inWorkspace(msaFile
))
16 "/ModuleSurfaceArea/SourceFiles/Filename" ]
18 for xmlPath
in xmlPaths
:
19 for f
in XmlList(msa
, xmlPath
):
20 filelist
.append(str(os
.path
.join(msaDir
, XmlElementData(f
))))
24 def parseSpd(spdFile
):
29 spdDir
= os
.path
.dirname(spdFile
)
31 spd
= xml
.dom
.minidom
.parse(inWorkspace(spdFile
))
34 "/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass/IncludeHeader",
35 "/PackageSurfaceArea/IndustryStdIncludes/IndustryStdHeader/IncludeHeader",
36 "/PackageSurfaceArea/<PackageHeaders/IncludePkgHeader" ]
38 for xmlPath
in xmlPaths
:
39 for f
in XmlList(spd
, xmlPath
):
40 filelist
.append(str(os
.path
.join(spdDir
, XmlElementData(f
))))
42 for f
in XmlList(spd
, "/PackageSurfaceArea/MsaFiles/Filename"):
43 msaFile
= str(os
.path
.join(spdDir
, XmlElementData(f
)))
44 filelist
+= parseMsa(msaFile
, spdDir
)
48 def makeFar(filelist
, farname
):
50 domImpl
= xml
.dom
.minidom
.getDOMImplementation()
51 man
= domImpl
.createDocument(None, "FrameworkArchiveManifest", None)
52 top_element
= man
.documentElement
54 header
= man
.createElement("FarHeader")
55 top_element
.appendChild(header
)
57 packList
= man
.createElement("FarPackageList")
58 top_element
.appendChild(packList
)
60 platList
= man
.createElement("FarPlatformList")
61 top_element
.appendChild(platList
)
63 contents
= man
.createElement("Contents")
64 top_element
.appendChild(contents
)
66 zip = zipfile
.ZipFile(farname
, "w")
67 for infile
in filelist
:
68 if not os
.path
.exists(inWorkspace(infile
)):
69 print "Skipping non-existent file '%s'." % infile
70 (_
, extension
) = os
.path
.splitext(infile
)
71 if extension
== ".spd":
72 filelist
= parseSpd(infile
)
74 package
= man
.createElement("FarPackage")
75 packList
.appendChild(package
)
77 spdfilename
= man
.createElement("FarFilename")
78 package
.appendChild(spdfilename
)
80 spdfilename
.appendChild( man
.createTextNode(infile
) )
82 for spdfile
in filelist
:
83 content
= man
.createElement("FarFilename")
84 content
.appendChild( man
.createTextNode(spdfile
))
85 contents
.appendChild(content
)
87 elif extension
== ".fpd":
90 platform
= man
.createElement("FarPlatform")
91 platList
.appendChild(platform
)
93 fpdfilename
= man
.createElement("FarFilename")
94 platform
.appendChild(fpdfilename
)
96 fpdfilename
.appendChild( man
.createTextNode(infile
) )
101 for f
in set(filelist
):
102 zip.write(inWorkspace(f
), f
)
103 zip.writestr("FrameworkArchiveManifest.xml", man
.toprettyxml(2*" "))
107 # This acts like the main() function for the script, unless it is 'import'ed
108 # into another script.
109 if __name__
== '__main__':
111 # Create a pretty printer for dumping data structures in a readable form.
112 # pp = pprint.PrettyPrinter(indent=2)
114 # Default name for far file.
115 farName
= "output.far"
117 # Process the command line args.
118 optlist
, args
= getopt
.getopt(sys
.argv
[1:], 'hf:', [ 'far=', 'help'])
121 if o
in ["-h", "--help"]:
123 Pass a list of .spd and .fpd files to be placed into a far for distribution.
124 You may give the name of the far with a -f or --far option. For example:
126 %s --far library.far MdePkg/MdePkg.spd
128 The file paths of .spd and .fpd are relative to the WORKSPACE envirnonment
129 which must be set to a valid workspace root directory.
130 """ % os
.path
.basename(sys
.argv
[0])
133 if o
in ["-f", "--far"]:
136 makeFar(args
, farName
)