]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/AutoGen/AutoGen.py
2 # Generate AutoGen.h, AutoGen.c and *.depex files
4 # Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>
5 # Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>
6 # Copyright (c) 2019, American Megatrends, Inc. All rights reserved.<BR>
8 # SPDX-License-Identifier: BSD-2-Clause-Patent
13 from __future__
import print_function
14 from __future__
import absolute_import
15 from Common
.DataType
import TAB_STAR
16 ## Base class for AutoGen
18 # This class just implements the cache mechanism of AutoGen objects.
20 class AutoGen(object):
21 # database to maintain the objects in each child class
22 __ObjectCache
= {} # (BuildTarget, ToolChain, ARCH, platform file): AutoGen object
26 # @param Class class object of real AutoGen class
27 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)
28 # @param Workspace Workspace directory or WorkspaceAutoGen object
29 # @param MetaFile The path of meta file
30 # @param Target Build target
31 # @param Toolchain Tool chain name
32 # @param Arch Target arch
33 # @param *args The specific class related parameters
34 # @param **kwargs The specific class related dict parameters
37 def __new__(cls
, Workspace
, MetaFile
, Target
, Toolchain
, Arch
, *args
, **kwargs
):
38 # check if the object has been created
39 Key
= (Target
, Toolchain
, Arch
, MetaFile
)
40 if Key
in cls
.__ObjectCache
:
41 # if it exists, just return it directly
42 return cls
.__ObjectCache
[Key
]
43 # it didnt exist. create it, cache it, then return it
44 RetVal
= cls
.__ObjectCache
[Key
] = super(AutoGen
, cls
).__new
__(cls
)
50 # The file path of platform file will be used to represent hash value of this object
52 # @retval int Hash value of the file path of platform file
55 return hash(self
.MetaFile
)
59 # The file path of platform file will be used to represent this object
61 # @retval string String of platform file path
64 return str(self
.MetaFile
)
67 def __eq__(self
, Other
):
68 return Other
and self
.MetaFile
== Other
72 return cls
.__ObjectCache
75 # The priority list while override build option
77 PrioList
= {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)
78 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
79 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE
80 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE
81 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
82 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
83 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE
84 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE
85 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE
86 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE
87 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE
88 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE
89 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE
90 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE
91 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE
92 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)
93 ## Calculate the priority value of the build option
95 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
97 # @retval Value Priority value based on the priority list.
99 def CalculatePriorityValue(Key
):
100 Target
, ToolChain
, Arch
, CommandType
, Attr
= Key
.split('_')
101 PriorityValue
= 0x11111
102 if Target
== TAB_STAR
:
103 PriorityValue
&= 0x01111
104 if ToolChain
== TAB_STAR
:
105 PriorityValue
&= 0x10111
107 PriorityValue
&= 0x11011
108 if CommandType
== TAB_STAR
:
109 PriorityValue
&= 0x11101
111 PriorityValue
&= 0x11110
113 return PrioList
["0x%0.5x" % PriorityValue
]