]>
Commit | Line | Data |
---|---|---|
1 | ## @file\r | |
2 | # This file is used to define each component of Target.txt file\r | |
3 | #\r | |
4 | # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r | |
5 | # This program and the accompanying materials\r | |
6 | # are licensed and made available under the terms and conditions of the BSD License\r | |
7 | # which accompanies this distribution. The full text of the license may be found at\r | |
8 | # http://opensource.org/licenses/bsd-license.php\r | |
9 | #\r | |
10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | #\r | |
13 | \r | |
14 | ##\r | |
15 | # Import Modules\r | |
16 | #\r | |
17 | import Common.LongFilePathOs as os\r | |
18 | import EdkLogger\r | |
19 | import DataType\r | |
20 | from BuildToolError import *\r | |
21 | import GlobalData\r | |
22 | from Common.LongFilePathSupport import OpenLongFilePath as open\r | |
23 | \r | |
24 | gDefaultTargetTxtFile = "target.txt"\r | |
25 | \r | |
26 | ## TargetTxtClassObject\r | |
27 | #\r | |
28 | # This class defined content used in file target.txt\r | |
29 | #\r | |
30 | # @param object: Inherited from object class\r | |
31 | # @param Filename: Input value for full path of target.txt\r | |
32 | #\r | |
33 | # @var TargetTxtDictionary: To store keys and values defined in target.txt\r | |
34 | #\r | |
35 | class TargetTxtClassObject(object):\r | |
36 | def __init__(self, Filename = None):\r | |
37 | self.TargetTxtDictionary = {\r | |
38 | DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM : '',\r | |
39 | DataType.TAB_TAT_DEFINES_ACTIVE_MODULE : '',\r | |
40 | DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF : '',\r | |
41 | DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER : '',\r | |
42 | DataType.TAB_TAT_DEFINES_TARGET : [],\r | |
43 | DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG : [],\r | |
44 | DataType.TAB_TAT_DEFINES_TARGET_ARCH : [],\r | |
45 | DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF : '',\r | |
46 | }\r | |
47 | self.ConfDirectoryPath = ""\r | |
48 | if Filename != None:\r | |
49 | self.LoadTargetTxtFile(Filename)\r | |
50 | \r | |
51 | ## LoadTargetTxtFile\r | |
52 | #\r | |
53 | # Load target.txt file and parse it, return a set structure to store keys and values\r | |
54 | #\r | |
55 | # @param Filename: Input value for full path of target.txt\r | |
56 | #\r | |
57 | # @retval set() A set structure to store keys and values\r | |
58 | # @retval 1 Error happenes in parsing\r | |
59 | #\r | |
60 | def LoadTargetTxtFile(self, Filename):\r | |
61 | if os.path.exists(Filename) and os.path.isfile(Filename):\r | |
62 | return self.ConvertTextFileToDict(Filename, '#', '=')\r | |
63 | else:\r | |
64 | EdkLogger.error("Target.txt Parser", FILE_NOT_FOUND, ExtraData=Filename)\r | |
65 | return 1\r | |
66 | \r | |
67 | ## ConvertTextFileToDict\r | |
68 | #\r | |
69 | # Convert a text file to a dictionary of (name:value) pairs.\r | |
70 | # The data is saved to self.TargetTxtDictionary\r | |
71 | #\r | |
72 | # @param FileName: Text filename\r | |
73 | # @param CommentCharacter: Comment char, be used to ignore comment content\r | |
74 | # @param KeySplitCharacter: Key split char, between key name and key value. Key1 = Value1, '=' is the key split char\r | |
75 | #\r | |
76 | # @retval 0 Convert successfully\r | |
77 | # @retval 1 Open file failed\r | |
78 | #\r | |
79 | def ConvertTextFileToDict(self, FileName, CommentCharacter, KeySplitCharacter):\r | |
80 | F = None\r | |
81 | try:\r | |
82 | F = open(FileName, 'r')\r | |
83 | self.ConfDirectoryPath = os.path.dirname(FileName)\r | |
84 | except:\r | |
85 | EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=FileName)\r | |
86 | if F != None:\r | |
87 | F.close()\r | |
88 | \r | |
89 | for Line in F:\r | |
90 | Line = Line.strip()\r | |
91 | if Line.startswith(CommentCharacter) or Line == '':\r | |
92 | continue\r | |
93 | \r | |
94 | LineList = Line.split(KeySplitCharacter, 1)\r | |
95 | Key = LineList[0].strip()\r | |
96 | if len(LineList) == 2:\r | |
97 | Value = LineList[1].strip()\r | |
98 | else:\r | |
99 | Value = ""\r | |
100 | \r | |
101 | if Key in [DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM, DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF, \\r | |
102 | DataType.TAB_TAT_DEFINES_ACTIVE_MODULE, DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]:\r | |
103 | self.TargetTxtDictionary[Key] = Value.replace('\\', '/')\r | |
104 | if Key == DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF and self.TargetTxtDictionary[Key]:\r | |
105 | if self.TargetTxtDictionary[Key].startswith("Conf/"):\r | |
106 | Tools_Def = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())\r | |
107 | if not os.path.exists(Tools_Def) or not os.path.isfile(Tools_Def):\r | |
108 | # If Conf/Conf does not exist, try just the Conf/ directory\r | |
109 | Tools_Def = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].replace("Conf/", "", 1).strip())\r | |
110 | else:\r | |
111 | # The File pointed to by TOOL_CHAIN_CONF is not in a Conf/ directory\r | |
112 | Tools_Def = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())\r | |
113 | self.TargetTxtDictionary[Key] = Tools_Def\r | |
114 | if Key == DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF and self.TargetTxtDictionary[Key]:\r | |
115 | if self.TargetTxtDictionary[Key].startswith("Conf/"):\r | |
116 | Build_Rule = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())\r | |
117 | if not os.path.exists(Build_Rule) or not os.path.isfile(Build_Rule):\r | |
118 | # If Conf/Conf does not exist, try just the Conf/ directory\r | |
119 | Build_Rule = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].replace("Conf/", "", 1).strip())\r | |
120 | else:\r | |
121 | # The File pointed to by BUILD_RULE_CONF is not in a Conf/ directory\r | |
122 | Build_Rule = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())\r | |
123 | self.TargetTxtDictionary[Key] = Build_Rule\r | |
124 | elif Key in [DataType.TAB_TAT_DEFINES_TARGET, DataType.TAB_TAT_DEFINES_TARGET_ARCH, \\r | |
125 | DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG]:\r | |
126 | self.TargetTxtDictionary[Key] = Value.split()\r | |
127 | elif Key == DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER:\r | |
128 | try:\r | |
129 | V = int(Value, 0)\r | |
130 | except:\r | |
131 | EdkLogger.error("build", FORMAT_INVALID, "Invalid number of [%s]: %s." % (Key, Value),\r | |
132 | File=FileName)\r | |
133 | self.TargetTxtDictionary[Key] = Value\r | |
134 | #elif Key not in GlobalData.gGlobalDefines:\r | |
135 | # GlobalData.gGlobalDefines[Key] = Value\r | |
136 | \r | |
137 | F.close()\r | |
138 | return 0\r | |
139 | \r | |
140 | ## Print the dictionary\r | |
141 | #\r | |
142 | # Print all items of dictionary one by one\r | |
143 | #\r | |
144 | # @param Dict: The dictionary to be printed\r | |
145 | #\r | |
146 | def printDict(Dict):\r | |
147 | if Dict != None:\r | |
148 | KeyList = Dict.keys()\r | |
149 | for Key in KeyList:\r | |
150 | if Dict[Key] != '':\r | |
151 | print Key + ' = ' + str(Dict[Key])\r | |
152 | \r | |
153 | ## Print the dictionary\r | |
154 | #\r | |
155 | # Print the items of dictionary which matched with input key\r | |
156 | #\r | |
157 | # @param list: The dictionary to be printed\r | |
158 | # @param key: The key of the item to be printed\r | |
159 | #\r | |
160 | def printList(Key, List):\r | |
161 | if type(List) == type([]):\r | |
162 | if len(List) > 0:\r | |
163 | if Key.find(TAB_SPLIT) != -1:\r | |
164 | print "\n" + Key\r | |
165 | for Item in List:\r | |
166 | print Item\r | |
167 | ## TargetTxtDict\r | |
168 | #\r | |
169 | # Load target.txt in input Conf dir\r | |
170 | #\r | |
171 | # @param ConfDir: Conf dir\r | |
172 | #\r | |
173 | # @retval Target An instance of TargetTxtClassObject() with loaded target.txt\r | |
174 | #\r | |
175 | def TargetTxtDict(ConfDir):\r | |
176 | Target = TargetTxtClassObject()\r | |
177 | Target.LoadTargetTxtFile(os.path.normpath(os.path.join(ConfDir, gDefaultTargetTxtFile)))\r | |
178 | return Target\r | |
179 | \r | |
180 | ##\r | |
181 | #\r | |
182 | # This acts like the main() function for the script, unless it is 'import'ed into another\r | |
183 | # script.\r | |
184 | #\r | |
185 | if __name__ == '__main__':\r | |
186 | pass\r | |
187 | Target = TargetTxtDict(os.getenv("WORKSPACE"))\r | |
188 | print Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER]\r | |
189 | print Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET]\r | |
190 | print Target.TargetTxtDictionary\r |