]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java
9e58ed914ae3e3bafabfcab6e18808d092ce2e13
[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 ModuleInfo.ui.println("Choose where to place the result");
27 if ((outputpath = ModuleInfo.ui.getFilepath()) == null) {
28 outputpath = modulepath;
29 }
30 ModuleInfo.ui.println(outputpath);
31 }
32
33 public String modulepath = null;
34
35 public String outputpath = null;
36
37 public String modulename = null;
38 public String guidvalue = null;
39 public String moduletype = null;
40 public String entrypoint = null;
41
42 public Set<String> localmodulesources = new HashSet<String>(); //contains both .c and .h
43 public Set<String> preprocessedccodes = new HashSet<String>();
44 public Set<String> msaorinf = new HashSet<String>(); //only a little, hash may be too big for this
45
46 public Set<String> hashfuncc = new HashSet<String>();
47 public Set<String> hashfuncd = new HashSet<String>();
48 public Set<String> hashnonlocalfunc = new HashSet<String>();
49 public Set<String> hashnonlocalmacro = new HashSet<String>();
50 public Set<String> hashEFIcall = new HashSet<String>();
51 public Set<String> hashr8only = new HashSet<String>();
52
53 public Set<String> hashrequiredr9libs = new HashSet<String>(); // hashrequiredr9libs is now all added in SourceFileReplacer
54 public Set<String> guid = new HashSet<String>();
55 public Set<String> protocol = new HashSet<String>();
56 public Set<String> ppi = new HashSet<String>();
57
58 public final void enroll(String filepath) throws Exception {
59 String[] temp;
60 if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") ||
61 filepath.contains(".H") || filepath.contains(".dxs") || filepath.contains(".uni")) {
62 temp = filepath.split("\\\\");
63 localmodulesources.add(temp[temp.length - 1]);
64 } else if (filepath.contains(".inf") || filepath.contains(".msa")) {
65 temp = filepath.split("\\\\");
66 msaorinf.add(temp[temp.length - 1]);
67 }
68 }
69
70 private static final boolean isModule(String path) {
71 String[] list = new File(path).list();
72 for (int i = 0 ; i < list.length ; i++) {
73 if (!new File(list[i]).isDirectory()) {
74 if (list[i].contains(".inf") || list[i].contains(".msa")) {
75 return true;
76 }
77 }
78 }
79 return false;
80 }
81
82 //---------------------------------------------------------------------------//
83
84 private static final void manipulate(ModuleInfo mi) throws Exception {
85
86 ModuleReader.ModuleScan(mi);
87
88 SourceFileReplacer.flush(mi); // some adding library actions are taken here,so it must be put before "MsaWriter"
89
90 // show result
91 if (ModuleInfo.printModuleInfo) {
92 ModuleInfo.ui.println("\nModule Information : ");
93 ModuleInfo.ui.println("Entrypoint : " + mi.entrypoint);
94 show(mi.protocol, "Protocol : ");
95 show(mi.ppi, "Ppi : ");
96 show(mi.guid, "Guid : ");
97 show(mi.hashfuncc, "call : ");
98 show(mi.hashfuncd, "def : ");
99 show(mi.hashEFIcall, "EFIcall : ");
100 show(mi.hashnonlocalmacro, "macro : ");
101 show(mi.hashnonlocalfunc, "nonlocal : ");
102 show(mi.hashr8only, "hashr8only : ");
103 }
104
105 new MsaWriter(mi).flush();
106
107 if (ModuleInfo.doCritic) {
108 Critic.fireAt(mi.outputpath + File.separator + "Migration_" + mi.modulename);
109 }
110
111 Common.deleteDir(mi.modulepath + File.separator + "temp");
112
113 ModuleInfo.ui.println("Errors Left : " + ModuleInfo.db.error);
114 ModuleInfo.ui.println("Complete!");
115 ModuleInfo.ui.println("Your R9 module was placed here: " + mi.modulepath + File.separator + "result");
116 ModuleInfo.ui.println("Your logfile was placed here: " + mi.modulepath);
117 }
118
119 private static final void show(Set<String> hash, String show) {
120 ModuleInfo.ui.println(show + hash.size());
121 ModuleInfo.ui.println(hash);
122 }
123
124 public static final void seekModule(String filepath) throws Exception {
125 if (ModuleInfo.isModule(filepath)) {
126 manipulate(new ModuleInfo(filepath));
127 }
128 }
129
130 public static final void triger(String path) throws Exception {
131 ModuleInfo.ui.println("Project Migration");
132 ModuleInfo.ui.println("Copyright (c) 2006, Intel Corporation");
133 Common.toDoAll(path, ModuleInfo.class.getMethod("seekModule", String.class), null, null, Common.DIR);
134 }
135
136 public static UI ui = null;
137 public static Database db = null;
138
139 public static final String migrationcomment = "//%$//";
140
141 public static boolean printModuleInfo = false;
142 public static boolean doCritic = false;
143
144 public static void main(String[] args) throws Exception {
145 ui = FirstPanel.init();
146 db = Database.init();
147 }
148 }