]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/GenBuild/org/tianocore/build/toolchain/ToolChainInfo.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / toolchain / ToolChainInfo.java
diff --git a/Tools/Java/Source/GenBuild/org/tianocore/build/toolchain/ToolChainInfo.java b/Tools/Java/Source/GenBuild/org/tianocore/build/toolchain/ToolChainInfo.java
new file mode 100644 (file)
index 0000000..9952c0b
--- /dev/null
@@ -0,0 +1,347 @@
+/** @file\r
+ToolChainInfo class\r
+\r
+This file is to define ToolChainInfo class.\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+\r
+package org.tianocore.build.toolchain;\r
+\r
+import java.util.LinkedHashSet;\r
+import java.util.Set;\r
+\r
+/**\r
+   ToolChainInfo collects valid build targets, tool chain tag, ARCHs and commands \r
+   information for real build use.\r
+ **/\r
+public class ToolChainInfo {\r
+    //\r
+    // build target set\r
+    // \r
+    private Set<String> targets = new LinkedHashSet<String>();\r
+    //\r
+    // tool chain tag name set\r
+    // \r
+    private Set<String> tagnames = new LinkedHashSet<String>();\r
+    //\r
+    // build archs set\r
+    // \r
+    private Set<String> archs = new LinkedHashSet<String>();\r
+    //\r
+    // build commands set\r
+    // \r
+    private Set<String> commands = new LinkedHashSet<String>();\r
+\r
+    /**\r
+     Add a list of targets in the form of string separated by space\r
+\r
+     @param targetList target list string\r
+     **/\r
+    public void addTargets(String targetList) {\r
+        //\r
+        // targetList some targets separated by space " "\r
+        //\r
+        if (targetList == null || targetList.length() == 0) {\r
+            targets.add("*");\r
+        } else {\r
+            addTargets(targetList.split(" "));\r
+        }\r
+    }\r
+\r
+    /**\r
+     Add a list of targets in the form of string array\r
+     \r
+     @param targetArray target string array\r
+     **/\r
+    public void addTargets(String[] targetArray) {\r
+        if (targetArray != null ) {\r
+            for (int i = 0; i < targetArray.length; i++) {\r
+                targets.add(targetArray[i]);\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+     Add a list of target in the form of set\r
+     \r
+     @param targetSet target string set\r
+     **/\r
+    public void addTargets(Set<String> targetSet) {\r
+        if (targetSet != null) {\r
+            targets.addAll(targetSet);\r
+        }\r
+    }\r
+\r
+    /**\r
+       Add a list of tool chain tag name in the form of string separated by space\r
+\r
+       @param tagnameList   Tool chain tag name list string\r
+     **/\r
+    public void addTagnames(String tagnameList) {\r
+        //\r
+        // tagnameList some tagnames separated by space " "\r
+        //\r
+        if (tagnameList == null || tagnameList.length() == 0) {\r
+            tagnames.add("*");\r
+        } else {\r
+            addTagnames(tagnameList.split(" "));\r
+        }\r
+    }\r
+\r
+    /**\r
+       Add a list of tool chain tag name in the form of string array\r
+       \r
+       @param tagnameArray  Tool chain tag names array\r
+     **/\r
+    public void addTagnames(String[] tagnameArray) {\r
+        if (tagnameArray != null ) {\r
+            for (int i = 0; i < tagnameArray.length; i++) {\r
+                tagnames.add(tagnameArray[i]);\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+       Add a list of tool chain tag name in the form of Set\r
+       \r
+       @param tagnameSet    Tool chain tag names set\r
+     **/\r
+    public void addTagnames(Set<String> tagnameSet) {\r
+        if (tagnameSet != null) {\r
+            tagnames.addAll(tagnameSet);\r
+        }\r
+    }\r
+\r
+    /**\r
+       Add a list of ARCH in the form of string\r
+       \r
+       @param archList  ARCH string\r
+     **/\r
+    public void addArchs(String archList) {\r
+        //\r
+        // archList some archs separated by space " "\r
+        //\r
+        if (archList == null || archList.length() == 0) {\r
+            archs.add("*");\r
+        } else {\r
+            addArchs(archList.split(" "));\r
+        }\r
+    }\r
+\r
+    /**\r
+       Add a list of ARCH in the form of string array\r
+       \r
+       @param archArray ARCH array\r
+     **/\r
+    public void addArchs(String[] archArray) {\r
+        if (archArray != null ) {\r
+            for (int i = 0; i < archArray.length; i++) {\r
+                archs.add(archArray[i]);\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+       Add a list of ARCH in the form of set\r
+       \r
+       @param archSet   ARCH set\r
+     **/\r
+    public void addArchs(Set<String> archSet) {\r
+        if (archSet != null) {\r
+            archs.addAll(archSet);\r
+        }\r
+    }\r
+\r
+    /**\r
+       Add a list of command in the form of string\r
+       \r
+       @param commandList   Command list string\r
+     **/\r
+    public void addCommands(String commandList) {\r
+        //\r
+        // archList some archs separated by space " "\r
+        //\r
+        if (commandList == null || commandList.length() == 0) {\r
+            commands.add("*");\r
+        } else {\r
+            addCommands(commandList.split(" "));\r
+        }\r
+    }\r
+\r
+    /**\r
+       Add a list of ARCH in the form of array\r
+       \r
+       @param commandArray  Commands array\r
+     **/\r
+    public void addCommands(String[] commandArray) {\r
+        if (commandArray != null ) {\r
+            for (int i = 0; i < commandArray.length; i++) {\r
+                commands.add(commandArray[i]);\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+       Add a list of ARCH in the form of set\r
+       \r
+       @param commandSet    Commands set\r
+     **/\r
+    public void addCommands(Set<String> commandSet) {\r
+        if (commandSet != null) {\r
+            commands.addAll(commandSet);\r
+        }\r
+    }\r
+\r
+    /**\r
+       Make a union operation on this ToolChainInfo and the given one.\r
+\r
+       @param info  Another ToolChainInfo object to merge with\r
+       \r
+       @return ToolChainInfo    Merged ToolChainInfo object\r
+     **/\r
+    public ToolChainInfo union(ToolChainInfo info) {\r
+        ToolChainInfo result = new ToolChainInfo();\r
+        result.addTargets(union(this.targets, info.targets));\r
+        result.addTagnames(union(this.tagnames, info.tagnames));\r
+        result.addArchs(union(this.archs, info.archs));\r
+        return result;\r
+    }\r
+\r
+    /**\r
+       Make a intersection operation on this ToolChainInfo and the given one\r
+\r
+       @param info  Another ToolChainInfo object to intersect with\r
+       \r
+       @return ToolChainInfo    Intersected ToolChainInfo object\r
+     **/\r
+    public ToolChainInfo intersection(ToolChainInfo info) {\r
+        ToolChainInfo result = new ToolChainInfo();\r
+        result.addTargets(intersection(this.targets, info.targets));\r
+        result.addTagnames(intersection(this.tagnames, info.tagnames));\r
+        result.addArchs(intersection(this.archs, info.archs));\r
+        return result;\r
+    }\r
+\r
+    /**\r
+       Make a union operation on two Sets\r
+\r
+       @param set1  One Set\r
+       @param set2  Another Set\r
+       \r
+       @return Set<String>  Merged Set object\r
+     **/\r
+    private Set<String> union(Set<String> set1, Set<String> set2) {\r
+        Set<String> result = new LinkedHashSet<String>();\r
+        result.addAll(set1);\r
+        result.addAll(set2);\r
+        result.remove("*");\r
+        return result;\r
+    }\r
+\r
+    /**\r
+       Make a intersection operation on two Sets with the consideration of wildcard.\r
+\r
+       @param set1  One Set\r
+       @param set2  Another Set\r
+       \r
+       @return Set<String>  The intersected Set object\r
+     **/\r
+    private Set<String> intersection(Set<String> set1, Set<String> set2) {\r
+        Set<String> result = new LinkedHashSet<String>();\r
+        boolean set1HasWildcard = set1.contains("*");\r
+        boolean set2HasWildcard = set2.contains("*");\r
+\r
+        if (set1HasWildcard && set2HasWildcard) {\r
+            //\r
+            // Both Sets have wildcard, the result will have all elements in them\r
+            // \r
+            result.addAll(set1);\r
+            result.addAll(set2);\r
+        } else if (set1HasWildcard) {\r
+            //\r
+            // Only set1 has wildcard, then result will have only set2 elements.\r
+            // \r
+            result.addAll(set2);\r
+        } else if (set2HasWildcard) {\r
+            //\r
+            // Only set2 has wildcard, then result will have only set1 elements.\r
+            // \r
+            result.addAll(set1);\r
+        } else {\r
+            //\r
+            // No wildcard in both Sets, the result will have the elements in both Sets.\r
+            // \r
+            result.addAll(set1);\r
+            result.retainAll(set2);\r
+        }\r
+\r
+        return result;\r
+    }\r
+\r
+    /**\r
+       Get target array.\r
+\r
+       @return String[]\r
+     **/\r
+    public String[] getTargets() {\r
+        return (String[])targets.toArray(new String[targets.size()]);\r
+    }\r
+\r
+    /**\r
+       Get tool chain tag name array.\r
+\r
+       @return String[]\r
+     **/\r
+    public String[] getTagnames() {\r
+        return (String[])tagnames.toArray(new String[tagnames.size()]);\r
+    }\r
+\r
+    /**\r
+       Get ARCH array.\r
+\r
+       @return String[]\r
+     **/\r
+    public String[] getArchs() {\r
+        return (String[])archs.toArray(new String[archs.size()]);\r
+    }\r
+\r
+    /**\r
+       Get command name array.\r
+\r
+       @return String[]\r
+     **/\r
+    public String[] getCommands() {\r
+        return (String[])commands.toArray(new String[commands.size()]);\r
+    }\r
+\r
+    /**\r
+       Override the Object's toString().\r
+\r
+       @return String\r
+     **/\r
+    public String toString() {\r
+        return  "  TARGET :" + targets + "\n" + \r
+                "  TAGNAME:" + tagnames + "\n" + \r
+                "  ARCH   :" + archs + "\n" + \r
+                "  COMMAND:" + commands;\r
+    }\r
+\r
+    /**\r
+       Remove the wildcard element in the tool chain information because they\r
+       are useless when retrieved.\r
+     **/\r
+    public void normalize() {\r
+        targets.remove("*");\r
+        tagnames.remove("*");\r
+        archs.remove("*");\r
+        commands.remove("*");\r
+    }\r
+}\r