X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FJava%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2Fautogen%2FAutogenLibOrder.java;h=7e87e28ba39e98bb382e842392614bef3db2df05;hp=8fb1be5cbea9cfa233210e514af164b117b4ed7a;hb=9d3d149f81a92771cffb5aacc99c324dde9847ab;hpb=d919bb8cf91225ad4df49bdf50cd37795aadc7e6 diff --git a/Tools/Java/Source/GenBuild/org/tianocore/build/autogen/AutogenLibOrder.java b/Tools/Java/Source/GenBuild/org/tianocore/build/autogen/AutogenLibOrder.java index 8fb1be5cbe..7e87e28ba3 100644 --- a/Tools/Java/Source/GenBuild/org/tianocore/build/autogen/AutogenLibOrder.java +++ b/Tools/Java/Source/GenBuild/org/tianocore/build/autogen/AutogenLibOrder.java @@ -1,15 +1,15 @@ /**@file AutogenLibOrder class. - This class is to reorder library instance sequence according to library + This class is to reorder library instance sequence according to library dependence. - + Copyright (c) 2006, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php - + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. @@ -62,12 +62,12 @@ public class AutogenLibOrder { /// String[1] is libraryConstructor name, String[2] is libDestructor name. /// private ModuleIdentification[] libInstanceList = null; - + /** Constructor function - + This function mainly initialize some member variable. - + @param libraryList List of the library instance. @throws Exception **/ @@ -81,16 +81,16 @@ public class AutogenLibOrder { libInstance = libraryList[i]; // // Fetch the constructor & destructor. - // + // Map libDoc = GlobalData.getDoc(libInstance, arch); SurfaceAreaQuery saq = new SurfaceAreaQuery(libDoc); libInstance.setConstructor(saq.getLibConstructorName()); libInstance.setDestructor(saq.getLibDestructorName()); - + // // Create library class consume database. // - libClassConsmList = saq.getLibraryClasses(CommonDefinition.ALWAYSCONSUMED, arch); + libClassConsmList = saq.getLibraryClasses(CommonDefinition.ALWAYSCONSUMED, arch, null); if (libClassConsmList != null) { if (this.libInstanceConsumes.containsKey(libInstance)) { throw new AutoGenException( @@ -104,7 +104,7 @@ public class AutogenLibOrder { // // Create library class implementer database // - libClassDeclList = saq.getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, arch); + libClassDeclList = saq.getLibraryClasses(CommonDefinition.ALWAYSPRODUCED, arch, null); if (libClassDeclList != null) { this.libInstanceProduces.put(libInstance, libClassDeclList); for (int j = 0; j < libClassDeclList.length; j++) { @@ -122,8 +122,8 @@ public class AutogenLibOrder { } // - // Create a consumed-by database - // + // Create a consumed-by database + // for (Iterator it = libClassProducer.keySet().iterator(); it.hasNext();) { String className = (String)it.next(); libInstance = libClassProducer.get(className); @@ -145,7 +145,7 @@ public class AutogenLibOrder { /** orderLibInstance - This function reorder the library instance according the library class + This function reorder the library instance according the library class dependency, using DAG anaylysis algothim @return List which content the ordered library instance. @@ -156,7 +156,7 @@ public class AutogenLibOrder { // // First, add the library instance without consumers to the Q - // + // for (int i = 0; i < libInstanceList.length; ++i) { if (libInstanceConsumedBy.get(libInstanceList[i]).size() == 0) { noConsumerList.add(libInstanceList[i]); @@ -174,6 +174,10 @@ public class AutogenLibOrder { continue; } HashSet consumedBy = libInstanceConsumedBy.get(m); + if (consumedBy.size() == 0) { + continue; + } + consumedBy.remove(n); if (consumedBy.size() == 0) { noConsumerList.addLast(m); @@ -200,10 +204,11 @@ public class AutogenLibOrder { if (consumer.hasConstructor()) { continue; } + // - // if there's no constructor in the library instance's consumer, + // if there's no constructor in the library instance's consumer, // remove it from the consumer list - // + // consumedBy.remove(consumer); circularlyConsumed = false; if (consumedBy.size() == 0) { @@ -216,27 +221,37 @@ public class AutogenLibOrder { break; } } + + if (noConsumerList.size() == 0 && !circularlyConsumed) { + break; + } } } // // Append the remaining library instance to the end of sorted list - // + // + boolean HasError = false; for (int i = 0; i < libInstanceList.length; ++i) { - if (libInstanceConsumedBy.get(libInstanceList[i]).size() > 0 && libInstanceList[i].hasConstructor()) { + HashSet consumedBy = libInstanceConsumedBy.get(libInstanceList[i]); + if (consumedBy.size() > 0 && libInstanceList[i].hasConstructor()) { EdkLog.log(EdkLog.EDK_ERROR, libInstanceList[i].getName() + " with constructor has a circular dependency!"); - // throw new AutoGenException("Circular dependency in library instances is found!"); + ModuleIdentification[] consumedByList = consumedBy.toArray(new ModuleIdentification[consumedBy.size()]); + for (int j = 0; j < consumedByList.length; ++j) { + EdkLog.log(EdkLog.EDK_ERROR, " consumed by " + consumedByList[j].getName()); + } + HasError = true; } if (!orderList.contains(libInstanceList[i])) { - if (libInstanceList[i].getName().equals("UefiBootServicesTableLib")) { - orderList.addFirst(libInstanceList[i]); - } else { - orderList.add(libInstanceList[i]); - } + orderList.add(libInstanceList[i]); } } + if (HasError) { + throw new AutoGenException("Circular dependency in library instances is found!"); + } + return orderList; } }