summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-12-13 20:09:39 +1300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-12-14 12:30:50 +0000
commit275b3fe5f47c5dabb5bd16e916bf6ad9118bee79 (patch)
tree20a9746f0df284a548e428c6bd8c6999a06efeff /meta/lib
parent45adbe370908901d0d2e94b3c4daea821772e2ff (diff)
downloadpoky-275b3fe5f47c5dabb5bd16e916bf6ad9118bee79.tar.gz
classes/patch: move several functions to oe.patch
Move patch_path(), src_patches() and should_apply() to oe.patch, making them easier to call from elsewhere (particularly across the UI/server boundary). (From OE-Core rev: 2724511e18810cc8082c1b028e3b7c8a8b5def56) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oe/patch.py107
-rw-r--r--meta/lib/oe/recipeutils.py12
2 files changed, 112 insertions, 7 deletions
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index dbefd28e67..456ee70f7d 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -769,3 +769,110 @@ class UserResolver(Resolver):
769 os.chdir(olddir) 769 os.chdir(olddir)
770 raise 770 raise
771 os.chdir(olddir) 771 os.chdir(olddir)
772
773
774def patch_path(url, fetch, workdir, expand=True):
775 """Return the local path of a patch, or None if this isn't a patch"""
776
777 local = fetch.localpath(url)
778 base, ext = os.path.splitext(os.path.basename(local))
779 if ext in ('.gz', '.bz2', '.Z'):
780 if expand:
781 local = os.path.join(workdir, base)
782 ext = os.path.splitext(base)[1]
783
784 urldata = fetch.ud[url]
785 if "apply" in urldata.parm:
786 apply = oe.types.boolean(urldata.parm["apply"])
787 if not apply:
788 return
789 elif ext not in (".diff", ".patch"):
790 return
791
792 return local
793
794def src_patches(d, all=False, expand=True):
795 workdir = d.getVar('WORKDIR', True)
796 fetch = bb.fetch2.Fetch([], d)
797 patches = []
798 sources = []
799 for url in fetch.urls:
800 local = patch_path(url, fetch, workdir, expand)
801 if not local:
802 if all:
803 local = fetch.localpath(url)
804 sources.append(local)
805 continue
806
807 urldata = fetch.ud[url]
808 parm = urldata.parm
809 patchname = parm.get('pname') or os.path.basename(local)
810
811 apply, reason = should_apply(parm, d)
812 if not apply:
813 if reason:
814 bb.note("Patch %s %s" % (patchname, reason))
815 continue
816
817 patchparm = {'patchname': patchname}
818 if "striplevel" in parm:
819 striplevel = parm["striplevel"]
820 elif "pnum" in parm:
821 #bb.msg.warn(None, "Deprecated usage of 'pnum' url parameter in '%s', please use 'striplevel'" % url)
822 striplevel = parm["pnum"]
823 else:
824 striplevel = '1'
825 patchparm['striplevel'] = striplevel
826
827 patchdir = parm.get('patchdir')
828 if patchdir:
829 patchparm['patchdir'] = patchdir
830
831 localurl = bb.fetch.encodeurl(('file', '', local, '', '', patchparm))
832 patches.append(localurl)
833
834 if all:
835 return sources
836
837 return patches
838
839
840def should_apply(parm, d):
841 if "mindate" in parm or "maxdate" in parm:
842 pn = d.getVar('PN', True)
843 srcdate = d.getVar('SRCDATE_%s' % pn, True)
844 if not srcdate:
845 srcdate = d.getVar('SRCDATE', True)
846
847 if srcdate == "now":
848 srcdate = d.getVar('DATE', True)
849
850 if "maxdate" in parm and parm["maxdate"] < srcdate:
851 return False, 'is outdated'
852
853 if "mindate" in parm and parm["mindate"] > srcdate:
854 return False, 'is predated'
855
856
857 if "minrev" in parm:
858 srcrev = d.getVar('SRCREV', True)
859 if srcrev and srcrev < parm["minrev"]:
860 return False, 'applies to later revisions'
861
862 if "maxrev" in parm:
863 srcrev = d.getVar('SRCREV', True)
864 if srcrev and srcrev > parm["maxrev"]:
865 return False, 'applies to earlier revisions'
866
867 if "rev" in parm:
868 srcrev = d.getVar('SRCREV', True)
869 if srcrev and parm["rev"] not in srcrev:
870 return False, "doesn't apply to revision"
871
872 if "notrev" in parm:
873 srcrev = d.getVar('SRCREV', True)
874 if srcrev and parm["notrev"] in srcrev:
875 return False, "doesn't apply to revision"
876
877 return True, None
878
diff --git a/meta/lib/oe/recipeutils.py b/meta/lib/oe/recipeutils.py
index ae83aabec1..92fa431e0b 100644
--- a/meta/lib/oe/recipeutils.py
+++ b/meta/lib/oe/recipeutils.py
@@ -382,6 +382,7 @@ def copy_recipe_files(d, tgt_dir, whole_dir=False, download=True):
382 382
383def get_recipe_local_files(d, patches=False, archives=False): 383def get_recipe_local_files(d, patches=False, archives=False):
384 """Get a list of local files in SRC_URI within a recipe.""" 384 """Get a list of local files in SRC_URI within a recipe."""
385 import oe.patch
385 uris = (d.getVar('SRC_URI', True) or "").split() 386 uris = (d.getVar('SRC_URI', True) or "").split()
386 fetch = bb.fetch2.Fetch(uris, d) 387 fetch = bb.fetch2.Fetch(uris, d)
387 # FIXME this list should be factored out somewhere else (such as the 388 # FIXME this list should be factored out somewhere else (such as the
@@ -393,7 +394,7 @@ def get_recipe_local_files(d, patches=False, archives=False):
393 for uri in uris: 394 for uri in uris:
394 if fetch.ud[uri].type == 'file': 395 if fetch.ud[uri].type == 'file':
395 if (not patches and 396 if (not patches and
396 bb.utils.exec_flat_python_func('patch_path', uri, fetch, '', expand=False)): 397 oe.patch.patch_path(uri, fetch, '', expand=False)):
397 continue 398 continue
398 # Skip files that are referenced by absolute path 399 # Skip files that are referenced by absolute path
399 fname = fetch.ud[uri].basepath 400 fname = fetch.ud[uri].basepath
@@ -418,10 +419,9 @@ def get_recipe_local_files(d, patches=False, archives=False):
418 419
419def get_recipe_patches(d): 420def get_recipe_patches(d):
420 """Get a list of the patches included in SRC_URI within a recipe.""" 421 """Get a list of the patches included in SRC_URI within a recipe."""
422 import oe.patch
423 patches = oe.patch.src_patches(d, expand=False)
421 patchfiles = [] 424 patchfiles = []
422 # Execute src_patches() defined in patch.bbclass - this works since that class
423 # is inherited globally
424 patches = bb.utils.exec_flat_python_func('src_patches', d, expand=False)
425 for patch in patches: 425 for patch in patches:
426 _, _, local, _, _, parm = bb.fetch.decodeurl(patch) 426 _, _, local, _, _, parm = bb.fetch.decodeurl(patch)
427 patchfiles.append(local) 427 patchfiles.append(local)
@@ -438,9 +438,7 @@ def get_recipe_patched_files(d):
438 change mode ('A' for add, 'D' for delete or 'M' for modify) 438 change mode ('A' for add, 'D' for delete or 'M' for modify)
439 """ 439 """
440 import oe.patch 440 import oe.patch
441 # Execute src_patches() defined in patch.bbclass - this works since that class 441 patches = oe.patch.src_patches(d, expand=False)
442 # is inherited globally
443 patches = bb.utils.exec_flat_python_func('src_patches', d, expand=False)
444 patchedfiles = {} 442 patchedfiles = {}
445 for patch in patches: 443 for patch in patches:
446 _, _, patchfile, _, _, parm = bb.fetch.decodeurl(patch) 444 _, _, patchfile, _, _, parm = bb.fetch.decodeurl(patch)