]>
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 | |
1ccc4d89 LG |
17 | from __future__ import print_function\r |
18 | from __future__ import absolute_import\r | |
1be2ed90 | 19 | import Common.LongFilePathOs as os\r |
f3fc5b47 GL |
20 | from . import EdkLogger\r |
21 | from . import DataType\r | |
22 | from .BuildToolError import *\r | |
23 | from . import GlobalData\r | |
1be2ed90 | 24 | from Common.LongFilePathSupport import OpenLongFilePath as open\r |
30fdf114 | 25 | \r |
97fa0ee9 | 26 | gDefaultTargetTxtFile = "target.txt"\r |
30fdf114 LG |
27 | \r |
28 | ## TargetTxtClassObject\r | |
29 | #\r | |
30 | # This class defined content used in file target.txt\r | |
31 | #\r | |
32 | # @param object: Inherited from object class\r | |
33 | # @param Filename: Input value for full path of target.txt\r | |
34 | #\r | |
35 | # @var TargetTxtDictionary: To store keys and values defined in target.txt\r | |
36 | #\r | |
37 | class TargetTxtClassObject(object):\r | |
38 | def __init__(self, Filename = None):\r | |
39 | self.TargetTxtDictionary = {\r | |
40 | DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM : '',\r | |
41 | DataType.TAB_TAT_DEFINES_ACTIVE_MODULE : '',\r | |
42 | DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF : '',\r | |
30fdf114 LG |
43 | DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER : '',\r |
44 | DataType.TAB_TAT_DEFINES_TARGET : [],\r | |
45 | DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG : [],\r | |
46 | DataType.TAB_TAT_DEFINES_TARGET_ARCH : [],\r | |
47 | DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF : '',\r | |
48 | }\r | |
97fa0ee9 | 49 | self.ConfDirectoryPath = ""\r |
4231a819 | 50 | if Filename is not None:\r |
30fdf114 LG |
51 | self.LoadTargetTxtFile(Filename)\r |
52 | \r | |
53 | ## LoadTargetTxtFile\r | |
54 | #\r | |
55 | # Load target.txt file and parse it, return a set structure to store keys and values\r | |
56 | #\r | |
57 | # @param Filename: Input value for full path of target.txt\r | |
58 | #\r | |
59 | # @retval set() A set structure to store keys and values\r | |
60 | # @retval 1 Error happenes in parsing\r | |
61 | #\r | |
62 | def LoadTargetTxtFile(self, Filename):\r | |
63 | if os.path.exists(Filename) and os.path.isfile(Filename):\r | |
64 | return self.ConvertTextFileToDict(Filename, '#', '=')\r | |
65 | else:\r | |
66 | EdkLogger.error("Target.txt Parser", FILE_NOT_FOUND, ExtraData=Filename)\r | |
67 | return 1\r | |
68 | \r | |
69 | ## ConvertTextFileToDict\r | |
70 | #\r | |
71 | # Convert a text file to a dictionary of (name:value) pairs.\r | |
72 | # The data is saved to self.TargetTxtDictionary\r | |
73 | #\r | |
74 | # @param FileName: Text filename\r | |
75 | # @param CommentCharacter: Comment char, be used to ignore comment content\r | |
76 | # @param KeySplitCharacter: Key split char, between key name and key value. Key1 = Value1, '=' is the key split char\r | |
77 | #\r | |
78 | # @retval 0 Convert successfully\r | |
79 | # @retval 1 Open file failed\r | |
80 | #\r | |
81 | def ConvertTextFileToDict(self, FileName, CommentCharacter, KeySplitCharacter):\r | |
82 | F = None\r | |
83 | try:\r | |
97fa0ee9 YL |
84 | F = open(FileName, 'r')\r |
85 | self.ConfDirectoryPath = os.path.dirname(FileName)\r | |
30fdf114 LG |
86 | except:\r |
87 | EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=FileName)\r | |
4231a819 | 88 | if F is not None:\r |
30fdf114 LG |
89 | F.close()\r |
90 | \r | |
91 | for Line in F:\r | |
92 | Line = Line.strip()\r | |
93 | if Line.startswith(CommentCharacter) or Line == '':\r | |
94 | continue\r | |
95 | \r | |
96 | LineList = Line.split(KeySplitCharacter, 1)\r | |
97 | Key = LineList[0].strip()\r | |
98 | if len(LineList) == 2:\r | |
99 | Value = LineList[1].strip()\r | |
100 | else:\r | |
101 | Value = ""\r | |
102 | \r | |
103 | if Key in [DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM, DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF, \\r | |
104 | DataType.TAB_TAT_DEFINES_ACTIVE_MODULE, DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]:\r | |
105 | self.TargetTxtDictionary[Key] = Value.replace('\\', '/')\r | |
97fa0ee9 YL |
106 | if Key == DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF and self.TargetTxtDictionary[Key]:\r |
107 | if self.TargetTxtDictionary[Key].startswith("Conf/"):\r | |
108 | Tools_Def = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())\r | |
109 | if not os.path.exists(Tools_Def) or not os.path.isfile(Tools_Def):\r | |
110 | # If Conf/Conf does not exist, try just the Conf/ directory\r | |
111 | Tools_Def = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].replace("Conf/", "", 1).strip())\r | |
112 | else:\r | |
113 | # The File pointed to by TOOL_CHAIN_CONF is not in a Conf/ directory\r | |
114 | Tools_Def = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())\r | |
115 | self.TargetTxtDictionary[Key] = Tools_Def\r | |
116 | if Key == DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF and self.TargetTxtDictionary[Key]:\r | |
117 | if self.TargetTxtDictionary[Key].startswith("Conf/"):\r | |
118 | Build_Rule = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())\r | |
119 | if not os.path.exists(Build_Rule) or not os.path.isfile(Build_Rule):\r | |
120 | # If Conf/Conf does not exist, try just the Conf/ directory\r | |
121 | Build_Rule = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].replace("Conf/", "", 1).strip())\r | |
122 | else:\r | |
123 | # The File pointed to by BUILD_RULE_CONF is not in a Conf/ directory\r | |
124 | Build_Rule = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())\r | |
125 | self.TargetTxtDictionary[Key] = Build_Rule\r | |
30fdf114 LG |
126 | elif Key in [DataType.TAB_TAT_DEFINES_TARGET, DataType.TAB_TAT_DEFINES_TARGET_ARCH, \\r |
127 | DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG]:\r | |
128 | self.TargetTxtDictionary[Key] = Value.split()\r | |
30fdf114 LG |
129 | elif Key == DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER:\r |
130 | try:\r | |
131 | V = int(Value, 0)\r | |
132 | except:\r | |
133 | EdkLogger.error("build", FORMAT_INVALID, "Invalid number of [%s]: %s." % (Key, Value),\r | |
134 | File=FileName)\r | |
135 | self.TargetTxtDictionary[Key] = Value\r | |
136 | #elif Key not in GlobalData.gGlobalDefines:\r | |
137 | # GlobalData.gGlobalDefines[Key] = Value\r | |
138 | \r | |
139 | F.close()\r | |
140 | return 0\r | |
141 | \r | |
30fdf114 LG |
142 | ## TargetTxtDict\r |
143 | #\r | |
97fa0ee9 | 144 | # Load target.txt in input Conf dir\r |
30fdf114 | 145 | #\r |
97fa0ee9 | 146 | # @param ConfDir: Conf dir\r |
30fdf114 LG |
147 | #\r |
148 | # @retval Target An instance of TargetTxtClassObject() with loaded target.txt\r | |
149 | #\r | |
97fa0ee9 | 150 | def TargetTxtDict(ConfDir):\r |
30fdf114 | 151 | Target = TargetTxtClassObject()\r |
97fa0ee9 | 152 | Target.LoadTargetTxtFile(os.path.normpath(os.path.join(ConfDir, gDefaultTargetTxtFile)))\r |
30fdf114 LG |
153 | return Target\r |
154 | \r | |
155 | ##\r | |
156 | #\r | |
157 | # This acts like the main() function for the script, unless it is 'import'ed into another\r | |
158 | # script.\r | |
159 | #\r | |
160 | if __name__ == '__main__':\r | |
161 | pass\r | |
162 | Target = TargetTxtDict(os.getenv("WORKSPACE"))\r | |
72443dd2 GL |
163 | print(Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER])\r |
164 | print(Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET])\r | |
165 | print(Target.TargetTxtDictionary)\r |