2 # This file is used to define each component of Target.txt file
4 # Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 from BuildToolError
import *
23 gDefaultTargetTxtFile
= "Conf/target.txt"
25 ## TargetTxtClassObject
27 # This class defined content used in file target.txt
29 # @param object: Inherited from object class
30 # @param Filename: Input value for full path of target.txt
32 # @var TargetTxtDictionary: To store keys and values defined in target.txt
34 class TargetTxtClassObject(object):
35 def __init__(self
, Filename
= None):
36 self
.TargetTxtDictionary
= {
37 DataType
.TAB_TAT_DEFINES_ACTIVE_PLATFORM
: '',
38 DataType
.TAB_TAT_DEFINES_ACTIVE_MODULE
: '',
39 DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
: '',
40 DataType
.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER
: '',
41 DataType
.TAB_TAT_DEFINES_TARGET
: [],
42 DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_TAG
: [],
43 DataType
.TAB_TAT_DEFINES_TARGET_ARCH
: [],
44 DataType
.TAB_TAT_DEFINES_BUILD_RULE_CONF
: '',
47 self
.LoadTargetTxtFile(Filename
)
51 # Load target.txt file and parse it, return a set structure to store keys and values
53 # @param Filename: Input value for full path of target.txt
55 # @retval set() A set structure to store keys and values
56 # @retval 1 Error happenes in parsing
58 def LoadTargetTxtFile(self
, Filename
):
59 if os
.path
.exists(Filename
) and os
.path
.isfile(Filename
):
60 return self
.ConvertTextFileToDict(Filename
, '#', '=')
62 EdkLogger
.error("Target.txt Parser", FILE_NOT_FOUND
, ExtraData
=Filename
)
65 ## ConvertTextFileToDict
67 # Convert a text file to a dictionary of (name:value) pairs.
68 # The data is saved to self.TargetTxtDictionary
70 # @param FileName: Text filename
71 # @param CommentCharacter: Comment char, be used to ignore comment content
72 # @param KeySplitCharacter: Key split char, between key name and key value. Key1 = Value1, '=' is the key split char
74 # @retval 0 Convert successfully
75 # @retval 1 Open file failed
77 def ConvertTextFileToDict(self
, FileName
, CommentCharacter
, KeySplitCharacter
):
80 F
= open(FileName
,'r')
82 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=FileName
)
88 if Line
.startswith(CommentCharacter
) or Line
== '':
91 LineList
= Line
.split(KeySplitCharacter
, 1)
92 Key
= LineList
[0].strip()
93 if len(LineList
) == 2:
94 Value
= LineList
[1].strip()
98 if Key
in [DataType
.TAB_TAT_DEFINES_ACTIVE_PLATFORM
, DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
, \
99 DataType
.TAB_TAT_DEFINES_ACTIVE_MODULE
, DataType
.TAB_TAT_DEFINES_BUILD_RULE_CONF
]:
100 self
.TargetTxtDictionary
[Key
] = Value
.replace('\\', '/')
101 elif Key
in [DataType
.TAB_TAT_DEFINES_TARGET
, DataType
.TAB_TAT_DEFINES_TARGET_ARCH
, \
102 DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_TAG
]:
103 self
.TargetTxtDictionary
[Key
] = Value
.split()
104 elif Key
== DataType
.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER
:
108 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid number of [%s]: %s." % (Key
, Value
),
110 self
.TargetTxtDictionary
[Key
] = Value
111 #elif Key not in GlobalData.gGlobalDefines:
112 # GlobalData.gGlobalDefines[Key] = Value
117 ## Print the dictionary
119 # Print all items of dictionary one by one
121 # @param Dict: The dictionary to be printed
125 KeyList
= Dict
.keys()
128 print Key
+ ' = ' + str(Dict
[Key
])
130 ## Print the dictionary
132 # Print the items of dictionary which matched with input key
134 # @param list: The dictionary to be printed
135 # @param key: The key of the item to be printed
137 def printList(Key
, List
):
138 if type(List
) == type([]):
140 if Key
.find(TAB_SPLIT
) != -1:
146 # Load target.txt in input workspace dir
148 # @param WorkSpace: Workspace dir
150 # @retval Target An instance of TargetTxtClassObject() with loaded target.txt
152 def TargetTxtDict(WorkSpace
):
153 Target
= TargetTxtClassObject()
154 Target
.LoadTargetTxtFile(os
.path
.normpath(os
.path
.join(WorkSpace
, gDefaultTargetTxtFile
)))
159 # This acts like the main() function for the script, unless it is 'import'ed into another
162 if __name__
== '__main__':
164 Target
= TargetTxtDict(os
.getenv("WORKSPACE"))
165 print Target
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER
]
166 print Target
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TARGET
]
167 print Target
.TargetTxtDictionary