## @file
# Common routines used by all tools
#
# Copyright (c) 2011, 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
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
'''
Misc
'''
##
# Import Modules
#
import re
## Convert GUID string in xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx style to C
# structure style
#
# @param Guid: The GUID string
#
Result = '{'
Result += '}}'
return Result
## Check whether GUID string is of format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
#
# @param GuidValue: The GUID value
#
## Regular expression used to find out register format of GUID
#
"([0-9a-fA-F]){4}-"
"([0-9a-fA-F]){4}-"
"([0-9a-fA-F]){4}-"
"([0-9a-fA-F]){12}\s*$")
return True
else:
return False
## Convert GUID string in C structure style to
# xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
#
# @param GuidValue: The GUID value in C structure format
#
return ''
try:
return "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" % (
)
except BaseException:
return ''
## Create directories
#
# @param Directory: The directory name
#
return True
try:
except BaseException:
return False
return True
## Remove directories, including files and sub-directories in it
#
# @param Directory: The directory name
#
return
if Recursively:
else:
## Store content in file
#
# This method is used to save file only when its content is changed. This is
# quite useful for "make" system to decide what will be re-built and what
# won't.
#
# @param File: The path of file
# @param Content: The new content of the file
# @param IsBinaryFile: The flag indicating if the file is binary file
# or not
#
if not IsBinaryFile:
try:
return False
except BaseException:
try:
except BaseException:
return True
## Get all files of a directory
#
# @param Root: Root dir
# @param SkipList : The files need be skipped
#
FileList = []
if SkipList:
continue
if not FullPath:
return FileList
## Get all non-metadata files of a directory
#
# @param Root: Root Dir
# @param SkipList : List of path need be skipped
# @param FullPath: True if the returned file should be full path
# @param PrefixPath: the path that need to be added to the files found
# @return: the list of files found
#
NewFileList = []
#
# skip '.dec', '.inf', '.dsc', '.fdf' files
#
return NewFileList
## Check if given file exists or not
#
# @param File: File name or path to be checked
# @param Dir: The directory the file is relative to
#
if Ext != None:
return False
return False
return True
## RealPath
#
# @param File: File name or path to be checked
# @param Dir: The directory the file is relative to
# @param OverrideDir: The override directory
#
if not NewFile and OverrideDir:
return NewFile
## RealPath2
#
# @param File: File name or path to be checked
# @param Dir: The directory the file is relative to
# @param OverrideDir: The override directory
#
if OverrideDir:
(OverrideDir, File))]
if NewFile:
else:
if NewFile:
if Dir:
else:
else:
return NewFile, ''
return None, None
#
# The class implements a new kind of dict which its keys or values can be
# accessed in the order they are added into the dict. It guarantees the order
# by making use of an internal list to keep a copy of keys.
#
## Constructor
#
## [] operator
#
## del operator
#
## used in "for k in dict" loop to ensure the correct order
#
## len() support
#
## "in" test support
#
## indexof support
#
## insert support
#
if Order == 'BEFORE':
elif Order == 'AFTER':
## append support
#
## hash key
#
## Empty the dict
#
## Return a copy of keys
#
Keys = []
return Keys
## Return a copy of values
#
Values = []
return Values
## Return a copy of (key, value) list
#
Items = []
return Items
## Iteration support
#
## Keys interation support
#
## Values interation support
#
## Return value related to a key, and remove the (key, value) from the dict
#
Value = None
return Value
## Return (key, value) pair, and remove the (key, value) from the dict
#
## update method
#
if Dict != None:
## CommonPath
#
# @param PathList: PathList
#
## PathClass
#
ToolCode=''):
else:
#
# Remove any '.' and '..' in path
#
#
# eliminate the side-effect of 'C:'
#
#
# file path should not start with path separator
#
else:
else:
else:
else:
if IsBinary:
else:
## Convert the object of this class to a string
#
# Convert member Path of the class to a string
#
## Override __eq__ function
#
# Check whether PathClass are the same
#
else:
## Override __hash__ function
#
# Use Path as key in hash table
#
## _GetFileKey
#
## Validate
#
ErrorCode = 0
ErrorInfo = ''
" [in file system]"
else:
## Check environment variables
#
# Check environment variables that must be set for build. Currently they are
#
# EDK_TOOLS_PATH The directory contains all tools needed by the build
# PATH $(EDK_TOOLS_PATH)/Bin/<sys> must be set in PATH
#
# If any of above environment variable is not set or has error, the build
# will be broken.
#
def CheckEnvVariable():
#
# check WORKSPACE
#
if "WORKSPACE" not in environ:
ExtraData="WORKSPACE")
elif ' ' in WorkspaceDir:
## Check whether all module types are in list
#
# check whether all module types (SUP_MODULE_LIST) are in list
#
# @param ModuleList: a list of ModuleType
#
for Module in SUP_MODULE_LIST:
if Module not in NewModuleList:
return False
else:
return True
## Dictionary that use comment(GenericComment, TailComment) as value,
# if a new comment which key already in the dic is inserted, then the
# comment will be merged.
# Key is (Statement, SupArch), when TailComment is added, it will ident
# according to Statement
#
## []= operator
#
else:
## =[] operator
#
## GenDummyHelpTextObj
#
# @retval HelpTxt: Generated dummy help text object
#
def GenDummyHelpTextObj():
HelpTxt = TextObject()
return HelpTxt
## ConvertVersionToDecimal, the minor version should be within 0 - 99
# <HexVersion> ::= "0x" <Major> <Minor>
# <Major> ::= (a-fA-F0-9){4}
# <Minor> ::= (a-fA-F0-9){4}
# <DecVersion> ::= (0-65535) ["." (0-99)]
#
# @param StringIn: The string contains version defined in INF file.
# It can be Decimal or Hex
#
else:
return StringIn
elif StringIn:
return StringIn + '.0'
else:
#
# when StringIn is '', return it directly
#
return StringIn
## GetHelpStringByRemoveHashKey
#
# Remove hash key at the header of string and return the remain.
#
# @param String: The string need to be processed.
#
ReturnString = ''
if String == '':
return String
else:
return ReturnString
## ConvPathFromAbsToRel
#
# Get relative file path from absolute path.
#
# @param Path: The string contain file absolute path.
# @param Root: The string contain the parent path of Path in.
#
#
#
# If Path is absolute path.
# It should be in Root.
#
else:
return Path
## ConvertPath
#
# Convert special characters to '_', '\' to '/'
# return converted path: Test!1.inf -> Test_1.inf
#
# @param Path: Path to be converted
#
RetPath = ''
elif Char == '\\':
else:
return RetPath
## ConvertSpec
#
# during install, convert the Spec string extract from UPD into INF allowable definition,
# the difference is period is allowed in the former (not the first letter) but not in the latter.
# return converted Spec string
#
# @param SpecStr: SpecStr to be converted
#
RetStr = ''
else:
return RetStr
## IsEqualList
#
# Judge two lists are identical(contain same item).
# The rule is elements in List A are in List B and elements in List B are in List A.
#
# @param ListA, ListB Lists need to be judged.
#
# @return True ListA and ListB are identical
# @return False ListA and ListB are different with each other
#
return True
return False
return False
return True
## ConvertArchList
#
# Convert item in ArchList if the start character is lower case.
# In UDP spec, Arch is only allowed as: [A-Z]([a-zA-Z0-9])*
#
# @param ArchList The ArchList need to be converted.
#
# @return NewList The ArchList been converted.
#
NewArchList = []
if not ArchList:
return NewArchList
return NewArchList
## ProcessLineExtender
#
# Process the LineExtender of Line in LineList.
# If one line ends with a line extender, then it will be combined together with next line.
#
# @param LineList The LineList need to be processed.
#
# @return NewList The ArchList been processed.
#
NewList = []
Count = 0
else:
return NewList
## ProcessEdkComment
#
# Process EDK style comment in LineList: c style /* */ comment or cpp style // comment
#
#
# @param LineList The LineList need to be processed.
#
# @return LineList The LineList been processed.
# @return FirstPos Where Edk comment is first found, -1 if not found
#
Count = 0
StartPos = -1
EndPos = -1
FirstPos = -1
#
# handling c style comment
#
continue
break
if FirstPos == -1:
#
# handling cpp style comment
#
if FirstPos == -1:
## GetLibInstanceInfo
#
# Get the information from Library Instance INF file.
#
# @param string. A string start with # and followed by INF file path
# @param WorkSpace. The WorkSpace directory used to combined with INF file path.
#
# @return GUID, Version
FileGuidString = ""
VerString = ""
if not String:
return None, None
#
# Remove "#" characters at the beginning
#
#
# Validate file name exist.
#
if not (ValidFile(FullFileName)):
#
#
else:
return False
if IsValidFileFlag:
FileLinesList = []
try:
try:
except BaseException:
finally:
except BaseException:
for Line in FileLinesList:
if FileGuidString:
if VerString:
return FileGuidString, VerString