X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FJava%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2FFrameworkBuildTask.java;h=e240150c29c471bc42f1ce79686e42842d80f8d2;hp=440510b522dbb106969ba8a1550e57d7a73f3c73;hb=2251a3601382e62e2b947512e51560d1f73dfd05;hpb=feccee87a78e68d575dbdf44b34ca0cb5a21ea8d diff --git a/Tools/Java/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java b/Tools/Java/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java index 440510b522..e240150c29 100644 --- a/Tools/Java/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java +++ b/Tools/Java/Source/GenBuild/org/tianocore/build/FrameworkBuildTask.java @@ -13,10 +13,8 @@ **/ package org.tianocore.build; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; -import java.io.InputStreamReader; import java.util.Hashtable; import java.util.Iterator; import java.util.LinkedHashSet; @@ -57,8 +55,7 @@ import org.tianocore.common.logger.EdkLog; 4. No MSA file, and ACTIVE_PLATFORM is specified, build the active platform; 5. No MSA file, no ACTIVE_PLATFORM, and no FPD file, report error; 6. No MSA file, no ACTIVE_PLATFORM, and only one FPD file, build the platform; - 7. No MSA file, no ACTIVE_PLATFORM, and more than one FPD files, list all platform - and let user choose one. + 7. No MSA file, no ACTIVE_PLATFORM, and more than one FPD files, Report Error!

@@ -76,15 +73,13 @@ import org.tianocore.common.logger.EdkLog; **/ public class FrameworkBuildTask extends Task{ - private Set buildFiles = new LinkedHashSet(); - private Set fpdFiles = new LinkedHashSet(); private Set msaFiles = new LinkedHashSet(); - // - // This is only for none-multi-thread build to reduce overriding message - // + /// + /// This is only for none-multi-thread build to reduce overriding message + /// public static Hashtable originalProperties = new Hashtable(); String toolsDefFilename = ToolDefinitions.DEFAULT_TOOLS_DEF_FILE_PATH; @@ -115,11 +110,17 @@ public class FrameworkBuildTask extends Task{ // set Logger // GenBuildLogger logger = new GenBuildLogger(getProject()); + EdkLog.setLogLevel(EdkLog.EDK_DEBUG); EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL")); EdkLog.setLogger(logger); try { processFrameworkBuild(); + }catch (BuildException e) { + // + // Add more logic process here + // + throw new BuildException(e.getMessage()); } catch (PcdAutogenException e) { // // Add more logic process here @@ -149,32 +150,27 @@ public class FrameworkBuildTask extends Task{ } private void processFrameworkBuild() throws EdkException, GenBuildException, AutoGenException, PcdAutogenException, PlatformPcdPreprocessBuildException { - // - // Seach build.xml -> .FPD -> .MSA file - // try { // - // Gen Current Working Directory + // Get current working dir // File dummyFile = new File("."); File cwd = dummyFile.getCanonicalFile(); File[] files = cwd.listFiles(); + + // + // Scan current dir, and find out all .FPD and .MSA files + // for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { - if (files[i].getName().equalsIgnoreCase("build.xml")) { + if (files[i].getName().endsWith(ToolDefinitions.FPD_EXTENSION)) { // - // First, search build.xml, if found, ANT call it - // - buildFiles.add(files[i]); - - } else if (files[i].getName().endsWith(ToolDefinitions.FPD_EXTENSION)) { - // - // Second, search FPD file, if found, build it + // Found FPD file // fpdFiles.add(files[i]); } else if (files[i].getName().endsWith(ToolDefinitions.MSA_EXTENSION)) { // - // Third, search MSA file, if found, build it + // Found MSA file // msaFiles.add(files[i]); } @@ -187,9 +183,9 @@ public class FrameworkBuildTask extends Task{ } // - // Deal with all environment variable (Add them to properties) + // Import all system environment variables to ANT properties // - backupSystemProperties(); + importSystemEnvVariables(); // // Read target.txt file @@ -201,21 +197,20 @@ public class FrameworkBuildTask extends Task{ // File workspacePath = new File(getProject().getProperty("WORKSPACE")); getProject().setProperty("WORKSPACE_DIR", workspacePath.getPath().replaceAll("(\\\\)", "/")); - GlobalData.initInfo(dbFilename, workspacePath.getPath(), toolsDefFilename); + GlobalData.initInfo(getProject(), dbFilename, workspacePath.getPath(), toolsDefFilename); // // If find MSA file and ACTIVE_PLATFORM is set, build the module; // else fail build. // If without MSA file, and ACTIVE_PLATFORM is set, build the ACTIVE_PLATFORM. // If ACTIVE_PLATFORM is not set, and only find one FPD file, build the platform; - // If find more than one FPD files, let user select one. + // If find more than one FPD files, report error. // File buildFile = null; - if (msaFiles.size() > 1) { - throw new BuildException("Having more than one MSA file in a directory is not allowed!"); - } else if (msaFiles.size() == 1 && activePlatform == null) { - throw new BuildException("If trying to build a single module, please set ACTIVE_PLATFORM in file [" + targetFilename + "]. "); - } else if (msaFiles.size() == 1 && activePlatform != null) { + if (msaFiles.size() > 0) { + if (activePlatform == null) { + throw new BuildException("If trying to build a single module, please set ACTIVE_PLATFORM in file [" + targetFilename + "]. "); + } // // Build the single module // @@ -225,8 +220,9 @@ public class FrameworkBuildTask extends Task{ } else if (fpdFiles.size() == 1) { buildFile = fpdFiles.toArray(new File[1])[0]; } else if (fpdFiles.size() > 1) { - buildFile = intercommuniteWithUser(); + throw new BuildException("Found " + fpdFiles.size() + " FPD files in current dir. "); } + // // If there is no build files or FPD files or MSA files, stop build // @@ -281,26 +277,30 @@ public class FrameworkBuildTask extends Task{ } File tmpFile = new File(GlobalData.getWorkspacePath() + File.separatorChar + activePlatform); EdkLog.log(this, "Using the FPD file [" + tmpFile.getPath() + "] for the active platform. "); - EdkLog.log(this, "Processing the MSA file [" + buildFile.getPath() + "] ..>> "); - GenBuildTask genBuildTask = new GenBuildTask(); - genBuildTask.setSingleModuleBuild(true); - genBuildTask.setType(type); - getProject().setProperty("PLATFORM_FILE", activePlatform); - if( !multithread) { - originalProperties.put("PLATFORM_FILE", activePlatform); + + File[] moduleFiles = msaFiles.toArray(new File[msaFiles.size()]); + for (int i = 0; i < moduleFiles.length; ++i) { + EdkLog.log(this, "Processing the MSA file [" + moduleFiles[i].getPath() + "] ..>> "); + GenBuildTask genBuildTask = new GenBuildTask(); + genBuildTask.setSingleModuleBuild(true); + genBuildTask.setType(type); + getProject().setProperty("PLATFORM_FILE", activePlatform); + if( !multithread) { + originalProperties.put("PLATFORM_FILE", activePlatform); + } + genBuildTask.setProject(getProject()); + genBuildTask.setMsaFile(moduleFiles[i]); + genBuildTask.perform(); } - genBuildTask.setProject(getProject()); - genBuildTask.setMsaFile(buildFile); - genBuildTask.perform(); } } /** - Transfer system environment variables to ANT properties. If system variable + Import system environment variables to ANT properties. If system variable already exiests in ANT properties, skip it. **/ - private void backupSystemProperties() { + private void importSystemEnvVariables() { Map sysProperties = System.getenv(); Iterator iter = sysProperties.keySet().iterator(); while (iter.hasNext()) { @@ -322,54 +322,6 @@ public class FrameworkBuildTask extends Task{ } } - private File intercommuniteWithUser(){ - File file = null; - if (fpdFiles.size() > 1) { - File[] allFiles = new File[fpdFiles.size()]; - int index = 0; - Iterator iter = fpdFiles.iterator(); - while (iter.hasNext()) { - allFiles[index] = iter.next(); - index++; - } - - EdkLog.log(this, "Finding " + allFiles.length + " FPD files: "); - for (int i = 0; i < allFiles.length; i++) { - System.out.println("[" + (i + 1) + "]: " + allFiles[i].getName()); - } - - boolean flag = true; - EdkLog.log(this, "Please select one of the following FPD files to build:[1] "); - do{ - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - try { - String str = br.readLine(); - if (str.trim().length() == 0) { - file = allFiles[0]; - flag = false; - continue ; - } - int indexSelect = Integer.parseInt(str); - if (indexSelect <=0 || indexSelect > allFiles.length) { - EdkLog.log(this, "Please enter a number between [1.." + allFiles.length + "]:[1] "); - continue ; - } else { - file = allFiles[indexSelect - 1]; - flag = false; - continue ; - } - } catch (Exception e) { - EdkLog.log(this, "Please enter a valid number:[1] "); - flag = true; - } - } while (flag); - } else if (fpdFiles.size() == 1) { - file = fpdFiles.toArray(new File[1])[0]; - } - return file; - } - - public void setType(String type) { if (type.equalsIgnoreCase("clean") || type.equalsIgnoreCase("cleanall")) { this.type = type.toLowerCase(); @@ -381,7 +333,7 @@ public class FrameworkBuildTask extends Task{ private void readTargetFile() throws EdkException{ String targetFile = getProject().getProperty("WORKSPACE_DIR") + File.separatorChar + targetFilename; - String[][] targetFileInfo = ConfigReader.parse(targetFile); + String[][] targetFileInfo = ConfigReader.parse(getProject(), targetFile); // // Get ToolChain Info from target.txt @@ -426,13 +378,20 @@ public class FrameworkBuildTask extends Task{ } str = getValue(ToolDefinitions.TARGET_KEY_MAX_CONCURRENT_THREAD_NUMBER, targetFileInfo); - if (str != null ) { + // + // Need to check the # of threads iff multithread is enabled. + // + if ((multithread) && (str != null )) { try { int threadNum = Integer.parseInt(str); if (threadNum > 0) { MAX_CONCURRENT_THREAD_NUMBER = threadNum; } } catch (Exception ex) { + // + // Give a warning message, and keep the default value + // + EdkLog.log(this, EdkLog.EDK_WARNING, "Incorrent number specified for MAX_CONCURRENT_THREAD_NUMBER in file [" + targetFilename + "]"); } } }