]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
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
)
161 def SetFileTimeStamp(self
,FileId
,TimeStamp
):
162 self
.TblFile
[FileId
-1][6] = TimeStamp
164 def GetFileTimeStamp(self
,FileId
):
165 return self
.TblFile
[FileId
-1][6]
168 ## Summarize all packages in the database
169 def GetPackageList(self
, Platform
, Arch
, TargetName
, ToolChainTag
):
170 self
.Platform
= Platform
172 Pa
= self
.BuildObject
[self
.Platform
, Arch
, TargetName
, ToolChainTag
]
174 # Get Package related to Modules
176 for Module
in Pa
.Modules
:
177 ModuleObj
= self
.BuildObject
[Module
, Arch
, TargetName
, ToolChainTag
]
178 for Package
in ModuleObj
.Packages
:
179 if Package
not in PackageList
:
180 PackageList
.append(Package
)
182 # Get Packages related to Libraries
184 for Lib
in Pa
.LibraryInstances
:
185 LibObj
= self
.BuildObject
[Lib
, Arch
, TargetName
, ToolChainTag
]
186 for Package
in LibObj
.Packages
:
187 if Package
not in PackageList
:
188 PackageList
.append(Package
)
189 for Package
in Pa
.Packages
:
190 if Package
in PackageList
:
192 PackageList
.append(Package
)
196 ## Summarize all platforms in the database
197 def PlatformList(self
):
199 for PlatformFile
in [item
[3] for item
in self
.TblFile
if item
[5] == MODEL_FILE_DSC
]:
201 RetVal
.append(self
.BuildObject
[PathClass(PlatformFile
), TAB_COMMON
])
206 def MapPlatform(self
, Dscfile
):
207 Platform
= self
.BuildObject
[PathClass(Dscfile
), TAB_COMMON
]
209 EdkLogger
.error('build', PARSER_ERROR
, "Failed to parser DSC file: %s" % Dscfile
)
212 BuildDB
= WorkspaceDatabase()
215 # This acts like the main() function for the script, unless it is 'import'ed into another
218 if __name__
== '__main__':