]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Python/MkFar.py
Start to build the manifest.
[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
26 filelist = [spdFile]
27 msaFileList = []
28
29 spdDir = os.path.dirname(spdFile)
30
31 spd = xml.dom.minidom.parse(inWorkspace(spdFile))
32
33 xmlPaths = [
34 "/PackageSurfaceArea/LibraryClassDeclarations/LibraryClass/IncludeHeader",
35 "/PackageSurfaceArea/IndustryStdIncludes/IndustryStdHeader/IncludeHeader",
36 "/PackageSurfaceArea/<PackageHeaders/IncludePkgHeader" ]
37
38 for xmlPath in xmlPaths:
39 for f in XmlList(spd, xmlPath):
40 filelist.append(str(os.path.join(spdDir, XmlElementData(f))))
41
42 for xmlPath in ["/PackageSurfaceArea/MsaFiles/Filename"]:
43 for f in XmlList(spd, xmlPath):
44 msaFile = str(os.path.join(spdDir, XmlElementData(f)))
e853a9d4 45 filelist += parseMsa(msaFile, spdDir)
46
47 return filelist
48
49def makeFar(filelist, farname):
50
51 man = \
52"""<?xml version="1.0" encoding="UTF-8"?>
53<FrameworkArchiveManifest>
54</FrameworkArchiveManifest>
55"""
69932b41 56
57 domImpl = xml.dom.minidom.getDOMImplementation()
58 man = domImpl.createDocument(None, "FrameworkArchiveManifest", None)
59 top_element = man.documentElement
60
61 header = man.createElement("FarHeader")
62 top_element.appendChild(header)
63
64 packList = man.createElement("FarPackageList")
65 top_element.appendChild(packList)
66
67 platList = man.createElement("FarPlatformList")
68 top_element.appendChild(platList)
69
70 contents = man.createElement("Contents")
71 top_element.appendChild(contents)
72
e853a9d4 73 zip = zipfile.ZipFile(farname, "w")
74 for file in args:
75 if not os.path.exists(inWorkspace(file)):
76 print "Skipping non-existent file '%s'." % file
77 (_, extension) = os.path.splitext(file)
78 if extension == ".spd":
79 filelist = parseSpd(file)
69932b41 80
81 for file in filelist:
82
83 package = man.createElement("FarPackage")
84 packList.appendChild(package)
85
86 spdfilename = man.createElement("FarFileName")
87 package.appendChild(spdfilename)
88
89 spdfilename.appendChild( man.createTextNode(file) )
90
e853a9d4 91 elif extension == ".fpd":
92 filelist = [file]
93 else:
94 filelist = []
95 for f in set(filelist):
96 zip.write(inWorkspace(f), f)
69932b41 97 zip.writestr("FrameworkArchiveManifest.xml", man.toprettyxml(" "))
e853a9d4 98 zip.close()
99 return
100
101# This acts like the main() function for the script, unless it is 'import'ed into another
102# script.
103if __name__ == '__main__':
104
105 # Create a pretty printer for dumping data structures in a readable form.
106 # pp = pprint.PrettyPrinter(indent=2)
107
108 # Process the command line args.
109 optlist, args = getopt.getopt(sys.argv[1:], 'h', [ 'example-long-arg=', 'testing'])
110
111 makeFar(args, "test.far")