]>
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 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 from __future__
import absolute_import
19 from Common
.StringUtils
import *
20 from Common
.DataType
import *
21 from Common
.Misc
import *
24 from .MetaDataTable
import *
25 from .MetaFileTable
import *
26 from .MetaFileParser
import *
28 from Workspace
.DecBuildData
import DecBuildData
29 from Workspace
.DscBuildData
import DscBuildData
30 from Workspace
.InfBuildData
import InfBuildData
34 # This class defined the build database for all modules, packages and platform.
35 # It will call corresponding parser for the given file if it cannot find it in
38 # @param DbPath Path of database file
39 # @param GlobalMacros Global macros used for replacement during file parsing
40 # @param RenewDb=False Create new database file if it's already there
42 class WorkspaceDatabase(object):
45 # internal class used for call corresponding file parser and caching the result
46 # to avoid unnecessary re-parsing
48 class BuildObjectFactory(object):
51 ".inf" : MODEL_FILE_INF
,
52 ".dec" : MODEL_FILE_DEC
,
53 ".dsc" : MODEL_FILE_DSC
,
58 MODEL_FILE_INF
: InfParser
,
59 MODEL_FILE_DEC
: DecParser
,
60 MODEL_FILE_DSC
: DscParser
,
63 # convert to xxxBuildData object
65 MODEL_FILE_INF
: InfBuildData
,
66 MODEL_FILE_DEC
: DecBuildData
,
67 MODEL_FILE_DSC
: DscBuildData
,
70 _CACHE_
= {} # (FilePath, Arch) : <object>
73 def __init__(self
, WorkspaceDb
):
74 self
.WorkspaceDb
= WorkspaceDb
76 # key = (FilePath, Arch=None)
77 def __contains__(self
, Key
):
83 return (FilePath
, Arch
) in self
._CACHE
_
85 # key = (FilePath, Arch=None, Target=None, Toolchain=None)
86 def __getitem__(self
, Key
):
102 # if it's generated before, just return the cached one
103 Key
= (FilePath
, Arch
, Target
, Toolchain
)
104 if Key
in self
._CACHE
_:
105 return self
._CACHE
_[Key
]
108 BuildObject
= self
.CreateBuildObject(FilePath
, Arch
, Target
, Toolchain
)
109 self
._CACHE
_[Key
] = BuildObject
111 def CreateBuildObject(self
,FilePath
, Arch
, Target
, Toolchain
):
113 if Ext
not in self
._FILE
_TYPE
_:
115 FileType
= self
._FILE
_TYPE
_[Ext
]
116 if FileType
not in self
._GENERATOR
_:
119 # get the parser ready for this file
120 MetaFile
= self
._FILE
_PARSER
_[FileType
](
124 MetaFileStorage(self
.WorkspaceDb
, FilePath
, FileType
)
126 # always do post-process, in case of macros change
127 MetaFile
.DoPostProcess()
128 # object the build is based on
129 BuildObject
= self
._GENERATOR
_[FileType
](
139 # placeholder for file format conversion
140 class TransformObjectFactory
:
141 def __init__(self
, WorkspaceDb
):
142 self
.WorkspaceDb
= WorkspaceDb
144 # key = FilePath, Arch
145 def __getitem__(self
, Key
):
148 ## Constructor of WorkspaceDatabase
150 # @param DbPath Path of database file
151 # @param GlobalMacros Global macros used for replacement during file parsing
152 # @param RenewDb=False Create new database file if it's already there
156 # create table for internal uses
157 self
.TblDataModel
= DataClass
.MODEL_LIST
161 # conversion object for build or file format conversion purpose
162 self
.BuildObject
= WorkspaceDatabase
.BuildObjectFactory(self
)
163 self
.TransformObject
= WorkspaceDatabase
.TransformObjectFactory(self
)
165 def SetFileTimeStamp(self
,FileId
,TimeStamp
):
166 self
.TblFile
[FileId
-1][6] = TimeStamp
168 def GetFileTimeStamp(self
,FileId
):
169 return self
.TblFile
[FileId
-1][6]
172 ## Summarize all packages in the database
173 def GetPackageList(self
, Platform
, Arch
, TargetName
, ToolChainTag
):
174 self
.Platform
= Platform
176 Pa
= self
.BuildObject
[self
.Platform
, Arch
, TargetName
, ToolChainTag
]
178 # Get Package related to Modules
180 for Module
in Pa
.Modules
:
181 ModuleObj
= self
.BuildObject
[Module
, Arch
, TargetName
, ToolChainTag
]
182 for Package
in ModuleObj
.Packages
:
183 if Package
not in PackageList
:
184 PackageList
.append(Package
)
186 # Get Packages related to Libraries
188 for Lib
in Pa
.LibraryInstances
:
189 LibObj
= self
.BuildObject
[Lib
, Arch
, TargetName
, ToolChainTag
]
190 for Package
in LibObj
.Packages
:
191 if Package
not 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
)
214 # This acts like the main() function for the script, unless it is 'import'ed into another
217 if __name__
== '__main__':