Sync BaseTool trunk (version r2649) into EDKII BaseTools.
Signed-off-by: Gao, Liming <liming.gao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15188 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -1,154 +1,154 @@
|
||||
## @file
|
||||
# Standardized Error Hanlding infrastructures.
|
||||
#
|
||||
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
FILE_OPEN_FAILURE = 1
|
||||
FILE_WRITE_FAILURE = 2
|
||||
FILE_PARSE_FAILURE = 3
|
||||
FILE_READ_FAILURE = 4
|
||||
FILE_CREATE_FAILURE = 5
|
||||
FILE_CHECKSUM_FAILURE = 6
|
||||
FILE_COMPRESS_FAILURE = 7
|
||||
FILE_DECOMPRESS_FAILURE = 8
|
||||
FILE_MOVE_FAILURE = 9
|
||||
FILE_DELETE_FAILURE = 10
|
||||
FILE_COPY_FAILURE = 11
|
||||
FILE_POSITIONING_FAILURE = 12
|
||||
FILE_ALREADY_EXIST = 13
|
||||
FILE_NOT_FOUND = 14
|
||||
FILE_TYPE_MISMATCH = 15
|
||||
FILE_CASE_MISMATCH = 16
|
||||
FILE_DUPLICATED = 17
|
||||
FILE_UNKNOWN_ERROR = 0x0FFF
|
||||
|
||||
OPTION_UNKNOWN = 0x1000
|
||||
OPTION_MISSING = 0x1001
|
||||
OPTION_CONFLICT = 0x1002
|
||||
OPTION_VALUE_INVALID = 0x1003
|
||||
OPTION_DEPRECATED = 0x1004
|
||||
OPTION_NOT_SUPPORTED = 0x1005
|
||||
OPTION_UNKNOWN_ERROR = 0x1FFF
|
||||
|
||||
PARAMETER_INVALID = 0x2000
|
||||
PARAMETER_MISSING = 0x2001
|
||||
PARAMETER_UNKNOWN_ERROR =0x2FFF
|
||||
|
||||
FORMAT_INVALID = 0x3000
|
||||
FORMAT_NOT_SUPPORTED = 0x3001
|
||||
FORMAT_UNKNOWN = 0x3002
|
||||
FORMAT_UNKNOWN_ERROR = 0x3FFF
|
||||
|
||||
RESOURCE_NOT_AVAILABLE = 0x4000
|
||||
RESOURCE_ALLOCATE_FAILURE = 0x4001
|
||||
RESOURCE_FULL = 0x4002
|
||||
RESOURCE_OVERFLOW = 0x4003
|
||||
RESOURCE_UNDERRUN = 0x4004
|
||||
RESOURCE_UNKNOWN_ERROR = 0x4FFF
|
||||
|
||||
ATTRIBUTE_NOT_AVAILABLE = 0x5000
|
||||
ATTRIBUTE_GET_FAILURE = 0x5001
|
||||
ATTRIBUTE_SET_FAILURE = 0x5002
|
||||
ATTRIBUTE_UPDATE_FAILURE = 0x5003
|
||||
ATTRIBUTE_ACCESS_DENIED = 0x5004
|
||||
ATTRIBUTE_UNKNOWN_ERROR = 0x5FFF
|
||||
|
||||
IO_NOT_READY = 0x6000
|
||||
IO_BUSY = 0x6001
|
||||
IO_TIMEOUT = 0x6002
|
||||
IO_UNKNOWN_ERROR = 0x6FFF
|
||||
|
||||
COMMAND_FAILURE = 0x7000
|
||||
|
||||
PERMISSION_FAILURE = 0x8000
|
||||
|
||||
CODE_ERROR = 0xC0DE
|
||||
|
||||
AUTOGEN_ERROR = 0xF000
|
||||
PARSER_ERROR = 0xF001
|
||||
BUILD_ERROR = 0xF002
|
||||
GENFDS_ERROR = 0xF003
|
||||
ECC_ERROR = 0xF004
|
||||
EOT_ERROR = 0xF005
|
||||
DDC_ERROR = 0xF009
|
||||
WARNING_AS_ERROR = 0xF006
|
||||
MIGRATION_ERROR = 0xF010
|
||||
ABORT_ERROR = 0xFFFE
|
||||
UNKNOWN_ERROR = 0xFFFF
|
||||
|
||||
## Error message of each error code
|
||||
gErrorMessage = {
|
||||
FILE_NOT_FOUND : "File/directory not found in workspace",
|
||||
FILE_OPEN_FAILURE : "File open failure",
|
||||
FILE_WRITE_FAILURE : "File write failure",
|
||||
FILE_PARSE_FAILURE : "File parse failure",
|
||||
FILE_READ_FAILURE : "File read failure",
|
||||
FILE_CREATE_FAILURE : "File create failure",
|
||||
FILE_CHECKSUM_FAILURE : "Invalid checksum of file",
|
||||
FILE_COMPRESS_FAILURE : "File compress failure",
|
||||
FILE_DECOMPRESS_FAILURE : "File decompress failure",
|
||||
FILE_MOVE_FAILURE : "File move failure",
|
||||
FILE_DELETE_FAILURE : "File delete failure",
|
||||
FILE_COPY_FAILURE : "File copy failure",
|
||||
FILE_POSITIONING_FAILURE: "Failed to seeking position",
|
||||
FILE_ALREADY_EXIST : "File or directory already exists",
|
||||
FILE_TYPE_MISMATCH : "Incorrect file type",
|
||||
FILE_CASE_MISMATCH : "File name case mismatch",
|
||||
FILE_DUPLICATED : "Duplicated file found",
|
||||
FILE_UNKNOWN_ERROR : "Unknown error encountered on file",
|
||||
|
||||
OPTION_UNKNOWN : "Unknown option",
|
||||
OPTION_MISSING : "Missing option",
|
||||
OPTION_CONFLICT : "Conflict options",
|
||||
OPTION_VALUE_INVALID : "Invalid value of option",
|
||||
OPTION_DEPRECATED : "Deprecated option",
|
||||
OPTION_NOT_SUPPORTED : "Unsupported option",
|
||||
OPTION_UNKNOWN_ERROR : "Unknown error when processing options",
|
||||
|
||||
PARAMETER_INVALID : "Invalid parameter",
|
||||
PARAMETER_MISSING : "Missing parameter",
|
||||
PARAMETER_UNKNOWN_ERROR : "Unknown error in parameters",
|
||||
|
||||
FORMAT_INVALID : "Invalid syntax/format",
|
||||
FORMAT_NOT_SUPPORTED : "Not supported syntax/format",
|
||||
FORMAT_UNKNOWN : "Unknown format",
|
||||
FORMAT_UNKNOWN_ERROR : "Unknown error in syntax/format ",
|
||||
|
||||
RESOURCE_NOT_AVAILABLE : "Not available",
|
||||
RESOURCE_ALLOCATE_FAILURE : "Allocate failure",
|
||||
RESOURCE_FULL : "Full",
|
||||
RESOURCE_OVERFLOW : "Overflow",
|
||||
RESOURCE_UNDERRUN : "Underrun",
|
||||
RESOURCE_UNKNOWN_ERROR : "Unknown error",
|
||||
|
||||
ATTRIBUTE_NOT_AVAILABLE : "Not available",
|
||||
ATTRIBUTE_GET_FAILURE : "Failed to retrieve",
|
||||
ATTRIBUTE_SET_FAILURE : "Failed to set",
|
||||
ATTRIBUTE_UPDATE_FAILURE: "Failed to update",
|
||||
ATTRIBUTE_ACCESS_DENIED : "Access denied",
|
||||
ATTRIBUTE_UNKNOWN_ERROR : "Unknown error when accessing",
|
||||
|
||||
COMMAND_FAILURE : "Failed to execute command",
|
||||
|
||||
IO_NOT_READY : "Not ready",
|
||||
IO_BUSY : "Busy",
|
||||
IO_TIMEOUT : "Timeout",
|
||||
IO_UNKNOWN_ERROR : "Unknown error in IO operation",
|
||||
|
||||
UNKNOWN_ERROR : "Unknown error",
|
||||
}
|
||||
|
||||
## Exception indicating a fatal error
|
||||
class FatalError(Exception):
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
## @file
|
||||
# Standardized Error Hanlding infrastructures.
|
||||
#
|
||||
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
FILE_OPEN_FAILURE = 1
|
||||
FILE_WRITE_FAILURE = 2
|
||||
FILE_PARSE_FAILURE = 3
|
||||
FILE_READ_FAILURE = 4
|
||||
FILE_CREATE_FAILURE = 5
|
||||
FILE_CHECKSUM_FAILURE = 6
|
||||
FILE_COMPRESS_FAILURE = 7
|
||||
FILE_DECOMPRESS_FAILURE = 8
|
||||
FILE_MOVE_FAILURE = 9
|
||||
FILE_DELETE_FAILURE = 10
|
||||
FILE_COPY_FAILURE = 11
|
||||
FILE_POSITIONING_FAILURE = 12
|
||||
FILE_ALREADY_EXIST = 13
|
||||
FILE_NOT_FOUND = 14
|
||||
FILE_TYPE_MISMATCH = 15
|
||||
FILE_CASE_MISMATCH = 16
|
||||
FILE_DUPLICATED = 17
|
||||
FILE_UNKNOWN_ERROR = 0x0FFF
|
||||
|
||||
OPTION_UNKNOWN = 0x1000
|
||||
OPTION_MISSING = 0x1001
|
||||
OPTION_CONFLICT = 0x1002
|
||||
OPTION_VALUE_INVALID = 0x1003
|
||||
OPTION_DEPRECATED = 0x1004
|
||||
OPTION_NOT_SUPPORTED = 0x1005
|
||||
OPTION_UNKNOWN_ERROR = 0x1FFF
|
||||
|
||||
PARAMETER_INVALID = 0x2000
|
||||
PARAMETER_MISSING = 0x2001
|
||||
PARAMETER_UNKNOWN_ERROR =0x2FFF
|
||||
|
||||
FORMAT_INVALID = 0x3000
|
||||
FORMAT_NOT_SUPPORTED = 0x3001
|
||||
FORMAT_UNKNOWN = 0x3002
|
||||
FORMAT_UNKNOWN_ERROR = 0x3FFF
|
||||
|
||||
RESOURCE_NOT_AVAILABLE = 0x4000
|
||||
RESOURCE_ALLOCATE_FAILURE = 0x4001
|
||||
RESOURCE_FULL = 0x4002
|
||||
RESOURCE_OVERFLOW = 0x4003
|
||||
RESOURCE_UNDERRUN = 0x4004
|
||||
RESOURCE_UNKNOWN_ERROR = 0x4FFF
|
||||
|
||||
ATTRIBUTE_NOT_AVAILABLE = 0x5000
|
||||
ATTRIBUTE_GET_FAILURE = 0x5001
|
||||
ATTRIBUTE_SET_FAILURE = 0x5002
|
||||
ATTRIBUTE_UPDATE_FAILURE = 0x5003
|
||||
ATTRIBUTE_ACCESS_DENIED = 0x5004
|
||||
ATTRIBUTE_UNKNOWN_ERROR = 0x5FFF
|
||||
|
||||
IO_NOT_READY = 0x6000
|
||||
IO_BUSY = 0x6001
|
||||
IO_TIMEOUT = 0x6002
|
||||
IO_UNKNOWN_ERROR = 0x6FFF
|
||||
|
||||
COMMAND_FAILURE = 0x7000
|
||||
|
||||
PERMISSION_FAILURE = 0x8000
|
||||
|
||||
CODE_ERROR = 0xC0DE
|
||||
|
||||
AUTOGEN_ERROR = 0xF000
|
||||
PARSER_ERROR = 0xF001
|
||||
BUILD_ERROR = 0xF002
|
||||
GENFDS_ERROR = 0xF003
|
||||
ECC_ERROR = 0xF004
|
||||
EOT_ERROR = 0xF005
|
||||
DDC_ERROR = 0xF009
|
||||
WARNING_AS_ERROR = 0xF006
|
||||
MIGRATION_ERROR = 0xF010
|
||||
ABORT_ERROR = 0xFFFE
|
||||
UNKNOWN_ERROR = 0xFFFF
|
||||
|
||||
## Error message of each error code
|
||||
gErrorMessage = {
|
||||
FILE_NOT_FOUND : "File/directory not found in workspace",
|
||||
FILE_OPEN_FAILURE : "File open failure",
|
||||
FILE_WRITE_FAILURE : "File write failure",
|
||||
FILE_PARSE_FAILURE : "File parse failure",
|
||||
FILE_READ_FAILURE : "File read failure",
|
||||
FILE_CREATE_FAILURE : "File create failure",
|
||||
FILE_CHECKSUM_FAILURE : "Invalid checksum of file",
|
||||
FILE_COMPRESS_FAILURE : "File compress failure",
|
||||
FILE_DECOMPRESS_FAILURE : "File decompress failure",
|
||||
FILE_MOVE_FAILURE : "File move failure",
|
||||
FILE_DELETE_FAILURE : "File delete failure",
|
||||
FILE_COPY_FAILURE : "File copy failure",
|
||||
FILE_POSITIONING_FAILURE: "Failed to seeking position",
|
||||
FILE_ALREADY_EXIST : "File or directory already exists",
|
||||
FILE_TYPE_MISMATCH : "Incorrect file type",
|
||||
FILE_CASE_MISMATCH : "File name case mismatch",
|
||||
FILE_DUPLICATED : "Duplicated file found",
|
||||
FILE_UNKNOWN_ERROR : "Unknown error encountered on file",
|
||||
|
||||
OPTION_UNKNOWN : "Unknown option",
|
||||
OPTION_MISSING : "Missing option",
|
||||
OPTION_CONFLICT : "Conflict options",
|
||||
OPTION_VALUE_INVALID : "Invalid value of option",
|
||||
OPTION_DEPRECATED : "Deprecated option",
|
||||
OPTION_NOT_SUPPORTED : "Unsupported option",
|
||||
OPTION_UNKNOWN_ERROR : "Unknown error when processing options",
|
||||
|
||||
PARAMETER_INVALID : "Invalid parameter",
|
||||
PARAMETER_MISSING : "Missing parameter",
|
||||
PARAMETER_UNKNOWN_ERROR : "Unknown error in parameters",
|
||||
|
||||
FORMAT_INVALID : "Invalid syntax/format",
|
||||
FORMAT_NOT_SUPPORTED : "Not supported syntax/format",
|
||||
FORMAT_UNKNOWN : "Unknown format",
|
||||
FORMAT_UNKNOWN_ERROR : "Unknown error in syntax/format ",
|
||||
|
||||
RESOURCE_NOT_AVAILABLE : "Not available",
|
||||
RESOURCE_ALLOCATE_FAILURE : "Allocate failure",
|
||||
RESOURCE_FULL : "Full",
|
||||
RESOURCE_OVERFLOW : "Overflow",
|
||||
RESOURCE_UNDERRUN : "Underrun",
|
||||
RESOURCE_UNKNOWN_ERROR : "Unknown error",
|
||||
|
||||
ATTRIBUTE_NOT_AVAILABLE : "Not available",
|
||||
ATTRIBUTE_GET_FAILURE : "Failed to retrieve",
|
||||
ATTRIBUTE_SET_FAILURE : "Failed to set",
|
||||
ATTRIBUTE_UPDATE_FAILURE: "Failed to update",
|
||||
ATTRIBUTE_ACCESS_DENIED : "Access denied",
|
||||
ATTRIBUTE_UNKNOWN_ERROR : "Unknown error when accessing",
|
||||
|
||||
COMMAND_FAILURE : "Failed to execute command",
|
||||
|
||||
IO_NOT_READY : "Not ready",
|
||||
IO_BUSY : "Busy",
|
||||
IO_TIMEOUT : "Timeout",
|
||||
IO_UNKNOWN_ERROR : "Unknown error in IO operation",
|
||||
|
||||
UNKNOWN_ERROR : "Unknown error",
|
||||
}
|
||||
|
||||
## Exception indicating a fatal error
|
||||
class FatalError(Exception):
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
|
@@ -13,4 +13,4 @@
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
gBUILD_VERSION = "Build 2640"
|
||||
gBUILD_VERSION = "Build 2649"
|
||||
|
@@ -1,269 +1,269 @@
|
||||
## @file
|
||||
# This file implements the log mechanism for Python tools.
|
||||
#
|
||||
# Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
## Import modules
|
||||
import sys, os, logging
|
||||
import traceback
|
||||
from BuildToolError import *
|
||||
|
||||
## Log level constants
|
||||
DEBUG_0 = 1
|
||||
DEBUG_1 = 2
|
||||
DEBUG_2 = 3
|
||||
DEBUG_3 = 4
|
||||
DEBUG_4 = 5
|
||||
DEBUG_5 = 6
|
||||
DEBUG_6 = 7
|
||||
DEBUG_7 = 8
|
||||
DEBUG_8 = 9
|
||||
DEBUG_9 = 10
|
||||
VERBOSE = 15
|
||||
INFO = 20
|
||||
WARN = 30
|
||||
QUIET = 40
|
||||
ERROR = 50
|
||||
|
||||
IsRaiseError = True
|
||||
|
||||
# Tool name
|
||||
_ToolName = os.path.basename(sys.argv[0])
|
||||
|
||||
# For validation purpose
|
||||
_LogLevels = [DEBUG_0, DEBUG_1, DEBUG_2, DEBUG_3, DEBUG_4, DEBUG_5, DEBUG_6, DEBUG_7, DEBUG_8, DEBUG_9, VERBOSE, WARN, INFO, ERROR, QUIET]
|
||||
|
||||
# For DEBUG level (All DEBUG_0~9 are applicable)
|
||||
_DebugLogger = logging.getLogger("tool_debug")
|
||||
_DebugFormatter = logging.Formatter("[%(asctime)s.%(msecs)d]: %(message)s", datefmt="%H:%M:%S")
|
||||
|
||||
# For VERBOSE, INFO, WARN level
|
||||
_InfoLogger = logging.getLogger("tool_info")
|
||||
_InfoFormatter = logging.Formatter("%(message)s")
|
||||
|
||||
# For ERROR level
|
||||
_ErrorLogger = logging.getLogger("tool_error")
|
||||
_ErrorFormatter = logging.Formatter("%(message)s")
|
||||
|
||||
# String templates for ERROR/WARN/DEBUG log message
|
||||
_ErrorMessageTemplate = '\n\n%(tool)s...\n%(file)s(%(line)s): error %(errorcode)04X: %(msg)s\n\t%(extra)s'
|
||||
_ErrorMessageTemplateWithoutFile = '\n\n%(tool)s...\n : error %(errorcode)04X: %(msg)s\n\t%(extra)s'
|
||||
_WarningMessageTemplate = '%(tool)s...\n%(file)s(%(line)s): warning: %(msg)s'
|
||||
_WarningMessageTemplateWithoutFile = '%(tool)s: : warning: %(msg)s'
|
||||
_DebugMessageTemplate = '%(file)s(%(line)s): debug: \n %(msg)s'
|
||||
|
||||
#
|
||||
# Flag used to take WARN as ERROR.
|
||||
# By default, only ERROR message will break the tools execution.
|
||||
#
|
||||
_WarningAsError = False
|
||||
|
||||
## Log debug message
|
||||
#
|
||||
# @param Level DEBUG level (DEBUG0~9)
|
||||
# @param Message Debug information
|
||||
# @param ExtraData More information associated with "Message"
|
||||
#
|
||||
def debug(Level, Message, ExtraData=None):
|
||||
if _DebugLogger.level > Level:
|
||||
return
|
||||
if Level > DEBUG_9:
|
||||
return
|
||||
|
||||
# Find out the caller method information
|
||||
CallerStack = traceback.extract_stack()[-2]
|
||||
TemplateDict = {
|
||||
"file" : CallerStack[0],
|
||||
"line" : CallerStack[1],
|
||||
"msg" : Message,
|
||||
}
|
||||
|
||||
if ExtraData != None:
|
||||
LogText = _DebugMessageTemplate % TemplateDict + "\n %s" % ExtraData
|
||||
else:
|
||||
LogText = _DebugMessageTemplate % TemplateDict
|
||||
|
||||
_DebugLogger.log(Level, LogText)
|
||||
|
||||
## Log verbose message
|
||||
#
|
||||
# @param Message Verbose information
|
||||
#
|
||||
def verbose(Message):
|
||||
return _InfoLogger.log(VERBOSE, Message)
|
||||
|
||||
## Log warning message
|
||||
#
|
||||
# Warning messages are those which might be wrong but won't fail the tool.
|
||||
#
|
||||
# @param ToolName The name of the tool. If not given, the name of caller
|
||||
# method will be used.
|
||||
# @param Message Warning information
|
||||
# @param File The name of file which caused the warning.
|
||||
# @param Line The line number in the "File" which caused the warning.
|
||||
# @param ExtraData More information associated with "Message"
|
||||
#
|
||||
def warn(ToolName, Message, File=None, Line=None, ExtraData=None):
|
||||
if _InfoLogger.level > WARN:
|
||||
return
|
||||
|
||||
# if no tool name given, use caller's source file name as tool name
|
||||
if ToolName == None or ToolName == "":
|
||||
ToolName = os.path.basename(traceback.extract_stack()[-2][0])
|
||||
|
||||
if Line == None:
|
||||
Line = "..."
|
||||
else:
|
||||
Line = "%d" % Line
|
||||
|
||||
TemplateDict = {
|
||||
"tool" : ToolName,
|
||||
"file" : File,
|
||||
"line" : Line,
|
||||
"msg" : Message,
|
||||
}
|
||||
|
||||
if File != None:
|
||||
LogText = _WarningMessageTemplate % TemplateDict
|
||||
else:
|
||||
LogText = _WarningMessageTemplateWithoutFile % TemplateDict
|
||||
|
||||
if ExtraData != None:
|
||||
LogText += "\n %s" % ExtraData
|
||||
|
||||
_InfoLogger.log(WARN, LogText)
|
||||
|
||||
# Raise an execption if indicated
|
||||
if _WarningAsError == True:
|
||||
raise FatalError(WARNING_AS_ERROR)
|
||||
|
||||
## Log INFO message
|
||||
info = _InfoLogger.info
|
||||
|
||||
## Log ERROR message
|
||||
#
|
||||
# Once an error messages is logged, the tool's execution will be broken by raising
|
||||
# an execption. If you don't want to break the execution later, you can give
|
||||
# "RaiseError" with "False" value.
|
||||
#
|
||||
# @param ToolName The name of the tool. If not given, the name of caller
|
||||
# method will be used.
|
||||
# @param ErrorCode The error code
|
||||
# @param Message Warning information
|
||||
# @param File The name of file which caused the error.
|
||||
# @param Line The line number in the "File" which caused the warning.
|
||||
# @param ExtraData More information associated with "Message"
|
||||
# @param RaiseError Raise an exception to break the tool's executuion if
|
||||
# it's True. This is the default behavior.
|
||||
#
|
||||
def error(ToolName, ErrorCode, Message=None, File=None, Line=None, ExtraData=None, RaiseError=IsRaiseError):
|
||||
if Line == None:
|
||||
Line = "..."
|
||||
else:
|
||||
Line = "%d" % Line
|
||||
|
||||
if Message == None:
|
||||
if ErrorCode in gErrorMessage:
|
||||
Message = gErrorMessage[ErrorCode]
|
||||
else:
|
||||
Message = gErrorMessage[UNKNOWN_ERROR]
|
||||
|
||||
if ExtraData == None:
|
||||
ExtraData = ""
|
||||
|
||||
TemplateDict = {
|
||||
"tool" : _ToolName,
|
||||
"file" : File,
|
||||
"line" : Line,
|
||||
"errorcode" : ErrorCode,
|
||||
"msg" : Message,
|
||||
"extra" : ExtraData
|
||||
}
|
||||
|
||||
if File != None:
|
||||
LogText = _ErrorMessageTemplate % TemplateDict
|
||||
else:
|
||||
LogText = _ErrorMessageTemplateWithoutFile % TemplateDict
|
||||
|
||||
_ErrorLogger.log(ERROR, LogText)
|
||||
if RaiseError:
|
||||
raise FatalError(ErrorCode)
|
||||
|
||||
# Log information which should be always put out
|
||||
quiet = _ErrorLogger.error
|
||||
|
||||
## Initialize log system
|
||||
def Initialize():
|
||||
#
|
||||
# Since we use different format to log different levels of message into different
|
||||
# place (stdout or stderr), we have to use different "Logger" objects to do this.
|
||||
#
|
||||
# For DEBUG level (All DEBUG_0~9 are applicable)
|
||||
_DebugLogger.setLevel(INFO)
|
||||
_DebugChannel = logging.StreamHandler(sys.stdout)
|
||||
_DebugChannel.setFormatter(_DebugFormatter)
|
||||
_DebugLogger.addHandler(_DebugChannel)
|
||||
|
||||
# For VERBOSE, INFO, WARN level
|
||||
_InfoLogger.setLevel(INFO)
|
||||
_InfoChannel = logging.StreamHandler(sys.stdout)
|
||||
_InfoChannel.setFormatter(_InfoFormatter)
|
||||
_InfoLogger.addHandler(_InfoChannel)
|
||||
|
||||
# For ERROR level
|
||||
_ErrorLogger.setLevel(INFO)
|
||||
_ErrorCh = logging.StreamHandler(sys.stderr)
|
||||
_ErrorCh.setFormatter(_ErrorFormatter)
|
||||
_ErrorLogger.addHandler(_ErrorCh)
|
||||
|
||||
## Set log level
|
||||
#
|
||||
# @param Level One of log level in _LogLevel
|
||||
def SetLevel(Level):
|
||||
if Level not in _LogLevels:
|
||||
info("Not supported log level (%d). Use default level instead." % Level)
|
||||
Level = INFO
|
||||
_DebugLogger.setLevel(Level)
|
||||
_InfoLogger.setLevel(Level)
|
||||
_ErrorLogger.setLevel(Level)
|
||||
|
||||
## Get current log level
|
||||
def GetLevel():
|
||||
return _InfoLogger.getEffectiveLevel()
|
||||
|
||||
## Raise up warning as error
|
||||
def SetWarningAsError():
|
||||
global _WarningAsError
|
||||
_WarningAsError = True
|
||||
|
||||
## Specify a file to store the log message as well as put on console
|
||||
#
|
||||
# @param LogFile The file path used to store the log message
|
||||
#
|
||||
def SetLogFile(LogFile):
|
||||
if os.path.exists(LogFile):
|
||||
os.remove(LogFile)
|
||||
|
||||
_Ch = logging.FileHandler(LogFile)
|
||||
_Ch.setFormatter(_DebugFormatter)
|
||||
_DebugLogger.addHandler(_Ch)
|
||||
|
||||
_Ch= logging.FileHandler(LogFile)
|
||||
_Ch.setFormatter(_InfoFormatter)
|
||||
_InfoLogger.addHandler(_Ch)
|
||||
|
||||
_Ch = logging.FileHandler(LogFile)
|
||||
_Ch.setFormatter(_ErrorFormatter)
|
||||
_ErrorLogger.addHandler(_Ch)
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
||||
|
||||
## @file
|
||||
# This file implements the log mechanism for Python tools.
|
||||
#
|
||||
# Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
## Import modules
|
||||
import sys, os, logging
|
||||
import traceback
|
||||
from BuildToolError import *
|
||||
|
||||
## Log level constants
|
||||
DEBUG_0 = 1
|
||||
DEBUG_1 = 2
|
||||
DEBUG_2 = 3
|
||||
DEBUG_3 = 4
|
||||
DEBUG_4 = 5
|
||||
DEBUG_5 = 6
|
||||
DEBUG_6 = 7
|
||||
DEBUG_7 = 8
|
||||
DEBUG_8 = 9
|
||||
DEBUG_9 = 10
|
||||
VERBOSE = 15
|
||||
INFO = 20
|
||||
WARN = 30
|
||||
QUIET = 40
|
||||
ERROR = 50
|
||||
|
||||
IsRaiseError = True
|
||||
|
||||
# Tool name
|
||||
_ToolName = os.path.basename(sys.argv[0])
|
||||
|
||||
# For validation purpose
|
||||
_LogLevels = [DEBUG_0, DEBUG_1, DEBUG_2, DEBUG_3, DEBUG_4, DEBUG_5, DEBUG_6, DEBUG_7, DEBUG_8, DEBUG_9, VERBOSE, WARN, INFO, ERROR, QUIET]
|
||||
|
||||
# For DEBUG level (All DEBUG_0~9 are applicable)
|
||||
_DebugLogger = logging.getLogger("tool_debug")
|
||||
_DebugFormatter = logging.Formatter("[%(asctime)s.%(msecs)d]: %(message)s", datefmt="%H:%M:%S")
|
||||
|
||||
# For VERBOSE, INFO, WARN level
|
||||
_InfoLogger = logging.getLogger("tool_info")
|
||||
_InfoFormatter = logging.Formatter("%(message)s")
|
||||
|
||||
# For ERROR level
|
||||
_ErrorLogger = logging.getLogger("tool_error")
|
||||
_ErrorFormatter = logging.Formatter("%(message)s")
|
||||
|
||||
# String templates for ERROR/WARN/DEBUG log message
|
||||
_ErrorMessageTemplate = '\n\n%(tool)s...\n%(file)s(%(line)s): error %(errorcode)04X: %(msg)s\n\t%(extra)s'
|
||||
_ErrorMessageTemplateWithoutFile = '\n\n%(tool)s...\n : error %(errorcode)04X: %(msg)s\n\t%(extra)s'
|
||||
_WarningMessageTemplate = '%(tool)s...\n%(file)s(%(line)s): warning: %(msg)s'
|
||||
_WarningMessageTemplateWithoutFile = '%(tool)s: : warning: %(msg)s'
|
||||
_DebugMessageTemplate = '%(file)s(%(line)s): debug: \n %(msg)s'
|
||||
|
||||
#
|
||||
# Flag used to take WARN as ERROR.
|
||||
# By default, only ERROR message will break the tools execution.
|
||||
#
|
||||
_WarningAsError = False
|
||||
|
||||
## Log debug message
|
||||
#
|
||||
# @param Level DEBUG level (DEBUG0~9)
|
||||
# @param Message Debug information
|
||||
# @param ExtraData More information associated with "Message"
|
||||
#
|
||||
def debug(Level, Message, ExtraData=None):
|
||||
if _DebugLogger.level > Level:
|
||||
return
|
||||
if Level > DEBUG_9:
|
||||
return
|
||||
|
||||
# Find out the caller method information
|
||||
CallerStack = traceback.extract_stack()[-2]
|
||||
TemplateDict = {
|
||||
"file" : CallerStack[0],
|
||||
"line" : CallerStack[1],
|
||||
"msg" : Message,
|
||||
}
|
||||
|
||||
if ExtraData != None:
|
||||
LogText = _DebugMessageTemplate % TemplateDict + "\n %s" % ExtraData
|
||||
else:
|
||||
LogText = _DebugMessageTemplate % TemplateDict
|
||||
|
||||
_DebugLogger.log(Level, LogText)
|
||||
|
||||
## Log verbose message
|
||||
#
|
||||
# @param Message Verbose information
|
||||
#
|
||||
def verbose(Message):
|
||||
return _InfoLogger.log(VERBOSE, Message)
|
||||
|
||||
## Log warning message
|
||||
#
|
||||
# Warning messages are those which might be wrong but won't fail the tool.
|
||||
#
|
||||
# @param ToolName The name of the tool. If not given, the name of caller
|
||||
# method will be used.
|
||||
# @param Message Warning information
|
||||
# @param File The name of file which caused the warning.
|
||||
# @param Line The line number in the "File" which caused the warning.
|
||||
# @param ExtraData More information associated with "Message"
|
||||
#
|
||||
def warn(ToolName, Message, File=None, Line=None, ExtraData=None):
|
||||
if _InfoLogger.level > WARN:
|
||||
return
|
||||
|
||||
# if no tool name given, use caller's source file name as tool name
|
||||
if ToolName == None or ToolName == "":
|
||||
ToolName = os.path.basename(traceback.extract_stack()[-2][0])
|
||||
|
||||
if Line == None:
|
||||
Line = "..."
|
||||
else:
|
||||
Line = "%d" % Line
|
||||
|
||||
TemplateDict = {
|
||||
"tool" : ToolName,
|
||||
"file" : File,
|
||||
"line" : Line,
|
||||
"msg" : Message,
|
||||
}
|
||||
|
||||
if File != None:
|
||||
LogText = _WarningMessageTemplate % TemplateDict
|
||||
else:
|
||||
LogText = _WarningMessageTemplateWithoutFile % TemplateDict
|
||||
|
||||
if ExtraData != None:
|
||||
LogText += "\n %s" % ExtraData
|
||||
|
||||
_InfoLogger.log(WARN, LogText)
|
||||
|
||||
# Raise an execption if indicated
|
||||
if _WarningAsError == True:
|
||||
raise FatalError(WARNING_AS_ERROR)
|
||||
|
||||
## Log INFO message
|
||||
info = _InfoLogger.info
|
||||
|
||||
## Log ERROR message
|
||||
#
|
||||
# Once an error messages is logged, the tool's execution will be broken by raising
|
||||
# an execption. If you don't want to break the execution later, you can give
|
||||
# "RaiseError" with "False" value.
|
||||
#
|
||||
# @param ToolName The name of the tool. If not given, the name of caller
|
||||
# method will be used.
|
||||
# @param ErrorCode The error code
|
||||
# @param Message Warning information
|
||||
# @param File The name of file which caused the error.
|
||||
# @param Line The line number in the "File" which caused the warning.
|
||||
# @param ExtraData More information associated with "Message"
|
||||
# @param RaiseError Raise an exception to break the tool's executuion if
|
||||
# it's True. This is the default behavior.
|
||||
#
|
||||
def error(ToolName, ErrorCode, Message=None, File=None, Line=None, ExtraData=None, RaiseError=IsRaiseError):
|
||||
if Line == None:
|
||||
Line = "..."
|
||||
else:
|
||||
Line = "%d" % Line
|
||||
|
||||
if Message == None:
|
||||
if ErrorCode in gErrorMessage:
|
||||
Message = gErrorMessage[ErrorCode]
|
||||
else:
|
||||
Message = gErrorMessage[UNKNOWN_ERROR]
|
||||
|
||||
if ExtraData == None:
|
||||
ExtraData = ""
|
||||
|
||||
TemplateDict = {
|
||||
"tool" : _ToolName,
|
||||
"file" : File,
|
||||
"line" : Line,
|
||||
"errorcode" : ErrorCode,
|
||||
"msg" : Message,
|
||||
"extra" : ExtraData
|
||||
}
|
||||
|
||||
if File != None:
|
||||
LogText = _ErrorMessageTemplate % TemplateDict
|
||||
else:
|
||||
LogText = _ErrorMessageTemplateWithoutFile % TemplateDict
|
||||
|
||||
_ErrorLogger.log(ERROR, LogText)
|
||||
if RaiseError:
|
||||
raise FatalError(ErrorCode)
|
||||
|
||||
# Log information which should be always put out
|
||||
quiet = _ErrorLogger.error
|
||||
|
||||
## Initialize log system
|
||||
def Initialize():
|
||||
#
|
||||
# Since we use different format to log different levels of message into different
|
||||
# place (stdout or stderr), we have to use different "Logger" objects to do this.
|
||||
#
|
||||
# For DEBUG level (All DEBUG_0~9 are applicable)
|
||||
_DebugLogger.setLevel(INFO)
|
||||
_DebugChannel = logging.StreamHandler(sys.stdout)
|
||||
_DebugChannel.setFormatter(_DebugFormatter)
|
||||
_DebugLogger.addHandler(_DebugChannel)
|
||||
|
||||
# For VERBOSE, INFO, WARN level
|
||||
_InfoLogger.setLevel(INFO)
|
||||
_InfoChannel = logging.StreamHandler(sys.stdout)
|
||||
_InfoChannel.setFormatter(_InfoFormatter)
|
||||
_InfoLogger.addHandler(_InfoChannel)
|
||||
|
||||
# For ERROR level
|
||||
_ErrorLogger.setLevel(INFO)
|
||||
_ErrorCh = logging.StreamHandler(sys.stderr)
|
||||
_ErrorCh.setFormatter(_ErrorFormatter)
|
||||
_ErrorLogger.addHandler(_ErrorCh)
|
||||
|
||||
## Set log level
|
||||
#
|
||||
# @param Level One of log level in _LogLevel
|
||||
def SetLevel(Level):
|
||||
if Level not in _LogLevels:
|
||||
info("Not supported log level (%d). Use default level instead." % Level)
|
||||
Level = INFO
|
||||
_DebugLogger.setLevel(Level)
|
||||
_InfoLogger.setLevel(Level)
|
||||
_ErrorLogger.setLevel(Level)
|
||||
|
||||
## Get current log level
|
||||
def GetLevel():
|
||||
return _InfoLogger.getEffectiveLevel()
|
||||
|
||||
## Raise up warning as error
|
||||
def SetWarningAsError():
|
||||
global _WarningAsError
|
||||
_WarningAsError = True
|
||||
|
||||
## Specify a file to store the log message as well as put on console
|
||||
#
|
||||
# @param LogFile The file path used to store the log message
|
||||
#
|
||||
def SetLogFile(LogFile):
|
||||
if os.path.exists(LogFile):
|
||||
os.remove(LogFile)
|
||||
|
||||
_Ch = logging.FileHandler(LogFile)
|
||||
_Ch.setFormatter(_DebugFormatter)
|
||||
_DebugLogger.addHandler(_Ch)
|
||||
|
||||
_Ch= logging.FileHandler(LogFile)
|
||||
_Ch.setFormatter(_InfoFormatter)
|
||||
_InfoLogger.addHandler(_Ch)
|
||||
|
||||
_Ch = logging.FileHandler(LogFile)
|
||||
_Ch.setFormatter(_ErrorFormatter)
|
||||
_ErrorLogger.addHandler(_Ch)
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
||||
|
||||
|
@@ -1,71 +1,71 @@
|
||||
## @file
|
||||
# This file is used to define common static strings used by INF/DEC/DSC files
|
||||
#
|
||||
# Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
import re
|
||||
|
||||
gIsWindows = None
|
||||
|
||||
gEdkCompatibilityPkg = "EdkCompatibilityPkg"
|
||||
gWorkspace = "."
|
||||
gEdkSource = "EdkCompatibilityPkg"
|
||||
gEfiSource = "."
|
||||
gEcpSource = "EdkCompatibilityPkg"
|
||||
|
||||
gOptions = None
|
||||
gCaseInsensitive = False
|
||||
gAllFiles = None
|
||||
|
||||
gGlobalDefines = {}
|
||||
gPlatformDefines = {}
|
||||
# PCD name and value pair for fixed at build and feature flag
|
||||
gPlatformPcds = {}
|
||||
# PCDs with type that are not fixed at build and feature flag
|
||||
gPlatformOtherPcds = {}
|
||||
gActivePlatform = None
|
||||
gCommandLineDefines = {}
|
||||
gEdkGlobal = {}
|
||||
gOverrideDir = {}
|
||||
|
||||
# for debug trace purpose when problem occurs
|
||||
gProcessingFile = ''
|
||||
gBuildingModule = ''
|
||||
|
||||
## Regular expression for matching macro used in DSC/DEC/INF file inclusion
|
||||
gMacroRefPattern = re.compile("\$\(([A-Z][_A-Z0-9]*)\)", re.UNICODE)
|
||||
gMacroDefPattern = re.compile("^(DEFINE|EDK_GLOBAL)[ \t]+")
|
||||
gMacroNamePattern = re.compile("^[A-Z][A-Z0-9_]*$")
|
||||
# C-style wide string pattern
|
||||
gWideStringPattern = re.compile('(\W|\A)L"')
|
||||
#
|
||||
# A global variable for whether current build in AutoGen phase or not.
|
||||
#
|
||||
gAutoGenPhase = False
|
||||
|
||||
#
|
||||
# The Conf dir outside the workspace dir
|
||||
#
|
||||
gConfDirectory = ''
|
||||
|
||||
#
|
||||
# The relative default database file path
|
||||
#
|
||||
gDatabasePath = ".cache/build.db"
|
||||
|
||||
#
|
||||
# Build flag for binary build
|
||||
#
|
||||
gIgnoreSource = False
|
||||
|
||||
#
|
||||
# FDF parser
|
||||
#
|
||||
gFdfParser = None
|
||||
## @file
|
||||
# This file is used to define common static strings used by INF/DEC/DSC files
|
||||
#
|
||||
# Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
import re
|
||||
|
||||
gIsWindows = None
|
||||
|
||||
gEdkCompatibilityPkg = "EdkCompatibilityPkg"
|
||||
gWorkspace = "."
|
||||
gEdkSource = "EdkCompatibilityPkg"
|
||||
gEfiSource = "."
|
||||
gEcpSource = "EdkCompatibilityPkg"
|
||||
|
||||
gOptions = None
|
||||
gCaseInsensitive = False
|
||||
gAllFiles = None
|
||||
|
||||
gGlobalDefines = {}
|
||||
gPlatformDefines = {}
|
||||
# PCD name and value pair for fixed at build and feature flag
|
||||
gPlatformPcds = {}
|
||||
# PCDs with type that are not fixed at build and feature flag
|
||||
gPlatformOtherPcds = {}
|
||||
gActivePlatform = None
|
||||
gCommandLineDefines = {}
|
||||
gEdkGlobal = {}
|
||||
gOverrideDir = {}
|
||||
|
||||
# for debug trace purpose when problem occurs
|
||||
gProcessingFile = ''
|
||||
gBuildingModule = ''
|
||||
|
||||
## Regular expression for matching macro used in DSC/DEC/INF file inclusion
|
||||
gMacroRefPattern = re.compile("\$\(([A-Z][_A-Z0-9]*)\)", re.UNICODE)
|
||||
gMacroDefPattern = re.compile("^(DEFINE|EDK_GLOBAL)[ \t]+")
|
||||
gMacroNamePattern = re.compile("^[A-Z][A-Z0-9_]*$")
|
||||
# C-style wide string pattern
|
||||
gWideStringPattern = re.compile('(\W|\A)L"')
|
||||
#
|
||||
# A global variable for whether current build in AutoGen phase or not.
|
||||
#
|
||||
gAutoGenPhase = False
|
||||
|
||||
#
|
||||
# The Conf dir outside the workspace dir
|
||||
#
|
||||
gConfDirectory = ''
|
||||
|
||||
#
|
||||
# The relative default database file path
|
||||
#
|
||||
gDatabasePath = ".cache/build.db"
|
||||
|
||||
#
|
||||
# Build flag for binary build
|
||||
#
|
||||
gIgnoreSource = False
|
||||
|
||||
#
|
||||
# FDF parser
|
||||
#
|
||||
gFdfParser = None
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user