]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Python/MkFar.py
Update APP flag for VS2003, VS2005PRO and WINDDK toolchain.
[mirror_edk2.git] / Tools / Python / MkFar.py
... / ...
CommitLineData
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
9 filelist = [msaFile]
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
26 filelist = []
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",
35 "/PackageSurfaceArea/PackageHeaders/IncludePkgHeader" ]
36
37 for xmlPath in xmlPaths:
38 for f in XmlList(spd, xmlPath):
39 filelist.append(str(os.path.join(spdDir, XmlElementData(f))))
40
41 for f in XmlList(spd, "/PackageSurfaceArea/MsaFiles/Filename"):
42 msaFile = str(os.path.join(spdDir, XmlElementData(f)))
43 filelist += parseMsa(msaFile, spdDir)
44
45 return filelist
46
47def makeFar(filelist, farname):
48
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)
55
56 packList = man.createElement("FarPackageList")
57 top_element.appendChild(packList)
58
59 platList = man.createElement("FarPlatformList")
60 top_element.appendChild(platList)
61
62 contents = man.createElement("Contents")
63 top_element.appendChild(contents)
64
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)
72
73 package = man.createElement("FarPackage")
74 packList.appendChild(package)
75
76 spdfilename = man.createElement("FarFilename")
77 package.appendChild(spdfilename)
78
79 spdfilename.appendChild( man.createTextNode(infile) )
80 zip.write(inWorkspace(infile), infile)
81
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)
87
88 elif extension == ".fpd":
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) )
97 zip.write(inWorkspace(infile), infile)
98
99 else:
100 print "Skipping file '%s' since is is not a .spd or .fpd." % infile
101
102 zip.writestr("FrameworkArchiveManifest.xml", man.toprettyxml(2*" "))
103 zip.close()
104 return
105
106# This acts like the main() function for the script, unless it is 'import'ed
107# into another script.
108if __name__ == '__main__':
109
110 # Create a pretty printer for dumping data structures in a readable form.
111 # pp = pprint.PrettyPrinter(indent=2)
112
113 # Default name for far file.
114 farName = "output.far"
115
116 # Process the command line args.
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
134
135 makeFar(args, farName)