]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
d955c78b258f5299ed0a0b384fa1a5ccb194fe8e
2 # This file is used to create a database used by build tool
4 # Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
5 # (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
12 from __future__
import absolute_import
13 from Common
.StringUtils
import *
14 from Common
.DataType
import *
15 from Common
.Misc
import *
18 from .MetaDataTable
import *
19 from .MetaFileTable
import *
20 from .MetaFileParser
import *
22 from Workspace
.DecBuildData
import DecBuildData
23 from Workspace
.DscBuildData
import DscBuildData
24 from Workspace
.InfBuildData
import InfBuildData
28 # This class defined the build database for all modules, packages and platform.
29 # It will call corresponding parser for the given file if it cannot find it in
32 # @param DbPath Path of database file
33 # @param GlobalMacros Global macros used for replacement during file parsing
34 # @param RenewDb=False Create new database file if it's already there
36 class WorkspaceDatabase(object):
39 # internal class used for call corresponding file parser and caching the result
40 # to avoid unnecessary re-parsing
42 class BuildObjectFactory(object):
45 ".inf" : MODEL_FILE_INF
,
46 ".dec" : MODEL_FILE_DEC
,
47 ".dsc" : MODEL_FILE_DSC
,
52 MODEL_FILE_INF
: InfParser
,
53 MODEL_FILE_DEC
: DecParser
,
54 MODEL_FILE_DSC
: DscParser
,
57 # convert to xxxBuildData object
59 MODEL_FILE_INF
: InfBuildData
,
60 MODEL_FILE_DEC
: DecBuildData
,
61 MODEL_FILE_DSC
: DscBuildData
,
64 _CACHE_
= {} # (FilePath, Arch) : <object>
69 def __init__(self
, WorkspaceDb
):
70 self
.WorkspaceDb
= WorkspaceDb
72 # key = (FilePath, Arch=None)
73 def __contains__(self
, Key
):
79 return (FilePath
, Arch
) in self
._CACHE
_
81 # key = (FilePath, Arch=None, Target=None, Toolchain=None)
82 def __getitem__(self
, Key
):
98 # if it's generated before, just return the cached one
99 Key
= (FilePath
, Arch
, Target
, Toolchain
)
100 if Key
in self
._CACHE
_:
101 return self
._CACHE
_[Key
]
104 BuildObject
= self
.CreateBuildObject(FilePath
, Arch
, Target
, Toolchain
)
105 self
._CACHE
_[Key
] = BuildObject
107 def CreateBuildObject(self
,FilePath
, Arch
, Target
, Toolchain
):
109 if Ext
not in self
._FILE
_TYPE
_:
111 FileType
= self
._FILE
_TYPE
_[Ext
]
112 if FileType
not in self
._GENERATOR
_:
115 # get the parser ready for this file
116 MetaFile
= self
._FILE
_PARSER
_[FileType
](
120 MetaFileStorage(self
.WorkspaceDb
, FilePath
, FileType
)
122 # always do post-process, in case of macros change
123 MetaFile
.DoPostProcess()
124 # object the build is based on
125 BuildObject
= self
._GENERATOR
_[FileType
](
135 # placeholder for file format conversion
136 class TransformObjectFactory
:
137 def __init__(self
, WorkspaceDb
):
138 self
.WorkspaceDb
= WorkspaceDb
140 # key = FilePath, Arch
141 def __getitem__(self
, Key
):
144 ## Constructor of WorkspaceDatabase
146 # @param DbPath Path of database file
147 # @param GlobalMacros Global macros used for replacement during file parsing
148 # @param RenewDb=False Create new database file if it's already there
152 # create table for internal uses
153 self
.TblDataModel
= DataClass
.MODEL_LIST
157 # conversion object for build or file format conversion purpose
158 self
.BuildObject
= WorkspaceDatabase
.BuildObjectFactory(self
)
159 self
.TransformObject
= WorkspaceDatabase
.TransformObjectFactory(self
)
162 ## Summarize all packages in the database
163 def GetPackageList(self
, Platform
, Arch
, TargetName
, ToolChainTag
):
164 self
.Platform
= Platform
166 Pa
= self
.BuildObject
[self
.Platform
, Arch
, TargetName
, ToolChainTag
]
168 # Get Package related to Modules
170 for Module
in Pa
.Modules
:
171 ModuleObj
= self
.BuildObject
[Module
, Arch
, TargetName
, ToolChainTag
]
172 for Package
in ModuleObj
.Packages
:
173 if Package
not in PackageList
:
174 PackageList
.append(Package
)
176 # Get Packages related to Libraries
178 for Lib
in Pa
.LibraryInstances
:
179 LibObj
= self
.BuildObject
[Lib
, Arch
, TargetName
, ToolChainTag
]
180 for Package
in LibObj
.Packages
:
181 if Package
not in PackageList
:
182 PackageList
.append(Package
)
183 for Package
in Pa
.Packages
:
184 if Package
in PackageList
:
186 PackageList
.append(Package
)
190 def MapPlatform(self
, Dscfile
):
191 Platform
= self
.BuildObject
[PathClass(Dscfile
), TAB_COMMON
]
193 EdkLogger
.error('build', PARSER_ERROR
, "Failed to parser DSC file: %s" % Dscfile
)
196 BuildDB
= WorkspaceDatabase()
199 # This acts like the main() function for the script, unless it is 'import'ed into another
202 if __name__
== '__main__':