]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java
3e4c4cbae2abb90736255a2bf46e6ed48c3b790d
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / ModuleInfo.java
1 /** @file
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 **/
13 package org.tianocore.migration;
14
15 import java.io.*;
16 import java.util.*;
17
18 /*
19 Class ModuleInfo is built for scanning the source files, it contains all the needed
20 information and all the temporary data.
21 */
22 public class ModuleInfo {
23 ModuleInfo(String modulepath) throws Exception {
24 this.modulepath = modulepath;
25
26 if (ModuleInfo.defaultoutput) {
27 this.outputpath = this.modulepath.replaceAll(Common.strseparate, "$1");
28 } else {
29 ModuleInfo.ui.println("Choose where to place the result");
30 if ((outputpath = ModuleInfo.ui.getFilepath()) == null) {
31 outputpath = modulepath;
32 }
33 ModuleInfo.ui.println("Output to: " + outputpath);
34 }
35 }
36
37 public String modulepath = null;
38
39 public String outputpath = null;
40
41 public String modulename = null;
42 public String guidvalue = null;
43 public String moduletype = null;
44 public String entrypoint = null;
45
46 public Set<String> localmodulesources = new HashSet<String>(); //contains both .c and .h
47 public Set<String> preprocessedccodes = new HashSet<String>();
48 public Set<String> msaorinf = new HashSet<String>(); //only a little, hash may be too big for this
49
50 public Set<String> hashfuncc = new HashSet<String>();
51 public Set<String> hashfuncd = new HashSet<String>();
52 public Set<String> hashnonlocalfunc = new HashSet<String>();
53 public Set<String> hashnonlocalmacro = new HashSet<String>();
54 public Set<String> hashEFIcall = new HashSet<String>();
55 public Set<String> hashr8only = new HashSet<String>();
56
57 public Set<String> hashrequiredr9libs = new HashSet<String>(); // hashrequiredr9libs is now all added in SourceFileReplacer
58 public Set<String> guid = new HashSet<String>();
59 public Set<String> protocol = new HashSet<String>();
60 public Set<String> ppi = new HashSet<String>();
61
62 public final void enroll(String filepath) throws Exception {
63 String[] temp;
64 if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") ||
65 filepath.contains(".H") || filepath.contains(".dxs") || filepath.contains(".uni")) {
66 temp = filepath.split("\\\\");
67 localmodulesources.add(temp[temp.length - 1]);
68 } else if (filepath.contains(".inf") || filepath.contains(".msa")) {
69 temp = filepath.split("\\\\");
70 msaorinf.add(temp[temp.length - 1]);
71 }
72 }
73
74 public static final boolean isModule(String path) {
75 String[] list = new File(path).list();
76 for (int i = 0 ; i < list.length ; i++) {
77 if (!new File(list[i]).isDirectory()) {
78 if (list[i].contains(".inf") || list[i].contains(".msa")) {
79 return true;
80 }
81 }
82 }
83 return false;
84 }
85
86 //---------------------------------------------------------------------------//
87
88 private static final void manipulate(ModuleInfo mi) throws Exception {
89
90 ModuleReader.ModuleScan(mi);
91
92 SourceFileReplacer.flush(mi); // some adding library actions are taken here,so it must be put before "MsaWriter"
93
94 // show result
95 if (ModuleInfo.printModuleInfo) {
96 ModuleInfo.ui.println("\nModule Information : ");
97 ModuleInfo.ui.println("Entrypoint : " + mi.entrypoint);
98 show(mi.protocol, "Protocol : ");
99 show(mi.ppi, "Ppi : ");
100 show(mi.guid, "Guid : ");
101 show(mi.hashfuncc, "call : ");
102 show(mi.hashfuncd, "def : ");
103 show(mi.hashEFIcall, "EFIcall : ");
104 show(mi.hashnonlocalmacro, "macro : ");
105 show(mi.hashnonlocalfunc, "nonlocal : ");
106 show(mi.hashr8only, "hashr8only : ");
107 }
108
109 new MsaWriter(mi).flush();
110
111 if (ModuleInfo.doCritic) {
112 Critic.fireAt(mi.outputpath + File.separator + "Migration_" + mi.modulename);
113 }
114
115 Common.deleteDir(mi.modulepath + File.separator + "temp");
116
117 ModuleInfo.ui.println("Errors Left : " + ModuleInfo.db.error);
118 ModuleInfo.ui.println("Complete!");
119 //ModuleInfo.ui.println("Your R9 module was placed here: " + mi.modulepath + File.separator + "result");
120 //ModuleInfo.ui.println("Your logfile was placed here: " + mi.modulepath);
121 }
122
123 private static final void show(Set<String> hash, String show) {
124 ModuleInfo.ui.println(show + hash.size());
125 ModuleInfo.ui.println(hash);
126 }
127
128 public static final void seekModule(String filepath) throws Exception {
129 if (ModuleInfo.isModule(filepath)) {
130 manipulate(new ModuleInfo(filepath));
131 }
132 }
133
134 public static final void triger(String path) throws Exception {
135 ModuleInfo.ui.println("Project Migration");
136 ModuleInfo.ui.println("Copyright (c) 2006, Intel Corporation");
137 Common.toDoAll(path, ModuleInfo.class.getMethod("seekModule", String.class), null, null, Common.DIR);
138 }
139
140 public static UI ui = null;
141 public static Database db = null;
142
143 public static final String migrationcomment = "//%$//";
144
145 public static boolean printModuleInfo = false;
146 public static boolean doCritic = false;
147 public static boolean defaultoutput = false;
148
149 public static void main(String[] args) throws Exception {
150 ui = FirstPanel.init();
151 db = Database.init();
152 }
153 }