BaseTools: Fix --hash Package and Module hash value.

The order of List enumeration is arbitrary.
Need to be sorted while calculating Package/Module hash, otherwise it
generate different hash value even nothing changes.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Derek Lin <derek.lin2@hpe.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
Lin, Derek
2018-05-09 17:03:23 +08:00
committed by Yonghong Zhu
parent 63c76537c6
commit 3f34e36d04

View File

@ -2,6 +2,8 @@
# Generate AutoGen.h, AutoGen.c and *.depex files # Generate AutoGen.h, AutoGen.c and *.depex files
# #
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>
#
# This program and the accompanying materials # This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License # 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 # which accompanies this distribution. The full text of the license may be found at
@ -670,6 +672,9 @@ class WorkspaceAutoGen(AutoGen):
return True return True
def _GenPkgLevelHash(self, Pkg): def _GenPkgLevelHash(self, Pkg):
if Pkg.PackageName in GlobalData.gPackageHash[Pkg.Arch]:
return
PkgDir = os.path.join(self.BuildDir, Pkg.Arch, Pkg.PackageName) PkgDir = os.path.join(self.BuildDir, Pkg.Arch, Pkg.PackageName)
CreateDirectory(PkgDir) CreateDirectory(PkgDir)
HashFile = os.path.join(PkgDir, Pkg.PackageName + '.hash') HashFile = os.path.join(PkgDir, Pkg.PackageName + '.hash')
@ -681,17 +686,16 @@ class WorkspaceAutoGen(AutoGen):
m.update(Content) m.update(Content)
# Get include files hash value # Get include files hash value
if Pkg.Includes: if Pkg.Includes:
for inc in Pkg.Includes: for inc in sorted(Pkg.Includes, key=lambda x: str(x)):
for Root, Dirs, Files in os.walk(str(inc)): for Root, Dirs, Files in os.walk(str(inc)):
for File in Files: for File in sorted(Files):
File_Path = os.path.join(Root, File) File_Path = os.path.join(Root, File)
f = open(File_Path, 'r') f = open(File_Path, 'r')
Content = f.read() Content = f.read()
f.close() f.close()
m.update(Content) m.update(Content)
SaveFileOnChange(HashFile, m.hexdigest(), True) SaveFileOnChange(HashFile, m.hexdigest(), True)
if Pkg.PackageName not in GlobalData.gPackageHash[Pkg.Arch]: GlobalData.gPackageHash[Pkg.Arch][Pkg.PackageName] = m.hexdigest()
GlobalData.gPackageHash[Pkg.Arch][Pkg.PackageName] = m.hexdigest()
def _GetMetaFiles(self, Target, Toolchain, Arch): def _GetMetaFiles(self, Target, Toolchain, Arch):
AllWorkSpaceMetaFiles = set() AllWorkSpaceMetaFiles = set()
@ -4432,13 +4436,13 @@ class ModuleAutoGen(AutoGen):
m.update(GlobalData.gPlatformHash) m.update(GlobalData.gPlatformHash)
# Add Package level hash # Add Package level hash
if self.DependentPackageList: if self.DependentPackageList:
for Pkg in self.DependentPackageList: for Pkg in sorted(self.DependentPackageList, key=lambda x: x.PackageName):
if Pkg.PackageName in GlobalData.gPackageHash[self.Arch]: if Pkg.PackageName in GlobalData.gPackageHash[self.Arch]:
m.update(GlobalData.gPackageHash[self.Arch][Pkg.PackageName]) m.update(GlobalData.gPackageHash[self.Arch][Pkg.PackageName])
# Add Library hash # Add Library hash
if self.LibraryAutoGenList: if self.LibraryAutoGenList:
for Lib in self.LibraryAutoGenList: for Lib in sorted(self.LibraryAutoGenList, key=lambda x: x.Name):
if Lib.Name not in GlobalData.gModuleHash[self.Arch]: if Lib.Name not in GlobalData.gModuleHash[self.Arch]:
Lib.GenModuleHash() Lib.GenModuleHash()
m.update(GlobalData.gModuleHash[self.Arch][Lib.Name]) m.update(GlobalData.gModuleHash[self.Arch][Lib.Name])
@ -4450,7 +4454,7 @@ class ModuleAutoGen(AutoGen):
m.update(Content) m.update(Content)
# Add Module's source files # Add Module's source files
if self.SourceFileList: if self.SourceFileList:
for File in self.SourceFileList: for File in sorted(self.SourceFileList, key=lambda x: str(x)):
f = open(str(File), 'r') f = open(str(File), 'r')
Content = f.read() Content = f.read()
f.close() f.close()