]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Common/TargetTxtClassObject.py
BaseTools:Change the case rules for ECC check pointer names
[mirror_edk2.git] / BaseTools / Source / Python / Common / TargetTxtClassObject.py
CommitLineData
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
2e351cbe 5# SPDX-License-Identifier: BSD-2-Clause-Patent\r
30fdf114
LG
6#\r
7\r
8##\r
9# Import Modules\r
10#\r
1ccc4d89
LG
11from __future__ import print_function\r
12from __future__ import absolute_import\r
08a54c9e 13from Common.buildoptions import BuildOption,BuildTarget\r
c60fb00f 14import Common.GlobalData as GlobalData\r
1be2ed90 15import Common.LongFilePathOs as os\r
f3fc5b47
GL
16from . import EdkLogger\r
17from . import DataType\r
18from .BuildToolError import *\r
c60fb00f 19\r
1be2ed90 20from Common.LongFilePathSupport import OpenLongFilePath as open\r
c60fb00f 21from Common.MultipleWorkspace import MultipleWorkspace as mws\r
30fdf114 22\r
97fa0ee9 23gDefaultTargetTxtFile = "target.txt"\r
30fdf114
LG
24\r
25## TargetTxtClassObject\r
26#\r
27# This class defined content used in file target.txt\r
28#\r
29# @param object: Inherited from object class\r
30# @param Filename: Input value for full path of target.txt\r
31#\r
32# @var TargetTxtDictionary: To store keys and values defined in target.txt\r
33#\r
34class TargetTxtClassObject(object):\r
35 def __init__(self, Filename = None):\r
36 self.TargetTxtDictionary = {\r
37 DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM : '',\r
38 DataType.TAB_TAT_DEFINES_ACTIVE_MODULE : '',\r
39 DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF : '',\r
30fdf114
LG
40 DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER : '',\r
41 DataType.TAB_TAT_DEFINES_TARGET : [],\r
42 DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG : [],\r
43 DataType.TAB_TAT_DEFINES_TARGET_ARCH : [],\r
44 DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF : '',\r
45 }\r
97fa0ee9 46 self.ConfDirectoryPath = ""\r
4231a819 47 if Filename is not None:\r
30fdf114
LG
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
97fa0ee9
YL
81 F = open(FileName, 'r')\r
82 self.ConfDirectoryPath = os.path.dirname(FileName)\r
30fdf114
LG
83 except:\r
84 EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=FileName)\r
4231a819 85 if F is not None:\r
30fdf114
LG
86 F.close()\r
87\r
88 for Line in F:\r
89 Line = Line.strip()\r
90 if Line.startswith(CommentCharacter) or Line == '':\r
91 continue\r
92\r
93 LineList = Line.split(KeySplitCharacter, 1)\r
94 Key = LineList[0].strip()\r
95 if len(LineList) == 2:\r
96 Value = LineList[1].strip()\r
97 else:\r
98 Value = ""\r
99\r
100 if Key in [DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM, DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF, \\r
101 DataType.TAB_TAT_DEFINES_ACTIVE_MODULE, DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]:\r
102 self.TargetTxtDictionary[Key] = Value.replace('\\', '/')\r
97fa0ee9
YL
103 if Key == DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF and self.TargetTxtDictionary[Key]:\r
104 if self.TargetTxtDictionary[Key].startswith("Conf/"):\r
105 Tools_Def = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())\r
106 if not os.path.exists(Tools_Def) or not os.path.isfile(Tools_Def):\r
107 # If Conf/Conf does not exist, try just the Conf/ directory\r
108 Tools_Def = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].replace("Conf/", "", 1).strip())\r
109 else:\r
110 # The File pointed to by TOOL_CHAIN_CONF is not in a Conf/ directory\r
111 Tools_Def = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())\r
112 self.TargetTxtDictionary[Key] = Tools_Def\r
113 if Key == DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF and self.TargetTxtDictionary[Key]:\r
114 if self.TargetTxtDictionary[Key].startswith("Conf/"):\r
115 Build_Rule = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())\r
116 if not os.path.exists(Build_Rule) or not os.path.isfile(Build_Rule):\r
117 # If Conf/Conf does not exist, try just the Conf/ directory\r
118 Build_Rule = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].replace("Conf/", "", 1).strip())\r
119 else:\r
120 # The File pointed to by BUILD_RULE_CONF is not in a Conf/ directory\r
121 Build_Rule = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())\r
122 self.TargetTxtDictionary[Key] = Build_Rule\r
30fdf114
LG
123 elif Key in [DataType.TAB_TAT_DEFINES_TARGET, DataType.TAB_TAT_DEFINES_TARGET_ARCH, \\r
124 DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG]:\r
125 self.TargetTxtDictionary[Key] = Value.split()\r
30fdf114
LG
126 elif Key == DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER:\r
127 try:\r
128 V = int(Value, 0)\r
129 except:\r
130 EdkLogger.error("build", FORMAT_INVALID, "Invalid number of [%s]: %s." % (Key, Value),\r
131 File=FileName)\r
132 self.TargetTxtDictionary[Key] = Value\r
133 #elif Key not in GlobalData.gGlobalDefines:\r
134 # GlobalData.gGlobalDefines[Key] = Value\r
135\r
136 F.close()\r
137 return 0\r
138\r
30fdf114
LG
139## TargetTxtDict\r
140#\r
97fa0ee9 141# Load target.txt in input Conf dir\r
30fdf114 142#\r
97fa0ee9 143# @param ConfDir: Conf dir\r
30fdf114
LG
144#\r
145# @retval Target An instance of TargetTxtClassObject() with loaded target.txt\r
146#\r
c60fb00f 147def TargetTxtDict():\r
30fdf114 148 Target = TargetTxtClassObject()\r
c60fb00f
FB
149 if BuildOption.ConfDirectory:\r
150 # Get alternate Conf location, if it is absolute, then just use the absolute directory name\r
151 ConfDirectoryPath = os.path.normpath(BuildOption.ConfDirectory)\r
152\r
153 if not os.path.isabs(ConfDirectoryPath):\r
154 # Since alternate directory name is not absolute, the alternate directory is located within the WORKSPACE\r
155 # This also handles someone specifying the Conf directory in the workspace. Using --conf=Conf\r
156 ConfDirectoryPath = mws.join(os.environ["WORKSPACE"], ConfDirectoryPath)\r
157 else:\r
158 if "CONF_PATH" in os.environ:\r
159 ConfDirectoryPath = os.path.normcase(os.path.normpath(os.environ["CONF_PATH"]))\r
160 else:\r
161 # Get standard WORKSPACE/Conf use the absolute path to the WORKSPACE/Conf\r
162 ConfDirectoryPath = mws.join(os.environ["WORKSPACE"], 'Conf')\r
163 GlobalData.gConfDirectory = ConfDirectoryPath\r
164 targettxt = os.path.normpath(os.path.join(ConfDirectoryPath, gDefaultTargetTxtFile))\r
165 if os.path.exists(targettxt):\r
166 Target.LoadTargetTxtFile(targettxt)\r
30fdf114
LG
167 return Target\r
168\r
c60fb00f 169TargetTxt = TargetTxtDict()\r
db01c8e3 170\r
30fdf114
LG
171##\r
172#\r
173# This acts like the main() function for the script, unless it is 'import'ed into another\r
174# script.\r
175#\r
176if __name__ == '__main__':\r
177 pass\r
178 Target = TargetTxtDict(os.getenv("WORKSPACE"))\r
72443dd2
GL
179 print(Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER])\r
180 print(Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET])\r
181 print(Target.TargetTxtDictionary)\r