summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/build.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-12-11 16:37:27 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-12-17 08:52:28 +0000
commit1a45c29ff13f6e78b9428336f813d0c3e0fd980a (patch)
treea723108d4783559eb983e94854fc4a0fbd042a94 /bitbake/lib/bb/build.py
parent878de40a501089048cffdc867b2ae1ad8a2ec9e5 (diff)
downloadpoky-1a45c29ff13f6e78b9428336f813d0c3e0fd980a.tar.gz
bitbake: build/siggen: Rework stamps functions
The current method of passing either a task's datastore, or dataCaches and a filename into the stamp functions is rather horrible. Due to the different contexts, fixing this is hard but we do control the bitbake side of the API usage so we can migrate those to use other functions and then only support a datastore in the public bb.build API which is only called from task context in OE-Core. (Bitbake rev: c79ecec580e4c2a141ae483ec0f6448f70593dcf) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/build.py')
-rw-r--r--bitbake/lib/bb/build.py149
1 files changed, 44 insertions, 105 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py
index 5ac191647c..5a1727116a 100644
--- a/bitbake/lib/bb/build.py
+++ b/bitbake/lib/bb/build.py
@@ -772,44 +772,7 @@ def exec_task(fn, task, d, profile = False):
772 event.fire(failedevent, d) 772 event.fire(failedevent, d)
773 return 1 773 return 1
774 774
775def stamp_internal(taskname, d, file_name, baseonly=False, noextra=False): 775def _get_cleanmask(taskname, mcfn):
776 """
777 Internal stamp helper function
778 Makes sure the stamp directory exists
779 Returns the stamp path+filename
780
781 In the bitbake core, d can be a CacheData and file_name will be set.
782 When called in task context, d will be a data store, file_name will not be set
783 """
784 taskflagname = taskname
785 if taskname.endswith("_setscene"):
786 taskflagname = taskname.replace("_setscene", "")
787
788 if file_name:
789 stamp = d.stamp[file_name]
790 extrainfo = d.stamp_extrainfo[file_name].get(taskflagname) or ""
791 else:
792 stamp = d.getVar('STAMP')
793 file_name = d.getVar('BB_FILENAME')
794 extrainfo = d.getVarFlag(taskflagname, 'stamp-extra-info') or ""
795
796 if baseonly:
797 return stamp
798 if noextra:
799 extrainfo = ""
800
801 if not stamp:
802 return
803
804 stamp = bb.parse.siggen.stampfile(stamp, file_name, taskname, extrainfo)
805
806 stampdir = os.path.dirname(stamp)
807 if cached_mtime_noerror(stampdir) == 0:
808 bb.utils.mkdirhier(stampdir)
809
810 return stamp
811
812def stamp_cleanmask_internal(taskname, d, file_name):
813 """ 776 """
814 Internal stamp helper function to generate stamp cleaning mask 777 Internal stamp helper function to generate stamp cleaning mask
815 Returns the stamp path+filename 778 Returns the stamp path+filename
@@ -817,27 +780,14 @@ def stamp_cleanmask_internal(taskname, d, file_name):
817 In the bitbake core, d can be a CacheData and file_name will be set. 780 In the bitbake core, d can be a CacheData and file_name will be set.
818 When called in task context, d will be a data store, file_name will not be set 781 When called in task context, d will be a data store, file_name will not be set
819 """ 782 """
820 taskflagname = taskname 783 cleanmask = bb.parse.siggen.stampcleanmask_mcfn(taskname, mcfn)
821 if taskname.endswith("_setscene"): 784 taskflagname = taskname.replace("_setscene", "")
822 taskflagname = taskname.replace("_setscene", "") 785 if cleanmask:
823 786 return [cleanmask, cleanmask.replace(taskflagname, taskflagname + "_setscene")]
824 if file_name: 787 return []
825 stamp = d.stampclean[file_name] 788
826 extrainfo = d.stamp_extrainfo[file_name].get(taskflagname) or "" 789def clean_stamp_mcfn(task, mcfn):
827 else: 790 cleanmask = _get_cleanmask(task, mcfn)
828 stamp = d.getVar('STAMPCLEAN')
829 file_name = d.getVar('BB_FILENAME')
830 extrainfo = d.getVarFlag(taskflagname, 'stamp-extra-info') or ""
831
832 if not stamp:
833 return []
834
835 cleanmask = bb.parse.siggen.stampcleanmask(stamp, file_name, taskname, extrainfo)
836
837 return [cleanmask, cleanmask.replace(taskflagname, taskflagname + "_setscene")]
838
839def clean_stamp(task, d, file_name = None):
840 cleanmask = stamp_cleanmask_internal(task, d, file_name)
841 for mask in cleanmask: 791 for mask in cleanmask:
842 for name in glob.glob(mask): 792 for name in glob.glob(mask):
843 # Preserve sigdata files in the stamps directory 793 # Preserve sigdata files in the stamps directory
@@ -847,33 +797,46 @@ def clean_stamp(task, d, file_name = None):
847 if name.endswith('.taint'): 797 if name.endswith('.taint'):
848 continue 798 continue
849 os.unlink(name) 799 os.unlink(name)
850 return
851 800
852def make_stamp(task, d, file_name = None): 801def clean_stamp(task, d):
802 mcfn = d.getVar('BB_FILENAME')
803 clean_stamp_mcfn(task, mcfn)
804
805def make_stamp_mcfn(task, mcfn):
806
807 basestamp = bb.parse.siggen.stampfile_mcfn(task, mcfn)
808
809 stampdir = os.path.dirname(basestamp)
810 if cached_mtime_noerror(stampdir) == 0:
811 bb.utils.mkdirhier(stampdir)
812
813 clean_stamp_mcfn(task, mcfn)
814
815 # Remove the file and recreate to force timestamp
816 # change on broken NFS filesystems
817 if basestamp:
818 bb.utils.remove(basestamp)
819 open(basestamp, "w").close()
820
821def make_stamp(task, d):
853 """ 822 """
854 Creates/updates a stamp for a given task 823 Creates/updates a stamp for a given task
855 (d can be a data dict or dataCache)
856 """ 824 """
857 clean_stamp(task, d, file_name) 825 mcfn = d.getVar('BB_FILENAME')
858 826
859 stamp = stamp_internal(task, d, file_name) 827 make_stamp_mcfn(task, mcfn)
860 # Remove the file and recreate to force timestamp
861 # change on broken NFS filesystems
862 if stamp:
863 bb.utils.remove(stamp)
864 open(stamp, "w").close()
865 828
866 # If we're in task context, write out a signature file for each task 829 # If we're in task context, write out a signature file for each task
867 # as it completes 830 # as it completes
868 if not task.endswith("_setscene") and not file_name: 831 if not task.endswith("_setscene"):
869 stampbase = stamp_internal(task, d, None, True) 832 stampbase = bb.parse.siggen.stampfile_base(mcfn)
870 file_name = d.getVar('BB_FILENAME') 833 bb.parse.siggen.dump_sigtask(mcfn, task, stampbase, True)
871 bb.parse.siggen.dump_sigtask(file_name, task, stampbase, True) 834
872 835
873def find_stale_stamps(task, d, file_name=None): 836def find_stale_stamps(task, mcfn):
874 current = stamp_internal(task, d, file_name) 837 current = bb.parse.siggen.stampfile_mcfn(task, mcfn)
875 current2 = stamp_internal(task + "_setscene", d, file_name) 838 current2 = bb.parse.siggen.stampfile_mcfn(task + "_setscene", mcfn)
876 cleanmask = stamp_cleanmask_internal(task, d, file_name) 839 cleanmask = _get_cleanmask(task, mcfn)
877 found = [] 840 found = []
878 for mask in cleanmask: 841 for mask in cleanmask:
879 for name in glob.glob(mask): 842 for name in glob.glob(mask):
@@ -887,38 +850,14 @@ def find_stale_stamps(task, d, file_name=None):
887 found.append(name) 850 found.append(name)
888 return found 851 return found
889 852
890def del_stamp(task, d, file_name = None): 853def write_taint(task, d):
891 """
892 Removes a stamp for a given task
893 (d can be a data dict or dataCache)
894 """
895 stamp = stamp_internal(task, d, file_name)
896 bb.utils.remove(stamp)
897
898def write_taint(task, d, file_name = None):
899 """ 854 """
900 Creates a "taint" file which will force the specified task and its 855 Creates a "taint" file which will force the specified task and its
901 dependents to be re-run the next time by influencing the value of its 856 dependents to be re-run the next time by influencing the value of its
902 taskhash. 857 taskhash.
903 (d can be a data dict or dataCache)
904 """
905 import uuid
906 if file_name:
907 taintfn = d.stamp[file_name] + '.' + task + '.taint'
908 else:
909 taintfn = d.getVar('STAMP') + '.' + task + '.taint'
910 bb.utils.mkdirhier(os.path.dirname(taintfn))
911 # The specific content of the taint file is not really important,
912 # we just need it to be random, so a random UUID is used
913 with open(taintfn, 'w') as taintf:
914 taintf.write(str(uuid.uuid4()))
915
916def stampfile(taskname, d, file_name = None, noextra=False):
917 """
918 Return the stamp for a given task
919 (d can be a data dict or dataCache)
920 """ 858 """
921 return stamp_internal(taskname, d, file_name, noextra=noextra) 859 mcfn = d.getVar('BB_FILENAME')
860 bb.parse.siggen.invalidate_task(task, mcfn)
922 861
923def add_tasks(tasklist, d): 862def add_tasks(tasklist, d):
924 task_deps = d.getVar('_task_deps', False) 863 task_deps = d.getVar('_task_deps', False)