2 # This file is used to define each component of Target.txt file
4 # Copyright (c) 2007 - 2014, 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.
17 import Common
.LongFilePathOs
as os
20 from BuildToolError
import *
22 from Common
.LongFilePathSupport
import OpenLongFilePath
as open
24 gDefaultTargetTxtFile
= "Conf/target.txt"
26 ## TargetTxtClassObject
28 # This class defined content used in file target.txt
30 # @param object: Inherited from object class
31 # @param Filename: Input value for full path of target.txt
33 # @var TargetTxtDictionary: To store keys and values defined in target.txt
35 class TargetTxtClassObject(object):
36 def __init__(self
, Filename
= None):
37 self
.TargetTxtDictionary
= {
38 DataType
.TAB_TAT_DEFINES_ACTIVE_PLATFORM
: '',
39 DataType
.TAB_TAT_DEFINES_ACTIVE_MODULE
: '',
40 DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
: '',
41 DataType
.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER
: '',
42 DataType
.TAB_TAT_DEFINES_TARGET
: [],
43 DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_TAG
: [],
44 DataType
.TAB_TAT_DEFINES_TARGET_ARCH
: [],
45 DataType
.TAB_TAT_DEFINES_BUILD_RULE_CONF
: '',
48 self
.LoadTargetTxtFile(Filename
)
52 # Load target.txt file and parse it, return a set structure to store keys and values
54 # @param Filename: Input value for full path of target.txt
56 # @retval set() A set structure to store keys and values
57 # @retval 1 Error happenes in parsing
59 def LoadTargetTxtFile(self
, Filename
):
60 if os
.path
.exists(Filename
) and os
.path
.isfile(Filename
):
61 return self
.ConvertTextFileToDict(Filename
, '#', '=')
63 EdkLogger
.error("Target.txt Parser", FILE_NOT_FOUND
, ExtraData
=Filename
)
66 ## ConvertTextFileToDict
68 # Convert a text file to a dictionary of (name:value) pairs.
69 # The data is saved to self.TargetTxtDictionary
71 # @param FileName: Text filename
72 # @param CommentCharacter: Comment char, be used to ignore comment content
73 # @param KeySplitCharacter: Key split char, between key name and key value. Key1 = Value1, '=' is the key split char
75 # @retval 0 Convert successfully
76 # @retval 1 Open file failed
78 def ConvertTextFileToDict(self
, FileName
, CommentCharacter
, KeySplitCharacter
):
81 F
= open(FileName
,'r')
83 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=FileName
)
89 if Line
.startswith(CommentCharacter
) or Line
== '':
92 LineList
= Line
.split(KeySplitCharacter
, 1)
93 Key
= LineList
[0].strip()
94 if len(LineList
) == 2:
95 Value
= LineList
[1].strip()
99 if Key
in [DataType
.TAB_TAT_DEFINES_ACTIVE_PLATFORM
, DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_CONF
, \
100 DataType
.TAB_TAT_DEFINES_ACTIVE_MODULE
, DataType
.TAB_TAT_DEFINES_BUILD_RULE_CONF
]:
101 self
.TargetTxtDictionary
[Key
] = Value
.replace('\\', '/')
102 elif Key
in [DataType
.TAB_TAT_DEFINES_TARGET
, DataType
.TAB_TAT_DEFINES_TARGET_ARCH
, \
103 DataType
.TAB_TAT_DEFINES_TOOL_CHAIN_TAG
]:
104 self
.TargetTxtDictionary
[Key
] = Value
.split()
105 elif Key
== DataType
.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER
:
109 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid number of [%s]: %s." % (Key
, Value
),
111 self
.TargetTxtDictionary
[Key
] = Value
112 #elif Key not in GlobalData.gGlobalDefines:
113 # GlobalData.gGlobalDefines[Key] = Value
118 ## Print the dictionary
120 # Print all items of dictionary one by one
122 # @param Dict: The dictionary to be printed
126 KeyList
= Dict
.keys()
129 print Key
+ ' = ' + str(Dict
[Key
])
131 ## Print the dictionary
133 # Print the items of dictionary which matched with input key
135 # @param list: The dictionary to be printed
136 # @param key: The key of the item to be printed
138 def printList(Key
, List
):
139 if type(List
) == type([]):
141 if Key
.find(TAB_SPLIT
) != -1:
147 # Load target.txt in input workspace dir
149 # @param WorkSpace: Workspace dir
151 # @retval Target An instance of TargetTxtClassObject() with loaded target.txt
153 def TargetTxtDict(WorkSpace
):
154 Target
= TargetTxtClassObject()
155 Target
.LoadTargetTxtFile(os
.path
.normpath(os
.path
.join(WorkSpace
, gDefaultTargetTxtFile
)))
160 # This acts like the main() function for the script, unless it is 'import'ed into another
163 if __name__
== '__main__':
165 Target
= TargetTxtDict(os
.getenv("WORKSPACE"))
166 print Target
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER
]
167 print Target
.TargetTxtDictionary
[DataType
.TAB_TAT_DEFINES_TARGET
]
168 print Target
.TargetTxtDictionary