]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Python/buildgen/BuildConfig.py
3 # Copyright (c) 2007, Intel Corporation
4 # All rights reserved. This program and the accompanying materials
5 # are licensed and made available under the terms and conditions of the BSD License
6 # which accompanies this distribution. The full text of the license may be found at
7 # http://opensource.org/licenses/bsd-license.php
9 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 """Tools and build configuration"""
17 def __init__(self
, file):
18 """file (target configuration file)"""
19 configFile
= open(file)
21 line
= configFile
.readline()
22 if line
== "": break ## no more line
26 if line
== "": continue
28 if line
[0] == '#': continue
31 print "! invalid configuration:", line
34 defStrings
= line
.split('=', 1)
35 name
= defStrings
[0].strip()
36 value
= defStrings
[1].strip()
41 def __getitem__(self
, attr
):
45 value
= dict.__getitem
__(self
, attr
)
50 class ToolConfig(dict):
51 def __init__(self
, file):
52 """file (tools configuration file path)"""
54 self
.Toolchains
= Set()
56 self
.ToolCodes
= Set()
58 self
.Attributes
= Set(["FAMILY", "NAME", "PATH", "FLAGS", "EXT", "DPATH", "SPATH", "LIBPATH", "INCLUDEPATH"])
60 configFile
= open(file)
62 line
= configFile
.readline()
67 if line
== "": continue
69 if line
[0] == '#': continue
72 print "! invalid definition:", line
75 # split the definition at the first "="
76 tool_def
= line
.split('=', 1)
77 name
= tool_def
[0].strip()
78 value
= tool_def
[1].strip()
80 # the name of a tool definition must have five parts concatenated by "_"
81 keys
= name
.split('_')
82 # skip non-definition line
83 if len(keys
) < 5: continue
85 keys
= (keys
[1], keys
[0], keys
[2], keys
[3], keys
[4])
88 ###############################################
90 ###############################################
91 if keys
[0] != '*': self
.Toolchains
.add(keys
[0])
92 if keys
[1] != '*': self
.Targets
.add(keys
[1])
93 if keys
[2] != '*': self
.Archs
.add(keys
[2])
94 if keys
[3] != '*': self
.ToolCodes
.add(keys
[3])
95 if keys
[4] == "FAMILY": self
.Families
.add(value
)
96 elif keys
[4] == '*': raise Exception("No * allowed in ATTRIBUTE field")
99 # expand the "*" in each field
102 def __getitem__(self
, attrs
):
106 if attrs
not in self
:
109 value
= dict.__getitem
__(self
, attrs
)
123 toolchains
= self
.Toolchains
125 toolchains
= [key
[0]]
127 for toolchain
in toolchains
:
129 targets
= self
.Targets
133 for target
in targets
:
141 toolcodes
= self
.ToolCodes
145 for toolcode
in toolcodes
:
147 summary
[(toolchain
, target
, arch
, toolcode
, attribute
)] = value
149 for toolchain
in self
.Toolchains
:
150 for target
in self
.Targets
:
151 for arch
in self
.Archs
:
152 for toolcode
in self
.ToolCodes
:
153 key
= (toolchain
, target
, arch
, toolcode
, "NAME")
154 if key
not in summary
: continue
155 for attr
in self
.Attributes
:
156 key
= (toolchain
, target
, arch
, toolcode
, attr
)
157 if key
not in summary
: continue
158 self
[key
] = summary
[key
]
164 s
+= entry
[0] + "_" + entry
[1] + "_" + entry
[2] + "_" + entry
[3] + "_" + entry
[4]
165 s
+= " = " + self
[entry
] + "\n"
168 class TargetConfig(Config
):
172 if __name__
== "__main__":
174 if "WORKSPACE" not in os
.environ
:
175 raise "No WORKSPACE given"
176 cfg
= ToolConfig(os
.path
.join(os
.environ
["WORKSPACE"], "Tools", "Conf", "tools_def.txt"))
177 tgt
= TargetConfig(os
.path
.join(os
.environ
["WORKSPACE"], "Tools", "Conf", "target.txt"))
180 print key
,"=",cfg
[key
]
184 print name
,"=",tgt
[name
]