]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/GenBuild/org/tianocore/build/toolchain/ToolChainMap.java
a) Cleaned tools_def.template
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / toolchain / ToolChainMap.java
index b9d24eb0b95d987b34a3489b9572820cc21c6d43..f3f07797bc2a41b6b49ab8bad26ed326adb2e1fb 100644 (file)
@@ -29,7 +29,7 @@ public class ToolChainMap {
     //\r
     // From which part of key can be used to match "*"\r
     // \r
-    private int matchLevel = ToolChainKey.keyLength - 2;\r
+    private int matchLevel = ToolChainKey.keyLength - 1;\r
 \r
     //\r
     // A Map object in which tool chain configuration information will be stored\r
@@ -211,98 +211,96 @@ public class ToolChainMap {
         ///\r
         /// In the current tool chain definition format (in name/value pair), \r
         /// there're five parts in the "name". The last part of the "name" must\r
-        /// not be "wildcard". So we should start combining "*" from the fourth part.\r
+        /// not be "wildcard". We should start combining "*" from left to right.\r
         /// We'll try all the possible combinations until the value can be fetched.\r
         ///  \r
         /// The following code implements the logic which will try to use, for example,\r
         /// following key parts combinations sequentially to get the value.\r
         /// \r
         /// TARGET_TOOLCHAIN_ARCH_TOOLCODE_ATTRIBUTE\r
-        /// TARGET_TOOLCHAIN_ARCH_*_ATTRIBUTE\r
-        /// TARGET_TOOLCHAIN_*_TOOLCODE_ATTRIBUTE\r
-        /// TARGET_TOOLCHAIN_*_*_ATTRIBUTE\r
-        /// TARGET_*_ARCH_TOOLCODE_ATTRIBUTE\r
-        /// TARGET_*_ARCH_*_ATTRIBUTE\r
-        /// TARGET_*_*_TOOLCODE_ATTRIBUTE\r
-        /// TARGET_*_*_*_ATTRIBUTE\r
-        /// *_TOOLCHAIN_ARCH_TOOLCODE_ATTRIBUTE\r
-        /// *_TOOLCHAIN_ARCH_*_ATTRIBUTE\r
-        /// *_TOOLCHAIN_*_TOOLCODE_ATTRIBUTE\r
-        /// *_TOOLCHAIN_*_*_ATTRIBUTE\r
-        /// *_*_ARCH_TOOLCODE_ATTRIBUTE\r
-        /// *_*_ARCH_*_ATTRIBUTE\r
-        /// *_*_*_TOOLCODE_ATTRIBUTE\r
-        /// *_*_*_*_ATTRIBUTE\r
+        /// ******_TOOLCHAIN_ARCH_TOOLCODE_ATTRIBUTE\r
+        /// TARGET_*********_ARCH_TOOLCODE_ATTRIBUTE\r
+        /// ******_*********_ARCH_TOOLCODE_ATTRIBUTE\r
+        /// TARGET_TOOLCHAIN_****_TOOLCODE_ATTRIBUTE\r
+        /// ******_TOOLCHAIN_****_TOOLCODE_ATTRIBUTE\r
+        /// TARGET_*********_****_TOOLCODE_ATTRIBUTE\r
+        /// ******_*********_****_TOOLCODE_ATTRIBUTE\r
+        /// TARGET_TOOLCHAIN_ARCH_********_ATTRIBUTE\r
+        /// ******_TOOLCHAIN_ARCH_********_ATTRIBUTE\r
+        /// TARGET_*********_ARCH_********_ATTRIBUTE\r
+        /// ******_*********_ARCH_********_ATTRIBUTE\r
+        /// TARGET_TOOLCHAIN_****_********_ATTRIBUTE\r
+        /// ******_TOOLCHAIN_****_********_ATTRIBUTE\r
+        /// TARGET_*********_****_********_ATTRIBUTE\r
+        /// ******_*********_****_********_ATTRIBUTE\r
         /// \r
 \r
         //\r
-        // level is used to control if all parts of "name" have been "wildcarded"\r
+        // The wildcard "*" appears regularly (2^n). "*" in TARGET appears 2^0 \r
+        // times at every 2^0 TARGET, "*" in TOOLCHAIN appears 2^1 times at \r
+        // every 2^1 TOOLCHAIN,  and "*" in TOOLCODE appears 2^3 times at every \r
+        // 2^3 TOOLCODE. We're going to use this to form all the combinations of key.\r
         // \r
-        int level = matchLevel;\r
-        while (level >= 0) {\r
+        int[] combinations = new int[matchLevel];\r
+        for (int i = 0; i < matchLevel; ++i) {\r
             //\r
-            // tmplevel is used to control if all parts of "name" between first\r
-            // "*" and fourth name part have been "wildcarded".\r
+            // initialize the array with 2^n\r
             // \r
-            int tmpLevel = level;\r
-            while (tmpLevel >= level) {\r
-                String[] tmpKeySet = tmpKey.getKeySet();\r
+            combinations[i] = 1 << (i + 1);\r
+        }\r
+\r
+        //\r
+        // when last part goes down to zero, we tried all combinations of key\r
+        // \r
+        int lastIndex = matchLevel - 1;\r
+        while (combinations[lastIndex] > 0) {\r
+            //\r
+            // form the key which has "*" in it\r
+            // \r
+            for (int i = 0; i < matchLevel; ++i) {\r
+                //\r
+                // start again if not finished\r
+                // \r
+                if (combinations[i] == 0) {\r
+                    combinations[i] = 1 << (i + 1);\r
+                }\r
+\r
+                //\r
+                // half of 2^n is "*", the rest is non-*\r
+                // \r
                 try {\r
-                    if (!tmpKeySet[tmpLevel].equals("*")) {\r
-                        //\r
-                        // If "tmplevel" part is not "*", set it to "*".\r
-                        // For example, at first loop, the key will become\r
-                        // TARGET_TOOLCHAIN_ARCH_*_ATTRIBUTE, and at next loop,\r
-                        // become TARGET_TOOLCHAIN_*_ARCH_ATTRIBUTE\r
-                        // \r
-                        tmpKey.setKey("*", tmpLevel);\r
-                        //\r
-                        // We'll try all possible combinations between current\r
-                        // part and the fourth part.\r
-                        // \r
-                        tmpLevel = matchLevel;\r
+                    if (combinations[i] > (1 << i)) {\r
+                        tmpKey.setKey(keySet[i], i);\r
                     } else {\r
-                        //\r
-                        // Restore original value of key if "*" at "tmplevel"\r
-                        // part of "name" has been checked\r
-                        // \r
-                        tmpKey.setKey(keySet[tmpLevel], tmpLevel);\r
-                        //\r
-                        // Try "*" at part left to "tmplevel" part of "name"\r
-                        // \r
-                        --tmpLevel;\r
-                        continue;\r
+                        tmpKey.setKey("*", i);\r
                     }\r
                 } catch (Exception e) {\r
                     return null;\r
                 }\r
 \r
+                combinations[i] -= 1;\r
+            }\r
+\r
+            //\r
+            // Try get the value from the map\r
+            // \r
+            result = map.get(tmpKey);\r
+            if (result != null) {\r
                 //\r
-                // Try get the value from the map\r
+                // The map actually has no exact key as the given "key", \r
+                // putting it back into map can speed up the get() next time\r
                 // \r
-                result = map.get(tmpKey);\r
-                if (result != null) {\r
-                    //\r
-                    // The map actually has no exact key as the given "key", \r
-                    // putting it back into map can speed up the get() next time\r
-                    // \r
-                    map.put(key, result);\r
-                    return result;\r
-                }\r
+                map.put(key, result);\r
+                return result;\r
             }\r
-            ///\r
-            /// If all possible combinations of "wildcard" between "level" and \r
-            /// the fourth part of "name" have been tried, try the left part\r
-            /// \r
-            --level;\r
         }\r
 \r
         //\r
         // The map actually has no exact key as the given "key", putting it back\r
         // into map can speed up the get() next time even we got nothing.\r
         // \r
-        map.put(key, result);\r
-        return result;\r
+        map.put(key, null);\r
+        return null;\r
     }\r
 \r
     /**\r