Update APP flag for VS2003, VS2005PRO and WINDDK toolchain.
[mirror_edk2.git] / Tools / Python / MkFar.py
CommitLineData
e853a9d4 1#!/usr/bin/env python
2
3import os, sys, re, getopt, string, glob, xml.dom.minidom, pprint, zipfile, tempfile
4from XmlRoutines import *
5from WorkspaceRoutines import *
6
7def parseMsa(msaFile, spdDir):
8
69932b41 9 filelist = [msaFile]
e853a9d4 10
11 msaDir = os.path.dirname(msaFile)
12
13 msa = xml.dom.minidom.parse(inWorkspace(msaFile))
14
15 xmlPaths = [
16 "/ModuleSurfaceArea/SourceFiles/Filename" ]
17
18 for xmlPath in xmlPaths:
19 for f in XmlList(msa, xmlPath):
20 filelist.append(str(os.path.join(msaDir, XmlElementData(f))))
21
22 return filelist
23
24def parseSpd(spdFile):
25
3ff56e5e 26 filelist = []
e853a9d4 27
28 spdDir = os.path.dirname(spdFile)
29
30 spd = xml.dom.minidom.parse(inWorkspace(spdFile))
31
32 xmlPaths = [
33 "/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass/IncludeHeader",
34 "/PackageSurfaceArea/IndustryStdIncludes/IndustryStdHeader/IncludeHeader",
3ff56e5e 35 "/PackageSurfaceArea/PackageHeaders/IncludePkgHeader" ]
e853a9d4 36
37 for xmlPath in xmlPaths:
38 for f in XmlList(spd, xmlPath):
39 filelist.append(str(os.path.join(spdDir, XmlElementData(f))))
40
d32aaa95 41 for f in XmlList(spd, "/PackageSurfaceArea/MsaFiles/Filename"):
42 msaFile = str(os.path.join(spdDir, XmlElementData(f)))
43 filelist += parseMsa(msaFile, spdDir)
e853a9d4 44
45 return filelist
46
47def makeFar(filelist, farname):
48
69932b41 49 domImpl = xml.dom.minidom.getDOMImplementation()
50 man = domImpl.createDocument(None, "FrameworkArchiveManifest", None)
51 top_element = man.documentElement
52
53 header = man.createElement("FarHeader")
54 top_element.appendChild(header)
d32aaa95 55
69932b41 56 packList = man.createElement("FarPackageList")
57 top_element.appendChild(packList)
d32aaa95 58
69932b41 59 platList = man.createElement("FarPlatformList")
60 top_element.appendChild(platList)
d32aaa95 61
69932b41 62 contents = man.createElement("Contents")
63 top_element.appendChild(contents)
d32aaa95 64
e853a9d4 65 zip = zipfile.ZipFile(farname, "w")
d32aaa95 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)
e853a9d4 70 if extension == ".spd":
d32aaa95 71 filelist = parseSpd(infile)
69932b41 72
d32aaa95 73 package = man.createElement("FarPackage")
74 packList.appendChild(package)
69932b41 75
d32aaa95 76 spdfilename = man.createElement("FarFilename")
77 package.appendChild(spdfilename)
69932b41 78
d32aaa95 79 spdfilename.appendChild( man.createTextNode(infile) )
3ff56e5e 80 zip.write(inWorkspace(infile), infile)
d32aaa95 81
82 for spdfile in filelist:
83 content = man.createElement("FarFilename")
84 content.appendChild( man.createTextNode(spdfile))
85 contents.appendChild(content)
3ff56e5e 86 zip.write(inWorkspace(spdfile), spdfile)
69932b41 87
e853a9d4 88 elif extension == ".fpd":
d32aaa95 89
90 platform = man.createElement("FarPlatform")
91 platList.appendChild(platform)
92
93 fpdfilename = man.createElement("FarFilename")
94 platform.appendChild(fpdfilename)
95
96 fpdfilename.appendChild( man.createTextNode(infile) )
3ff56e5e 97 zip.write(inWorkspace(infile), infile)
d32aaa95 98
e853a9d4 99 else:
3ff56e5e 100 print "Skipping file '%s' since is is not a .spd or .fpd." % infile
d32aaa95 101
d0f7ef3e 102 zip.writestr("FrameworkArchiveManifest.xml", man.toprettyxml(2*" "))
e853a9d4 103 zip.close()
104 return
105
d0f7ef3e 106# This acts like the main() function for the script, unless it is 'import'ed
107# into another script.
e853a9d4 108if __name__ == '__main__':
109
110 # Create a pretty printer for dumping data structures in a readable form.
111 # pp = pprint.PrettyPrinter(indent=2)
112
d0f7ef3e 113 # Default name for far file.
114 farName = "output.far"
115
e853a9d4 116 # Process the command line args.
d0f7ef3e 117 optlist, args = getopt.getopt(sys.argv[1:], 'hf:', [ 'far=', 'help'])
118
119 for o, a in optlist:
120 if o in ["-h", "--help"]:
121 print """
122Pass a list of .spd and .fpd files to be placed into a far for distribution.
123You may give the name of the far with a -f or --far option. For example:
124
125 %s --far library.far MdePkg/MdePkg.spd
126
127The file paths of .spd and .fpd are relative to the WORKSPACE envirnonment
128which must be set to a valid workspace root directory.
129""" % os.path.basename(sys.argv[0])
130
131 sys.exit()
132 if o in ["-f", "--far"]:
133 farName = a
e853a9d4 134
d0f7ef3e 135 makeFar(args, farName)