summaryrefslogtreecommitdiffstats
path: root/meta/classes
diff options
context:
space:
mode:
authorJoshua Watt <jpewhacker@gmail.com>2019-01-21 16:39:19 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-01-22 14:35:58 +0000
commit1d86f65ff54164f23d96d76dec4b1f468f4bab06 (patch)
tree7b4cf11cc005b6cdc45e56cdb0d664a5375da20e /meta/classes
parent6fd870e6a1f61d17e43cf30db4259a939db93820 (diff)
downloadpoky-1d86f65ff54164f23d96d76dec4b1f468f4bab06.tar.gz
classes/sstate: Update output hash
Updates the output hash calculation for determining if tasks are equivalent. The new algorithm does the following based on feedback: 1) The output hash function was moved to the OE library. 2) All files are printed in a single line tabular format 3) Prints the file type and mode in a user-friendly ls-like format 4) Includes the file owner and group (by name, not ID). These are only included if the task is run under pseudo since that is the only time they can be consistently determined. 5) File size is included for regular files (From OE-Core rev: 4bd297dfe92851f3b44f6b5560bac9d8f9ccf9f2) Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-rw-r--r--meta/classes/sstate.bbclass65
1 files changed, 3 insertions, 62 deletions
diff --git a/meta/classes/sstate.bbclass b/meta/classes/sstate.bbclass
index 763fce07f9..2f0bbd2d7d 100644
--- a/meta/classes/sstate.bbclass
+++ b/meta/classes/sstate.bbclass
@@ -83,9 +83,9 @@ SSTATE_SIG_PASSPHRASE ?= ""
83# Whether to verify the GnUPG signatures when extracting sstate archives 83# Whether to verify the GnUPG signatures when extracting sstate archives
84SSTATE_VERIFY_SIG ?= "0" 84SSTATE_VERIFY_SIG ?= "0"
85 85
86SSTATE_HASHEQUIV_METHOD ?= "OEOuthashBasic" 86SSTATE_HASHEQUIV_METHOD ?= "oe.sstatesig.OEOuthashBasic"
87SSTATE_HASHEQUIV_METHOD[doc] = "The function used to calculate the output hash \ 87SSTATE_HASHEQUIV_METHOD[doc] = "The fully-qualified function used to calculate \
88 for a task, which in turn is used to determine equivalency. \ 88 the output hash for a task, which in turn is used to determine equivalency. \
89 " 89 "
90 90
91SSTATE_HASHEQUIV_SERVER ?= "" 91SSTATE_HASHEQUIV_SERVER ?= ""
@@ -782,65 +782,6 @@ python sstate_sign_package () {
782 d.getVar('SSTATE_SIG_PASSPHRASE'), armor=False) 782 d.getVar('SSTATE_SIG_PASSPHRASE'), armor=False)
783} 783}
784 784
785def OEOuthashBasic(path, sigfile, task, d):
786 import hashlib
787 import stat
788
789 def update_hash(s):
790 s = s.encode('utf-8')
791 h.update(s)
792 if sigfile:
793 sigfile.write(s)
794
795 h = hashlib.sha256()
796 prev_dir = os.getcwd()
797
798 try:
799 os.chdir(path)
800
801 update_hash("OEOuthashBasic\n")
802
803 # It is only currently useful to get equivalent hashes for things that
804 # can be restored from sstate. Since the sstate object is named using
805 # SSTATE_PKGSPEC and the task name, those should be included in the
806 # output hash calculation.
807 update_hash("SSTATE_PKGSPEC=%s\n" % d.getVar('SSTATE_PKGSPEC'))
808 update_hash("task=%s\n" % task)
809
810 for root, dirs, files in os.walk('.', topdown=True):
811 # Sort directories and files to ensure consistent ordering
812 dirs.sort()
813 files.sort()
814
815 for f in files:
816 path = os.path.join(root, f)
817 s = os.lstat(path)
818
819 # Hash file path
820 update_hash(path + '\n')
821
822 # Hash file mode
823 update_hash("\tmode=0x%x\n" % stat.S_IMODE(s.st_mode))
824 update_hash("\ttype=0x%x\n" % stat.S_IFMT(s.st_mode))
825
826 if stat.S_ISBLK(s.st_mode) or stat.S_ISBLK(s.st_mode):
827 # Hash device major and minor
828 update_hash("\tdev=%d,%d\n" % (os.major(s.st_rdev), os.minor(s.st_rdev)))
829 elif stat.S_ISLNK(s.st_mode):
830 # Hash symbolic link
831 update_hash("\tsymlink=%s\n" % os.readlink(path))
832 else:
833 fh = hashlib.sha256()
834 # Hash file contents
835 with open(path, 'rb') as d:
836 for chunk in iter(lambda: d.read(4096), b""):
837 fh.update(chunk)
838 update_hash("\tdigest=%s\n" % fh.hexdigest())
839 finally:
840 os.chdir(prev_dir)
841
842 return h.hexdigest()
843
844python sstate_report_unihash() { 785python sstate_report_unihash() {
845 report_unihash = getattr(bb.parse.siggen, 'report_unihash', None) 786 report_unihash = getattr(bb.parse.siggen, 'report_unihash', None)
846 787