]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # This file is used to define each component of Target.txt file\r | |
3 | #\r | |
1be2ed90 | 4 | # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r |
40d841f6 | 5 | # This program and the accompanying materials\r |
30fdf114 LG |
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 | |
1be2ed90 | 17 | import Common.LongFilePathOs as os\r |
30fdf114 LG |
18 | import EdkLogger\r |
19 | import DataType\r | |
20 | from BuildToolError import *\r | |
21 | import GlobalData\r | |
1be2ed90 | 22 | from Common.LongFilePathSupport import OpenLongFilePath as open\r |
30fdf114 LG |
23 | \r |
24 | gDefaultTargetTxtFile = "Conf/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 | |
30fdf114 LG |
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 | if Filename != None:\r | |
48 | self.LoadTargetTxtFile(Filename)\r | |
49 | \r | |
50 | ## LoadTargetTxtFile\r | |
51 | #\r | |
52 | # Load target.txt file and parse it, return a set structure to store keys and values\r | |
53 | #\r | |
54 | # @param Filename: Input value for full path of target.txt\r | |
55 | #\r | |
56 | # @retval set() A set structure to store keys and values\r | |
57 | # @retval 1 Error happenes in parsing\r | |
58 | #\r | |
59 | def LoadTargetTxtFile(self, Filename):\r | |
60 | if os.path.exists(Filename) and os.path.isfile(Filename):\r | |
61 | return self.ConvertTextFileToDict(Filename, '#', '=')\r | |
62 | else:\r | |
63 | EdkLogger.error("Target.txt Parser", FILE_NOT_FOUND, ExtraData=Filename)\r | |
64 | return 1\r | |
65 | \r | |
66 | ## ConvertTextFileToDict\r | |
67 | #\r | |
68 | # Convert a text file to a dictionary of (name:value) pairs.\r | |
69 | # The data is saved to self.TargetTxtDictionary\r | |
70 | #\r | |
71 | # @param FileName: Text filename\r | |
72 | # @param CommentCharacter: Comment char, be used to ignore comment content\r | |
73 | # @param KeySplitCharacter: Key split char, between key name and key value. Key1 = Value1, '=' is the key split char\r | |
74 | #\r | |
75 | # @retval 0 Convert successfully\r | |
76 | # @retval 1 Open file failed\r | |
77 | #\r | |
78 | def ConvertTextFileToDict(self, FileName, CommentCharacter, KeySplitCharacter):\r | |
79 | F = None\r | |
80 | try:\r | |
81 | F = open(FileName,'r')\r | |
82 | except:\r | |
83 | EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=FileName)\r | |
84 | if F != None:\r | |
85 | F.close()\r | |
86 | \r | |
87 | for Line in F:\r | |
88 | Line = Line.strip()\r | |
89 | if Line.startswith(CommentCharacter) or Line == '':\r | |
90 | continue\r | |
91 | \r | |
92 | LineList = Line.split(KeySplitCharacter, 1)\r | |
93 | Key = LineList[0].strip()\r | |
94 | if len(LineList) == 2:\r | |
95 | Value = LineList[1].strip()\r | |
96 | else:\r | |
97 | Value = ""\r | |
98 | \r | |
99 | if Key in [DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM, DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF, \\r | |
100 | DataType.TAB_TAT_DEFINES_ACTIVE_MODULE, DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]:\r | |
101 | self.TargetTxtDictionary[Key] = Value.replace('\\', '/')\r | |
102 | elif Key in [DataType.TAB_TAT_DEFINES_TARGET, DataType.TAB_TAT_DEFINES_TARGET_ARCH, \\r | |
103 | DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG]:\r | |
104 | self.TargetTxtDictionary[Key] = Value.split()\r | |
30fdf114 LG |
105 | elif Key == DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER:\r |
106 | try:\r | |
107 | V = int(Value, 0)\r | |
108 | except:\r | |
109 | EdkLogger.error("build", FORMAT_INVALID, "Invalid number of [%s]: %s." % (Key, Value),\r | |
110 | File=FileName)\r | |
111 | self.TargetTxtDictionary[Key] = Value\r | |
112 | #elif Key not in GlobalData.gGlobalDefines:\r | |
113 | # GlobalData.gGlobalDefines[Key] = Value\r | |
114 | \r | |
115 | F.close()\r | |
116 | return 0\r | |
117 | \r | |
118 | ## Print the dictionary\r | |
119 | #\r | |
120 | # Print all items of dictionary one by one\r | |
121 | #\r | |
122 | # @param Dict: The dictionary to be printed\r | |
123 | #\r | |
124 | def printDict(Dict):\r | |
125 | if Dict != None:\r | |
126 | KeyList = Dict.keys()\r | |
127 | for Key in KeyList:\r | |
128 | if Dict[Key] != '':\r | |
129 | print Key + ' = ' + str(Dict[Key])\r | |
130 | \r | |
131 | ## Print the dictionary\r | |
132 | #\r | |
133 | # Print the items of dictionary which matched with input key\r | |
134 | #\r | |
135 | # @param list: The dictionary to be printed\r | |
136 | # @param key: The key of the item to be printed\r | |
137 | #\r | |
138 | def printList(Key, List):\r | |
139 | if type(List) == type([]):\r | |
140 | if len(List) > 0:\r | |
141 | if Key.find(TAB_SPLIT) != -1:\r | |
142 | print "\n" + Key\r | |
143 | for Item in List:\r | |
144 | print Item\r | |
145 | ## TargetTxtDict\r | |
146 | #\r | |
147 | # Load target.txt in input workspace dir\r | |
148 | #\r | |
149 | # @param WorkSpace: Workspace dir\r | |
150 | #\r | |
151 | # @retval Target An instance of TargetTxtClassObject() with loaded target.txt\r | |
152 | #\r | |
153 | def TargetTxtDict(WorkSpace):\r | |
154 | Target = TargetTxtClassObject()\r | |
155 | Target.LoadTargetTxtFile(os.path.normpath(os.path.join(WorkSpace, gDefaultTargetTxtFile)))\r | |
156 | return Target\r | |
157 | \r | |
158 | ##\r | |
159 | #\r | |
160 | # This acts like the main() function for the script, unless it is 'import'ed into another\r | |
161 | # script.\r | |
162 | #\r | |
163 | if __name__ == '__main__':\r | |
164 | pass\r | |
165 | Target = TargetTxtDict(os.getenv("WORKSPACE"))\r | |
166 | print Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER]\r | |
167 | print Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET]\r | |
168 | print Target.TargetTxtDictionary\r |