from AutoGen.ModuleAutoGenHelper import PlatformInfo,WorkSpaceInfo\r
from AutoGen.CacheIR import ModuleBuildCacheIR\r
import json\r
+import tempfile\r
\r
## Mapping Makefile type\r
gMakeTypeMap = {TAB_COMPILER_MSFT:"nmake", "GCC":"gmake"}\r
try:\r
ModuleHashPairList = [] # tuple list: [tuple(PreMakefileHash, MakeHash)]\r
if os.path.exists(ModuleHashPair):\r
- f = open(ModuleHashPair, 'r')\r
- ModuleHashPairList = json.load(f)\r
- f.close()\r
+ with open(ModuleHashPair, 'r') as f:\r
+ ModuleHashPairList = json.load(f)\r
PreMakeHash = gDict[(self.MetaFile.Path, self.Arch)].PreMakefileHashHexDigest\r
MakeHash = gDict[(self.MetaFile.Path, self.Arch)].MakeHashHexDigest\r
ModuleHashPairList.append((PreMakeHash, MakeHash))\r
\r
if os.path.exists (self.TimeStampPath):\r
os.remove (self.TimeStampPath)\r
- with open(self.TimeStampPath, 'w+') as fd:\r
+ with tempfile.NamedTemporaryFile('w+', dir=os.path.dirname(self.TimeStampPath), delete=False) as tf:\r
for f in FileSet:\r
- fd.write(f)\r
- fd.write("\n")\r
+ tf.write(f)\r
+ tf.write("\n")\r
+ tempname = tf.name\r
+ SaveFileOnChange(self.TimeStampPath, tempname, False)\r
\r
# Ignore generating makefile when it is a binary module\r
if self.IsBinaryModule:\r
MewIR.MakefilePath = MakefilePath\r
MewIR.DependencyHeaderFileSet = Makefile.DependencyHeaderFileSet\r
MewIR.CreateMakeFileDone = True\r
- with GlobalData.file_lock:\r
+ with GlobalData.cache_lock:\r
try:\r
IR = gDict[(self.MetaFile.Path, self.Arch)]\r
IR.MakefilePath = MakefilePath\r
self.IsCodeFileCreated = True\r
MewIR = ModuleBuildCacheIR(self.MetaFile.Path, self.Arch)\r
MewIR.CreateCodeFileDone = True\r
- with GlobalData.file_lock:\r
+ with GlobalData.cache_lock:\r
try:\r
IR = gDict[(self.MetaFile.Path, self.Arch)]\r
IR.CreateCodeFileDone = True\r
m.update(GlobalData.gModuleHash[self.Arch][Lib.Name].encode('utf-8'))\r
\r
# Add Module self\r
- f = open(str(self.MetaFile), 'rb')\r
- Content = f.read()\r
- f.close()\r
+ with open(str(self.MetaFile), 'rb') as f:\r
+ Content = f.read()\r
m.update(Content)\r
\r
# Add Module's source files\r
if gDict[(self.MetaFile.Path, self.Arch)].ModuleFilesChain:\r
return gDict[(self.MetaFile.Path, self.Arch)]\r
\r
+ # skip if the module cache already crashed\r
+ if (self.MetaFile.Path, self.Arch) in gDict and \\r
+ gDict[(self.MetaFile.Path, self.Arch)].CacheCrash:\r
+ return\r
+\r
DependencyFileSet = set()\r
# Add Module Meta file\r
DependencyFileSet.add(self.MetaFile)\r
if not os.path.exists(str(File)):\r
EdkLogger.quiet("[cache warning]: header file %s is missing for module: %s[%s]" % (File, self.MetaFile.Path, self.Arch))\r
continue\r
- f = open(str(File), 'rb')\r
- Content = f.read()\r
- f.close()\r
+ with open(str(File), 'rb') as f:\r
+ Content = f.read()\r
m.update(Content)\r
FileList.append((str(File), hashlib.md5(Content).hexdigest()))\r
\r
MewIR.ModuleFilesHashDigest = m.digest()\r
MewIR.ModuleFilesHashHexDigest = m.hexdigest()\r
MewIR.ModuleFilesChain = FileList\r
- with GlobalData.file_lock:\r
+ with GlobalData.cache_lock:\r
try:\r
IR = gDict[(self.MetaFile.Path, self.Arch)]\r
IR.ModuleFilesHashDigest = m.digest()\r
gDict[(self.MetaFile.Path, self.Arch)].PreMakefileHashHexDigest:\r
return gDict[(self.MetaFile.Path, self.Arch)]\r
\r
+ # skip if the module cache already crashed\r
+ if (self.MetaFile.Path, self.Arch) in gDict and \\r
+ gDict[(self.MetaFile.Path, self.Arch)].CacheCrash:\r
+ return\r
+\r
# skip binary module\r
if self.IsBinaryModule:\r
return\r
# Add Module self\r
m.update(gDict[(self.MetaFile.Path, self.Arch)].ModuleFilesHashDigest)\r
\r
- with GlobalData.file_lock:\r
+ with GlobalData.cache_lock:\r
IR = gDict[(self.MetaFile.Path, self.Arch)]\r
IR.PreMakefileHashHexDigest = m.hexdigest()\r
gDict[(self.MetaFile.Path, self.Arch)] = IR\r
gDict[(self.MetaFile.Path, self.Arch)].MakeHeaderFilesHashDigest:\r
return gDict[(self.MetaFile.Path, self.Arch)]\r
\r
+ # skip if the module cache already crashed\r
+ if (self.MetaFile.Path, self.Arch) in gDict and \\r
+ gDict[(self.MetaFile.Path, self.Arch)].CacheCrash:\r
+ return\r
+\r
# skip binary module\r
if self.IsBinaryModule:\r
return\r
m.update(Content)\r
FileList.append((str(File), hashlib.md5(Content).hexdigest()))\r
\r
- with GlobalData.file_lock:\r
+ with GlobalData.cache_lock:\r
IR = gDict[(self.MetaFile.Path, self.Arch)]\r
IR.AutoGenFileList = self.AutoGenFileList.keys()\r
IR.MakeHeaderFilesHashChain = FileList\r
gDict[(self.MetaFile.Path, self.Arch)].MakeHashChain:\r
return gDict[(self.MetaFile.Path, self.Arch)]\r
\r
+ # skip if the module cache already crashed\r
+ if (self.MetaFile.Path, self.Arch) in gDict and \\r
+ gDict[(self.MetaFile.Path, self.Arch)].CacheCrash:\r
+ return\r
+\r
# skip binary module\r
if self.IsBinaryModule:\r
return\r
New.sort(key=lambda x: str(x))\r
MakeHashChain += New\r
\r
- with GlobalData.file_lock:\r
+ with GlobalData.cache_lock:\r
IR = gDict[(self.MetaFile.Path, self.Arch)]\r
IR.MakeHashDigest = m.digest()\r
IR.MakeHashHexDigest = m.hexdigest()\r
if not GlobalData.gBinCacheSource:\r
return False\r
\r
+ if gDict[(self.MetaFile.Path, self.Arch)].PreMakeCacheHit:\r
+ return True\r
+\r
+ if gDict[(self.MetaFile.Path, self.Arch)].CacheCrash:\r
+ return False\r
+\r
# If Module is binary, do not skip by cache\r
if self.IsBinaryModule:\r
return False\r
ModuleHashPair = path.join(FileDir, self.Name + ".ModuleHashPair")\r
if not os.path.exists(ModuleHashPair):\r
EdkLogger.quiet("[cache warning]: Cannot find ModuleHashPair file: %s" % ModuleHashPair)\r
+ with GlobalData.cache_lock:\r
+ IR = gDict[(self.MetaFile.Path, self.Arch)]\r
+ IR.CacheCrash = True\r
+ gDict[(self.MetaFile.Path, self.Arch)] = IR\r
return False\r
\r
try:\r
- f = open(ModuleHashPair, 'r')\r
- ModuleHashPairList = json.load(f)\r
- f.close()\r
+ with open(ModuleHashPair, 'r') as f:\r
+ ModuleHashPairList = json.load(f)\r
except:\r
EdkLogger.quiet("[cache warning]: fail to load ModuleHashPair file: %s" % ModuleHashPair)\r
return False\r
if self.Name == "PcdPeim" or self.Name == "PcdDxe":\r
CreatePcdDatabaseCode(self, TemplateString(), TemplateString())\r
\r
- with GlobalData.file_lock:\r
+ with GlobalData.cache_lock:\r
IR = gDict[(self.MetaFile.Path, self.Arch)]\r
IR.PreMakeCacheHit = True\r
gDict[(self.MetaFile.Path, self.Arch)] = IR\r
if not GlobalData.gBinCacheSource:\r
return False\r
\r
+ if gDict[(self.MetaFile.Path, self.Arch)].MakeCacheHit:\r
+ return True\r
+\r
+ if gDict[(self.MetaFile.Path, self.Arch)].CacheCrash:\r
+ return False\r
+\r
# If Module is binary, do not skip by cache\r
if self.IsBinaryModule:\r
print("[cache miss]: checkpoint_Makefile: binary module:", self.MetaFile.Path, self.Arch)\r
# .inc is contains binary information so do not skip by hash as well\r
for f_ext in self.SourceFileList:\r
if '.inc' in str(f_ext):\r
- with GlobalData.file_lock:\r
+ with GlobalData.cache_lock:\r
IR = gDict[(self.MetaFile.Path, self.Arch)]\r
IR.MakeCacheHit = False\r
gDict[(self.MetaFile.Path, self.Arch)] = IR\r
ModuleHashPair = path.join(FileDir, self.Name + ".ModuleHashPair")\r
if not os.path.exists(ModuleHashPair):\r
EdkLogger.quiet("[cache warning]: Cannot find ModuleHashPair file: %s" % ModuleHashPair)\r
+ with GlobalData.cache_lock:\r
+ IR = gDict[(self.MetaFile.Path, self.Arch)]\r
+ IR.CacheCrash = True\r
+ gDict[(self.MetaFile.Path, self.Arch)] = IR\r
return False\r
\r
try:\r
- f = open(ModuleHashPair, 'r')\r
- ModuleHashPairList = json.load(f)\r
- f.close()\r
+ with open(ModuleHashPair, 'r') as f:\r
+ ModuleHashPairList = json.load(f)\r
except:\r
EdkLogger.quiet("[cache warning]: fail to load ModuleHashPair file: %s" % ModuleHashPair)\r
return False\r
\r
if self.Name == "PcdPeim" or self.Name == "PcdDxe":\r
CreatePcdDatabaseCode(self, TemplateString(), TemplateString())\r
- with GlobalData.file_lock:\r
+ with GlobalData.cache_lock:\r
IR = gDict[(self.MetaFile.Path, self.Arch)]\r
IR.MakeCacheHit = True\r
gDict[(self.MetaFile.Path, self.Arch)] = IR\r
if not GlobalData.gBinCacheSource:\r
return\r
\r
+ # skip if the module cache already crashed\r
+ if gDict[(self.MetaFile.Path, self.Arch)].CacheCrash:\r
+ return\r
+\r
# skip binary module\r
if self.IsBinaryModule:\r
return\r
return\r
\r
try:\r
- f = open(ModuleHashPair, 'r')\r
- ModuleHashPairList = json.load(f)\r
- f.close()\r
+ with open(ModuleHashPair, 'r') as f:\r
+ ModuleHashPairList = json.load(f)\r
except:\r
EdkLogger.quiet("[cache insight]: Cannot load ModuleHashPair file for module: %s[%s]" % (self.MetaFile.Path, self.Arch))\r
return\r