X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FMigrationTools%2Forg%2Ftianocore%2Fmigration%2FModuleInfo.java;h=2f3af0309e9c16b8fda479de182c0eab1d5bfec2;hp=b238551cac84ca18dc6e7af3094358c61bb515a1;hb=d1d10647bfa04dc45c5b19272deabbfe1bb9da95;hpb=719cebfea79fc6a8cdf06e1694a6596b4db69d1b diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java b/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java index b238551cac..2f3af0309e 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java @@ -21,16 +21,24 @@ import java.util.regex.*; information and all the temporary data. */ public class ModuleInfo { - ModuleInfo(String modulepath, UI ui, Database db) throws Exception { + ModuleInfo(String modulepath) throws Exception { this.modulepath = modulepath; - this.ui = ui; - this.db = db; + + ui.println("Choose where to place the result"); + if ((outputpath = ui.getFilepath()) == null) { + outputpath = modulepath; + } + ui.println(outputpath); + moduleScan(); } + + public static UI ui = null; //if MIM is still usefull, this can be given to it + public static Database db = null; //if MIM is still usefull, this can be given to it - private String modulepath = null; - private Database db = null; - private UI ui = null; + public String modulepath = null; + + public String outputpath = null; public String modulename = null; public String guidvalue = null; @@ -39,6 +47,7 @@ public class ModuleInfo { public Set localmodulesources = new HashSet(); //contains both .c and .h public Set preprocessedccodes = new HashSet(); + public Set msaorinf = new HashSet(); //only a little, hash may be too big for this public Set hashfuncc = new HashSet(); public Set hashfuncd = new HashSet(); @@ -55,55 +64,26 @@ public class ModuleInfo { private static String migrationcomment = "//%$//"; private void moduleScan() throws Exception { - String[] list = new File(modulepath).list(); - boolean hasInf = false; - String infname = null; - boolean hasMsa = false; - String msaname = null; - - for (int i = 0 ; i < list.length ; i++) { - if (new File(list[i]).isDirectory()) { - ; - } else { - if (list[i].contains(".c") || list[i].contains(".C")) { - localmodulesources.add(list[i]); - } else if (list[i].contains(".h") || list[i].contains(".H")) { - localmodulesources.add(list[i]); //the case that several .inf or .msa found is not concerned - } else if (list[i].contains(".dxs")) { - localmodulesources.add(list[i]); - } else if (list[i].contains(".uni")) { - localmodulesources.add(list[i]); - } else if (list[i].contains(".inf")) { - if (ui.yesOrNo("Found .inf file : " + list[i] + "\nDo you want to use this file as this module's .inf?")) { - hasInf = true; - infname = list[i]; - } else { - continue; - } - } else if (list[i].contains(".msa")) { - if (ui.yesOrNo("Found .msa file : " + list[i] + "\nDo you want to use this file as this module's .msa?")) { - hasMsa = true; - msaname = list[i]; - } else { - continue; - } - } - } - } + Common.toDoAll(modulepath, ModuleInfo.class.getMethod("enroll", String.class), this, null, Common.FILE); - ModuleReader mr = new ModuleReader(modulepath, this, db); - if (hasInf) { // this sequence shows using .inf as default - mr.readInf(infname); - } else if (hasMsa) { - mr.readMsa(msaname); - } else { + String filename = null; + if (msaorinf.isEmpty()) { ui.println("No INF nor MSA file found!"); + System.exit(0); + } else { + filename = ui.choose("Found .inf or .msa file for module\n" + modulepath + "\nChoose one Please", msaorinf.toArray()); + } + //ModuleReader mr = new ModuleReader(modulepath, this, db, ui); + if (filename.contains(".inf")) { + ModuleReader.readInf(filename, this); + } else if (filename.contains(".msa")) { + ModuleReader.readMsa(filename, this); } CommentOutNonLocalHFile(); parsePreProcessedSourceCode(); - - new SourceFileReplacer(modulepath, this, db, ui).flush(); // some adding library actions are taken here,so it must be put before "MsaWriter" + + new SourceFileReplacer(modulepath, outputpath, this, db, ui).flush(); // some adding library actions are taken here,so it must be put before "MsaWriter" // show result if (ui.yesOrNo("Parse of the Module Information has completed. View details?")) { @@ -120,12 +100,10 @@ public class ModuleInfo { show(hashr8only, "hashr8only : "); } - new MsaWriter(modulepath, this, db).flush(); - - // remove temp directory - //File tempdir = new File(modulepath + File.separator + "temp"); - //System.out.println("Deleting Dir"); - //if (tempdir.exists()) tempdir.d; + new MsaWriter(modulepath, outputpath, this, db, ui).flush(); + + Common.deleteDir(modulepath + File.separator + "temp"); + //Common.toDoAll(modulepath + File.separator + "temp", Common.class.getMethod("deleteDir", String.class), null, null, Common.DIR); ui.println("Errors Left : " + db.error); ui.println("Complete!"); @@ -137,7 +115,7 @@ public class ModuleInfo { ui.println(show + hash.size()); ui.println(hash); } - + // add '//' to all non-local include lines private void CommentOutNonLocalHFile() throws IOException { BufferedReader rd; @@ -146,20 +124,18 @@ public class ModuleInfo { PrintWriter outfile; Pattern ptninclude = Pattern.compile("[\"<](.*[.]h)[\">]"); - Matcher mtcinclude; - - File tempdir = new File(modulepath + File.separator + "temp" + File.separator); - if (!tempdir.exists()) tempdir.mkdir(); - + Matcher mtrinclude; + Iterator ii = localmodulesources.iterator(); while ( ii.hasNext() ) { curFile = ii.next(); rd = new BufferedReader(new FileReader(modulepath + File.separator + curFile)); + Common.ensureDir(modulepath + File.separator + "temp" + File.separator + curFile); outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "temp" + File.separator + curFile))); while ((line = rd.readLine()) != null) { if (line.contains("#include")) { - mtcinclude = ptninclude.matcher(line); - if (mtcinclude.find() && localmodulesources.contains(mtcinclude.group(1))) { + mtrinclude = ptninclude.matcher(line); + if (mtrinclude.find() && localmodulesources.contains(mtrinclude.group(1))) { } else { line = migrationcomment + line; } @@ -170,15 +146,7 @@ public class ModuleInfo { outfile.close(); } } - /* - private void search(String line, Pattern ptn, Method md) { - matmacro = Func.ptntmacro.matcher(line); - while (matmacro.find()) { - if ((temp = Func.registerMacro(matmacro, this, db)) != null) { - } - } - } - */ + private void parsePreProcessedSourceCode() throws Exception { //Cl cl = new Cl(modulepath); //cl.execute("Fat.c"); @@ -187,19 +155,20 @@ public class ModuleInfo { //System.out.println("Note!!!! The CL is not implemented now , pls do it manually!!! RUN :"); //System.out.println("cl " + modulepath + "\\temp\\*.c" + " -P"); //String[] list = new File(modulepath + File.separator + "temp").list(); // without CL , add - String[] list = new File(modulepath).list(); - for (int i = 0 ; i < list.length ; i++) { - if (list[i].contains(".c")) { // without CL , change to .i - preprocessedccodes.add(list[i]); - } - } - // - Iterator ii = preprocessedccodes.iterator(); BufferedReader rd = null; String ifile = null; String line = null; String temp = null; - //StringBuffer result = new StringBuffer(); + + Iterator ii = localmodulesources.iterator(); + while (ii.hasNext()) { + temp = ii.next(); + if (temp.contains(".c")) { + preprocessedccodes.add(temp); + } + } + + ii = preprocessedccodes.iterator(); Pattern patefifuncc = Pattern.compile("g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)",Pattern.MULTILINE); Pattern patentrypoint = Pattern.compile("EFI_([A-Z]*)_ENTRY_POINT\\s*\\(([^\\(\\)]*)\\)",Pattern.MULTILINE); @@ -234,7 +203,7 @@ public class ModuleInfo { // find guid matguid = Guid.ptnguid.matcher(line); // several ways to implement this , which one is faster ? : while (matguid.find()) { // 1.currently , find once , then call to identify which is it - if ((temp = Guid.register(matguid, this, db)) != null) { // 2.use 3 different matchers , search 3 times to find each + if ((temp = Guid.register(matguid, this, db)) != null) { // 2.use 3 different matchers , search 3 times to find each //matguid.appendReplacement(result, db.getR9Guidname(temp)); // search the database for all 3 kinds of guids , high cost } } @@ -288,7 +257,40 @@ public class ModuleInfo { } } - public static void main(String[] args) throws Exception { - FirstPanel.init(); + public final void enroll(String filepath) throws Exception { + String[] temp; + if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") || + filepath.contains(".H") || filepath.contains(".dxs") || filepath.contains(".uni")) { + temp = filepath.split("\\\\"); + localmodulesources.add(temp[temp.length - 1]); + } else if (filepath.contains(".inf") || filepath.contains(".msa")) { + temp = filepath.split("\\\\"); + msaorinf.add(temp[temp.length - 1]); + } + } + + public static final void seekModule(String filepath) throws Exception { + if (isModule(filepath)) { + //System.out.println("I'm in"); + new ModuleInfo(filepath); + } } -} + + private static final boolean isModule(String path) { + String[] list = new File(path).list(); + for (int i = 0 ; i < list.length ; i++) { + if (!new File(list[i]).isDirectory()) { + if (list[i].contains(".inf") || list[i].contains(".msa")) { + return true; + } + } + } + return false; + } +/* + public static final void main(String[] args) throws Exception { + ui = FirstPanel.init(); + db = new Database(); + } + */ +} \ No newline at end of file