]>
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
):
28 spdDir
= os
.path
.dirname(spdFile
)
30 spd
= xml
.dom
.minidom
.parse(inWorkspace(spdFile
))
33 "/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass/IncludeHeader",
34 "/PackageSurfaceArea/IndustryStdIncludes/IndustryStdHeader/IncludeHeader",
35 "/PackageSurfaceArea/PackageHeaders/IncludePkgHeader" ]
37 for xmlPath
in xmlPaths
:
38 for f
in XmlList(spd
, xmlPath
):
39 filelist
.append(str(os
.path
.join(spdDir
, XmlElementData(f
))))
41 for f
in XmlList(spd
, "/PackageSurfaceArea/MsaFiles/Filename"):
42 msaFile
= str(os
.path
.join(spdDir
, XmlElementData(f
)))
43 filelist
+= parseMsa(msaFile
, spdDir
)
47 def makeFar(filelist
, farname
):
49 domImpl
= xml
.dom
.minidom
.getDOMImplementation()
50 man
= domImpl
.createDocument(None, "FrameworkArchiveManifest", None)
51 top_element
= man
.documentElement
53 header
= man
.createElement("FarHeader")
54 top_element
.appendChild(header
)
56 packList
= man
.createElement("FarPackageList")
57 top_element
.appendChild(packList
)
59 platList
= man
.createElement("FarPlatformList")
60 top_element
.appendChild(platList
)
62 contents
= man
.createElement("Contents")
63 top_element
.appendChild(contents
)
65 zip = zipfile
.ZipFile(farname
, "w")
66 for infile
in filelist
:
67 if not os
.path
.exists(inWorkspace(infile
)):
68 print "Skipping non-existent file '%s'." % infile
69 (_
, extension
) = os
.path
.splitext(infile
)
70 if extension
== ".spd":
71 filelist
= parseSpd(infile
)
73 package
= man
.createElement("FarPackage")
74 packList
.appendChild(package
)
76 spdfilename
= man
.createElement("FarFilename")
77 package
.appendChild(spdfilename
)
79 spdfilename
.appendChild( man
.createTextNode(infile
) )
80 zip.write(inWorkspace(infile
), infile
)
82 for spdfile
in filelist
:
83 content
= man
.createElement("FarFilename")
84 content
.appendChild( man
.createTextNode(spdfile
))
85 contents
.appendChild(content
)
86 zip.write(inWorkspace(spdfile
), spdfile
)
88 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
) )
97 zip.write(inWorkspace(infile
), infile
)
100 print "Skipping file '%s' since is is not a .spd or .fpd." % infile
102 zip.writestr("FrameworkArchiveManifest.xml", man
.toprettyxml(2*" "))
106 # This acts like the main() function for the script, unless it is 'import'ed
107 # into another script.
108 if __name__
== '__main__':
110 # Create a pretty printer for dumping data structures in a readable form.
111 # pp = pprint.PrettyPrinter(indent=2)
113 # Default name for far file.
114 farName
= "output.far"
116 # Process the command line args.
117 optlist
, args
= getopt
.getopt(sys
.argv
[1:], 'hf:', [ 'far=', 'help'])
120 if o
in ["-h", "--help"]:
122 Pass a list of .spd and .fpd files to be placed into a far for distribution.
123 You may give the name of the far with a -f or --far option. For example:
125 %s --far library.far MdePkg/MdePkg.spd
127 The file paths of .spd and .fpd are relative to the WORKSPACE envirnonment
128 which must be set to a valid workspace root directory.
129 """ % os
.path
.basename(sys
.argv
[0])
132 if o
in ["-f", "--far"]:
135 makeFar(args
, farName
)