Distinguish PEIM entrypoint and driver entrypoint
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / MsaWriter.java
CommitLineData
b0282412 1/** @file\r
2 \r
3 Copyright (c) 2006, Intel Corporation\r
4 All rights reserved. This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8 \r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11 \r
12 **/\r
0dc8c589 13package org.tianocore.migration;\r
14\r
15import java.io.*;\r
16import java.util.*;\r
17\r
18import org.tianocore.*;\r
19import org.tianocore.SupportedArchitectures.Enum;\r
20import org.apache.xmlbeans.*;\r
21\r
22public class MsaWriter {\r
27e0221a 23 MsaWriter(ModuleInfo moduleinfo) {\r
24 mi = moduleinfo;\r
25 }\r
0dc8c589 26\r
27e0221a 27 private ModuleInfo mi;\r
28 \r
29 private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();\r
30 \r
31 private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.addNewModuleSurfaceArea();\r
32 private MsaHeaderDocument.MsaHeader msaheader = msa.addNewMsaHeader();\r
33 private ModuleDefinitionsDocument.ModuleDefinitions md = msa.addNewModuleDefinitions();\r
34 private SourceFilesDocument.SourceFiles sourcefiles = msa.addNewSourceFiles(); //found local .h files are not written\r
35 private GuidsDocument.Guids guids;\r
36 private ProtocolsDocument.Protocols protocols;\r
37 private PPIsDocument.PPIs ppis;\r
38 private PackageDependenciesDocument.PackageDependencies pd = msa.addNewPackageDependencies();\r
39 private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = msa.addNewLibraryClassDefinitions();\r
40 private ExternsDocument.Externs externs = msa.addNewExterns();\r
41 \r
42 private String Query (String requirement) throws Exception {\r
43 String answer;\r
44 BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));\r
45 System.out.println(requirement);\r
46 while ((answer = rd.readLine()).length() == 0) ;\r
47 return answer;\r
48 }\r
49 \r
50 private void addSourceFiles (String name) { // furthur modification needed\r
51 List<Enum> arch = new ArrayList<Enum>();\r
52 FilenameDocument.Filename filename;\r
53 filename = sourcefiles.addNewFilename();\r
54 filename.setStringValue(name);\r
55 \r
56 if (name.contains("x64" + File.separator)) { // filename ???\r
57 arch.add(SupportedArchitectures.X_64);\r
58 System.out.println("x64" + File.separator);\r
59 filename.setSupArchList(arch);\r
60 } else if (name.contains("Ia32" + File.separator)) { // filename ???\r
61 arch.add(SupportedArchitectures.IA_32);\r
62 System.out.println("Ia32" + File.separator);\r
63 filename.setSupArchList(arch);\r
64 } else if (name.contains("Ipf" + File.separator)) { // filename ???\r
65 arch.add(SupportedArchitectures.IPF);\r
66 System.out.println("Ipf" + File.separator);\r
67 filename.setSupArchList(arch);\r
68 } else if (name.contains("Ebc" + File.separator)) { // filename ???\r
69 arch.add(SupportedArchitectures.EBC);\r
70 System.out.println("Ebc" + File.separator);\r
71 filename.setSupArchList(arch);\r
72 }\r
73 }\r
74 \r
75 private ModuleSurfaceAreaDocument fulfillMsadoc() throws Exception {\r
76 Iterator<String> it;\r
77 String temp;\r
78 \r
79 if (mi.modulename != null) {\r
80 msaheader.setModuleName(mi.modulename);\r
81 } else {\r
82 msaheader.setModuleName(mi.modulename = Query("Module Name Not Found! Please Input ModuleName"));\r
83 }\r
84 if (mi.guidvalue == null) {\r
85 mi.guidvalue = UUID.randomUUID().toString();\r
86 MigrationTool.ui.println ("Guid value can not be retrieved from inf file. Generate " + mi.guidvalue + " at random!"); \r
87 } \r
88 msaheader.setGuidValue(mi.guidvalue);\r
89 if (mi.moduletype != null) {\r
90 msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.getModuleType()));\r
27e0221a 91 } else {\r
92 msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.moduletype = Query("Guid Value Not Found! Please Input Guid Value")));\r
93 }\r
fb840aa8 94\r
27e0221a 95 msaheader.setCopyright("Copyright (c) 2006, Intel Corporation");\r
96 msaheader.setVersion("1.0");\r
97 msaheader.setAbstract("Component name for module " + mi.modulename);\r
98 msaheader.setDescription("FIX ME!");\r
99 msaheader.addNewLicense().setStringValue("All rights reserved.\n" +\r
100 " This software and associated documentation (if any) is furnished\n" +\r
101 " under a license and may only be used or copied in accordance\n" +\r
102 " with the terms of the license. Except as permitted by such\n" +\r
103 " license, no part of this software or documentation may be\n" +\r
104 " reproduced, stored in a retrieval system, or transmitted in any\n" +\r
105 " form or by any means without the express written consent of\n" +\r
106 " Intel Corporation.");\r
107 msaheader.setSpecification("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");\r
108 \r
109 List<Enum> arch = new ArrayList<Enum>();\r
110 arch.add(SupportedArchitectures.IA_32);\r
111 arch.add(SupportedArchitectures.X_64);\r
112 arch.add(SupportedArchitectures.IPF);\r
113 arch.add(SupportedArchitectures.EBC);\r
114 md.setSupportedArchitectures(arch);\r
115 md.setBinaryModule(false);\r
116 md.setOutputFileBasename(mi.modulename);\r
117 \r
118 pd.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");\r
77dd49a7 119 pd.addNewPackage().setPackageGuid("68169ab0-d41b-4009-9060-292c253ac43d");\r
27e0221a 120 externs.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");\r
121 externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");\r
37e5cd65 122 if (mi.entrypoint != null) {\r
123 externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);\r
124 org.tianocore.ModuleTypeDef.Enum moduleType = msaheader.getModuleType();\r
125 if (moduleType == ModuleTypeDef.PEIM) {\r
126 mi.hashrequiredr9libs.add("PeimEntryPoint");\r
127 } else {\r
128 mi.hashrequiredr9libs.add("UefiDriverEntryPoint");\r
129 }\r
130 }\r
131 \r
27e0221a 132 it = mi.localmodulesources.iterator();\r
133 while (it.hasNext()) {\r
134 addSourceFiles(it.next());\r
135 }\r
136 if (!mi.protocol.isEmpty()) {\r
137 protocols = msa.addNewProtocols();\r
138 it = mi.protocol.iterator();\r
139 while (it.hasNext()) {\r
140 if ((temp = it.next()) != null) {\r
141 ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();\r
142 pr.setProtocolCName(temp);\r
143 pr.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
144 }\r
145 }\r
146 }\r
147 if (!mi.ppi.isEmpty()) {\r
148 ppis = msa.addNewPPIs();\r
149 it = mi.ppi.iterator();\r
150 while (it.hasNext()) {\r
151 if ((temp = it.next()) != null) {\r
152 PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();\r
153 pp.setPpiCName(temp);\r
154 pp.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
155 }\r
156 }\r
157 }\r
158 if (!mi.guid.isEmpty()) {\r
159 guids = msa.addNewGuids();\r
160 it = mi.guid.iterator();\r
161 while (it.hasNext()) {\r
162 if ((temp = it.next()) != null) {\r
163 GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();\r
164 gcn.setGuidCName(temp);\r
165 gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
166 }\r
167 }\r
168 }\r
169 it = mi.hashrequiredr9libs.iterator();\r
170 while (it.hasNext()) {\r
171 if ((temp = it.next()) != null && !temp.matches("%")) {\r
172 LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();\r
173 lc.setKeyword(temp);\r
174 lc.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
175 }\r
176 }\r
177 \r
178 return msadoc;\r
179 }\r
180 \r
181 public void flush() throws Exception {\r
0dc8c589 182 XmlOptions options = new XmlOptions();\r
183\r
184 options.setCharacterEncoding("UTF-8");\r
185 options.setSavePrettyPrint();\r
186 options.setSavePrettyPrintIndent(2);\r
187 options.setUseDefaultNamespace();\r
188 \r
27e0221a 189 BufferedWriter bw = new BufferedWriter(new FileWriter(MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + mi.modulename + ".msa"));\r
190 fulfillMsadoc().save(bw, options);\r
191 //MsaTreeEditor.init(mi, ui, msadoc);\r
192 bw.flush();\r
193 bw.close();\r
194 }\r
6f55be9f 195\r
27e0221a 196 private static void flush(String path, ModuleSurfaceAreaDocument msadoc) throws Exception {\r
6f55be9f 197 XmlOptions options = new XmlOptions();\r
198\r
199 options.setCharacterEncoding("UTF-8");\r
200 options.setSavePrettyPrint();\r
201 options.setSavePrettyPrintIndent(2);\r
202 options.setUseDefaultNamespace();\r
203\r
27e0221a 204 BufferedWriter bw = new BufferedWriter(new FileWriter(path));\r
205 msadoc.save(bw, options);\r
206 bw.flush();\r
207 bw.close();\r
208 }\r
209 \r
210 public static final void parse(String msafile) throws Exception {\r
211 ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(msafile);\r
212 flush("c:\\temp.msa", msadoc);\r
213 }\r
0dc8c589 214}\r